php - WooCommerce - 获取给定客户的订单数量

标签 php wordpress woocommerce

我需要找到某个特定客户之前曾与该商店有过业务往来。

为了实现这一点,我需要找到给定客户的订单数量。

我怎样才能做到这一点?

我尝试谷歌搜索,但没有找到任何解决方案。

最佳答案

只需输入用户 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/

相关文章:

php - 可以从谷歌检查器工具复制粘贴并覆盖吗

wordpress - 没有 PayPal 帐户无法启用结帐

php - WordPress PHP htmlspecialchars(get_field... 无法读取数组?

php - 删除未关闭的 html 标签 - 同时将内容粘贴到带有 contenteditable 的 div

php - 覆盖 WooCommerce 中的购物车商品价格和图像

wordpress - 通过模板名称查询 WordPress 中的页面

php - Wordpress 在选择自定义字段时应用特定的 css

php - Firefox 检测到服务器正在以永远无法完成的方式重定向对此地址的请求

wordpress - wordpress 中的 TreeView /层次结构

php - 为 WooCommerce 3 中定义的产品类别自定义添加到购物车重定向