【问题标题】:"WC_Abstract_Legacy_Order->__get, wc_doing_it_wrong" WooCommerce error“WC_Abstract_Legacy_Order->__get, wc_doing_it_wrong” WooCommerce 错误
【发布时间】:2020-07-19 10:05:22
【问题描述】:

我的函数导致错误 «WC_Abstract_Legacy_Order->__get, wc_doing_it_wrong»。我已经了解了同样的问题,但仍然无法在我的函数中找到错误调用的位置,请帮助。

Woocommerce 4.3。

函数如下:

add_action( 'init', 'loyal_customer_auto_coupon', 10, 1);

function loyal_customer_auto_coupon(){
    
    if ( is_user_logged_in() ) {
        
        $customer = get_current_user_id();
        $acf_user = 'user_' . $customer;
        $loyal = get_field('loyal_customer_coupon', $acf_user); 

        if ($loyal == '') {
            $all_orders = wc_get_customer_order_count( $customer );

            if ( $all_orders > 4 ) {
                $args = array(
                    'customer_id' => $customer
                );
                $orders = wc_get_orders($args);

                $completed_order_count = 0;
                foreach ($orders as $order) {
                    if ( $order->status == 'completed' ) {
                        if ( $order->total > 14.99 ) {
                            $completed_order_count++;
                        }
                    }
                }
            }
        }
    }
}

【问题讨论】:

    标签: php wordpress woocommerce error-handling orders


    【解决方案1】:

    由于无法直接访问 WooCommerce 3 对象属性,因此您将使用 WC_Order 方法。所以在你的代码中,替换

    • $order->status$order->get_status()
    • $order->total$order->get_total()

    它应该可以解决您的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-08-16
      • 2018-12-30
      • 2018-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-11
      • 2016-02-26
      相关资源
      最近更新 更多