From 1996305c34df5510438c015fc2d6632f0d1bb1f5 Mon Sep 17 00:00:00 2001 From: Timur Karimov Date: Mon, 17 Apr 2023 14:17:04 +0200 Subject: [PATCH] Add null check to prevent fatal error when WC()->cart is null --- includes/class-wc-payments-upe-checkout.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/includes/class-wc-payments-upe-checkout.php b/includes/class-wc-payments-upe-checkout.php index f962b87ef74..230a2cfde40 100644 --- a/includes/class-wc-payments-upe-checkout.php +++ b/includes/class-wc-payments-upe-checkout.php @@ -118,7 +118,8 @@ public function get_payment_fields_js_config() { } elseif ( WC_Payments_Features::is_upe_deferred_intent_enabled() ) { $payment_fields['checkoutTitle'] = $this->gateway->get_checkout_title(); $payment_fields['currency'] = get_woocommerce_currency(); - $payment_fields['cartTotal'] = WC_Payments_Utils::prepare_amount( WC()->cart->get_total( '' ), get_woocommerce_currency() ); + $cart_total = ( WC()->cart ? WC()->cart->get_total( '' ) : 0 ); + $payment_fields['cartTotal'] = WC_Payments_Utils::prepare_amount( $cart_total, get_woocommerce_currency() ); } $enabled_billing_fields = [];