From 5f6eea9c61787cea5f70e463df5734ab32f52eb7 Mon Sep 17 00:00:00 2001 From: Thomas Roberts Date: Thu, 9 Nov 2023 01:18:55 +0000 Subject: [PATCH] Return early if content retrieval fails --- src/Domain/Services/JetpackWooCommerceAnalytics.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Domain/Services/JetpackWooCommerceAnalytics.php b/src/Domain/Services/JetpackWooCommerceAnalytics.php index 87b086f9f0c..4b0e320a3db 100644 --- a/src/Domain/Services/JetpackWooCommerceAnalytics.php +++ b/src/Domain/Services/JetpackWooCommerceAnalytics.php @@ -274,6 +274,16 @@ public function get_cart_checkout_info() { $checkout_template = get_block_template( $checkout_template_id ); } + // Something failed with the template retrieval, return early with 0 values rather than let a warning appear. + if ( ! $cart_template || ! $checkout_template ) { + return array( + 'cart_page_contains_cart_block' => 0, + 'cart_page_contains_cart_shortcode' => 0, + 'checkout_page_contains_checkout_block' => 0, + 'checkout_page_contains_checkout_shortcode' => 0, + ); + } + // Update the info transient with data we got from the templates, if the site isn't using WC Blocks we // won't be doing this so no concern about overwriting. // Sites that load this code will be loading it on a page using the relevant block, but we still need to check