繁体   English   中英

获取数据get_posts()并将其传递给wordpress函数

[英]Getting data get_posts() and passing it to a function wordpress

因此,我正在考虑如何将旧订单发送到mailchimp。 由于我无法真正找到更多有关此方面的信息,因此我正在测试一些东西,直到获得一些合理的结果。

<?php     
// Get all customer orders
$customer_orders = get_posts( array(
    'numberposts' => -1,
    'meta_key'    => '_customer_user',
    'meta_value'  => get_current_user_id(),
    'post_type'   => wc_get_order_types(),
    'post_status' => array_keys( wc_get_order_statuses() ),
) );

var_dump($customer_orders); //to see what I'm working with

echo "test";
require_once('../public_html/wp-content/plugins/woochimp/woochimp.php'); 

foreach($customer_orders as $cuord) {
    $order = $cuord->ID; 
    echo ($cuord->post_date);
    echo "<br>";
    on_completed($order); //I'm trying to run this as it should try to send some data to mailchimp.
}
?>

当我调用on_completed函数时,似乎中断了foreach循环。 我究竟做错了什么?

on_completed函数:(来自插件WooChimp)

    /**
     * Subscribe on order completed status and send Ecommerce360 data
     *
     * @access public
     * @param int $order_id
     * @return void
     */
    public function on_completed($order_id)
    {
        // Check if functionality is enabled
        if (!$this->opt['woochimp_enabled']) {
            return;
        }

        // Check if WC order class is available and MailChimp is loaded
        if (class_exists('WC_Order') && $this->load_mailchimp()) {

            // Do we need to subscribe user on completed order or payment?
            $subscribe_on_completed = get_post_meta($order_id, 'woochimp_subscribe_on_completed', true);
            $subscribe_on_payment = get_post_meta($order_id, 'woochimp_subscribe_on_payment', true);

            foreach (array('auto', 'checkbox') as $sets_type) {
                if ($subscribe_on_completed == $sets_type || $subscribe_on_payment == $sets_type) {
                    $this->subscribe_checkout($order_id, $sets_type);
                }
            }

            // Check if we need to send order data or was it already sent
            if (!$this->opt['woochimp_send_order_data'] || self::order_data_sent($order_id)) {
                return;
            }

            // Get args
            $args = $this->prepare_order_data($order_id);

            // Send order data
            try {
                $this->mailchimp->ecomm_order_add($args);
                update_post_meta($order_id, '_woochimp_ecomm_sent', 1);
            }
            catch (Exception $e) {
                $this->woochimp_log_write($e);
            }
        }
    }

如果在try catch块中放置了on_completed($ order)函数调用,您会看到什么错误消息文本? 下面的例子:

try {
    on_completed($order);
} catch (Exception $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
}

另外,请检查您的Web服务器error_log。 执行代码时,您是否看到任何错误?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM