From c64d174817cdd0d511610cf889f54bfbf0f6c875 Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Thu, 18 May 2023 10:42:18 +0200 Subject: [PATCH] Fix `get_cart_contents` null error --- modules/ppcp-button/src/Assets/SmartButton.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/ppcp-button/src/Assets/SmartButton.php b/modules/ppcp-button/src/Assets/SmartButton.php index 2f1f60f86..1b11c5970 100644 --- a/modules/ppcp-button/src/Assets/SmartButton.php +++ b/modules/ppcp-button/src/Assets/SmartButton.php @@ -1397,7 +1397,11 @@ class SmartButton implements SmartButtonInterface { } } - $items = WC()->cart->get_cart_contents(); + $cart = WC()->cart ?? null; + if ( ! $cart || $cart->is_empty() ) { + return ''; + } + $items = $cart->get_cart_contents(); foreach ( $items as $item ) { $product = wc_get_product( $item['product_id'] ); assert( $product instanceof WC_Product );