Commit 15b87d77193 for woocommerce

commit 15b87d77193b5ef06896d085fa453512196bf02f
Author: Chris Lilitsas <1105590+xristos3490@users.noreply.github.com>
Date:   Thu Oct 15 12:14:52 2026 +0300

    Log a warning when a stock notification email class is missing from the mailer (#69508)

    tweak: log a warning when a BIS email class is missing from the mailer

    EmailManager::send_stock_notification_email(), send_verify_email() and
    send_verified_email() returned silently when their email class was not
    registered with WC_Emails. Log a warning (source
    wc-customer-stock-notifications) with the notification ID instead.

    The missing registration itself was fixed in #69538 by building the
    mailer lazily in the block email editor integration; this only makes a
    repeat of that failure visible in the logs.

diff --git a/plugins/woocommerce/changelog/tweak-wooplug-7907-bis-missing-email-warning b/plugins/woocommerce/changelog/tweak-wooplug-7907-bis-missing-email-warning
new file mode 100644
index 00000000000..e5d8cde9b3b
--- /dev/null
+++ b/plugins/woocommerce/changelog/tweak-wooplug-7907-bis-missing-email-warning
@@ -0,0 +1,4 @@
+Significance: patch
+Type: tweak
+
+Log a warning when a back in stock notification email is not registered with the mailer.
diff --git a/plugins/woocommerce/src/Internal/StockNotifications/Emails/EmailManager.php b/plugins/woocommerce/src/Internal/StockNotifications/Emails/EmailManager.php
index abee6708a30..181056929c6 100644
--- a/plugins/woocommerce/src/Internal/StockNotifications/Emails/EmailManager.php
+++ b/plugins/woocommerce/src/Internal/StockNotifications/Emails/EmailManager.php
@@ -283,9 +283,12 @@ class EmailManager {
 		$emails = WC()->mailer()->get_emails();
 		$email  = $emails['WC_Email_Customer_Stock_Notification'] ?? null;

-		if ( $email instanceof CustomerStockNotificationEmail ) {
-			$email->trigger( $notification );
+		if ( ! $email instanceof CustomerStockNotificationEmail ) {
+			$this->log_missing_email( 'WC_Email_Customer_Stock_Notification', $notification );
+			return;
 		}
+
+		$email->trigger( $notification );
 	}

 	/**
@@ -298,9 +301,12 @@ class EmailManager {
 		$emails = WC()->mailer()->get_emails();
 		$email  = $emails['WC_Email_Customer_Stock_Notification_Verify'] ?? null;

-		if ( $email instanceof CustomerStockNotificationVerifyEmail ) {
-			$email->trigger( $notification );
+		if ( ! $email instanceof CustomerStockNotificationVerifyEmail ) {
+			$this->log_missing_email( 'WC_Email_Customer_Stock_Notification_Verify', $notification );
+			return;
 		}
+
+		$email->trigger( $notification );
 	}

 	/**
@@ -313,8 +319,28 @@ class EmailManager {
 		$emails = WC()->mailer()->get_emails();
 		$email  = $emails['WC_Email_Customer_Stock_Notification_Verified'] ?? null;

-		if ( $email instanceof CustomerStockNotificationVerifiedEmail ) {
-			$email->trigger( $notification );
+		if ( ! $email instanceof CustomerStockNotificationVerifiedEmail ) {
+			$this->log_missing_email( 'WC_Email_Customer_Stock_Notification_Verified', $notification );
+			return;
 		}
+
+		$email->trigger( $notification );
+	}
+
+	/**
+	 * Log that an email could not be sent because its class is not registered with the mailer.
+	 *
+	 * @param string       $email_key    The key the email is registered under in `WC_Emails`.
+	 * @param Notification $notification The notification object.
+	 * @return void
+	 */
+	private function log_missing_email( string $email_key, Notification $notification ): void {
+		wc_get_logger()->warning(
+			sprintf( 'Email %s is not registered with the mailer; nothing was sent for notification %d.', $email_key, $notification->get_id() ),
+			array(
+				'source'          => 'wc-customer-stock-notifications',
+				'notification_id' => $notification->get_id(),
+			)
+		);
 	}
 }
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 9c3dca42b07..4cd60a77479 100644
--- a/plugins/woocommerce/tests/php/src/Internal/StockNotifications/Emails/EmailManagerTests.php
+++ b/plugins/woocommerce/tests/php/src/Internal/StockNotifications/Emails/EmailManagerTests.php
@@ -101,6 +101,36 @@ class EmailManagerTests extends \WC_Unit_Test_Case {
 		$this->assertArrayHasKey( 'WC_Email_Customer_Stock_Notification_Verified', $emails );
 	}

+	/**
+	 * @testdox Should log a warning instead of failing silently when the email class is missing from the mailer.
+	 */
+	public function test_send_verify_email_logs_a_warning_when_the_email_is_not_registered() {
+		$notification = $this->build_notification();
+
+		$logger = $this->getMockBuilder( \WC_Logger_Interface::class )->getMock();
+		$logger->expects( $this->once() )
+			->method( 'warning' )
+			->with( $this->stringContains( 'WC_Email_Customer_Stock_Notification_Verify' ) );
+		$use_logger = function () use ( $logger ) {
+			return $logger;
+		};
+		add_filter( 'woocommerce_logging_class', $use_logger );
+
+		$drop_bis_emails = function ( $emails ) {
+			unset( $emails['WC_Email_Customer_Stock_Notification_Verify'] );
+			return $emails;
+		};
+		add_filter( 'woocommerce_email_classes', $drop_bis_emails, 20 );
+		$this->reset_email_singleton();
+
+		$this->sut->send_verify_email( $notification );
+
+		remove_filter( 'woocommerce_email_classes', $drop_bis_emails, 20 );
+		remove_filter( 'woocommerce_logging_class', $use_logger );
+
+		$this->assertEmpty( $this->sent_to );
+	}
+
 	/**
 	 * @testdox Should dispatch the verify email to the notification's user email when send_verify_email is called.
 	 */