【发布时间】:2017-05-25 23:49:45
【问题描述】:
在我的 Woocommerce 网站中,我的最大订单容量为 50。
我正在尝试与购物车中的客户沟通我们关闭订单之前留下的订单。
我需要从最大值 50 中减去每个订单中已处理的商品总数 + 购物车中的新订单。
我已经尝试使用此代码:
function display_woocommerce_order_count() {
global $woocommerce;
$args = array(
'post_type' => 'shop_order',
'post_status' => 'publish',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'shop_order_status',
'field' => 'slug',
'terms' => array('processing')
)
)
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
$order_id = $loop->post->ID;
$order = new WC_Order($order_id);
$order_count = 0;
foreach( $order as $product ) {
$order_item = $product['qty'];
if($qty) {
$order_count += $order_item;
}
}
ob_start();
//Echo the number of items in cart.
$count = $woocommerce->cart->cart_contents_count;
//Difference max - orders processing - cart items
$total_diff = 50 - number_format($order_count) - $count;
echo $total_diff;
return ob_get_clean();
}
我怎样才能使它按预期工作?
谢谢
【问题讨论】:
标签: php wordpress woocommerce cart orders