Commit e33f79df6da for woocommerce

commit e33f79df6daf2fe7ad968561bbc885e1b74f2034
Author: Chris Lilitsas <1105590+xristos3490@users.noreply.github.com>
Date:   Thu Oct 15 13:04:58 2026 +0300

    Return shoppers to the product after the back-in-stock login prompt (#69824)

    fix: return shoppers to the product after logging in from the back-in-stock prompt

    With the require-account setting on, the "Please log in" link on an
    out-of-stock product pointed at the bare My Account URL, so shoppers
    landed on the dashboard after logging in and had to find the product
    again. The link now carries a redirect_to parameter with the product
    permalink, which the My Account login form turns into its hidden
    redirect field.

diff --git a/plugins/woocommerce/changelog/fix-wooplug-7920-bis-login-link-redirect b/plugins/woocommerce/changelog/fix-wooplug-7920-bis-login-link-redirect
new file mode 100644
index 00000000000..219b929ecc0
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-wooplug-7920-bis-login-link-redirect
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Return shoppers to the product page after they log in from the back-in-stock "Please log in" prompt.
diff --git a/plugins/woocommerce/src/Internal/StockNotifications/Frontend/ProductPageIntegration.php b/plugins/woocommerce/src/Internal/StockNotifications/Frontend/ProductPageIntegration.php
index 4ff262da232..71bdc75203a 100644
--- a/plugins/woocommerce/src/Internal/StockNotifications/Frontend/ProductPageIntegration.php
+++ b/plugins/woocommerce/src/Internal/StockNotifications/Frontend/ProductPageIntegration.php
@@ -177,8 +177,11 @@ class ProductPageIntegration {
 			return;
 		}

+		// The My Account login form turns `redirect_to` into its hidden `redirect` field, so the shopper comes back here after logging in.
+		$login_url = add_query_arg( 'redirect_to', rawurlencode( $product->get_permalink() ), wc_get_page_permalink( 'myaccount' ) );
+
 		$text = __( 'Please {login_link} to sign up for stock notifications.', 'woocommerce' );
-		$text = str_replace( '{login_link}', '<a href="' . esc_url( wc_get_account_endpoint_url( 'dashboard' ) ) . '">' . _x( 'log in', 'back in stock form', 'woocommerce' ) . '</a>', $text );
+		$text = str_replace( '{login_link}', '<a href="' . esc_url( $login_url ) . '">' . _x( 'log in', 'back in stock form', 'woocommerce' ) . '</a>', $text );
 		wc_print_notice( $text, 'notice' );
 	}

diff --git a/plugins/woocommerce/tests/php/src/Internal/StockNotifications/Frontend/ProductPageIntegrationTest.php b/plugins/woocommerce/tests/php/src/Internal/StockNotifications/Frontend/ProductPageIntegrationTest.php
index 6983aa79eba..e13b8174002 100644
--- a/plugins/woocommerce/tests/php/src/Internal/StockNotifications/Frontend/ProductPageIntegrationTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/StockNotifications/Frontend/ProductPageIntegrationTest.php
@@ -186,6 +186,28 @@ class ProductPageIntegrationTest extends WC_Unit_Test_Case {
 		$this->assertStringContainsString( 'wc_bis_form', $markup, 'The Back in Stock form should render when the simple product hook fires from a classic template.' );
 	}

+	/**
+	 * @testdox Should send guests back to the product after logging in when an account is required.
+	 */
+	public function test_login_link_returns_guest_to_the_product_when_account_is_required(): void {
+		update_option( 'woocommerce_customer_stock_notifications_require_account', 'yes' );
+		wp_set_current_user( 0 );
+		$product_id = $this->create_and_visit_out_of_stock_simple_product();
+
+		try {
+			ob_start();
+			do_action( 'woocommerce_simple_add_to_cart' );
+			$markup = ob_get_clean();
+		} finally {
+			delete_option( 'woocommerce_customer_stock_notifications_require_account' );
+		}
+
+		$expected_url = add_query_arg( 'redirect_to', rawurlencode( get_permalink( $product_id ) ), wc_get_page_permalink( 'myaccount' ) );
+
+		$this->assertStringContainsString( 'Please <a href="' . esc_url( $expected_url ) . '">log in</a> to sign up for stock notifications.', $markup, 'The login link should return the shopper to the product page after logging in.' );
+		$this->assertStringNotContainsString( 'wc_bis_form', $markup, 'The Back in Stock form should not render for a guest when an account is required.' );
+	}
+
 	/**
 	 * @testdox Should render the form inside the legacy Add to Cart Form block.
 	 */