我需要找到某个特定客户之前曾与该商店有过业务往来。
为了实现这一点,我需要找到给定客户的订单数量。
我怎样才能做到这一点?
我尝试谷歌搜索,但没有找到任何解决方案。
最佳答案
只需输入用户 ID,您就会得到订单总数:
$numorders = wc_get_customer_order_count( $userid );
为了我自己的目的更进一步,我使用此代码来获取客户未取消订单的数量,因为我不想计算失败的订单尝试次数:
// Get TOTAL number of orders for customer
$numorders = wc_get_customer_order_count( $userid );
// Get CANCELLED orders for customer
$args = array(
'customer_id' => $userid,
'post_status' => 'cancelled',
'post_type' => 'shop_order',
'return' => 'ids',
);
$numorders_cancelled = 0;
$numorders_cancelled = count( wc_get_orders( $args ) ); // count the array of orders
// NON-CANCELLED equals TOTAL minus CANCELLED
$num_not_cancelled = $numorders - $numorders_cancelled;
关于php - WooCommerce - 获取给定客户的订单数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30497669/