Commit 0fbd0c93230 for woocommerce

commit 0fbd0c93230539fcfeadfb643525f3f81a503fec
Author: Karol Manijak <20098064+kmanijak@users.noreply.github.com>
Date:   Tue Jul 7 14:53:35 2026 +0200

    Fix Product Collection fatal in new post editor (#66225)

    * Fix post-new editor WooCommerce includes

    * Add changelog for post-new editor includes fix

    * Improve post-new editor include regression test

diff --git a/plugins/woocommerce/changelog/66124-load-post-new-editor-includes b/plugins/woocommerce/changelog/66124-load-post-new-editor-includes
new file mode 100644
index 00000000000..e6166c1bdb2
--- /dev/null
+++ b/plugins/woocommerce/changelog/66124-load-post-new-editor-includes
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Load frontend includes during new post editor requests to avoid Product Collection block hydration fatals.
diff --git a/plugins/woocommerce/includes/class-woocommerce.php b/plugins/woocommerce/includes/class-woocommerce.php
index 8d335928797..c53fd3b6376 100644
--- a/plugins/woocommerce/includes/class-woocommerce.php
+++ b/plugins/woocommerce/includes/class-woocommerce.php
@@ -326,6 +326,7 @@ final class WooCommerce {
 		add_action( 'after_setup_theme', array( $this, 'setup_environment' ) );
 		add_action( 'after_setup_theme', array( $this, 'include_template_functions' ), 11 );
 		add_action( 'load-post.php', array( $this, 'includes' ) );
+		add_action( 'load-post-new.php', array( $this, 'includes' ) );
 		add_action( 'init', array( $this, 'init' ), 0 );
 		add_action( 'init', array( $this, 'maybe_init_order_reviews' ), 1 );
 		add_action( 'init', array( $this, 'maybe_init_abandoned_cart_recovery' ), 1 );
diff --git a/plugins/woocommerce/tests/php/includes/class-woocommerce-test.php b/plugins/woocommerce/tests/php/includes/class-woocommerce-test.php
index b9163670132..3d1e92b8d5a 100644
--- a/plugins/woocommerce/tests/php/includes/class-woocommerce-test.php
+++ b/plugins/woocommerce/tests/php/includes/class-woocommerce-test.php
@@ -70,4 +70,47 @@ class WooCommerce_Test extends \WC_Unit_Test_Case {
 		$_SERVER['REQUEST_URI'] = '/wp-json/wc/v3/products';
 		$this->assertEquals( WC()->is_rest_api_request(), true );
 	}
+
+	/**
+	 * @testdox Should load WooCommerce includes in post editor load actions.
+	 */
+	public function test_loads_woocommerce_includes_for_post_editor_load_actions(): void {
+		$this->assertSame(
+			10,
+			has_action( 'load-post.php', array( WC(), 'includes' ) ),
+			'Existing post editor requests should invoke WooCommerce includes before block rendering.'
+		);
+		$this->assertSame(
+			10,
+			has_action( 'load-post-new.php', array( WC(), 'includes' ) ),
+			'New post editor requests should invoke WooCommerce includes before block rendering.'
+		);
+
+		$original_query     = WC()->query;
+		$original_screen    = $GLOBALS['current_screen'] ?? null;
+		WC()->query         = null;
+		$query_after_action = null;
+		set_current_screen( 'post' );
+
+		try {
+			$this->assertTrue( is_admin(), 'New post editor load action should run in an admin context.' );
+			// phpcs:disable WooCommerce.Commenting.CommentHooks.MissingHookComment, WordPress.NamingConventions.ValidHookName.UseUnderscores
+			do_action( 'load-post-new.php' );
+			// phpcs:enable WooCommerce.Commenting.CommentHooks.MissingHookComment, WordPress.NamingConventions.ValidHookName.UseUnderscores
+			$query_after_action = WC()->query;
+		} finally {
+			WC()->query                = $original_query;
+			$GLOBALS['current_screen'] = $original_screen; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
+		}
+
+		$this->assertInstanceOf(
+			WC_Query::class,
+			$query_after_action,
+			'New post editor load action should invoke WooCommerce includes.'
+		);
+		$this->assertTrue(
+			function_exists( 'wc_set_notices' ),
+			'New post editor load action should load frontend includes such as wc-notice-functions.php.'
+		);
+	}
 }