Commit 975c4f40fe for woocommerce

commit 975c4f40fe3570ea4712e961a9cbe92603f3fe6a
Author: Thomas Roberts <5656702+opr@users.noreply.github.com>
Date:   Thu Jan 22 10:13:31 2026 +0000

    Prevent warnings when accessing templates without content (#62886)

    * Check template and content exist before parsing

    * Add changelog

    * Remove fixed PHPStan error from baseline

diff --git a/plugins/woocommerce/changelog/fix-template-access-warning b/plugins/woocommerce/changelog/fix-template-access-warning
new file mode 100644
index 0000000000..e692f57a20
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-template-access-warning
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Prevent PHP warnings when accessing templates without content
diff --git a/plugins/woocommerce/phpstan-baseline.neon b/plugins/woocommerce/phpstan-baseline.neon
index 63d46a3f6e..24d95d16bc 100644
--- a/plugins/woocommerce/phpstan-baseline.neon
+++ b/plugins/woocommerce/phpstan-baseline.neon
@@ -77802,12 +77802,6 @@ parameters:
 			count: 1
 			path: src/Internal/Utilities/ArrayUtil.php

-		-
-			message: '#^Cannot access property \$content on WP_Block_Template\|null\.$#'
-			identifier: property.nonObject
-			count: 1
-			path: src/Internal/Utilities/BlocksUtil.php
-
 		-
 			message: '#^Call to an undefined method WC_Data_Store\:\:get_order_type\(\)\.$#'
 			identifier: method.notFound
diff --git a/plugins/woocommerce/src/Internal/Utilities/BlocksUtil.php b/plugins/woocommerce/src/Internal/Utilities/BlocksUtil.php
index 77a78a4601..be61dc0b04 100644
--- a/plugins/woocommerce/src/Internal/Utilities/BlocksUtil.php
+++ b/plugins/woocommerce/src/Internal/Utilities/BlocksUtil.php
@@ -65,7 +65,12 @@ class BlocksUtil {
 	 */
 	public static function get_block_from_template_part( $block_name, $template_part_slug ) {
 		$template = get_block_template( get_stylesheet() . '//' . $template_part_slug, 'wp_template_part' );
-		$blocks   = parse_blocks( $template->content );
+
+		if ( ! $template || null === $template->content ) {
+			return array();
+		}
+
+		$blocks = parse_blocks( $template->content );

 		$flatten_blocks = self::flatten_blocks( $blocks );