Commit 171f4f54896 for woocommerce
commit 171f4f54896a8bffd7d9d291b3e70469264df24f
Author: Pavel Dohnal <pavel.dohnal@automattic.com>
Date: Fri Nov 27 13:36:36 2026 +0100
Add block editor support for the remaining six core emails (#71426)
* Add block email editor versions of the order withdrawal emails
With the block email editor on, the customer and admin order
withdrawal emails had no block template. They were missing from the
editor and were still sent in the classic design, next to block
emails.
List both emails for the block editor when the order withdrawal
feature is on, add their block templates, and render the request
details through a dedicated content template. The general block
content expects an order and printed the order table (or failed on
the plain request data), so it can't be used here. The text matches
the classic emails.
* Check the customer withdrawal block email has no order table
* Add block email editor versions of the back-in-stock emails
With the block email editor on, the three back-in-stock emails (sign-up
verification, sign-up confirmation and the back-in-stock notification)
had no block template, so they were missing from the editor and sent
in the classic design.
List them for the block editor when the back-in-stock feature is on,
add a block template for each, and render the intro, product, button
and sign-up note through a shared content template. The text matches
the classic emails; the new heading and footer strings use curly
apostrophes.
* Add block email editor version of the Analytics report download email
The email ReportExporter sends with a report download link was not a
listed email: it had no title or settings and kept the classic design
with the block email editor on.
When the block editor is on, list it with the other emails so it can
be edited there, give it a title and description, and add its block
templates next to the classic ones. It has no on/off or format
setting, since the export always sends it, and no Cc or Bcc, since the
link goes to the person who ran the export. The download link is now
a button, as in the other block emails.
Also cover all three email groups in the changelog entry.
* Show the report download email's real status and a sample preview
In the block email editor the Analytics report download email showed
as Inactive, although it was always sent, and its preview had no
report name, an empty download link and a raw {report_name} in the
subject.
The email now honours its on/off switch like the other emails, but
only while the block email editor is on, since that is the only place
the switch can be changed. A store that turned it off and then turned
the editor off still gets its report emails. The preview fills in a
sample Orders report for last month.
* Always send the report download email and show it as active
Letting merchants switch the Analytics report download email off lost
their large exports: Analytics still says the report will be emailed,
and the file has no other way to reach them. So the email has no
on/off setting again and is always sent.
The editor read the status from the missing setting and showed the
email as inactive. It now falls back to is_enabled() for any email
without an on/off setting. The preview date range now uses the same
helper as real sends, so its separator and time zone match.
* Remove baseline entry for the deleted ReportCSVEmail::init_settings
The method was removed with the report download email's block version,
so PHPStan reports the entry as unmatched and the CI check fails.
* Keep the email enabled filter for the report download email
The is_enabled() override returned true directly, so the public
woocommerce_email_enabled_admin_report_export_download filter no longer
ran. It now runs that filter with true as the default.
* Do not save an on/off value for emails without that setting
The editor's status control wrote enabled=no for the report download
email, which has no on/off setting, so the choice was stored but never
used. Save it only when the email has the setting, as the unpaid timeout
toggle already does.
* Document the email enabled filter in the report download email
The Lint job requires a @since tag on every hook docblock, and a
"documented in" reference has none. The filter has existed since
WooCommerce 2.0.0.
* Mark the report download email as manual
The email is sent only when a merchant exports a report, and it has
no on/off setting. The editor showed a status control for it that
saved a value nothing reads. A guard in EmailApiController skipped
that save for any email without an enabled field, which also dropped
status changes for extension emails that remove the field but still
read the stored option.
Marking the email as manual uses the existing signal: the email list
and the editor show it as Manual and disable the status control.
EmailApiController goes back to its trunk behaviour.
* List back-in-stock emails on sites using the alpha constant
The block editor listed the three back-in-stock emails only when the
feature option was on. Sites that turned the feature on with the
WOOCOMMERCE_BIS_ALPHA_ENABLED constant still register and send these
emails, but they went out in the classic design. Use
is_enabled_before_init(), which counts the constant, like the other
stock notification checks outside the feature's own init.
* Reuse translated strings in the back-in-stock block emails
The block templates used curly apostrophes in "It's back in stock!" and
"Wasn't you?", which made them new strings. The classic emails already
ship both with straight apostrophes, so reusing them keeps the existing
translations.
* Remove unused heading and additional content from report email
The report download email is only listed with the block editor on, and
its block design doesn't read the heading or the additional content.
Both settings could be saved but changed nothing.
* Say who gets an email without a recipient field in the editor
The editor sidebar said "This email is sent to Customer." for every
email without a recipient field. The Analytics report download email
has none because it goes to the person who exported the report, so the
sidebar named the wrong recipient. The editor data now says whether an
email goes to the customer; when it doesn't, the sidebar says the email
is sent to the person who requested it.
diff --git a/plugins/woocommerce/changelog/add-WOOPLUG-8320-remaining-emails-block-editor b/plugins/woocommerce/changelog/add-WOOPLUG-8320-remaining-emails-block-editor
new file mode 100644
index 00000000000..8d682a6ad48
--- /dev/null
+++ b/plugins/woocommerce/changelog/add-WOOPLUG-8320-remaining-emails-block-editor
@@ -0,0 +1,4 @@
+Significance: minor
+Type: add
+
+The order withdrawal, back-in-stock and Analytics report download emails can now be edited in the block email editor.
diff --git a/plugins/woocommerce/client/admin/client/wp-admin-scripts/email-editor-integration/__tests__/sidebar-settings.test.tsx b/plugins/woocommerce/client/admin/client/wp-admin-scripts/email-editor-integration/__tests__/sidebar-settings.test.tsx
index 37dae56ff3b..a134c4ebfba 100644
--- a/plugins/woocommerce/client/admin/client/wp-admin-scripts/email-editor-integration/__tests__/sidebar-settings.test.tsx
+++ b/plugins/woocommerce/client/admin/client/wp-admin-scripts/email-editor-integration/__tests__/sidebar-settings.test.tsx
@@ -309,6 +309,30 @@ describe( 'Email editor sidebar settings', () => {
);
} );
+ it( 'says who receives an email without a recipient field that is not sent to the customer', () => {
+ mockEntityState.woocommerceData = {
+ ...defaultWooCommerceData,
+ recipient: null,
+ is_customer_email: false,
+ };
+ mockEntityState.editedWooCommerceData = {
+ ...mockEntityState.woocommerceData,
+ };
+ renderSettings( {
+ recordEvent: jest.fn(),
+ debouncedRecordEvent: jest.fn(),
+ } );
+
+ expect(
+ screen.getByText(
+ 'This email is sent to the person who requested it.'
+ )
+ ).toBeInTheDocument();
+ expect(
+ screen.queryByText( 'This email is sent to Customer.' )
+ ).not.toBeInTheDocument();
+ } );
+
it( 'updates and clears CC and BCC recipients', async () => {
const recordEvent = jest.fn();
const debouncedRecordEvent = jest.fn();
diff --git a/plugins/woocommerce/client/admin/client/wp-admin-scripts/email-editor-integration/global.d.ts b/plugins/woocommerce/client/admin/client/wp-admin-scripts/email-editor-integration/global.d.ts
index dbfb4d6279a..9d483f12066 100644
--- a/plugins/woocommerce/client/admin/client/wp-admin-scripts/email-editor-integration/global.d.ts
+++ b/plugins/woocommerce/client/admin/client/wp-admin-scripts/email-editor-integration/global.d.ts
@@ -38,6 +38,8 @@ interface EmailWooCommerceData {
subject_partial: string | null;
default_subject: string | null;
is_manual: boolean;
+ /** Whether the email goes to the customer. Older data may not include it. */
+ is_customer_email?: boolean;
enabled: boolean;
/** `null` means this email has no such setting. */
send_on_unpaid_timeout: boolean | null;
diff --git a/plugins/woocommerce/client/admin/client/wp-admin-scripts/email-editor-integration/sidebar_settings.tsx b/plugins/woocommerce/client/admin/client/wp-admin-scripts/email-editor-integration/sidebar_settings.tsx
index c0d3b6f46dc..bed0159f2cc 100644
--- a/plugins/woocommerce/client/admin/client/wp-admin-scripts/email-editor-integration/sidebar_settings.tsx
+++ b/plugins/woocommerce/client/admin/client/wp-admin-scripts/email-editor-integration/sidebar_settings.tsx
@@ -184,10 +184,15 @@ const SidebarSettings = ( {
>
{ woocommerce_email_data.recipient === null ? (
<p className="woocommerce-email-editor-recipients-help">
- { __(
- 'This email is sent to Customer.',
- 'woocommerce'
- ) }
+ { woocommerce_email_data.is_customer_email === false
+ ? __(
+ 'This email is sent to the person who requested it.',
+ 'woocommerce'
+ )
+ : __(
+ 'This email is sent to Customer.',
+ 'woocommerce'
+ ) }
</p>
) : (
<TextControl
diff --git a/plugins/woocommerce/includes/class-wc-emails.php b/plugins/woocommerce/includes/class-wc-emails.php
index 8e47080cb86..f77fa80c058 100644
--- a/plugins/woocommerce/includes/class-wc-emails.php
+++ b/plugins/woocommerce/includes/class-wc-emails.php
@@ -16,6 +16,7 @@ use Automattic\WooCommerce\Blocks\Package;
use Automattic\WooCommerce\Blocks\Domain\Services\CheckoutFields;
use Automattic\WooCommerce\Enums\ProductType;
use Automattic\WooCommerce\Admin\Features\Fulfillments\Fulfillment;
+use Automattic\WooCommerce\Admin\ReportCSVEmail;
use Automattic\WooCommerce\Utilities\FeaturesUtil;
defined( 'ABSPATH' ) || exit;
@@ -328,6 +329,8 @@ class WC_Emails {
// Enable custom partially refunded order email for the block email editor.
if ( FeaturesUtil::feature_is_enabled( 'block_email_editor' ) ) {
$this->emails['WC_Email_Customer_Partially_Refunded_Order'] = include __DIR__ . '/emails/class-wc-email-customer-partially-refunded-order.php';
+ // The Analytics report export email is sent by ReportExporter; it is listed here only so it can be edited in the block email editor.
+ $this->emails['WC_Email_Admin_Report_Export_Download'] = new ReportCSVEmail();
}
/**
diff --git a/plugins/woocommerce/includes/emails/class-wc-email-customer-order-withdrawal-requested.php b/plugins/woocommerce/includes/emails/class-wc-email-customer-order-withdrawal-requested.php
index 59e5bd058ad..663ba966227 100644
--- a/plugins/woocommerce/includes/emails/class-wc-email-customer-order-withdrawal-requested.php
+++ b/plugins/woocommerce/includes/emails/class-wc-email-customer-order-withdrawal-requested.php
@@ -59,6 +59,8 @@ if ( ! class_exists( 'WC_Email_Customer_Order_Withdrawal_Requested', false ) ) :
$this->formatter = new OrderWithdrawalEmailDataFormatter();
parent::__construct();
+
+ $this->template_block_content = 'emails/block/general-block-content-for-order-withdrawal-emails.php';
}
/**
@@ -140,6 +142,23 @@ if ( ! class_exists( 'WC_Email_Customer_Order_Withdrawal_Requested', false ) ) :
);
}
+ /**
+ * Get block editor email template content.
+ *
+ * @return string
+ */
+ public function get_block_editor_email_template_content() {
+ return wc_get_template_html(
+ $this->template_block_content,
+ array(
+ 'detail_rows' => $this->formatter->get_detail_rows( $this->withdrawal_data, $this->submitted_at ),
+ 'sent_to_admin' => false,
+ 'plain_text' => false,
+ 'email' => $this,
+ )
+ );
+ }
+
/**
* Get content plain.
*
diff --git a/plugins/woocommerce/includes/emails/class-wc-email-order-withdrawal-requested.php b/plugins/woocommerce/includes/emails/class-wc-email-order-withdrawal-requested.php
index 4e6de719184..ba7e27acb25 100644
--- a/plugins/woocommerce/includes/emails/class-wc-email-order-withdrawal-requested.php
+++ b/plugins/woocommerce/includes/emails/class-wc-email-order-withdrawal-requested.php
@@ -82,7 +82,8 @@ if ( ! class_exists( 'WC_Email_Order_Withdrawal_Requested', false ) ) :
parent::__construct();
- $this->recipient = $this->get_option( 'recipient', get_option( 'admin_email' ) );
+ $this->recipient = $this->get_option( 'recipient', get_option( 'admin_email' ) );
+ $this->template_block_content = 'emails/block/general-block-content-for-order-withdrawal-emails.php';
}
/**
@@ -212,6 +213,26 @@ if ( ! class_exists( 'WC_Email_Order_Withdrawal_Requested', false ) ) :
);
}
+ /**
+ * Get block editor email template content.
+ *
+ * @return string
+ */
+ public function get_block_editor_email_template_content() {
+ return wc_get_template_html(
+ $this->template_block_content,
+ array(
+ 'detail_rows' => $this->formatter->get_detail_rows( $this->withdrawal_data, $this->submitted_at ),
+ 'matched_order' => $this->matched_order,
+ 'outside_withdrawal_window' => $this->outside_withdrawal_window,
+ 'withdrawal_window_warning' => $this->withdrawal_window_warning,
+ 'sent_to_admin' => true,
+ 'plain_text' => false,
+ 'email' => $this,
+ )
+ );
+ }
+
/**
* Get content plain.
*
diff --git a/plugins/woocommerce/includes/react-admin/emails/block-admin-report-export-download.php b/plugins/woocommerce/includes/react-admin/emails/block-admin-report-export-download.php
new file mode 100644
index 00000000000..2fc999945ad
--- /dev/null
+++ b/plugins/woocommerce/includes/react-admin/emails/block-admin-report-export-download.php
@@ -0,0 +1,25 @@
+<?php
+/**
+ * Admin report export download email (initial block version)
+ *
+ * This template can be overridden by editing it in the WooCommerce email editor.
+ *
+ * @package WooCommerce\Admin\Templates\Emails\Block
+ * @version 11.5.0
+ */
+
+use Automattic\WooCommerce\Internal\EmailEditor\BlockEmailRenderer;
+
+defined( 'ABSPATH' ) || exit;
+
+// phpcs:disable Squiz.PHP.EmbeddedPhp.ContentBeforeOpen -- removed to prevent empty new lines.
+// phpcs:disable Squiz.PHP.EmbeddedPhp.ContentAfterEnd -- removed to prevent empty new lines.
+?>
+
+<!-- wp:heading -->
+<h2 class="wp-block-heading"><?php echo esc_html__( 'Your Report Download', 'woocommerce' ); ?></h2>
+<!-- /wp:heading -->
+
+<!-- wp:woocommerce/email-content {"lock":{"move":false,"remove":true}} -->
+<div class="wp-block-woocommerce-email-content"> <?php echo esc_html( BlockEmailRenderer::WOO_EMAIL_CONTENT_PLACEHOLDER ); ?> </div>
+<!-- /wp:woocommerce/email-content -->
diff --git a/plugins/woocommerce/includes/react-admin/emails/block-content-admin-report-export-download.php b/plugins/woocommerce/includes/react-admin/emails/block-content-admin-report-export-download.php
new file mode 100644
index 00000000000..f034f244fdd
--- /dev/null
+++ b/plugins/woocommerce/includes/react-admin/emails/block-content-admin-report-export-download.php
@@ -0,0 +1,39 @@
+<?php
+/**
+ * Block content for the admin report export download email
+ *
+ * Used to render information for the email editor WooCommerce content block (BlockEmailRenderer::WOO_EMAIL_CONTENT_PLACEHOLDER).
+ *
+ * @package WooCommerce\Admin\Templates\Emails\Block
+ * @version 11.5.0
+ *
+ * @var string $report_name Report name, e.g. "Orders".
+ * @var string $date_range Date range the report covers. Empty for reports without one.
+ * @var string $download_url Report download link.
+ * @var string $retention How long the download link stays valid, e.g. "1 week".
+ */
+
+defined( 'ABSPATH' ) || exit;
+
+// phpcs:disable Squiz.PHP.EmbeddedPhp.ContentBeforeOpen -- removed to prevent empty new lines.
+// phpcs:disable Squiz.PHP.EmbeddedPhp.ContentAfterEnd -- removed to prevent empty new lines.
+
+wc_get_template(
+ 'emails/email-button.php',
+ array(
+ 'url' => $download_url,
+ /* translators: %s: report name */
+ 'label' => sprintf( __( 'Download your %s Report', 'woocommerce' ), $report_name ),
+ )
+);
+
+if ( ! empty( $date_range ) ) : ?>
+<p><?php
+ /* translators: %s: the date range the report covers, e.g. "June 1, 2025 - June 30, 2025" */
+ echo esc_html( sprintf( __( 'Date range: %s', 'woocommerce' ), $date_range ) );
+?></p>
+<?php endif; ?>
+<p><?php
+ /* translators: %s: length of time the download link stays valid, e.g. "1 week" */
+ echo esc_html( sprintf( __( 'This link is available for %s.', 'woocommerce' ), $retention ) );
+?></p>
diff --git a/plugins/woocommerce/phpstan-baseline.neon b/plugins/woocommerce/phpstan-baseline.neon
index 79fe2a9de95..4e08fdbea2e 100644
--- a/plugins/woocommerce/phpstan-baseline.neon
+++ b/plugins/woocommerce/phpstan-baseline.neon
@@ -46147,12 +46147,6 @@ parameters:
count: 1
path: src/Admin/ReportCSVEmail.php
- -
- message: '#^Method Automattic\\WooCommerce\\Admin\\ReportCSVEmail\:\:init_settings\(\) has no return type specified\.$#'
- identifier: missingType.return
- count: 1
- path: src/Admin/ReportCSVEmail.php
-
-
message: '#^Method Automattic\\WooCommerce\\Admin\\ReportCSVEmail\:\:trigger\(\) has no return type specified\.$#'
identifier: missingType.return
diff --git a/plugins/woocommerce/src/Admin/ReportCSVEmail.php b/plugins/woocommerce/src/Admin/ReportCSVEmail.php
index 66bde6eb2c6..fd41c8ce294 100644
--- a/plugins/woocommerce/src/Admin/ReportCSVEmail.php
+++ b/plugins/woocommerce/src/Admin/ReportCSVEmail.php
@@ -55,10 +55,15 @@ class ReportCSVEmail extends \WC_Email {
public function __construct() {
$this->placeholders['{report_date_range}'] = '';
- $this->id = 'admin_report_export_download';
- $this->template_base = WC()->plugin_path() . '/includes/react-admin/emails/';
- $this->template_html = 'html-admin-report-export-download.php';
- $this->template_plain = 'plain-admin-report-export-download.php';
+ $this->id = 'admin_report_export_download';
+ $this->title = __( 'Analytics report download', 'woocommerce' );
+ $this->description = __( 'Sent to the person who exports an Analytics report, with a link to download it.', 'woocommerce' );
+ $this->supports_cc_bcc = false;
+ $this->manual = true;
+ $this->template_base = WC()->plugin_path() . '/includes/react-admin/emails/';
+ $this->template_html = 'html-admin-report-export-download.php';
+ $this->template_plain = 'plain-admin-report-export-download.php';
+ $this->template_block_content = 'block-content-admin-report-export-download.php';
/**
* Used to customise report email labels.
@@ -91,14 +96,53 @@ class ReportCSVEmail extends \WC_Email {
}
/**
- * This email has no user-facing settings.
+ * Initialise settings form fields.
+ *
+ * The email has no on/off or format setting: an emailed export has no other way to reach the merchant.
+ * Its block design doesn't use the heading or additional content, so those settings are left out too.
*/
- public function init_form_fields() {}
+ public function init_form_fields() {
+ parent::init_form_fields();
+ unset( $this->form_fields['enabled'], $this->form_fields['email_type'], $this->form_fields['heading'], $this->form_fields['additional_content'] );
+ }
+
+ /**
+ * The email is always sent when a merchant exports a report by email.
+ *
+ * @return bool
+ */
+ public function is_enabled() {
+ /**
+ * Filters whether the email is enabled and will be sent.
+ *
+ * @since 2.0.0
+ *
+ * @param bool $enabled Whether the email is enabled.
+ * @param mixed $object The object the email is about.
+ * @param \WC_Email $email The email.
+ */
+ return apply_filters( 'woocommerce_email_enabled_' . $this->id, true, $this->object, $this );
+ }
/**
- * This email has no user-facing settings.
+ * Fill the email with a sample Orders report for the email preview.
+ *
+ * @since 11.5.0
+ * @return void
*/
- public function init_settings() {}
+ public function prepare_for_preview() {
+ $this->report_type = $this->report_labels['orders'] ?? __( 'Orders', 'woocommerce' );
+ $this->placeholders['{report_name}'] = $this->report_type;
+ $this->download_url = 'https://example.com/report-download';
+ $this->set_report_date_range(
+ ReportExporter::get_export_date_range_label(
+ array(
+ 'after' => wp_date( 'Y-m-d', strtotime( 'first day of last month' ) ),
+ 'before' => wp_date( 'Y-m-d', strtotime( 'last day of last month' ) ),
+ )
+ )
+ );
+ }
/**
* Return email type.
@@ -157,6 +201,28 @@ class ReportCSVEmail extends \WC_Email {
);
}
+ /**
+ * Get block editor email template content.
+ *
+ * @return string
+ */
+ public function get_block_editor_email_template_content() {
+ return wc_get_template_html(
+ $this->template_block_content,
+ array(
+ 'report_name' => $this->report_type,
+ 'date_range' => $this->report_date_range,
+ 'download_url' => $this->download_url,
+ 'sent_to_admin' => true,
+ 'plain_text' => false,
+ 'email' => $this,
+ 'retention' => $this->get_retention_period(),
+ ),
+ '',
+ $this->template_base
+ );
+ }
+
/**
* Get content plain.
*
diff --git a/plugins/woocommerce/src/Internal/Admin/EmailPreview/EmailPreview.php b/plugins/woocommerce/src/Internal/Admin/EmailPreview/EmailPreview.php
index d8eeeaa9d0a..fd21e94250f 100644
--- a/plugins/woocommerce/src/Internal/Admin/EmailPreview/EmailPreview.php
+++ b/plugins/woocommerce/src/Internal/Admin/EmailPreview/EmailPreview.php
@@ -7,6 +7,7 @@ declare( strict_types=1 );
namespace Automattic\WooCommerce\Internal\Admin\EmailPreview;
+use Automattic\WooCommerce\Admin\ReportCSVEmail;
use Automattic\WooCommerce\Internal\EmailEditor\WooContentProcessor;
use Automattic\WooCommerce\Enums\OrderStatus;
use Throwable;
@@ -231,6 +232,9 @@ class EmailPreview {
if ( 'WC_Email_Customer_Refunded_Order' === $email_type ) {
$this->email->partial_refund = false;
}
+ if ( $this->email instanceof ReportCSVEmail ) {
+ $this->email->prepare_for_preview();
+ }
$this->email->set_object( $object );
}
$this->email->placeholders = array_merge(
diff --git a/plugins/woocommerce/src/Internal/EmailEditor/EmailApiController.php b/plugins/woocommerce/src/Internal/EmailEditor/EmailApiController.php
index 18367d7f68d..6eafed15c16 100644
--- a/plugins/woocommerce/src/Internal/EmailEditor/EmailApiController.php
+++ b/plugins/woocommerce/src/Internal/EmailEditor/EmailApiController.php
@@ -79,6 +79,7 @@ class EmailApiController {
return array(
'enabled' => is_null( $enabled ) ? $email->is_enabled() : 'yes' === $enabled,
'is_manual' => $email->is_manual(),
+ 'is_customer_email' => $email->is_customer_email(),
'subject' => $email->get_option( 'subject' ),
'subject_full' => $email->get_option( 'subject_full' ), // For customer_refunded_order email type because it has two different subjects.
'subject_partial' => $email->get_option( 'subject_partial' ),
diff --git a/plugins/woocommerce/src/Internal/EmailEditor/WCTransactionalEmails/WCTransactionalEmails.php b/plugins/woocommerce/src/Internal/EmailEditor/WCTransactionalEmails/WCTransactionalEmails.php
index 6670076b56e..8d78c9ee87e 100644
--- a/plugins/woocommerce/src/Internal/EmailEditor/WCTransactionalEmails/WCTransactionalEmails.php
+++ b/plugins/woocommerce/src/Internal/EmailEditor/WCTransactionalEmails/WCTransactionalEmails.php
@@ -3,6 +3,8 @@ declare(strict_types=1);
namespace Automattic\WooCommerce\Internal\EmailEditor\WCTransactionalEmails;
+use Automattic\WooCommerce\Internal\StockNotifications\Emails\EmailManager;
+use Automattic\WooCommerce\Internal\StockNotifications\StockNotifications;
use Automattic\WooCommerce\Utilities\FeaturesUtil;
/**
@@ -21,6 +23,7 @@ class WCTransactionalEmails {
*/
public static $core_transactional_emails = array(
'admin_payment_gateway_enabled',
+ 'admin_report_export_download',
'cancelled_order',
'customer_cancelled_order',
'customer_completed_order',
@@ -71,6 +74,15 @@ class WCTransactionalEmails {
$emails = array_merge( $emails, $fulfillment_emails );
}
+ if ( FeaturesUtil::feature_is_enabled( 'order_withdrawal' ) ) {
+ $emails[] = 'customer_order_withdrawal_requested';
+ $emails[] = 'order_withdrawal_requested';
+ }
+
+ if ( StockNotifications::is_enabled_before_init() ) {
+ $emails = array_merge( $emails, EmailManager::$email_ids );
+ }
+
return $emails;
}
diff --git a/plugins/woocommerce/src/Internal/StockNotifications/Emails/CustomerStockNotificationEmail.php b/plugins/woocommerce/src/Internal/StockNotifications/Emails/CustomerStockNotificationEmail.php
index d616ac02af6..eb1ffe36e49 100644
--- a/plugins/woocommerce/src/Internal/StockNotifications/Emails/CustomerStockNotificationEmail.php
+++ b/plugins/woocommerce/src/Internal/StockNotifications/Emails/CustomerStockNotificationEmail.php
@@ -41,6 +41,8 @@ class CustomerStockNotificationEmail extends WC_Email {
// Call parent constructor.
parent::__construct();
+
+ $this->template_block_content = 'emails/block/general-block-content-for-stock-notification-emails.php';
}
/**
@@ -118,6 +120,32 @@ class CustomerStockNotificationEmail extends WC_Email {
);
}
+ /**
+ * Get block editor email template content.
+ *
+ * @return string
+ */
+ public function get_block_editor_email_template_content() {
+ $notification = $this->object;
+ if ( ! $notification instanceof Notification ) {
+ return '';
+ }
+
+ return wc_get_template_html(
+ $this->template_block_content,
+ array_merge(
+ $this->get_additional_template_args(),
+ array(
+ 'notification' => $notification,
+ 'product' => $notification->get_product(),
+ 'intro_content' => $this->get_intro_content(),
+ 'plain_text' => false,
+ 'email' => $this,
+ ),
+ ),
+ );
+ }
+
/**
* Get content plain.
*
diff --git a/plugins/woocommerce/src/Internal/StockNotifications/Emails/CustomerStockNotificationVerifiedEmail.php b/plugins/woocommerce/src/Internal/StockNotifications/Emails/CustomerStockNotificationVerifiedEmail.php
index 5e0bf9aadc6..d98ce8fc371 100644
--- a/plugins/woocommerce/src/Internal/StockNotifications/Emails/CustomerStockNotificationVerifiedEmail.php
+++ b/plugins/woocommerce/src/Internal/StockNotifications/Emails/CustomerStockNotificationVerifiedEmail.php
@@ -36,6 +36,8 @@ class CustomerStockNotificationVerifiedEmail extends WC_Email {
// Call parent constructor.
parent::__construct();
+
+ $this->template_block_content = 'emails/block/general-block-content-for-stock-notification-emails.php';
}
/**
@@ -113,6 +115,32 @@ class CustomerStockNotificationVerifiedEmail extends WC_Email {
);
}
+ /**
+ * Get block editor email template content.
+ *
+ * @return string
+ */
+ public function get_block_editor_email_template_content() {
+ $notification = $this->object;
+ if ( ! $notification instanceof Notification ) {
+ return '';
+ }
+
+ return wc_get_template_html(
+ $this->template_block_content,
+ array_merge(
+ $this->get_additional_template_args(),
+ array(
+ 'notification' => $notification,
+ 'product' => $notification->get_product(),
+ 'intro_content' => $this->get_intro_content(),
+ 'plain_text' => false,
+ 'email' => $this,
+ ),
+ ),
+ );
+ }
+
/**
* Get content plain.
*
diff --git a/plugins/woocommerce/src/Internal/StockNotifications/Emails/CustomerStockNotificationVerifyEmail.php b/plugins/woocommerce/src/Internal/StockNotifications/Emails/CustomerStockNotificationVerifyEmail.php
index b59ff6fe9e6..4ab9eef6681 100644
--- a/plugins/woocommerce/src/Internal/StockNotifications/Emails/CustomerStockNotificationVerifyEmail.php
+++ b/plugins/woocommerce/src/Internal/StockNotifications/Emails/CustomerStockNotificationVerifyEmail.php
@@ -37,6 +37,8 @@ class CustomerStockNotificationVerifyEmail extends WC_Email {
// Call parent constructor.
parent::__construct();
+
+ $this->template_block_content = 'emails/block/general-block-content-for-stock-notification-emails.php';
}
/**
@@ -114,6 +116,32 @@ class CustomerStockNotificationVerifyEmail extends WC_Email {
);
}
+ /**
+ * Get block editor email template content.
+ *
+ * @return string
+ */
+ public function get_block_editor_email_template_content() {
+ $notification = $this->object;
+ if ( ! $notification instanceof Notification ) {
+ return '';
+ }
+
+ return wc_get_template_html(
+ $this->template_block_content,
+ array_merge(
+ $this->get_additional_template_args(),
+ array(
+ 'notification' => $notification,
+ 'product' => $notification->get_product(),
+ 'intro_content' => $this->get_intro_content(),
+ 'plain_text' => false,
+ 'email' => $this,
+ ),
+ ),
+ );
+ }
+
/**
* Get content plain.
*
diff --git a/plugins/woocommerce/templates/emails/block/admin-order-withdrawal-requested.php b/plugins/woocommerce/templates/emails/block/admin-order-withdrawal-requested.php
new file mode 100644
index 00000000000..47625dd8532
--- /dev/null
+++ b/plugins/woocommerce/templates/emails/block/admin-order-withdrawal-requested.php
@@ -0,0 +1,40 @@
+<?php
+/**
+ * Admin order withdrawal request email (initial block version)
+ *
+ * This template can be overridden by editing it in the WooCommerce email editor.
+ *
+ * HOWEVER, on occasion WooCommerce will need to update template files and you
+ * (the theme developer) will need to copy the new files to your theme to
+ * maintain compatibility. We try to do this as little as possible, but it does
+ * happen. When this occurs the version of the template file will be bumped and
+ * the readme will list any important changes.
+ *
+ * @see https://woocommerce.com/document/template-structure/
+ * @package WooCommerce\Templates\Emails\Block
+ * @version 11.5.0
+ */
+
+use Automattic\WooCommerce\Internal\EmailEditor\BlockEmailRenderer;
+
+defined( 'ABSPATH' ) || exit;
+
+// phpcs:disable Squiz.PHP.EmbeddedPhp.ContentBeforeOpen -- removed to prevent empty new lines.
+// phpcs:disable Squiz.PHP.EmbeddedPhp.ContentAfterEnd -- removed to prevent empty new lines.
+?>
+
+<!-- wp:heading -->
+<h2 class="wp-block-heading"><?php echo esc_html__( 'Order withdrawal request received', 'woocommerce' ); ?></h2>
+<!-- /wp:heading -->
+
+<!-- wp:paragraph -->
+<p><?php echo esc_html__( 'A customer submitted an order withdrawal request.', 'woocommerce' ); ?></p>
+<!-- /wp:paragraph -->
+
+<!-- wp:woocommerce/email-content {"lock":{"move":false,"remove":true}} -->
+<div class="wp-block-woocommerce-email-content"> <?php echo esc_html( BlockEmailRenderer::WOO_EMAIL_CONTENT_PLACEHOLDER ); ?> </div>
+<!-- /wp:woocommerce/email-content -->
+
+<!-- wp:paragraph -->
+<p><?php echo esc_html__( 'Review the request details and contact the customer about next steps.', 'woocommerce' ); ?></p>
+<!-- /wp:paragraph -->
diff --git a/plugins/woocommerce/templates/emails/block/customer-order-withdrawal-requested.php b/plugins/woocommerce/templates/emails/block/customer-order-withdrawal-requested.php
new file mode 100644
index 00000000000..18bbf30d731
--- /dev/null
+++ b/plugins/woocommerce/templates/emails/block/customer-order-withdrawal-requested.php
@@ -0,0 +1,40 @@
+<?php
+/**
+ * Customer order withdrawal request email (initial block version)
+ *
+ * This template can be overridden by editing it in the WooCommerce email editor.
+ *
+ * HOWEVER, on occasion WooCommerce will need to update template files and you
+ * (the theme developer) will need to copy the new files to your theme to
+ * maintain compatibility. We try to do this as little as possible, but it does
+ * happen. When this occurs the version of the template file will be bumped and
+ * the readme will list any important changes.
+ *
+ * @see https://woocommerce.com/document/template-structure/
+ * @package WooCommerce\Templates\Emails\Block
+ * @version 11.5.0
+ */
+
+use Automattic\WooCommerce\Internal\EmailEditor\BlockEmailRenderer;
+
+defined( 'ABSPATH' ) || exit;
+
+// phpcs:disable Squiz.PHP.EmbeddedPhp.ContentBeforeOpen -- removed to prevent empty new lines.
+// phpcs:disable Squiz.PHP.EmbeddedPhp.ContentAfterEnd -- removed to prevent empty new lines.
+?>
+
+<!-- wp:heading -->
+<h2 class="wp-block-heading"><?php echo esc_html__( 'We received your withdrawal request', 'woocommerce' ); ?></h2>
+<!-- /wp:heading -->
+
+<!-- wp:paragraph -->
+<p><?php echo esc_html__( 'We have received your request to withdraw from the order below.', 'woocommerce' ); ?></p>
+<!-- /wp:paragraph -->
+
+<!-- wp:woocommerce/email-content {"lock":{"move":false,"remove":true}} -->
+<div class="wp-block-woocommerce-email-content"> <?php echo esc_html( BlockEmailRenderer::WOO_EMAIL_CONTENT_PLACEHOLDER ); ?> </div>
+<!-- /wp:woocommerce/email-content -->
+
+<!-- wp:paragraph -->
+<p><?php echo esc_html__( 'We will review your request and contact you about next steps, including any refund due.', 'woocommerce' ); ?></p>
+<!-- /wp:paragraph -->
diff --git a/plugins/woocommerce/templates/emails/block/customer-stock-notification-verified.php b/plugins/woocommerce/templates/emails/block/customer-stock-notification-verified.php
new file mode 100644
index 00000000000..d8866966131
--- /dev/null
+++ b/plugins/woocommerce/templates/emails/block/customer-stock-notification-verified.php
@@ -0,0 +1,36 @@
+<?php
+/**
+ * Back in stock sign-up confirmation email (initial block version)
+ *
+ * This template can be overridden by editing it in the WooCommerce email editor.
+ *
+ * HOWEVER, on occasion WooCommerce will need to update template files and you
+ * (the theme developer) will need to copy the new files to your theme to
+ * maintain compatibility. We try to do this as little as possible, but it does
+ * happen. When this occurs the version of the template file will be bumped and
+ * the readme will list any important changes.
+ *
+ * @see https://woocommerce.com/document/template-structure/
+ * @package WooCommerce\Templates\Emails\Block
+ * @version 11.5.0
+ */
+
+use Automattic\WooCommerce\Internal\EmailEditor\BlockEmailRenderer;
+
+defined( 'ABSPATH' ) || exit;
+
+// phpcs:disable Squiz.PHP.EmbeddedPhp.ContentBeforeOpen -- removed to prevent empty new lines.
+// phpcs:disable Squiz.PHP.EmbeddedPhp.ContentAfterEnd -- removed to prevent empty new lines.
+?>
+
+<!-- wp:heading -->
+<h2 class="wp-block-heading"><?php echo esc_html__( 'Sign-up successful', 'woocommerce' ); ?></h2>
+<!-- /wp:heading -->
+
+<!-- wp:woocommerce/email-content {"lock":{"move":false,"remove":true}} -->
+<div class="wp-block-woocommerce-email-content"> <?php echo esc_html( BlockEmailRenderer::WOO_EMAIL_CONTENT_PLACEHOLDER ); ?> </div>
+<!-- /wp:woocommerce/email-content -->
+
+<!-- wp:paragraph -->
+<p><?php echo esc_html__( 'Thanks for shopping with us.', 'woocommerce' ); ?></p>
+<!-- /wp:paragraph -->
diff --git a/plugins/woocommerce/templates/emails/block/customer-stock-notification-verify.php b/plugins/woocommerce/templates/emails/block/customer-stock-notification-verify.php
new file mode 100644
index 00000000000..4fe263140f3
--- /dev/null
+++ b/plugins/woocommerce/templates/emails/block/customer-stock-notification-verify.php
@@ -0,0 +1,36 @@
+<?php
+/**
+ * Back in stock sign-up verification email (initial block version)
+ *
+ * This template can be overridden by editing it in the WooCommerce email editor.
+ *
+ * HOWEVER, on occasion WooCommerce will need to update template files and you
+ * (the theme developer) will need to copy the new files to your theme to
+ * maintain compatibility. We try to do this as little as possible, but it does
+ * happen. When this occurs the version of the template file will be bumped and
+ * the readme will list any important changes.
+ *
+ * @see https://woocommerce.com/document/template-structure/
+ * @package WooCommerce\Templates\Emails\Block
+ * @version 11.5.0
+ */
+
+use Automattic\WooCommerce\Internal\EmailEditor\BlockEmailRenderer;
+
+defined( 'ABSPATH' ) || exit;
+
+// phpcs:disable Squiz.PHP.EmbeddedPhp.ContentBeforeOpen -- removed to prevent empty new lines.
+// phpcs:disable Squiz.PHP.EmbeddedPhp.ContentAfterEnd -- removed to prevent empty new lines.
+?>
+
+<!-- wp:heading -->
+<h2 class="wp-block-heading"><?php echo esc_html__( 'Confirm sign-up', 'woocommerce' ); ?></h2>
+<!-- /wp:heading -->
+
+<!-- wp:woocommerce/email-content {"lock":{"move":false,"remove":true}} -->
+<div class="wp-block-woocommerce-email-content"> <?php echo esc_html( BlockEmailRenderer::WOO_EMAIL_CONTENT_PLACEHOLDER ); ?> </div>
+<!-- /wp:woocommerce/email-content -->
+
+<!-- wp:paragraph -->
+<p><?php echo esc_html__( 'Thanks for shopping with us.', 'woocommerce' ); ?></p>
+<!-- /wp:paragraph -->
diff --git a/plugins/woocommerce/templates/emails/block/customer-stock-notification.php b/plugins/woocommerce/templates/emails/block/customer-stock-notification.php
new file mode 100644
index 00000000000..de715b368d4
--- /dev/null
+++ b/plugins/woocommerce/templates/emails/block/customer-stock-notification.php
@@ -0,0 +1,36 @@
+<?php
+/**
+ * Back in stock notification email (initial block version)
+ *
+ * This template can be overridden by editing it in the WooCommerce email editor.
+ *
+ * HOWEVER, on occasion WooCommerce will need to update template files and you
+ * (the theme developer) will need to copy the new files to your theme to
+ * maintain compatibility. We try to do this as little as possible, but it does
+ * happen. When this occurs the version of the template file will be bumped and
+ * the readme will list any important changes.
+ *
+ * @see https://woocommerce.com/document/template-structure/
+ * @package WooCommerce\Templates\Emails\Block
+ * @version 11.5.0
+ */
+
+use Automattic\WooCommerce\Internal\EmailEditor\BlockEmailRenderer;
+
+defined( 'ABSPATH' ) || exit;
+
+// phpcs:disable Squiz.PHP.EmbeddedPhp.ContentBeforeOpen -- removed to prevent empty new lines.
+// phpcs:disable Squiz.PHP.EmbeddedPhp.ContentAfterEnd -- removed to prevent empty new lines.
+?>
+
+<!-- wp:heading -->
+<h2 class="wp-block-heading"><?php echo esc_html__( 'It\'s back in stock!', 'woocommerce' ); ?></h2>
+<!-- /wp:heading -->
+
+<!-- wp:woocommerce/email-content {"lock":{"move":false,"remove":true}} -->
+<div class="wp-block-woocommerce-email-content"> <?php echo esc_html( BlockEmailRenderer::WOO_EMAIL_CONTENT_PLACEHOLDER ); ?> </div>
+<!-- /wp:woocommerce/email-content -->
+
+<!-- wp:paragraph -->
+<p><?php echo esc_html__( 'Thanks for shopping with us.', 'woocommerce' ); ?></p>
+<!-- /wp:paragraph -->
diff --git a/plugins/woocommerce/templates/emails/block/general-block-content-for-order-withdrawal-emails.php b/plugins/woocommerce/templates/emails/block/general-block-content-for-order-withdrawal-emails.php
new file mode 100644
index 00000000000..4508907cf44
--- /dev/null
+++ b/plugins/woocommerce/templates/emails/block/general-block-content-for-order-withdrawal-emails.php
@@ -0,0 +1,54 @@
+<?php
+/**
+ * General block content for order withdrawal emails
+ *
+ * Note: This template is only used in the order withdrawal emails.
+ *
+ * Used to render information for the email editor WooCommerce content block (BlockEmailRenderer::WOO_EMAIL_CONTENT_PLACEHOLDER).
+ *
+ * @see https://woocommerce.com/document/template-structure/
+ * @package WooCommerce\Templates\Emails\Block
+ * @version 11.5.0
+ *
+ * @var array<string,string> $detail_rows Withdrawal request detail rows.
+ * @var \WC_Order|null $matched_order Matched order, if found. Admin email only.
+ * @var bool $outside_withdrawal_window Whether the matched order is outside the withdrawal window.
+ * @var string $withdrawal_window_warning Withdrawal window warning message.
+ * @var bool $sent_to_admin Whether sent to admin.
+ */
+
+defined( 'ABSPATH' ) || exit;
+
+if ( $sent_to_admin ) :
+ if ( $matched_order instanceof WC_Order ) : ?>
+ <p><?php esc_html_e( 'WooCommerce matched this request to an order and added an order note.', 'woocommerce' ); ?></p>
+ <?php else : ?>
+ <p><?php esc_html_e( 'WooCommerce could not match this request to an order automatically, so no order note was added.', 'woocommerce' ); ?></p>
+ <?php
+ endif;
+endif;
+?>
+
+<ul>
+ <?php foreach ( $detail_rows as $label => $value ) : ?>
+ <li><strong><?php echo esc_html( $label ); ?>:</strong> <?php echo nl2br( esc_html( $value ) ); ?></li>
+ <?php endforeach; ?>
+</ul>
+
+<?php if ( $sent_to_admin && $matched_order instanceof WC_Order ) : ?>
+ <?php if ( $outside_withdrawal_window ) : ?>
+ <p><?php echo esc_html( $withdrawal_window_warning ); ?></p>
+ <?php endif; ?>
+ <p>
+ <?php
+ printf(
+ /* translators: %d: order ID. */
+ esc_html__( 'Matched order ID: %d', 'woocommerce' ),
+ absint( $matched_order->get_id() )
+ );
+ ?>
+ </p>
+ <?php if ( '' !== $matched_order->get_edit_order_url() ) : ?>
+ <p><a href="<?php echo esc_url( $matched_order->get_edit_order_url() ); ?>"><?php esc_html_e( 'View matched order', 'woocommerce' ); ?></a></p>
+ <?php endif; ?>
+<?php endif; ?>
diff --git a/plugins/woocommerce/templates/emails/block/general-block-content-for-stock-notification-emails.php b/plugins/woocommerce/templates/emails/block/general-block-content-for-stock-notification-emails.php
new file mode 100644
index 00000000000..d306dca8eed
--- /dev/null
+++ b/plugins/woocommerce/templates/emails/block/general-block-content-for-stock-notification-emails.php
@@ -0,0 +1,94 @@
+<?php
+/**
+ * General block content for back-in-stock emails
+ *
+ * Note: This template is only used in the back-in-stock emails.
+ *
+ * Used to render information for the email editor WooCommerce content block (BlockEmailRenderer::WOO_EMAIL_CONTENT_PLACEHOLDER).
+ *
+ * @see https://woocommerce.com/document/template-structure/
+ * @package WooCommerce\Templates\Emails\Block
+ * @version 11.5.0
+ *
+ * @var Notification $notification Notification object.
+ * @var \WC_Product $product Product object.
+ * @var string $intro_content Introduction content.
+ * @var bool $plain_text Whether the email is plain text.
+ * @var \WC_Email $email Email object.
+ * @var bool $is_guest Whether the sign-up belongs to a guest. Not set for the verification email.
+ * @var string $account_link Link to manage notifications in the customer's account. Not set for the verification email.
+ * @var string $unsubscribe_link Unsubscribe link. Not set for the verification email.
+ * @var string $button_text Shop button text. Back-in-stock email only.
+ * @var string $button_link Shop button link. Back-in-stock email only.
+ * @var string $verification_button_text Confirm button text. Verification email only.
+ * @var string $verification_link Confirm button link. Verification email only.
+ * @var string $verification_expiration_threshold How long the confirm link stays valid. Verification email only.
+ */
+
+use Automattic\WooCommerce\Internal\StockNotifications\Notification;
+
+defined( 'ABSPATH' ) || exit;
+
+// phpcs:disable Squiz.PHP.EmbeddedPhp.ContentBeforeOpen -- removed to prevent empty new lines.
+// phpcs:disable Squiz.PHP.EmbeddedPhp.ContentAfterEnd -- removed to prevent empty new lines.
+
+echo wp_kses_post( wpautop( wptexturize( $intro_content ) ) );
+?>
+
+<div style="text-align: center;">
+ <?php
+ /**
+ * Hook: woocommerce_email_stock_notification_product.
+ *
+ * @since 10.2.0
+ *
+ * @hooked \Automattic\WooCommerce\Internal\StockNotifications\Emails\EmailTemplatesController::email_product_image - 10
+ * @hooked \Automattic\WooCommerce\Internal\StockNotifications\Emails\EmailTemplatesController::email_product_title - 20
+ * @hooked \Automattic\WooCommerce\Internal\StockNotifications\Emails\EmailTemplatesController::email_product_attributes - 30
+ * @hooked \Automattic\WooCommerce\Internal\StockNotifications\Emails\EmailTemplatesController::email_product_price - 40
+ */
+ do_action( 'woocommerce_email_stock_notification_product', $product, $notification, $plain_text, $email );
+
+ if ( isset( $verification_link ) ) {
+ wc_get_template(
+ 'emails/email-button.php',
+ array(
+ 'url' => $verification_link,
+ 'label' => $verification_button_text,
+ )
+ );
+ ?>
+ <p><?php
+ // translators: %s: how long the verification link stays valid, e.g. "60 minutes".
+ echo esc_html( sprintf( __( 'This link will remain active for %s.', 'woocommerce' ), $verification_expiration_threshold ) );
+ ?></p>
+ <?php
+ } elseif ( isset( $button_link ) ) {
+ wc_get_template(
+ 'emails/email-button.php',
+ array(
+ 'url' => $button_link,
+ 'label' => $button_text,
+ )
+ );
+ }
+ ?>
+</div>
+
+<p><?php
+if ( isset( $verification_link ) ) {
+ esc_html_e( 'You have received this message because your e-mail address was used to sign up for stock notifications on our store. Wasn\'t you? Please get in touch with us if you keep receiving these messages.', 'woocommerce' );
+} else {
+ esc_html_e( 'You have received this message because your e-mail address was used to sign up for stock notifications on our store.', 'woocommerce' );
+ echo ' ';
+ if ( ! $is_guest && $account_link ) {
+ $account_link_tag = sprintf( '<a href="%1$s">%2$s</a>', esc_url( $account_link ), esc_html_x( 'click here', 'account management cta for stock notifications for existing customers', 'woocommerce' ) );
+ // translators: %s: "click here" link to the customer's account.
+ echo wp_kses_post( sprintf( __( 'To manage your notifications, %s to log in to your account.', 'woocommerce' ), $account_link_tag ) );
+ } else {
+ $unsubscribe_link_tag = sprintf( '<a href="%1$s">%2$s</a>', esc_url( $unsubscribe_link ), esc_html_x( 'click here', 'unsubscribe cta for stock notifications for guests', 'woocommerce' ) );
+ // translators: %s: "click here" unsubscribe link.
+ echo wp_kses_post( sprintf( __( 'To stop receiving these messages, %s to unsubscribe.', 'woocommerce' ), $unsubscribe_link_tag ) );
+ }
+}
+?></p>
diff --git a/plugins/woocommerce/tests/php/includes/emails/class-wc-email-order-withdrawal-block-email-test.php b/plugins/woocommerce/tests/php/includes/emails/class-wc-email-order-withdrawal-block-email-test.php
new file mode 100644
index 00000000000..f144385088c
--- /dev/null
+++ b/plugins/woocommerce/tests/php/includes/emails/class-wc-email-order-withdrawal-block-email-test.php
@@ -0,0 +1,147 @@
+<?php
+declare( strict_types = 1 );
+
+use Automattic\WooCommerce\EmailEditor\Bootstrap;
+use Automattic\WooCommerce\EmailEditor\Email_Editor_Container;
+use Automattic\WooCommerce\EmailEditor\Engine\Dependency_Check;
+use Automattic\WooCommerce\Internal\EmailEditor\Integration;
+use Automattic\WooCommerce\Internal\EmailEditor\Package;
+use Automattic\WooCommerce\Internal\EmailEditor\WCTransactionalEmails\WCTransactionalEmails;
+use Automattic\WooCommerce\Internal\OrderWithdrawal\OrderWithdrawalFormProcessor;
+
+/**
+ * Block email editor versions of the order withdrawal emails.
+ *
+ * @covers WC_Email_Customer_Order_Withdrawal_Requested
+ * @covers WC_Email_Order_Withdrawal_Requested
+ */
+class WC_Email_Order_Withdrawal_Block_Email_Test extends \WC_Unit_Test_Case {
+
+ /**
+ * Turn on the block email editor and the order withdrawal feature, and load the email classes.
+ */
+ public function setUp(): void {
+ parent::setUp();
+
+ update_option( 'woocommerce_feature_block_email_editor_enabled', 'yes' );
+ update_option( 'woocommerce_feature_order_withdrawal_enabled', 'yes' );
+
+ $bootstrap = \WC_Unit_Tests_Bootstrap::instance();
+ require_once $bootstrap->plugin_dir . '/includes/emails/class-wc-email.php';
+ require_once $bootstrap->plugin_dir . '/includes/emails/class-wc-email-customer-order-withdrawal-requested.php';
+ require_once $bootstrap->plugin_dir . '/includes/emails/class-wc-email-order-withdrawal-requested.php';
+
+ wc_get_container()->get( Package::class )->init();
+ wc_get_container()->get( Integration::class )->initialize();
+ Email_Editor_Container::container()->get( Bootstrap::class )->initialize();
+ }
+
+ /**
+ * @testdox The withdrawal emails are listed in the block email editor only when the order withdrawal feature is on.
+ * @testWith ["yes", true]
+ * ["no", false]
+ *
+ * @param string $feature_enabled Value of the order withdrawal feature option.
+ * @param bool $expected_listed Whether the withdrawal emails should be listed.
+ */
+ public function test_withdrawal_emails_are_listed_with_the_feature( string $feature_enabled, bool $expected_listed ): void {
+ update_option( 'woocommerce_feature_order_withdrawal_enabled', $feature_enabled );
+
+ $emails = WCTransactionalEmails::get_core_transactional_emails();
+
+ $this->assertSame( $expected_listed, in_array( 'customer_order_withdrawal_requested', $emails, true ) );
+ $this->assertSame( $expected_listed, in_array( 'order_withdrawal_requested', $emails, true ) );
+ }
+
+ /**
+ * @testdox The customer email is sent in the block design with the request details and without an order table.
+ */
+ public function test_customer_email_is_sent_in_block_design(): void {
+ $this->skip_if_unsupported_environment();
+
+ $email = new WC_Email_Customer_Order_Withdrawal_Requested();
+ $email->object = (object) $this->get_withdrawal_data();
+ $email->withdrawal_data = $this->get_withdrawal_data();
+ $email->submitted_at = 1767225600;
+
+ $content = $email->get_content();
+
+ $this->assertStringContainsString( 'We received your withdrawal request', $content );
+ $this->assertStringContainsString( 'Please take back the blue mug.', $content );
+ $this->assertStringContainsString( 'Specific items only', $content );
+ $this->assertStringNotContainsString( 'email-order-details', $content );
+ $this->assertStringContainsString( '. All Rights Reserved.', $content, 'Only the block email template renders this footer.' );
+ }
+
+ /**
+ * @testdox The customer email block content shows the request details, and no order table in the preview, where the email object is an order.
+ */
+ public function test_customer_block_content_has_no_order_table_for_an_order(): void {
+ $order = wc_create_order();
+
+ $email = new WC_Email_Customer_Order_Withdrawal_Requested();
+ $email->object = $order;
+ $email->withdrawal_data = $this->get_withdrawal_data();
+ $email->submitted_at = 1767225600;
+
+ $content = $email->get_block_editor_email_template_content();
+
+ $this->assertStringContainsString( 'Please take back the blue mug.', $content );
+ $this->assertStringNotContainsString( 'email-order-details', $content );
+ }
+
+ /**
+ * @testdox The admin email is sent in the block design and says whether the request was matched to an order.
+ * @testWith [true, "WooCommerce matched this request to an order and added an order note."]
+ * [false, "WooCommerce could not match this request to an order automatically, so no order note was added."]
+ *
+ * @param bool $matched Whether the request was matched to an order.
+ * @param string $expected_text Sentence the email should contain.
+ */
+ public function test_admin_email_is_sent_in_block_design( bool $matched, string $expected_text ): void {
+ $this->skip_if_unsupported_environment();
+
+ $order = $matched ? wc_create_order() : null;
+
+ $email = new WC_Email_Order_Withdrawal_Requested();
+ $email->object = $order ? $order : (object) $this->get_withdrawal_data();
+ $email->withdrawal_data = $this->get_withdrawal_data();
+ $email->matched_order = $order;
+ $email->submitted_at = 1767225600;
+
+ $content = $email->get_content();
+
+ $this->assertStringContainsString( 'Order withdrawal request received', $content );
+ $this->assertStringContainsString( $expected_text, $content );
+ $this->assertStringContainsString( 'Please take back the blue mug.', $content );
+ $this->assertStringContainsString( '. All Rights Reserved.', $content, 'Only the block email template renders this footer.' );
+ if ( $order ) {
+ $this->assertStringContainsString( 'Matched order ID: ' . $order->get_id(), $content );
+ }
+ }
+
+ /**
+ * Withdrawal form data as the form processor normalizes it.
+ *
+ * @return array<string,string>
+ */
+ private function get_withdrawal_data(): array {
+ return array(
+ OrderWithdrawalFormProcessor::FIELD_FIRST_NAME => 'Jane',
+ OrderWithdrawalFormProcessor::FIELD_LAST_NAME => 'Doe',
+ OrderWithdrawalFormProcessor::FIELD_EMAIL => 'jane@example.com',
+ OrderWithdrawalFormProcessor::FIELD_ORDER_NUMBER => '1234',
+ OrderWithdrawalFormProcessor::FIELD_WITHDRAWAL_TYPE => OrderWithdrawalFormProcessor::WITHDRAWAL_TYPE_SPECIFIC,
+ OrderWithdrawalFormProcessor::FIELD_ADDITIONAL_DETAILS => 'Please take back the blue mug.',
+ );
+ }
+
+ /**
+ * Skip when the test environment can't run the block email editor.
+ */
+ private function skip_if_unsupported_environment(): void {
+ if ( ! Email_Editor_Container::container()->get( Dependency_Check::class )->are_dependencies_met() ) {
+ $this->markTestSkipped( 'The test environment does not meet the block email editor requirements.' );
+ }
+ }
+}
diff --git a/plugins/woocommerce/tests/php/src/Admin/ReportCSVEmailTest.php b/plugins/woocommerce/tests/php/src/Admin/ReportCSVEmailTest.php
index 038690be869..28142541f1e 100644
--- a/plugins/woocommerce/tests/php/src/Admin/ReportCSVEmailTest.php
+++ b/plugins/woocommerce/tests/php/src/Admin/ReportCSVEmailTest.php
@@ -11,6 +11,12 @@ namespace Automattic\WooCommerce\Tests\Admin;
use Automattic\WooCommerce\Admin\ReportCSVEmail;
use Automattic\WooCommerce\Admin\ReportExporter;
+use Automattic\WooCommerce\EmailEditor\Bootstrap;
+use Automattic\WooCommerce\EmailEditor\Email_Editor_Container;
+use Automattic\WooCommerce\EmailEditor\Engine\Dependency_Check;
+use Automattic\WooCommerce\Internal\EmailEditor\Integration;
+use Automattic\WooCommerce\Internal\Admin\EmailPreview\EmailPreview;
+use Automattic\WooCommerce\Internal\EmailEditor\Package;
use WC_Unit_Test_Case;
/**
@@ -173,4 +179,128 @@ class ReportCSVEmailTest extends WC_Unit_Test_Case {
return $sent ? $sent['subject'] : '';
}
+
+ /**
+ * @testdox The email is listed with the other emails only when the block email editor is on.
+ * @testWith ["yes", true]
+ * ["no", false]
+ *
+ * @param string $block_editor_enabled Value of the block email editor feature option.
+ * @param bool $expected_listed Whether the email should be listed.
+ */
+ public function test_email_is_listed_only_with_the_block_editor( string $block_editor_enabled, bool $expected_listed ): void {
+ update_option( 'woocommerce_feature_block_email_editor_enabled', $block_editor_enabled );
+
+ $emails = new \WC_Emails();
+
+ $this->assertSame( $expected_listed, isset( $emails->emails['WC_Email_Admin_Report_Export_Download'] ) );
+ }
+
+ /**
+ * @testdox With the block email editor on, the email is sent in the block design with the download link, date range and retention period.
+ */
+ public function test_email_is_sent_in_block_design(): void {
+ $this->enable_block_email_editor();
+
+ $content = $this->create_email( 'June 1, 2026 - June 30, 2026' )->get_content();
+
+ $this->assertStringContainsString( 'Your Report Download', $content );
+ $this->assertStringContainsString( 'Download your Orders Report', $content );
+ $this->assertStringContainsString( 'filename=wc-orders-report-export', $content );
+ $this->assertStringContainsString( 'Date range: June 1, 2026 - June 30, 2026', $content );
+ $this->assertStringContainsString( 'This link is available for ' . human_time_diff( 0, ReportExporter::EXPORT_RETENTION_PERIOD ) . '.', $content );
+ $this->assertStringContainsString( '. All Rights Reserved.', $content, 'Only the block email template renders this footer.' );
+ }
+
+ /**
+ * @testdox The email is always sent, even with an "off" value saved, because emailed exports have no other way to reach the merchant.
+ * @testWith ["yes"]
+ * ["no"]
+ *
+ * @param string $block_editor_enabled Value of the block email editor feature option.
+ */
+ public function test_email_is_always_sent( string $block_editor_enabled ): void {
+ update_option( 'woocommerce_feature_block_email_editor_enabled', $block_editor_enabled );
+ update_option( 'woocommerce_admin_report_export_download_settings', array( 'enabled' => 'no' ) );
+ $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) );
+ $mailer = tests_retrieve_phpmailer_instance();
+ $before = count( $mailer->mock_sent );
+
+ ( new ReportCSVEmail() )->trigger( $user_id, 'orders', 'https://example.org/?action=woocommerce_admin_download_report_csv&filename=wc-orders-report-export' );
+
+ $this->assertSame( 1, count( $mailer->mock_sent ) - $before );
+ }
+
+ /**
+ * @testdox The email reports itself enabled, and extensions can still change that through the woocommerce_email_enabled_ filter.
+ */
+ public function test_is_enabled_runs_the_email_enabled_filter(): void {
+ $email = new ReportCSVEmail();
+ $this->assertTrue( $email->is_enabled() );
+
+ add_filter( 'woocommerce_email_enabled_admin_report_export_download', '__return_false' );
+ $enabled = $email->is_enabled();
+ remove_filter( 'woocommerce_email_enabled_admin_report_export_download', '__return_false' );
+
+ $this->assertFalse( $enabled );
+ }
+
+ /**
+ * @testdox The email has no settings its block design doesn't use: on/off, format, heading and additional content.
+ */
+ public function test_email_has_only_the_settings_its_block_design_uses(): void {
+ $fields = ( new ReportCSVEmail() )->get_form_fields();
+
+ $this->assertArrayHasKey( 'subject', $fields );
+ foreach ( array( 'enabled', 'email_type', 'heading', 'additional_content' ) as $key ) {
+ $this->assertArrayNotHasKey( $key, $fields, "The \"$key\" setting has no effect on this email." );
+ }
+ }
+
+ /**
+ * @testdox The email is manual, so the email list and the editor show it as "Manual" without an on/off control.
+ */
+ public function test_email_is_manual(): void {
+ $this->assertTrue( ( new ReportCSVEmail() )->is_manual() );
+ }
+
+ /**
+ * @testdox The email preview shows a sample Orders report instead of an empty report name.
+ */
+ public function test_preview_shows_a_sample_report(): void {
+ $this->enable_block_email_editor();
+ $this->reset_mailer();
+
+ try {
+ $preview = new EmailPreview();
+ $preview->set_email_type( ReportCSVEmail::class );
+
+ $this->assertStringNotContainsString( '{report_name}', $preview->get_subject() );
+ $this->assertStringContainsString( 'Download your Orders Report', $preview->get_email()->get_block_editor_email_template_content() );
+ } finally {
+ $this->reset_mailer();
+ }
+ }
+
+ /**
+ * Turn on the block email editor and set it up, or skip when the environment can't run it.
+ */
+ private function enable_block_email_editor(): void {
+ update_option( 'woocommerce_feature_block_email_editor_enabled', 'yes' );
+ wc_get_container()->get( Package::class )->init();
+ wc_get_container()->get( Integration::class )->initialize();
+ Email_Editor_Container::container()->get( Bootstrap::class )->initialize();
+ if ( ! Email_Editor_Container::container()->get( Dependency_Check::class )->are_dependencies_met() ) {
+ $this->markTestSkipped( 'The test environment does not meet the block email editor requirements.' );
+ }
+ }
+
+ /**
+ * Reset the WC_Emails singleton, so the next WC()->mailer() call builds its list of emails again.
+ */
+ private function reset_mailer(): void {
+ $instance = new \ReflectionProperty( \WC_Emails::class, 'instance' );
+ $instance->setAccessible( true );
+ $instance->setValue( null, null );
+ }
}
diff --git a/plugins/woocommerce/tests/php/src/Internal/EmailEditor/EmailApiControllerTest.php b/plugins/woocommerce/tests/php/src/Internal/EmailEditor/EmailApiControllerTest.php
index 816d5cb600d..ab205d7f02a 100644
--- a/plugins/woocommerce/tests/php/src/Internal/EmailEditor/EmailApiControllerTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/EmailEditor/EmailApiControllerTest.php
@@ -309,6 +309,7 @@ class EmailApiControllerTest extends \WC_Unit_Test_Case {
)
);
$mock_email->method( 'supports_cc_bcc' )->willReturn( true );
+ $mock_email->method( 'is_customer_email' )->willReturn( true );
$mock_email->method( 'get_default_subject' )->willReturn( 'Default Subject' );
$mock_email->method( 'get_form_fields' )->willReturn(
array(
@@ -328,6 +329,7 @@ class EmailApiControllerTest extends \WC_Unit_Test_Case {
$result = $controller->get_email_data( $post_data );
$this->assertNull( $result['recipient'] );
$this->assertNull( $result['send_on_unpaid_timeout'] );
+ $this->assertTrue( $result['is_customer_email'], 'The editor needs this to say who receives an email without a recipient field.' );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/EmailEditor/WCTransactionalEmails/WCTransactionalEmailsTest.php b/plugins/woocommerce/tests/php/src/Internal/EmailEditor/WCTransactionalEmails/WCTransactionalEmailsTest.php
index 6e054e03df2..782dd51129a 100644
--- a/plugins/woocommerce/tests/php/src/Internal/EmailEditor/WCTransactionalEmails/WCTransactionalEmailsTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/EmailEditor/WCTransactionalEmails/WCTransactionalEmailsTest.php
@@ -4,6 +4,7 @@ declare( strict_types=1 );
namespace Automattic\WooCommerce\Tests\Internal\EmailEditor\WCTransactionalEmails;
+use Automattic\Jetpack\Constants;
use Automattic\WooCommerce\Internal\EmailEditor\WCTransactionalEmails\WCTransactionalEmails;
/**
@@ -69,6 +70,25 @@ class WCTransactionalEmailsTest extends \WC_Unit_Test_Case {
$this->assertNotContains( 'custom_email', $emails );
}
+ /**
+ * @testdox The back-in-stock emails are listed on a site that still turns the feature on with the alpha constant.
+ */
+ public function test_stock_notification_emails_are_listed_with_the_alpha_constant(): void {
+ update_option( 'woocommerce_feature_customer_stock_notifications_enabled', 'no' );
+ update_option( 'woocommerce_db_version', '11.1.0' );
+ Constants::set_constant( 'WOOCOMMERCE_BIS_ALPHA_ENABLED', true );
+
+ try {
+ $emails = WCTransactionalEmails::get_core_transactional_emails();
+ } finally {
+ Constants::clear_single_constant( 'WOOCOMMERCE_BIS_ALPHA_ENABLED' );
+ }
+
+ $this->assertContains( 'customer_stock_notification', $emails );
+ $this->assertContains( 'customer_stock_notification_verify', $emails );
+ $this->assertContains( 'customer_stock_notification_verified', $emails );
+ }
+
/**
* @testdox Deprecated init_email_templates() is a no-op that triggers a deprecation notice.
*/
diff --git a/plugins/woocommerce/tests/php/src/Internal/StockNotifications/Emails/StockNotificationBlockEmailsTests.php b/plugins/woocommerce/tests/php/src/Internal/StockNotifications/Emails/StockNotificationBlockEmailsTests.php
new file mode 100644
index 00000000000..647f9de3760
--- /dev/null
+++ b/plugins/woocommerce/tests/php/src/Internal/StockNotifications/Emails/StockNotificationBlockEmailsTests.php
@@ -0,0 +1,174 @@
+<?php
+
+declare( strict_types = 1 );
+namespace Automattic\WooCommerce\Tests\Internal\StockNotifications\Emails;
+
+use Automattic\WooCommerce\EmailEditor\Bootstrap;
+use Automattic\WooCommerce\EmailEditor\Email_Editor_Container;
+use Automattic\WooCommerce\EmailEditor\Engine\Dependency_Check;
+use Automattic\WooCommerce\Internal\EmailEditor\Integration;
+use Automattic\WooCommerce\Internal\EmailEditor\Package;
+use Automattic\WooCommerce\Internal\EmailEditor\WCTransactionalEmails\WCTransactionalEmails;
+use Automattic\WooCommerce\Internal\StockNotifications\Emails\CustomerStockNotificationEmail;
+use Automattic\WooCommerce\Internal\StockNotifications\Emails\CustomerStockNotificationVerifiedEmail;
+use Automattic\WooCommerce\Internal\StockNotifications\Emails\CustomerStockNotificationVerifyEmail;
+use Automattic\WooCommerce\Internal\StockNotifications\Emails\EmailTemplatesController;
+use Automattic\WooCommerce\Internal\StockNotifications\Enums\NotificationStatus;
+use Automattic\WooCommerce\Internal\StockNotifications\Frontend\MyAccountEndpoint;
+use Automattic\WooCommerce\Internal\StockNotifications\Notification;
+use Automattic\WooCommerce\Internal\StockNotifications\StockNotifications;
+use Automattic\WooCommerce\Tests\Internal\StockNotifications\StockNotificationsFeatureTrait;
+use WC_Helper_Product;
+
+/**
+ * Block email editor versions of the back-in-stock emails.
+ */
+class StockNotificationBlockEmailsTests extends \WC_Unit_Test_Case {
+
+ use StockNotificationsFeatureTrait;
+
+ /**
+ * Turn on the block email editor and the back-in-stock feature.
+ */
+ public function setUp(): void {
+ parent::setUp();
+ $this->enable_stock_notifications_feature();
+ update_option( 'woocommerce_feature_block_email_editor_enabled', 'yes' );
+
+ wc_get_container()->get( Package::class )->init();
+ wc_get_container()->get( Integration::class )->initialize();
+ Email_Editor_Container::container()->get( Bootstrap::class )->initialize();
+ ( new EmailTemplatesController() )->register_template_hooks();
+ }
+
+ /**
+ * Restore the feature option.
+ */
+ public function tearDown(): void {
+ $this->restore_stock_notifications_feature_option();
+ parent::tearDown();
+ WC()->query->init_query_vars();
+ }
+
+ /**
+ * @testdox The back-in-stock emails are listed in the block email editor only when the feature is on.
+ * @testWith ["yes", true]
+ * ["no", false]
+ *
+ * @param string $feature_enabled Value of the back-in-stock feature option.
+ * @param bool $expected_listed Whether the back-in-stock emails should be listed.
+ */
+ public function test_emails_are_listed_with_the_feature( string $feature_enabled, bool $expected_listed ): void {
+ update_option( StockNotifications::ENABLE_OPTION_NAME, $feature_enabled );
+
+ $emails = WCTransactionalEmails::get_core_transactional_emails();
+
+ $this->assertSame( $expected_listed, in_array( 'customer_stock_notification', $emails, true ) );
+ $this->assertSame( $expected_listed, in_array( 'customer_stock_notification_verify', $emails, true ) );
+ $this->assertSame( $expected_listed, in_array( 'customer_stock_notification_verified', $emails, true ) );
+ }
+
+ /**
+ * @testdox The $email_class email is sent in the block design with the product, its action and the sign-up note.
+ * @dataProvider provider_emails
+ *
+ * @param string $email_class Email class.
+ * @param string $heading Expected heading.
+ * @param string[] $expected_text Text the email should contain.
+ */
+ public function test_email_is_sent_in_block_design( string $email_class, string $heading, array $expected_text ): void {
+ $this->skip_if_unsupported_environment();
+
+ $notification = $this->create_notification();
+
+ $email = new $email_class();
+ $email->prepare_email( $notification );
+
+ $content = $email->get_content();
+
+ $this->assertStringContainsString( $heading, $content );
+ $this->assertStringContainsString( 'Blue Mug', $content );
+ foreach ( $expected_text as $text ) {
+ $this->assertStringContainsString( $text, $content );
+ }
+ $this->assertStringContainsString( 'Thanks for shopping with us.', $content );
+ $this->assertStringContainsString( '. All Rights Reserved.', $content, 'Only the block email template renders this footer.' );
+ }
+
+ /**
+ * @testdox A registered customer gets a link to manage notifications in their account instead of an unsubscribe link.
+ */
+ public function test_registered_customer_gets_account_link(): void {
+ $this->skip_if_unsupported_environment();
+
+ update_option( MyAccountEndpoint::ENDPOINT_OPTION, 'stock-notifications' );
+ new MyAccountEndpoint();
+ WC()->query->init_query_vars();
+
+ $notification = $this->create_notification();
+ $notification->set_user_id( self::factory()->user->create( array( 'role' => 'customer' ) ) );
+ $notification->save();
+
+ $email = new CustomerStockNotificationEmail();
+ $email->prepare_email( $notification );
+
+ $content = $email->get_content();
+
+ $this->assertStringContainsString( 'To manage your notifications,', $content );
+ $this->assertStringContainsString( 'stock-notifications', $content );
+ $this->assertStringNotContainsString( 'email_link_action=unsubscribe', $content );
+ }
+
+ /**
+ * Create a pending guest notification for a saved product named Blue Mug.
+ *
+ * @return Notification
+ */
+ private function create_notification(): Notification {
+ $product = WC_Helper_Product::create_simple_product();
+ $product->set_name( 'Blue Mug' );
+ $product->save();
+
+ $notification = new Notification();
+ $notification->set_product_id( $product->get_id() );
+ $notification->set_status( NotificationStatus::PENDING );
+ $notification->set_user_email( 'guest@example.com' );
+ $notification->save();
+
+ return $notification;
+ }
+
+ /**
+ * Skip when the test environment can't run the block email editor.
+ */
+ private function skip_if_unsupported_environment(): void {
+ if ( ! Email_Editor_Container::container()->get( Dependency_Check::class )->are_dependencies_met() ) {
+ $this->markTestSkipped( 'The test environment does not meet the block email editor requirements.' );
+ }
+ }
+
+ /**
+ * Each back-in-stock email with its heading and the text only it shows.
+ *
+ * @return array<string, array{0: string, 1: string, 2: string[]}>
+ */
+ public static function provider_emails(): array {
+ return array(
+ 'back in stock' => array(
+ CustomerStockNotificationEmail::class,
+ 'It\'s back in stock!',
+ array( 'Shop Now', 'email_link_action=unsubscribe', 'To stop receiving these messages,' ),
+ ),
+ 'confirm sign-up' => array(
+ CustomerStockNotificationVerifyEmail::class,
+ 'Confirm sign-up',
+ array( 'Confirm', 'email_link_action=verify', 'This link will remain active for', 'Wasn\'t you?' ),
+ ),
+ 'sign-up successful' => array(
+ CustomerStockNotificationVerifiedEmail::class,
+ 'Sign-up successful',
+ array( 'email_link_action=unsubscribe', 'To stop receiving these messages,' ),
+ ),
+ );
+ }
+}