Commit 44228a5f41 for woocommerce

commit 44228a5f4145b1f3b0d10a517a6e585d7b7af4dc
Author: Mike Jolley <mike.jolley@me.com>
Date:   Wed Dec 10 15:45:36 2025 +0000

    Fix `woocommerce_block_asset_resource_hints` cache under multisite (#62211)

    * Use constants class for wc version

    * Use site_url rather than guess_url

    Guest URL contains the path, so cache would be invalidated depending on the current page

    * Change set_site_transient to set_transient so it works on a per-site basis, not across a network

    * Changelog

diff --git a/plugins/woocommerce/changelog/wooplug-5912-woocommerce-blocks-wrong-domain-in-wp_resource_hints-on b/plugins/woocommerce/changelog/wooplug-5912-woocommerce-blocks-wrong-domain-in-wp_resource_hints-on
new file mode 100644
index 0000000000..8ebc948c10
--- /dev/null
+++ b/plugins/woocommerce/changelog/wooplug-5912-woocommerce-blocks-wrong-domain-in-wp_resource_hints-on
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Update woocommerce_block_asset_resource_hints to work per-site, rather than across the network on multisite instances
diff --git a/plugins/woocommerce/src/Blocks/AssetsController.php b/plugins/woocommerce/src/Blocks/AssetsController.php
index 8c39aa670f..fc80042eb5 100644
--- a/plugins/woocommerce/src/Blocks/AssetsController.php
+++ b/plugins/woocommerce/src/Blocks/AssetsController.php
@@ -3,6 +3,7 @@ declare( strict_types = 1 );

 namespace Automattic\WooCommerce\Blocks;

+use Automattic\Jetpack\Constants;
 use Automattic\WooCommerce\Blocks\Assets\Api as AssetApi;
 use Automattic\WooCommerce\Admin\Features\Features;

@@ -261,12 +262,12 @@ final class AssetsController {
 			return null;
 		}

-		$cache = get_site_transient( 'woocommerce_block_asset_resource_hints' );
+		$cache = get_transient( 'woocommerce_block_asset_resource_hints' );

 		$current_version = array(
-			'woocommerce' => WOOCOMMERCE_VERSION,
+			'woocommerce' => Constants::get_constant( 'WC_VERSION' ),
 			'wordpress'   => get_bloginfo( 'version' ),
-			'site_url'    => wp_guess_url(),
+			'site_url'    => site_url(),
 		);

 		if ( isset( $cache['version'] ) && $cache['version'] === $current_version ) {
@@ -287,14 +288,14 @@ final class AssetsController {
 		$updated = array(
 			'files'   => $cache ?? array(),
 			'version' => array(
-				'woocommerce' => WOOCOMMERCE_VERSION,
+				'woocommerce' => Constants::get_constant( 'WC_VERSION' ),
 				'wordpress'   => get_bloginfo( 'version' ),
-				'site_url'    => wp_guess_url(),
+				'site_url'    => site_url(),
 			),
 		);

 		$updated['files'][ $filename ] = $data;
-		set_site_transient( 'woocommerce_block_asset_resource_hints', $updated, WEEK_IN_SECONDS );
+		set_transient( 'woocommerce_block_asset_resource_hints', $updated, WEEK_IN_SECONDS );
 	}

 	/**
diff --git a/plugins/woocommerce/tests/php/src/Blocks/AssetsController.php b/plugins/woocommerce/tests/php/src/Blocks/AssetsController.php
index 6ef55bbff3..d49820f0c6 100644
--- a/plugins/woocommerce/tests/php/src/Blocks/AssetsController.php
+++ b/plugins/woocommerce/tests/php/src/Blocks/AssetsController.php
@@ -3,6 +3,7 @@ declare( strict_types = 1 );

 namespace Automattic\WooCommerce\Tests\Blocks;

+use Automattic\Jetpack\Constants;
 use Automattic\WooCommerce\Blocks\Assets\Api;
 use Automattic\WooCommerce\Blocks\AssetsController as TestedAssetsController;

@@ -195,12 +196,12 @@ class AssetsController extends \WP_UnitTestCase {
 				),
 			),
 			'version' => array(
-				'woocommerce' => WOOCOMMERCE_VERSION,
+				'woocommerce' => Constants::get_constant( 'WC_VERSION' ),
 				'wordpress'   => get_bloginfo( 'version' ),
-				'site_url'    => wp_guess_url(),
+				'site_url'    => site_url(),
 			),
 		);
-		set_site_transient( 'woocommerce_block_asset_resource_hints', $mock_cache );
+		set_transient( 'woocommerce_block_asset_resource_hints', $mock_cache );

 		$urls = $this->assets_controller->add_resource_hints( array(), 'prefetch' );

@@ -217,7 +218,7 @@ class AssetsController extends \WP_UnitTestCase {
 	 */
 	public function resource_hints_invalid_cache_provider(): array {
 		return array(
-			array( 'woocommerce', WOOCOMMERCE_VERSION . '-old' ),
+			array( 'woocommerce', Constants::get_constant( 'WC_VERSION' ) . '-old' ),
 			array( 'wordpress', get_bloginfo( 'version' ) . '-old' ),
 			array( 'site_url', 'http://old-url.local' ),
 		);
@@ -234,9 +235,9 @@ class AssetsController extends \WP_UnitTestCase {
 	 */
 	public function test_additional_resource_hints_invalid_cache( string $key, string $value ) {
 		$mock_version         = array(
-			'woocommerce' => WOOCOMMERCE_VERSION,
+			'woocommerce' => Constants::get_constant( 'WC_VERSION' ),
 			'wordpress'   => get_bloginfo( 'version' ),
-			'site_url'    => wp_guess_url(),
+			'site_url'    => site_url(),
 		);
 		$mock_version[ $key ] = $value;

@@ -259,7 +260,7 @@ class AssetsController extends \WP_UnitTestCase {
 			),
 			'version' => $mock_version,
 		);
-		set_site_transient( 'woocommerce_block_asset_resource_hints', $mock_cache );
+		set_transient( 'woocommerce_block_asset_resource_hints', $mock_cache );

 		$urls = $this->assets_controller->add_resource_hints( array(), 'prefetch' );