Skip to content

Commit

Permalink
[WC Analytics] Fix fatal error when cart is null (#40729)
Browse files Browse the repository at this point in the history
* Prevent fatal when cat is null

* Changelog
  • Loading branch information
puntope authored Dec 24, 2024
1 parent 325eaaa commit 70ea294
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Fix fatal when WC()->cart returns null
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,9 @@ public function post_contains_text( $post_id, $text ) {
*/
public function get_cart_total() {
$cart = WC()->cart;
if ( $cart === null ) {
return 0;
}
return $cart->get_total( 'tracking' );
}

Expand All @@ -595,6 +598,9 @@ public function get_cart_total() {
*/
public function get_cart_subtotal() {
$cart = WC()->cart;
if ( $cart === null ) {
return 0;
}
return $cart->get_subtotal();
}

Expand All @@ -605,6 +611,9 @@ public function get_cart_subtotal() {
*/
public function get_cart_shipping_total() {
$cart = WC()->cart;
if ( $cart === null ) {
return 0;
}
return $cart->get_shipping_total();
}

Expand All @@ -615,6 +624,9 @@ public function get_cart_shipping_total() {
*/
public function get_cart_taxes() {
$cart = WC()->cart;
if ( $cart === null ) {
return 0;
}
return $cart->get_taxes_total();
}

Expand All @@ -625,6 +637,9 @@ public function get_cart_taxes() {
*/
public function get_total_discounts() {
$cart = WC()->cart;
if ( $cart === null ) {
return 0;
}
return $cart->get_discount_total();
}

Expand All @@ -635,6 +650,9 @@ public function get_total_discounts() {
*/
public function get_cart_items_count() {
$cart = WC()->cart;
if ( $cart === null ) {
return 0;
}
return $cart->get_cart_contents_count();
}
}

0 comments on commit 70ea294

Please sign in to comment.