My function causes error «WC_Abstract_Legacy_Order->__get, wc_doing_it_wrong». I’ve learned about same issues but still can’t find where in my function wrong calls are, please help.
Woocommerce 4.3.
Here’s the function:
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++; } } } } } } }
Advertisement
Answer
Since WooCommerce 3 Object properties can’t be accessed directly, instead you will use WC_Order
methods. So in your code, replace
$order->status
by$order->get_status()
$order->total
by$order->get_total()
It should solve your issue.