Commit f67f81774f1 for woocommerce

commit f67f81774f17f3b4aab12fc0e6936d8b58c5bfd5
Author: Seghir Nadir <nadir.seghir@gmail.com>
Date:   Tue Aug 4 10:37:37 2026 +0200

    Revert the legacy script shim loading strategy change (#64431) (#67309)

    * Revert "Fix legacy script shim loading strategy mismatch breaking third-party payment gateways (#64431)"

    This reverts commit 72754252cdd6cfea4e2c77fc3e923e10ee26a43c.

    * Add changelog entry for the #64431 revert

    * Clarify the revert changelog entry

    * Fix in_footer docblocks instead of restoring PHPStan baseline entries

    * Fix linting

    ---------

    Co-authored-by: Tom Cafferkey <tjcafferkey@gmail.com>

diff --git a/plugins/woocommerce/changelog/revert-64431-legacy-shim-loading-strategy b/plugins/woocommerce/changelog/revert-64431-legacy-shim-loading-strategy
new file mode 100644
index 00000000000..4631eb5affc
--- /dev/null
+++ b/plugins/woocommerce/changelog/revert-64431-legacy-shim-loading-strategy
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Revert the legacy script blocking change (#64431) that broke the classic cart and checkout on sites loading a second jQuery instance.
diff --git a/plugins/woocommerce/includes/class-wc-frontend-scripts.php b/plugins/woocommerce/includes/class-wc-frontend-scripts.php
index ad783c71fde..110f28c73f9 100644
--- a/plugins/woocommerce/includes/class-wc-frontend-scripts.php
+++ b/plugins/woocommerce/includes/class-wc-frontend-scripts.php
@@ -139,11 +139,11 @@ class WC_Frontend_Scripts {
 	 * Register a script for use.
 	 *
 	 * @uses   wp_register_script()
-	 * @param  string                                          $handle    Name of the script. Should be unique.
-	 * @param  string                                          $path      Full URL of the script, or path of the script relative to the WordPress root directory.
-	 * @param  string[]                                        $deps      An array of registered script handles this script depends on.
-	 * @param  string                                          $version   String specifying script version number, if it has one, which is added to the URL as a query string for cache busting purposes. If version is set to false, a version number is automatically added equal to current installed WordPress version. If set to null, no version is added.
-	 * @param  bool|array{strategy?: string, in_footer?: bool} $in_footer Whether to enqueue the script before </body> (boolean), or an array of arguments such as 'strategy' and 'in_footer'. Default array( 'strategy' => 'defer' ).
+	 * @param  string        $handle    Name of the script. Should be unique.
+	 * @param  string        $path      Full URL of the script, or path of the script relative to the WordPress root directory.
+	 * @param  string[]      $deps      An array of registered script handles this script depends on.
+	 * @param  string        $version   String specifying script version number, if it has one, which is added to the URL as a query string for cache busting purposes. If version is set to false, a version number is automatically added equal to current installed WordPress version. If set to null, no version is added.
+	 * @param  boolean|array $in_footer Whether to enqueue the script before </body>, or an array of loading strategy arguments as accepted by wp_register_script(). Default 'defer' strategy.
 	 */
 	private static function register_script( $handle, $path, $deps = array( 'jquery' ), $version = WC_VERSION, $in_footer = array( 'strategy' => 'defer' ) ) {
 		self::$registered_scripts[] = $handle;
@@ -154,11 +154,11 @@ class WC_Frontend_Scripts {
 	 * Register and enqueue a script for use.
 	 *
 	 * @uses   wp_enqueue_script()
-	 * @param  string                                          $handle    Name of the script. Should be unique.
-	 * @param  string                                          $path      Full URL of the script, or path of the script relative to the WordPress root directory.
-	 * @param  string[]                                        $deps      An array of registered script handles this script depends on.
-	 * @param  string                                          $version   String specifying script version number, if it has one, which is added to the URL as a query string for cache busting purposes. If version is set to false, a version number is automatically added equal to current installed WordPress version. If set to null, no version is added.
-	 * @param  bool|array{strategy?: string, in_footer?: bool} $in_footer Whether to enqueue the script before </body> (boolean), or an array of arguments such as 'strategy' and 'in_footer'. Default array( 'strategy' => 'defer' ).
+	 * @param  string        $handle    Name of the script. Should be unique.
+	 * @param  string        $path      Full URL of the script, or path of the script relative to the WordPress root directory.
+	 * @param  string[]      $deps      An array of registered script handles this script depends on.
+	 * @param  string        $version   String specifying script version number, if it has one, which is added to the URL as a query string for cache busting purposes. If version is set to false, a version number is automatically added equal to current installed WordPress version. If set to null, no version is added.
+	 * @param  boolean|array $in_footer Whether to enqueue the script before </body>, or an array of loading strategy arguments as accepted by wp_enqueue_script(). Default 'defer' strategy.
 	 */
 	private static function enqueue_script( $handle, $path = '', $deps = array( 'jquery' ), $version = WC_VERSION, $in_footer = array( 'strategy' => 'defer' ) ) {
 		if ( ! in_array( $handle, self::$registered_scripts, true ) && $path ) {
@@ -414,25 +414,10 @@ class WC_Frontend_Scripts {
 		$register_scripts = self::get_scripts();

 		foreach ( $register_scripts as $name => $props ) {
-			$is_legacy_handle = isset( $props['legacy_handle'] );
-
-			/*
-			 * Scripts with legacy alias handles must use a blocking strategy.
-			 * WordPress (since 6.3) silently discards loading strategies on alias
-			 * scripts (registered with src=false). If the real script uses defer
-			 * but the alias cannot inherit it, the strategy mismatch breaks
-			 * dependency resolution for third-party code that depends on the
-			 * legacy handle (e.g. payment gateways using 'jquery-payment').
-			 *
-			 * Using blocking for both the real script and its alias ensures
-			 * consistent execution order through the dependency chain.
-			 */
-			$in_footer = $is_legacy_handle ? true : array( 'strategy' => 'defer' );
-
-			self::register_script( $name, $props['src'], $props['deps'], $props['version'], $in_footer );
-
-			if ( $is_legacy_handle ) {
-				self::register_script( $props['legacy_handle'], false, array( $name ), $props['version'], $in_footer );
+			self::register_script( $name, $props['src'], $props['deps'], $props['version'] );
+
+			if ( isset( $props['legacy_handle'] ) ) {
+				self::register_script( $props['legacy_handle'], false, array( $name ), $props['version'], true );
 			}
 		}
 	}
diff --git a/plugins/woocommerce/tests/php/includes/class-wc-frontend-scripts-test.php b/plugins/woocommerce/tests/php/includes/class-wc-frontend-scripts-test.php
index 66b4e1813e1..3bee3ef9035 100644
--- a/plugins/woocommerce/tests/php/includes/class-wc-frontend-scripts-test.php
+++ b/plugins/woocommerce/tests/php/includes/class-wc-frontend-scripts-test.php
@@ -232,38 +232,4 @@ class WC_Frontend_Scripts_Test extends WC_Unit_Test_Case {
 		$this->assertNotContains( 'cod', $data['gateways_with_custom_place_order_button'] );
 		$this->assertNotContains( 'cheque', $data['gateways_with_custom_place_order_button'] );
 	}
-
-	/**
-	 * Test that scripts with legacy handles and their aliases use blocking strategy.
-	 *
-	 * WordPress (since 6.3) discards loading strategies on alias scripts
-	 * (src=false). To avoid strategy mismatches, both the real script and
-	 * its legacy alias must be registered as blocking (in_footer=true).
-	 */
-	public function test_legacy_handle_scripts_use_blocking_strategy(): void {
-		$reflection = new ReflectionClass( 'WC_Frontend_Scripts' );
-		$method     = $reflection->getMethod( 'register_scripts' );
-		$method->setAccessible( true );
-		$method->invoke( null );
-
-		$get_scripts_method = $reflection->getMethod( 'get_scripts' );
-		$get_scripts_method->setAccessible( true );
-		$scripts = $get_scripts_method->invoke( null );
-
-		foreach ( $scripts as $name => $props ) {
-			if ( ! isset( $props['legacy_handle'] ) ) {
-				continue;
-			}
-
-			$legacy_handle = $props['legacy_handle'];
-
-			// Real script must be blocking (no defer strategy).
-			$real_strategy = wp_scripts()->get_data( $name, 'strategy' );
-			$this->assertFalse( $real_strategy, "Real handle '{$name}' should not have a loading strategy (blocking)." );
-
-			// Alias script must also be blocking.
-			$legacy_strategy = wp_scripts()->get_data( $legacy_handle, 'strategy' );
-			$this->assertFalse( $legacy_strategy, "Legacy handle '{$legacy_handle}' should not have a loading strategy (blocking)." );
-		}
-	}
 }