Commit d9a788fb30f for woocommerce

commit d9a788fb30fc59377eac6c785dc9c9bbb56e1236
Author: Chris Lilitsas <1105590+xristos3490@users.noreply.github.com>
Date:   Fri Oct 16 01:54:45 2026 +0300

    Honor redirect_to on the My Account registration form (#69855)

    fix: honor redirect_to on the My Account registration form

    Hook BlockTypesController::redirect_to_field() to woocommerce_register_form_end
    so the registration form carries the same hidden redirect input as the login
    form. WC_Form_Handler::process_registration() already reads $_POST['redirect'],
    so shoppers who register from /my-account/?redirect_to=... now land on that URL
    instead of the dashboard.

diff --git a/plugins/woocommerce/changelog/fix-wooplug-7994-register-form-redirect-to b/plugins/woocommerce/changelog/fix-wooplug-7994-register-form-redirect-to
new file mode 100644
index 00000000000..a15583ccfab
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-wooplug-7994-register-form-redirect-to
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Return shoppers to the `redirect_to` URL after they register from the My Account page, matching the existing login behavior.
diff --git a/plugins/woocommerce/src/Blocks/BlockTypesController.php b/plugins/woocommerce/src/Blocks/BlockTypesController.php
index a99f607688c..f1f233f1d6a 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypesController.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypesController.php
@@ -86,6 +86,7 @@ final class BlockTypesController {
 		add_filter( 'block_categories_all', array( $this, 'register_block_categories' ), 10, 2 );
 		add_filter( 'render_block', array( $this, 'add_data_attributes' ), self::DATA_ATTRIBUTES_PRIORITY, 2 );
 		add_action( 'woocommerce_login_form_end', array( $this, 'redirect_to_field' ) );
+		add_action( 'woocommerce_register_form_end', array( $this, 'redirect_to_field' ) );
 		add_filter( 'widget_types_to_hide_from_legacy_widget_block', array( $this, 'hide_legacy_widgets_with_block_equivalent' ) );
 		add_filter( 'block_type_metadata', array( $this, 'handle_block_type_metadata' ) );
 		add_filter( 'block_type_metadata_settings', array( $this, 'use_single_block_editor_style' ), 10, 2 );
@@ -458,7 +459,7 @@ final class BlockTypesController {
 	}

 	/**
-	 * Adds a redirect field to the login form so blocks can redirect users after login.
+	 * Adds a redirect field to the login and registration forms so blocks can redirect users after they log in or register.
 	 */
 	public function redirect_to_field() {
 		// phpcs:ignore WordPress.Security.NonceVerification
diff --git a/plugins/woocommerce/tests/php/src/Blocks/BlockTypesController.php b/plugins/woocommerce/tests/php/src/Blocks/BlockTypesController.php
index b54d3077213..ce644be78e1 100644
--- a/plugins/woocommerce/tests/php/src/Blocks/BlockTypesController.php
+++ b/plugins/woocommerce/tests/php/src/Blocks/BlockTypesController.php
@@ -181,4 +181,56 @@ class BlockTypesController extends WC_Unit_Test_Case {

 		$this->assertArrayNotHasKey( 'version', $result );
 	}
+
+	/**
+	 * @testdox Should output a hidden redirect field on the login and registration forms when redirect_to is set.
+	 *
+	 * @dataProvider redirect_to_form_hooks_provider
+	 *
+	 * @param string $hook The form hook to fire.
+	 */
+	public function test_redirect_to_field_outputs_hidden_input( string $hook ): void {
+		$_GET['redirect_to'] = 'https://example.com/product/?a=1&b=2';
+
+		try {
+			ob_start();
+			// phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment -- Firing the form hook under test.
+			do_action( $hook );
+			$output = ob_get_clean();
+		} finally {
+			unset( $_GET['redirect_to'] );
+		}
+
+		$this->assertStringContainsString( '<input type="hidden" name="redirect" value="https://example.com/product/?a=1&amp;b=2" />', $output );
+	}
+
+	/**
+	 * @testdox Should output nothing on the login and registration forms when redirect_to is empty.
+	 *
+	 * @dataProvider redirect_to_form_hooks_provider
+	 *
+	 * @param string $hook The form hook to fire.
+	 */
+	public function test_redirect_to_field_outputs_nothing_without_redirect_to( string $hook ): void {
+		unset( $_GET['redirect_to'] );
+
+		ob_start();
+		// phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment -- Firing the form hook under test.
+		do_action( $hook );
+		$output = ob_get_clean();
+
+		$this->assertSame( '', $output );
+	}
+
+	/**
+	 * Form hooks that should receive the hidden redirect field.
+	 *
+	 * @return array<string, array{string}>
+	 */
+	public function redirect_to_form_hooks_provider(): array {
+		return array(
+			'login form'        => array( 'woocommerce_login_form_end' ),
+			'registration form' => array( 'woocommerce_register_form_end' ),
+		);
+	}
 }