所以,我想清楚如何發送我的舊訂單到mailchimp。由於我無法在這方面找到很多信息,所以我正在測試一些東西,直到我得到一些合理的結果。獲取數據get_posts()並將它傳遞給一個函數wordpress
<?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功能嗎:) –
我已將它添加到帖子中,但它現在可能會有點複雜。 該函數所在的插件無縫工作。我認爲它的工作原理,但我可以給它一個錯誤的價值.. –