Commit e832994d37c for woocommerce

commit e832994d37cb38f08d5ec9e47851db3e3d08cb70
Author: Tom Cafferkey <tjcafferkey@gmail.com>
Date:   Wed Nov 25 14:28:50 2026 +0000

    Fix legacy order redirects on WordPress 7.2 (#70927)

    * Fix legacy order redirects on WordPress 7.2

    * Add changelog entry for legacy order redirects

diff --git a/plugins/woocommerce/changelog/fix-70910-hpos-legacy-order-redirects b/plugins/woocommerce/changelog/fix-70910-hpos-legacy-order-redirects
new file mode 100644
index 00000000000..857d162839a
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-70910-hpos-legacy-order-redirects
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Restore redirects from HPOS order links to legacy order screens on WordPress 7.2.
diff --git a/plugins/woocommerce/src/Internal/Admin/Orders/COTRedirectionController.php b/plugins/woocommerce/src/Internal/Admin/Orders/COTRedirectionController.php
index 4d96d25bf0f..7783bf4bd36 100644
--- a/plugins/woocommerce/src/Internal/Admin/Orders/COTRedirectionController.php
+++ b/plugins/woocommerce/src/Internal/Admin/Orders/COTRedirectionController.php
@@ -12,6 +12,10 @@ namespace Automattic\WooCommerce\Internal\Admin\Orders;
  *         'admin_page_access_denied',
  *         array( wc_get_container()->get( COTRedirectionController::class ), 'handle_hpos_admin_requests' )
  *     );
+ *     remove_action(
+ *         'wp_admin_page_not_found',
+ *         array( wc_get_container()->get( COTRedirectionController::class ), 'handle_hpos_admin_requests' )
+ *     );
  */
 class COTRedirectionController {

@@ -19,12 +23,13 @@ class COTRedirectionController {
 	 * Add hooks needed to perform our magic.
 	 */
 	public function setup(): void {
-		// Only take action in cases where access to the admin screen would otherwise be denied.
+		// WordPress 7.2+ uses a separate hook for unregistered admin pages.
+		add_action( 'wp_admin_page_not_found', array( $this, 'handle_hpos_admin_requests' ) );
 		add_action( 'admin_page_access_denied', array( $this, 'handle_hpos_admin_requests' ) );
 	}

 	/**
-	 * Listen for denied admin requests and, if they appear to relate to HPOS admin screens, potentially
+	 * Listen for missing or denied admin requests and, if they appear to relate to HPOS admin screens, potentially
 	 * redirect the user to the equivalent CPT-driven screens.
 	 *
 	 * @param array|null $query_params The query parameters to use when determining the redirect. If not provided, the $_GET superglobal will be used.
diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/Orders/COTRedirectionControllerTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/Orders/COTRedirectionControllerTest.php
index a18f16d1845..14b5a68dbff 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Admin/Orders/COTRedirectionControllerTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Admin/Orders/COTRedirectionControllerTest.php
@@ -59,6 +59,71 @@ class COTRedirectionControllerTest extends \WC_Unit_Test_Case {
 		return $return;
 	}

+	/**
+	 * @testdox Redirects HPOS requests from both missing-page and access-denied hooks, leaving unrelated requests unchanged.
+	 *
+	 * @dataProvider provide_admin_request_redirects
+	 * @param string $hook The admin request hook.
+	 * @param array  $query_params The request query parameters.
+	 * @param string $expected_path The expected redirect path, or an empty string for no redirect.
+	 */
+	public function test_redirects_from_admin_request_hooks( string $hook, array $query_params, string $expected_path ): void {
+		$original_get = $_GET; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Preserve the request while simulating admin hooks.
+		$_GET         = $query_params;
+
+		try {
+			do_action( $hook );
+
+			$this->assertSame(
+				'' === $expected_path ? '' : get_admin_url( null, $expected_path ),
+				$this->get_redirect_attempt(),
+				'Admin request hooks should redirect only HPOS order requests to the equivalent posts screens.'
+			);
+		} finally {
+			$_GET = $original_get;
+		}
+	}
+
+	/**
+	 * Provides requests for both current and legacy WordPress admin hooks.
+	 *
+	 * @return array
+	 */
+	public function provide_admin_request_redirects(): array {
+		$requests = array(
+			'order list'   => array(
+				array( 'page' => 'wc-orders' ),
+				'edit.php?post_type=shop_order',
+			),
+			'order editor' => array(
+				array(
+					'page'   => 'wc-orders',
+					'action' => 'edit',
+					'id'     => '123',
+				),
+				'post.php?action=edit&post=123',
+			),
+			'new order'    => array(
+				array(
+					'page'   => 'wc-orders',
+					'action' => 'new',
+				),
+				'post-new.php?post_type=shop_order',
+			),
+			'other page'   => array( array( 'page' => 'foo' ), '' ),
+			'no page'      => array( array(), '' ),
+		);
+		$cases    = array();
+
+		foreach ( array( 'admin_page_access_denied', 'wp_admin_page_not_found' ) as $hook ) {
+			foreach ( $requests as $name => $request ) {
+				$cases[ $hook . ': ' . $name ] = array( $hook, $request[0], $request[1] );
+			}
+		}
+
+		return $cases;
+	}
+
 	/**
 	 * Test that redirects only occur in relation to HPOS admin screen requests.
 	 *