我的函数导致错误“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++;
}
}
}
}
}
}
}
最佳答案
由于不能直接访问WooCommerce 3对象属性,因此您将使用WC_Order
方法。因此,在您的代码中,替换
$order->status
通过$order->get_status()
$order->total
通过$order->get_total()
它应该可以解决您的问题。
关于php - “WC_Abstract_Legacy_Order->__get, wc_doing_it_wrong” WooCommerce错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62978844/