Error in admin order display due to WC()->cart === null
-
We are using Stripe on most orders, even with PayPal installed.
On any order, even ones without using PayPal to check out we are getting an error in class-wc-gateway-ppec-plugin.php on line 452:
Notice: Trying to get property of non-object in /home/customer/www/breakoutcontent.com/public_html/wp-content/plugins/woocommerce-gateway-paypal-express-checkout/includes/class-wc-gateway-ppec-plugin.php on line 459
public static function needs_shipping() { /* (I've added this TEST which removes the error...) if(WC()->cart){ $cart_contents = WC()->cart->cart_contents; } */ $cart_contents = WC()->cart->cart_contents; $needs_shipping = false; if ( ! empty( $cart_contents ) ) { foreach ( $cart_contents as $cart_item_key => $values ) { if ( $values['data']->needs_shipping() ) { $needs_shipping = true; break; } } } return apply_filters( 'woocommerce_cart_needs_shipping', $needs_shipping ); }
The problem appears to be that when in the admin backend, there is no cart currently available after checkout and so the WC()->cart is null.
If we deactivate PayPal Checkout the error doesn’t appear.
It seems related to a similar error: https://github.com/woocommerce/woocommerce/issues/23758
The suggestion is: you need to ways check if is not null first, or even if get_cart is callable.As we can’t override this within your plugin (it’ll get wiped next update)
Can you update your code to apply this please?
- The topic ‘Error in admin order display due to WC()->cart === null’ is closed to new replies.