【发布时间】:2016-08-28 07:36:08
【问题描述】:
所以,我正在研究如何将旧订单发送到 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);
}
}
}
【问题讨论】:
-
我们可以看看on_completed函数吗:)
-
我已将其添加到帖子中,但现在可能有点复杂。此功能所在的插件可以无缝运行。我认为它有效,但我可能给它一个错误的值..
标签: php wordpress function foreach