diff --git a/plugins/woocommerce/changelog/pr-32747 b/plugins/woocommerce/changelog/pr-32747 new file mode 100644 index 00000000000..a91bbff2d41 --- /dev/null +++ b/plugins/woocommerce/changelog/pr-32747 @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Add check for $wp_query before calling is_cart to prevent doing_it_wrong notice. diff --git a/plugins/woocommerce/includes/class-wc-cache-helper.php b/plugins/woocommerce/includes/class-wc-cache-helper.php index 32500527c5e..e80611619ae 100644 --- a/plugins/woocommerce/includes/class-wc-cache-helper.php +++ b/plugins/woocommerce/includes/class-wc-cache-helper.php @@ -41,6 +41,8 @@ class WC_Cache_Helper { * @since 3.6.0 */ public static function additional_nocache_headers( $headers ) { + global $wp_query; + $agent = isset( $_SERVER['HTTP_USER_AGENT'] ) ? wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized $set_cache = false; @@ -64,7 +66,7 @@ class WC_Cache_Helper { $set_cache = true; } - if ( false !== strpos( $agent, 'Chrome' ) && is_cart() ) { + if ( false !== strpos( $agent, 'Chrome' ) && isset( $wp_query ) && is_cart() ) { $set_cache = true; }