Error in Admin View Order display – due to WC()->cart === null
-
We’ve the latest version of all plugins.
We are using Stripe on most orders, even with PayPal installed.An error is displayed in the backend when viewing 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/__OURDOMAIN___/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.
OR
If we deactivate Checkout Field Editor for WooCommerce 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.I’ve let PayPal plugin know of this, however, I’ve run Plugin Detective against it and found the problem isn’t there when “Checkout Field Editor for WooCommerce” is disabled.
However, the error is NOT triggered an alert with your plugin turned off.
We don’t know WHAT is triggering this within your plugin.
- The topic ‘Error in Admin View Order display – due to WC()->cart === null’ is closed to new replies.