From 7465e3ba24535537643924f6440ec3d3752d411b Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Thu, 27 Mar 2025 10:18:46 +0000 Subject: [PATCH] Update WooCommerce.php Getting 500 errors in Google Search console from old links to `site.com/?add-to-cart=832` where that product ID isn't for sale anymore. Don't track if product not available anymore. --- src/Integrations/WooCommerce.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Integrations/WooCommerce.php b/src/Integrations/WooCommerce.php index 9eec455..e582d8c 100644 --- a/src/Integrations/WooCommerce.php +++ b/src/Integrations/WooCommerce.php @@ -204,6 +204,9 @@ public function track_direct_add_to_cart() { * @codeCoverageIgnore Because we can't test XHR requests here. */ public function track_add_to_cart( $product, $add_to_cart_data ) { + if ( !$product ) { + return; + } $product_data = $this->clean_data( $product->get_data() ); $added_to_cart = $this->clean_data( $add_to_cart_data ); $cart = WC()->cart;