【问题标题】:WooCommerce checking for first-time ordersWooCommerce 检查首次订单
【发布时间】:2022-11-22 04:09:02
【问题描述】:

有没有办法在woocommerce_payment_complete检查处理的订单是否是第一次订单而不是续订?我没有通过 $order 对象看到任何相关内容。

我在 woocommerce_payment_complete 挂钩处使用一个函数来检查订单是第一次订购还是续订,然后通过 curl 方法发送数据,但不确定如何进行基本检查?

【问题讨论】:

    标签: php woocommerce


    【解决方案1】:
    `function returningCustomer($billingEmail){
        // Get all customer orders
        if(get_current_user_id() != 0){
            $customer_orders = get_posts( array(
                'numberposts' => 2, // more than 1
                'meta_key'    => '_customer_user',
                'meta_value'  => get_current_user_id(),
                'post_type'   => 'shop_order', // WC orders post type
                'post_status' => 'wc-completed', // Only orders with completed
                'fields'      => 'ids', // Return Ids completed
            ) );
            // return "true" when customer has already at least one order
            // (false if not)
            return count($customer_orders) > 1 ? true : false;
        }
        else {
            $customer_orders_email = get_posts( array(
                'numberposts' => 2, // more than 1
                'meta_key'    => '_billing_email',
                'meta_value'  => $billingEmail,
                'post_type'   => 'shop_order', // WC orders post type
                'post_status' => 'wc-completed', // Only orders with completed
                'fields'      => 'ids', // Return Ids completed
            ) );
            // return "true" when customer has already at least one order
            // (false if not)
            return count($customer_orders_email) > 1 ? true : false;
        }
    }`
    

    相信这应该有效

    【讨论】:

      猜你喜欢
      • 2019-08-18
      • 2020-12-01
      • 2019-01-01
      • 2016-07-10
      • 2014-09-14
      • 2021-07-01
      • 1970-01-01
      • 2019-12-15
      • 1970-01-01
      相关资源
      最近更新 更多