Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WC Analytics] Fix fatal error when cart is null #40729

Merged
merged 2 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
Loading