Commit 7a9d35becb7 for woocommerce

commit 7a9d35becb74117de691ebb8837478450899a39f
Author: Chris Lilitsas <1105590+xristos3490@users.noreply.github.com>
Date:   Thu Oct 15 17:00:40 2026 +0300

    Build stock notification email links on home_url() instead of siteurl (#69507)

    * fix: build BIS email action links on home_url() instead of siteurl

    * test: assert email links no longer contain the siteurl subdirectory

diff --git a/plugins/woocommerce/changelog/fix-wooplug-7931-bis-email-links-home-url b/plugins/woocommerce/changelog/fix-wooplug-7931-bis-email-links-home-url
new file mode 100644
index 00000000000..c280429535a
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-wooplug-7931-bis-email-links-home-url
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Point back-in-stock email links to the store front end when WordPress is installed in a subdirectory.
diff --git a/plugins/woocommerce/src/Internal/StockNotifications/Emails/CustomerStockNotificationEmail.php b/plugins/woocommerce/src/Internal/StockNotifications/Emails/CustomerStockNotificationEmail.php
index 54978eeedb1..69131b34f76 100644
--- a/plugins/woocommerce/src/Internal/StockNotifications/Emails/CustomerStockNotificationEmail.php
+++ b/plugins/woocommerce/src/Internal/StockNotifications/Emails/CustomerStockNotificationEmail.php
@@ -184,7 +184,7 @@ class CustomerStockNotificationEmail extends WC_Email {
 						'email_link_action_key' => $unsubscribe_key,
 						'notification_id'       => $notification->get_id(),
 					),
-					get_option( 'siteurl' )
+					home_url( '/' )
 				)
 			),
 			'is_guest'         => $is_guest,
diff --git a/plugins/woocommerce/src/Internal/StockNotifications/Emails/CustomerStockNotificationVerifiedEmail.php b/plugins/woocommerce/src/Internal/StockNotifications/Emails/CustomerStockNotificationVerifiedEmail.php
index 5bd646998df..baa4cc94ad4 100644
--- a/plugins/woocommerce/src/Internal/StockNotifications/Emails/CustomerStockNotificationVerifiedEmail.php
+++ b/plugins/woocommerce/src/Internal/StockNotifications/Emails/CustomerStockNotificationVerifiedEmail.php
@@ -155,7 +155,7 @@ class CustomerStockNotificationVerifiedEmail extends WC_Email {
 						'email_link_action_key' => $unsubscribe_key,
 						'notification_id'       => $notification->get_id(),
 					),
-					get_option( 'siteurl' )
+					home_url( '/' )
 				)
 			),
 		);
diff --git a/plugins/woocommerce/src/Internal/StockNotifications/Emails/CustomerStockNotificationVerifyEmail.php b/plugins/woocommerce/src/Internal/StockNotifications/Emails/CustomerStockNotificationVerifyEmail.php
index f9a4c81aea6..b59ff6fe9e6 100644
--- a/plugins/woocommerce/src/Internal/StockNotifications/Emails/CustomerStockNotificationVerifyEmail.php
+++ b/plugins/woocommerce/src/Internal/StockNotifications/Emails/CustomerStockNotificationVerifyEmail.php
@@ -180,7 +180,7 @@ class CustomerStockNotificationVerifyEmail extends WC_Email {
 						'email_link_action_key' => $verification_key,
 						'notification_id'       => $notification->get_id(),
 					),
-					get_option( 'siteurl' )
+					home_url( '/' )
 				)
 			),
 		);
diff --git a/plugins/woocommerce/tests/php/src/Internal/StockNotifications/Emails/EmailManagerTests.php b/plugins/woocommerce/tests/php/src/Internal/StockNotifications/Emails/EmailManagerTests.php
index 4cd60a77479..6c2681c9b33 100644
--- a/plugins/woocommerce/tests/php/src/Internal/StockNotifications/Emails/EmailManagerTests.php
+++ b/plugins/woocommerce/tests/php/src/Internal/StockNotifications/Emails/EmailManagerTests.php
@@ -30,6 +30,13 @@ class EmailManagerTests extends \WC_Unit_Test_Case {
 	 */
 	private $sent_to = array();

+	/**
+	 * Captured `wp_mail()` message bodies.
+	 *
+	 * @var string[]
+	 */
+	private $sent_messages = array();
+
 	/**
 	 * Set up test fixtures.
 	 */
@@ -57,7 +64,8 @@ class EmailManagerTests extends \WC_Unit_Test_Case {
 	 */
 	public function tearDown(): void {
 		remove_filter( 'pre_wp_mail', array( $this, 'capture_pre_wp_mail' ), 10 );
-		$this->sent_to = array();
+		$this->sent_to       = array();
+		$this->sent_messages = array();
 		$this->restore_stock_notifications_feature_option();
 		// Discard this test's `WC_Emails` build so later tests rebuild their own from
 		// whatever filters are active for them, rather than inheriting this test's list.
@@ -83,7 +91,8 @@ class EmailManagerTests extends \WC_Unit_Test_Case {
 	 */
 	public function capture_pre_wp_mail( $short_circuit, $atts ): bool {
 		unset( $short_circuit );
-		$recipients = is_array( $atts['to'] ?? null ) ? $atts['to'] : array( $atts['to'] ?? '' );
+		$recipients            = is_array( $atts['to'] ?? null ) ? $atts['to'] : array( $atts['to'] ?? '' );
+		$this->sent_messages[] = (string) ( $atts['message'] ?? '' );
 		foreach ( $recipients as $recipient ) {
 			$this->sent_to[ $recipient ] = true;
 		}
@@ -161,6 +170,37 @@ class EmailManagerTests extends \WC_Unit_Test_Case {
 		$this->assertArrayHasKey( $notification->get_user_email(), $this->sent_to );
 	}

+	/**
+	 * @testdox Should build the $email_method action link on home_url() when WordPress core lives in a subdirectory.
+	 * @dataProvider provider_email_send_methods
+	 *
+	 * @param string $email_method EmailManager method that sends the email.
+	 */
+	public function test_email_action_link_uses_home_url_when_core_is_in_subdirectory( string $email_method ) {
+		add_filter( 'option_home', fn() => 'https://shop.example' );
+		add_filter( 'option_siteurl', fn() => 'https://shop.example/wp' );
+		$notification = $this->build_notification();
+
+		$this->sut->$email_method( $notification );
+
+		$this->assertCount( 1, $this->sent_messages );
+		$this->assertStringContainsString( 'https://shop.example/?email_link_action=', $this->sent_messages[0] );
+		$this->assertStringNotContainsString( 'https://shop.example/wp', $this->sent_messages[0] );
+	}
+
+	/**
+	 * EmailManager methods that send a BIS email with an action link.
+	 *
+	 * @return array<string, array<string>>
+	 */
+	public function provider_email_send_methods(): array {
+		return array(
+			'stock notification' => array( 'send_stock_notification_email' ),
+			'verify'             => array( 'send_verify_email' ),
+			'verified'           => array( 'send_verified_email' ),
+		);
+	}
+
 	/**
 	 * Build a persisted notification for an in-stock simple product.
 	 *