Commit 6bf2604834 for woocommerce

commit 6bf26048344e72fd9eb0c3628048961bf5613711
Author: Yuliyan Slavchev <yuliyan.slavchev@gmail.com>
Date:   Wed Jun 18 13:44:41 2025 +0300

    Use email sender options for stock notifications (#58932)

    * Use email sender options for stock notifications

    * Add changelog entry

    * Remove code duplication

diff --git a/plugins/woocommerce/changelog/wooplug-819-enhancement-notifications-out-of-stock-send-to-default b/plugins/woocommerce/changelog/wooplug-819-enhancement-notifications-out-of-stock-send-to-default
new file mode 100644
index 0000000000..3b1a146853
--- /dev/null
+++ b/plugins/woocommerce/changelog/wooplug-819-enhancement-notifications-out-of-stock-send-to-default
@@ -0,0 +1,4 @@
+Significance: patch
+Type: update
+
+Use email sender options for low stock, no stock, and backorder notifications.
diff --git a/plugins/woocommerce/includes/class-wc-emails.php b/plugins/woocommerce/includes/class-wc-emails.php
index 3760ce1092..776b18f317 100644
--- a/plugins/woocommerce/includes/class-wc-emails.php
+++ b/plugins/woocommerce/includes/class-wc-emails.php
@@ -815,6 +815,22 @@ class WC_Emails {
 		return true;
 	}

+	/**
+	 * Add email sender filters.
+	 */
+	private function add_email_sender_filters() {
+		add_filter( 'wp_mail_from', array( $this, 'get_from_address' ) );
+		add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ) );
+	}
+
+	/**
+	 * Remove email sender filters.
+	 */
+	private function remove_email_sender_filters() {
+		remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ) );
+		remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ) );
+	}
+
 	/**
 	 * Low stock notification email.
 	 *
@@ -852,6 +868,8 @@ class WC_Emails {
 			html_entity_decode( wp_strip_all_tags( $product->get_stock_quantity() ) )
 		);

+		$this->add_email_sender_filters();
+
 		wp_mail(
 			/**
 			 * Filter the recipient of the low stock notification email.
@@ -899,6 +917,8 @@ class WC_Emails {
 			 */
 			apply_filters( 'woocommerce_email_attachments', array(), 'low_stock', $product, null )
 		);
+
+		$this->remove_email_sender_filters();
 	}

 	/**
@@ -934,6 +954,8 @@ class WC_Emails {
 		/* translators: %s: product name */
 		$message = sprintf( __( '%s is out of stock.', 'woocommerce' ), html_entity_decode( wp_strip_all_tags( $product->get_formatted_name() ), ENT_QUOTES, get_bloginfo( 'charset' ) ) );

+		$this->add_email_sender_filters();
+
 		wp_mail(
 			/**
 			 * Filter the recipient of the no stock notification email.
@@ -981,6 +1003,8 @@ class WC_Emails {
 			 */
 			apply_filters( 'woocommerce_email_attachments', array(), 'no_stock', $product, null )
 		);
+
+		$this->remove_email_sender_filters();
 	}

 	/**
@@ -1015,6 +1039,8 @@ class WC_Emails {
 		/* translators: 1: backordered quantity 2: product name 3: order number */
 		$message = sprintf( __( '%1$s units of %2$s have been backordered in order #%3$s.', 'woocommerce' ), $backordered_quantity, html_entity_decode( wp_strip_all_tags( $args['product']->get_formatted_name() ), ENT_QUOTES, get_bloginfo( 'charset' ) ), $order->get_order_number() );

+		$this->add_email_sender_filters();
+
 		wp_mail(
 			/**
 			 * Filter the recipient of the backorder notification email.
@@ -1062,6 +1088,8 @@ class WC_Emails {
 			 */
 			apply_filters( 'woocommerce_email_attachments', array(), 'backorder', $args, null )
 		);
+
+		$this->remove_email_sender_filters();
 	}

 	/**