Commit 6887bcf14c9 for woocommerce
commit 6887bcf14c9e12e5d9a9edea47c90c305c5a8dac
Author: Miguel Gasca <miguel.gasca@automattic.com>
Date: Tue Nov 24 15:00:31 2026 +0100
Show email addresses unchanged on withdrawal, Review Order and back-in-stock pages (#70193)
* Skip texturizing address elements on more block-theme pages
Review Order, order withdrawal, stock notifications, and a notice that
already contains an address element need the same exclusion as order
received and view order. Classic themes stay unchanged.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Keep order withdrawal emails literal in block themes
The confirmation note, the review note, and the email review row sit
inside address. Other notes stay paragraphs. A review row without a
key stays on the escaped text path.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Keep Review Order emails literal in block themes
The meta line on the form and the empty state is an address element,
so the billing email is not texturized. The class on that line stays
the same.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Keep back-in-stock verification emails literal in block themes
Account and guest notices wrap the sentence in address and escape the
email. Cancel notices stay escaped in the caller. The changelog covers
the withdrawal, Review Order, and back-in-stock pages.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Stop address email lines inheriting italic browser styles
Review Order meta, withdrawal notes, and review rows stay upright and
lose the browser margin. Verification notices stay inside the sentence.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Escape the My Account verification sentence before wrapping it.
The guest notice already escapes the translated sentence. The account resend left it raw, so a translation could add HTML around the email.
Co-authored-by: Cursor <cursoragent@cursor.com>
* test: Sign in as the order owner in the Review Order meta line test
The Review Order meta line now shows the customer's name and email only
to the signed-in owner of the order (#71228). The test rendered the
templates as a guest, so the email it checks never appeared and the test
failed against current trunk.
Sign in as the order's customer before rendering, and reset the current
user in tearDown so later tests start as a guest.
* refactor: Simplify the address texturize checks
The stock notifications endpoint check duplicated the queued-notice
check: that page shows no email except in the resend notice, which the
notice check already finds. The notice check itself guarded against
states wc_get_notices() already handles, such as a missing session.
Drop the endpoint check and its import, reduce the notice check to one
loop, and inline the address tag literal.
* refactor: Escape the cancel notice where it is built
resend() returned escaped HTML and cancel() returned plain text, so the
action handler had to branch on the action to escape only one of them.
cancel() now escapes its own success text, so both return escaped
notices and the handler passes the result straight to wc_add_notice().
* refactor: Read the withdrawal review row key with ??
Match the null-coalescing reads on the surrounding lines instead of a
separate isset() and cast.
* refactor: Drop address CSS rules that change nothing
Browsers already show address as a block with no margin. The Review
Order meta margin also lost to the breadcrumb rule, which is more
specific. Keep font-style: normal, which undoes the browser's italics.
* fix: Wrap emails in address only on block themes
The resend notices, withdrawal email notes and Review Order meta line
used <address> on every theme. wp_is_block_theme() themes texturize the
whole page, which is why the wrapper exists, and it is the check
TexturizeExclusions already uses. Other themes gained nothing from the
wrapper and lost something instead: themes that drop WooCommerce's
stylesheet, such as Storefront, never load the reset, so the text
showed italic and on its own line.
Use <address> only when wp_is_block_theme() is true and keep the
previous <p> and plain-text markup otherwise. The resend notice tests
become helpers so the same flows run under a classic theme.
* fix: Keep the Review Order meta line spacing on block themes
On block themes the meta line became an <address>, which has no
default margin, so it sat about 21px higher than the <p> it replaced.
Give the address variant the paragraph's 1em block margin. Classic
themes still print a <p>, so the selector leaves them unchanged.
* fix: Style customer email addresses in the block theme stylesheet
The rules that keep the <address> around customer emails upright and
inline lived in woocommerce.css. Twenty Twenty-Two and Twenty
Twenty-Three replace that stylesheet with their own, so on those themes
the withdrawal notes and verification notices showed italic, and the
notices broke onto their own line. The withdrawal note also had no
margin, unlike the <p> notes beside it.
Move the rules to woocommerce-blocktheme.css, which every block theme
loads and the only place <address> is printed, and give the withdrawal
note the paragraph's 1em block margin.
* fix: Skip texturizing only for verification email notices
Any queued notice containing <address> turned off texturizing for every
address element on the page, so a plugin's own address notice could
trigger it too.
Mark the verification notices with a woocommerce-verification-email
class and only skip when a notice carries it. wptexturize() matches tag
names only, so on the page view right after a resend other address
elements still keep their plain punctuation; that view is the only one
affected.
* refactor: Wrap the guest verification notice before adding it
The guest resend built the block-theme address wrapper inside the
wc_add_notice() call, so a ternary and four concatenations sat in the
first argument. It parsed correctly, but it was hard to see where the
ternary ended and the notice type began.
Wrap the notice in an if block first and pass the result on its own.
The output is unchanged.
* fix: Match the withdrawal email row by key, not an internal constant
The withdrawal review template found the email row by comparing each
row's key with OrderWithdrawalFormProcessor::FIELD_EMAIL. Themes copy
this template to override it, so the copy would depend on an Internal
class that can change or move without notice.
Compare the key with the 'email' literal instead. Row keys are template
arguments, read the same way as 'label' and 'value'.
* fix: Match the withdrawal page on its endpoint key
TexturizeExclusions found the withdrawal page with is_wc_endpoint_url(),
which checks the endpoint's slug (withdraw-order). The form itself
renders whenever the endpoint key (order-withdrawal) is set. A request
with only the key, such as /my-account/?order-withdrawal=, showed the
form but still texturized the customer's email.
Check the key directly. WooCommerce copies the slug into the key on
every request, so generated withdrawal URLs still match.
---------
Co-authored-by: Cursor <cursoragent@cursor.com>
diff --git a/plugins/woocommerce/changelog/66192-fix-wptexturize-email-followup b/plugins/woocommerce/changelog/66192-fix-wptexturize-email-followup
new file mode 100644
index 00000000000..7a41ab05d67
--- /dev/null
+++ b/plugins/woocommerce/changelog/66192-fix-wptexturize-email-followup
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Show customer email addresses exactly as entered on the order withdrawal, Review Order and back-in-stock pages in block themes.
diff --git a/plugins/woocommerce/client/legacy/css/order-review.scss b/plugins/woocommerce/client/legacy/css/order-review.scss
index f1c68f8b255..51a39937cfd 100644
--- a/plugins/woocommerce/client/legacy/css/order-review.scss
+++ b/plugins/woocommerce/client/legacy/css/order-review.scss
@@ -15,6 +15,12 @@
}
}
+ // Block themes print the meta line as an address, which browsers show in italics and without a paragraph's margin.
+ address.woocommerce-review-order__meta {
+ margin-block: 1em;
+ font-style: normal;
+ }
+
// Nested for the weight to beat a theme's own button rules.
& &__submit[aria-disabled="true"] {
opacity: 0.5;
diff --git a/plugins/woocommerce/client/legacy/css/woocommerce-blocktheme.scss b/plugins/woocommerce/client/legacy/css/woocommerce-blocktheme.scss
index 08dd7e16f3e..ae79ec586e8 100644
--- a/plugins/woocommerce/client/legacy/css/woocommerce-blocktheme.scss
+++ b/plugins/woocommerce/client/legacy/css/woocommerce-blocktheme.scss
@@ -521,6 +521,27 @@ a.added_to_cart {
}
}
+/**
+* Customer emails
+*/
+// Block themes print customer emails in <address> so wptexturize() leaves them unchanged. Show them like the text they replace.
+.woocommerce-message address,
+.wc-block-components-notice-banner address {
+ display: inline;
+ margin: 0;
+ font-style: normal;
+}
+
+.woocommerce-order-withdrawal-content__review-row address {
+ margin: 0;
+ font-style: normal;
+}
+
+address.woocommerce-order-withdrawal-content__note {
+ margin-block: 1em;
+ font-style: normal;
+}
+
/**
* Store notice
*/
diff --git a/plugins/woocommerce/src/Internal/OrderWithdrawal/OrderWithdrawalFormView.php b/plugins/woocommerce/src/Internal/OrderWithdrawal/OrderWithdrawalFormView.php
index f8036146942..16a7631336e 100644
--- a/plugins/woocommerce/src/Internal/OrderWithdrawal/OrderWithdrawalFormView.php
+++ b/plugins/woocommerce/src/Internal/OrderWithdrawal/OrderWithdrawalFormView.php
@@ -93,27 +93,32 @@ final class OrderWithdrawalFormView {
* Get rows for the review screen.
*
* @param array<string,string> $data Form data.
- * @return array<int,array{label:string,value:string}>
+ * @return array<int,array{key:string,label:string,value:string}>
*/
private function get_review_rows( array $data ): array {
return array(
array(
+ 'key' => OrderWithdrawalFormProcessor::FIELD_FIRST_NAME,
'label' => __( 'Name', 'woocommerce' ),
'value' => $this->get_customer_name( $data ),
),
array(
+ 'key' => OrderWithdrawalFormProcessor::FIELD_EMAIL,
'label' => __( 'Email address', 'woocommerce' ),
'value' => $data[ OrderWithdrawalFormProcessor::FIELD_EMAIL ],
),
array(
+ 'key' => OrderWithdrawalFormProcessor::FIELD_ORDER_NUMBER,
'label' => __( 'Order number', 'woocommerce' ),
'value' => $data[ OrderWithdrawalFormProcessor::FIELD_ORDER_NUMBER ],
),
array(
+ 'key' => OrderWithdrawalFormProcessor::FIELD_WITHDRAWAL_TYPE,
'label' => __( 'Withdrawing', 'woocommerce' ),
'value' => $this->get_withdrawal_type_label( $data[ OrderWithdrawalFormProcessor::FIELD_WITHDRAWAL_TYPE ] ),
),
array(
+ 'key' => OrderWithdrawalFormProcessor::FIELD_ADDITIONAL_DETAILS,
'label' => __( 'Additional details', 'woocommerce' ),
'value' => '' === $data[ OrderWithdrawalFormProcessor::FIELD_ADDITIONAL_DETAILS ] ? __( 'None provided', 'woocommerce' ) : $data[ OrderWithdrawalFormProcessor::FIELD_ADDITIONAL_DETAILS ],
),
diff --git a/plugins/woocommerce/src/Internal/Orders/TexturizeExclusions.php b/plugins/woocommerce/src/Internal/Orders/TexturizeExclusions.php
index 050327aa025..702fa41cb40 100644
--- a/plugins/woocommerce/src/Internal/Orders/TexturizeExclusions.php
+++ b/plugins/woocommerce/src/Internal/Orders/TexturizeExclusions.php
@@ -7,6 +7,8 @@ declare( strict_types = 1 );
namespace Automattic\WooCommerce\Internal\Orders;
+use Automattic\WooCommerce\Internal\OrderReviews\Endpoint;
+use Automattic\WooCommerce\Internal\OrderWithdrawal\OrderWithdrawalEndpoint;
use Automattic\WooCommerce\Internal\RegisterHooksInterface;
/**
@@ -18,6 +20,13 @@ use Automattic\WooCommerce\Internal\RegisterHooksInterface;
*/
class TexturizeExclusions implements RegisterHooksInterface {
+ /**
+ * Class on the address element that wraps a stock notification verification notice.
+ *
+ * Only a queued notice with this class turns on the skip, so an address in another plugin's notice does not.
+ */
+ public const VERIFICATION_EMAIL_CLASS = 'woocommerce-verification-email';
+
/**
* Register hooks and filters.
*/
@@ -26,18 +35,80 @@ class TexturizeExclusions implements RegisterHooksInterface {
}
/**
- * Add `address` to the tags wptexturize() skips on the order received and view order pages.
+ * Skip texturizing address elements on block-theme requests that show a customer email.
*
- * Block themes texturize the whole template HTML, including the customer details.
+ * Block themes texturize the whole template HTML, including customer details.
*
* @internal For exclusive usage within this class, backwards compatibility not guaranteed.
*/
public function skip_address_texturize_on_order_pages(): void {
- if ( wp_is_block_theme() && ( is_order_received_page() || is_view_order_page() ) ) {
+ if ( $this->should_skip_address_texturize() ) {
add_filter( 'no_texturize_tags', array( $this, 'add_address_tag' ) );
}
}
+ /**
+ * Whether this block-theme request shows a customer email inside an address element.
+ *
+ * @return bool
+ */
+ private function should_skip_address_texturize(): bool {
+ global $wp;
+
+ if ( ! wp_is_block_theme() ) {
+ return false;
+ }
+
+ if ( is_order_received_page() || is_view_order_page() || $this->is_review_order_page() ) {
+ return true;
+ }
+
+ // The withdrawal form renders on the endpoint key, which WooCommerce also fills from the slug.
+ if ( isset( $wp->query_vars[ OrderWithdrawalEndpoint::ENDPOINT_KEY ] ) ) {
+ return true;
+ }
+
+ return $this->queued_notices_contain_verification_email();
+ }
+
+ /**
+ * Whether this request is the Review Order page for an order.
+ *
+ * A review-order query var on any other page does not count, matching Endpoint::render_shortcode().
+ *
+ * @return bool
+ */
+ private function is_review_order_page(): bool {
+ global $wp;
+
+ $page_id = (int) wc_get_page_id( Endpoint::PAGE_KEY );
+
+ return $page_id > 0 && is_page( $page_id ) && isset( $wp->query_vars[ Endpoint::QUERY_VAR ] );
+ }
+
+ /**
+ * Whether a queued notice is a verification email notice.
+ *
+ * Guest resends redirect to the product or shop page, so they are not a fixed endpoint. wptexturize() only skips by tag name,
+ * so on that page view every address element keeps its plain punctuation, not just the notice.
+ *
+ * @return bool
+ */
+ private function queued_notices_contain_verification_email(): bool {
+ $marker = '<address class="' . self::VERIFICATION_EMAIL_CLASS . '">';
+
+ foreach ( wc_get_notices() as $group ) {
+ foreach ( (array) $group as $notice ) {
+ $message = $notice['notice'] ?? $notice;
+ if ( is_string( $message ) && false !== strpos( $message, $marker ) ) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
/**
* Add `address` to the tags wptexturize() skips.
*
diff --git a/plugins/woocommerce/src/Internal/StockNotifications/Frontend/MyAccountEndpoint.php b/plugins/woocommerce/src/Internal/StockNotifications/Frontend/MyAccountEndpoint.php
index ce30000bd0d..67285b4e241 100644
--- a/plugins/woocommerce/src/Internal/StockNotifications/Frontend/MyAccountEndpoint.php
+++ b/plugins/woocommerce/src/Internal/StockNotifications/Frontend/MyAccountEndpoint.php
@@ -7,6 +7,7 @@ declare( strict_types = 1 );
namespace Automattic\WooCommerce\Internal\StockNotifications\Frontend;
+use Automattic\WooCommerce\Internal\Orders\TexturizeExclusions;
use Automattic\WooCommerce\Internal\StockNotifications\Enums\NotificationCancellationSource;
use Automattic\WooCommerce\Internal\StockNotifications\Enums\NotificationStatus;
use Automattic\WooCommerce\Internal\StockNotifications\Factory;
@@ -500,7 +501,7 @@ class MyAccountEndpoint {
$this->redirect_with_error( $result->get_error_message(), $page );
}
- \wc_add_notice( esc_html( $result ) );
+ \wc_add_notice( $result );
wp_safe_redirect( self::get_endpoint_url( $page ) );
exit;
}
@@ -509,7 +510,7 @@ class MyAccountEndpoint {
* Send the verification email again for a pending notification.
*
* @param Notification $notification The notification, already checked to belong to the current user.
- * @return string|\WP_Error Success notice text, or the error to show instead.
+ * @return string|\WP_Error Escaped success notice, or the error to show instead.
*/
private function resend( Notification $notification ) {
$result = $this->notification_management_service->resend_verification_email( $notification );
@@ -517,15 +518,21 @@ class MyAccountEndpoint {
return $result;
}
- /* translators: %s: email address the verification email was sent to. */
- return sprintf( __( 'Verification email sent to "%s". Please check your inbox!', 'woocommerce' ), $notification->get_user_email() );
+ $notice = sprintf(
+ /* translators: %s: email address the verification email was sent to. */
+ esc_html__( 'Verification email sent to "%s". Please check your inbox!', 'woocommerce' ),
+ esc_html( $notification->get_user_email() )
+ );
+
+ // Block themes texturize the whole page, but skip address elements.
+ return wp_is_block_theme() ? '<address class="' . TexturizeExclusions::VERIFICATION_EMAIL_CLASS . '">' . $notice . '</address>' : $notice;
}
/**
* Flip a pending or active notification to `cancelled` on the customer's behalf.
*
* @param Notification $notification The notification, already checked to belong to the current user.
- * @return string|\WP_Error Success notice text, or the error to show instead.
+ * @return string|\WP_Error Escaped success notice, or the error to show instead.
*/
private function cancel( Notification $notification ) {
if ( ! self::is_cancellable( $notification ) ) {
@@ -547,11 +554,11 @@ class MyAccountEndpoint {
$product_name = $notification->get_product_name();
if ( '' === $product_name ) {
- return __( 'Back in stock notification cancelled.', 'woocommerce' );
+ return esc_html__( 'Back in stock notification cancelled.', 'woocommerce' );
}
/* translators: %s: product name */
- return sprintf( __( 'Back in stock notification for "%s" cancelled.', 'woocommerce' ), $product_name );
+ return sprintf( esc_html__( 'Back in stock notification for "%s" cancelled.', 'woocommerce' ), esc_html( $product_name ) );
}
/**
diff --git a/plugins/woocommerce/src/Internal/StockNotifications/Frontend/NotificationManagementService.php b/plugins/woocommerce/src/Internal/StockNotifications/Frontend/NotificationManagementService.php
index 256d6d55c23..6d5ab3b1af8 100644
--- a/plugins/woocommerce/src/Internal/StockNotifications/Frontend/NotificationManagementService.php
+++ b/plugins/woocommerce/src/Internal/StockNotifications/Frontend/NotificationManagementService.php
@@ -4,6 +4,7 @@ declare( strict_types=1 );
namespace Automattic\WooCommerce\Internal\StockNotifications\Frontend;
+use Automattic\WooCommerce\Internal\Orders\TexturizeExclusions;
use Automattic\WooCommerce\Internal\StockNotifications\Emails\EmailManager;
use Automattic\WooCommerce\Internal\StockNotifications\Enums\NotificationStatus;
use Automattic\WooCommerce\Internal\StockNotifications\Factory;
@@ -144,8 +145,18 @@ class NotificationManagementService {
exit;
}
- /* translators: %s user email. */
- wc_add_notice( sprintf( esc_html__( 'Verification email sent to %s.', 'woocommerce' ), $notification->get_user_email() ), 'success' );
+ $notice = sprintf(
+ /* translators: %s user email. */
+ esc_html__( 'Verification email sent to %s.', 'woocommerce' ),
+ esc_html( $notification->get_user_email() )
+ );
+
+ // Block themes texturize the whole page, but skip address elements.
+ if ( wp_is_block_theme() ) {
+ $notice = '<address class="' . TexturizeExclusions::VERIFICATION_EMAIL_CLASS . '">' . $notice . '</address>';
+ }
+
+ wc_add_notice( $notice, 'success' );
wp_safe_redirect( $redirect_url );
exit;
}
diff --git a/plugins/woocommerce/templates/myaccount/form-order-withdrawal.php b/plugins/woocommerce/templates/myaccount/form-order-withdrawal.php
index 4a6524c5a01..77b860b165e 100644
--- a/plugins/woocommerce/templates/myaccount/form-order-withdrawal.php
+++ b/plugins/woocommerce/templates/myaccount/form-order-withdrawal.php
@@ -12,7 +12,7 @@
*
* @see https://woocommerce.com/document/template-structure/
* @package WooCommerce\Templates
- * @version 11.3.0
+ * @version 11.4.0
*/
defined( 'ABSPATH' ) || exit;
@@ -44,6 +44,9 @@ if ( $theme_button_class ) {
$button_class = implode( ' ', $button_classes );
$secondary_button_class = implode( ' ', array_merge( $button_classes, array( 'woocommerce-order-withdrawal-content__button--secondary' ) ) );
+// Block themes texturize the whole page, but skip address elements, so the email goes in one there.
+$is_block_theme = wp_is_block_theme();
+$email_note_tag = $is_block_theme ? 'address' : 'p';
?>
<div class="woocommerce-order-withdrawal-content">
@@ -51,7 +54,7 @@ $secondary_button_class = implode( ' ', array_merge( $button_classes, array( 'wo
<?php if ( 'confirmation' === $screen ) : ?>
<p><strong><?php esc_html_e( 'Your withdrawal has been submitted.', 'woocommerce' ); ?></strong></p>
- <p class="woocommerce-order-withdrawal-content__note">
+ <<?php echo tag_escape( $email_note_tag ); ?> class="woocommerce-order-withdrawal-content__note">
<?php
printf(
/* translators: %s: Email address. */
@@ -59,7 +62,7 @@ $secondary_button_class = implode( ' ', array_merge( $button_classes, array( 'wo
esc_html( $data['email'] ?? '' )
);
?>
- </p>
+ </<?php echo tag_escape( $email_note_tag ); ?>>
<p class="woocommerce-order-withdrawal-content__note"><?php esc_html_e( 'We\'ll review your request and contact you about next steps, including any refund due.', 'woocommerce' ); ?></p>
<p><a href="<?php echo esc_url( $shop_url ); ?>"><?php esc_html_e( 'Back to the shop', 'woocommerce' ); ?></a></p>
<?php elseif ( 'review' === $screen ) : ?>
@@ -75,12 +78,20 @@ $secondary_button_class = implode( ' ', array_merge( $button_classes, array( 'wo
<?php foreach ( $review_rows as $review_row ) : ?>
<div class="woocommerce-order-withdrawal-content__review-row">
<dt><?php echo esc_html( $review_row['label'] ?? '' ); ?></dt>
- <dd><?php echo nl2br( esc_html( $review_row['value'] ?? '' ) ); ?></dd>
+ <dd>
+ <?php
+ if ( $is_block_theme && 'email' === ( $review_row['key'] ?? '' ) ) {
+ printf( '<address>%s</address>', esc_html( $review_row['value'] ?? '' ) );
+ } else {
+ echo nl2br( esc_html( $review_row['value'] ?? '' ) );
+ }
+ ?>
+ </dd>
</div>
<?php endforeach; ?>
</dl>
- <p class="woocommerce-order-withdrawal-content__note">
+ <<?php echo tag_escape( $email_note_tag ); ?> class="woocommerce-order-withdrawal-content__note">
<?php
printf(
/* translators: %s: Email address. */
@@ -88,7 +99,7 @@ $secondary_button_class = implode( ' ', array_merge( $button_classes, array( 'wo
esc_html( $data['email'] ?? '' )
);
?>
- </p>
+ </<?php echo tag_escape( $email_note_tag ); ?>>
<form class="woocommerce-OrderWithdrawalForm" action="<?php echo esc_url( $form_action_url ); ?>" method="post" novalidate>
<?php foreach ( $hidden_fields as $hidden_field ) : ?>
diff --git a/plugins/woocommerce/templates/order/customer-review-order-empty.php b/plugins/woocommerce/templates/order/customer-review-order-empty.php
index ad5ea988665..e89e486071e 100644
--- a/plugins/woocommerce/templates/order/customer-review-order-empty.php
+++ b/plugins/woocommerce/templates/order/customer-review-order-empty.php
@@ -6,7 +6,7 @@
*
* @see https://woocommerce.com/document/template-structure/
* @package WooCommerce\Templates
- * @version 11.3.0
+ * @version 11.4.0
*
* @var WC_Order $order Order being reviewed.
* @var int $reviewed_count Number of items reviewed on this order.
@@ -19,11 +19,13 @@ if ( ! $order instanceof WC_Order ) {
}
$meta_line = \Automattic\WooCommerce\Internal\OrderReviews\Meta::line_for_order( $order );
+// Block themes texturize the whole page, but skip address elements, so the email goes in one there.
+$meta_tag = wp_is_block_theme() ? 'address' : 'p';
?>
<div class="woocommerce-review-order woocommerce-review-order--empty">
- <p class="woocommerce-breadcrumb woocommerce-review-order__meta">
+ <<?php echo tag_escape( $meta_tag ); ?> class="woocommerce-breadcrumb woocommerce-review-order__meta">
<?php echo esc_html( $meta_line ); ?>
- </p>
+ </<?php echo tag_escape( $meta_tag ); ?>>
<h1 class="woocommerce-review-order__empty-title">
<?php
diff --git a/plugins/woocommerce/templates/order/customer-review-order.php b/plugins/woocommerce/templates/order/customer-review-order.php
index 139c920f944..811377bc092 100644
--- a/plugins/woocommerce/templates/order/customer-review-order.php
+++ b/plugins/woocommerce/templates/order/customer-review-order.php
@@ -6,7 +6,7 @@
*
* @see https://woocommerce.com/document/template-structure/
* @package WooCommerce\Templates
- * @version 11.3.0
+ * @version 11.4.0
*
* @var WC_Order $order Order being reviewed.
*/
@@ -90,11 +90,13 @@ if ( ! $has_unreviewed_row ) {
$order_key = (string) $order->get_order_key();
$wp_button_class = wc_wp_theme_get_element_class_name( 'button' ) ? ' ' . wc_wp_theme_get_element_class_name( 'button' ) : '';
+// Block themes texturize the whole page, but skip address elements, so the email goes in one there.
+$meta_tag = wp_is_block_theme() ? 'address' : 'p';
?>
<div class="woocommerce-review-order">
- <p class="woocommerce-breadcrumb woocommerce-review-order__meta">
+ <<?php echo tag_escape( $meta_tag ); ?> class="woocommerce-breadcrumb woocommerce-review-order__meta">
<?php echo esc_html( $meta_line ); ?>
- </p>
+ </<?php echo tag_escape( $meta_tag ); ?>>
<?php // Focusable so dismissing the notice can hand focus back. ?>
<h1 class="woocommerce-review-order__title" tabindex="-1">
diff --git a/plugins/woocommerce/tests/php/src/Internal/Orders/TexturizeExclusionsTest.php b/plugins/woocommerce/tests/php/src/Internal/Orders/TexturizeExclusionsTest.php
index 4a051561942..98f3cdd5966 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Orders/TexturizeExclusionsTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Orders/TexturizeExclusionsTest.php
@@ -3,8 +3,22 @@ declare( strict_types = 1 );
namespace Automattic\WooCommerce\Tests\Internal\Orders;
+use Automattic\WooCommerce\Internal\OrderReviews\Endpoint;
use Automattic\WooCommerce\Internal\Orders\TexturizeExclusions;
+use Automattic\WooCommerce\Internal\OrderWithdrawal\OrderWithdrawalController;
+use Automattic\WooCommerce\Internal\OrderWithdrawal\OrderWithdrawalEndpoint;
+use Automattic\WooCommerce\Internal\OrderWithdrawal\OrderWithdrawalFormProcessor;
+use Automattic\WooCommerce\Internal\OrderWithdrawal\OrderWithdrawalFormState;
+use Automattic\WooCommerce\Internal\OrderWithdrawal\OrderWithdrawalFormView;
+use Automattic\WooCommerce\Internal\StockNotifications\Emails\EmailManager;
+use Automattic\WooCommerce\Internal\StockNotifications\Enums\NotificationStatus;
+use Automattic\WooCommerce\Internal\StockNotifications\Frontend\MyAccountEndpoint;
+use Automattic\WooCommerce\Internal\StockNotifications\Frontend\MyAccountView;
+use Automattic\WooCommerce\Internal\StockNotifications\Frontend\NotificationManagementService;
+use Automattic\WooCommerce\Internal\StockNotifications\Notification;
+use Automattic\WooCommerce\Tests\Internal\StockNotifications\StockNotificationsFeatureTrait;
use WC_Helper_Order;
+use WC_Helper_Product;
use WC_Order;
use WC_Unit_Test_Case;
@@ -15,6 +29,8 @@ use WC_Unit_Test_Case;
*/
class TexturizeExclusionsTest extends WC_Unit_Test_Case {
+ use StockNotificationsFeatureTrait;
+
/**
* The System Under Test.
*
@@ -44,6 +60,7 @@ class TexturizeExclusionsTest extends WC_Unit_Test_Case {
*/
public function tearDown(): void {
switch_theme( $this->original_theme );
+ wp_set_current_user( 0 );
parent::tearDown();
}
@@ -97,6 +114,334 @@ class TexturizeExclusionsTest extends WC_Unit_Test_Case {
);
}
+ /**
+ * @testdox On the Review Order and order withdrawal pages, address content is not texturized, while other text is.
+ *
+ * @testWith ["review-order"]
+ * ["order-withdrawal"]
+ *
+ * @param string $page Email page under test.
+ */
+ public function test_skips_address_texturize_on_block_theme_email_pages( string $page ): void {
+ $this->open_block_theme_email_page( $page );
+
+ $this->sut->skip_address_texturize_on_order_pages();
+ $text = $this->texturize_to_text( "<address>o'neil--shop@48x17.com</address><p>3x4 -- done</p>" );
+
+ $this->assertStringContainsString( "o'neil--shop@48x17.com", $text, 'Address content should not be texturized.' );
+ $this->assertStringContainsString( '3×4 — done', $text, 'Text outside the address should still be texturized.' );
+ }
+
+ /**
+ * @testdox A withdrawal request with only the endpoint key, not its slug, still skips address texturizing.
+ */
+ public function test_skips_address_texturize_on_withdrawal_request_with_only_the_endpoint_key(): void {
+ global $wp;
+
+ update_option( 'woocommerce_feature_order_withdrawal_enabled', 'yes' );
+ wc_get_container()->get( OrderWithdrawalController::class )->register_feature_hooks();
+ $page_id = self::factory()->post->create( array( 'post_type' => 'page' ) );
+ update_option( 'woocommerce_myaccount_page_id', $page_id );
+ $this->go_to( add_query_arg( OrderWithdrawalEndpoint::ENDPOINT_KEY, '', get_permalink( $page_id ) ) );
+ $this->assertArrayNotHasKey( OrderWithdrawalEndpoint::ENDPOINT_SLUG, $wp->query_vars, 'The request should carry only the endpoint key.' );
+
+ $this->sut->skip_address_texturize_on_order_pages();
+
+ $this->assertStringContainsString(
+ "o'neil--shop@48x17.com",
+ $this->texturize_to_text( "<address>o'neil--shop@48x17.com</address>" ),
+ 'Address content should not be texturized.'
+ );
+ }
+
+ /**
+ * @testdox A review-order query var on another page still texturizes address content.
+ */
+ public function test_texturizes_address_when_review_order_query_var_is_on_another_page(): void {
+ global $wp;
+
+ $other_page_id = self::factory()->post->create( array( 'post_type' => 'page' ) );
+ $review_page_id = self::factory()->post->create( array( 'post_type' => 'page' ) );
+ update_option( 'woocommerce_review_order_page_id', $review_page_id );
+ $this->go_to( get_permalink( $other_page_id ) );
+ $wp->query_vars[ Endpoint::QUERY_VAR ] = '15';
+
+ $this->sut->skip_address_texturize_on_order_pages();
+
+ $this->assertStringNotContainsString(
+ "o'neil--shop@48x17.com",
+ $this->texturize_to_text( "<address>o'neil--shop@48x17.com</address>" ),
+ 'Address content should be texturized.'
+ );
+ }
+
+ /**
+ * @testdox A queued verification email notice skips texturizing address elements, and other text still changes.
+ */
+ public function test_skips_address_texturize_when_a_verification_email_notice_is_queued(): void {
+ $this->go_to( get_permalink( self::factory()->post->create( array( 'post_type' => 'page' ) ) ) );
+ wc_add_notice( '<address class="' . TexturizeExclusions::VERIFICATION_EMAIL_CLASS . '">o\'neil--shop@48x17.com</address>', 'success' );
+
+ $this->sut->skip_address_texturize_on_order_pages();
+ $text = $this->texturize_to_text( "<address>o'neil--shop@48x17.com</address><p>3x4 -- done</p>" );
+
+ $this->assertStringContainsString( "o'neil--shop@48x17.com", $text, 'Address content should not be texturized.' );
+ $this->assertStringContainsString( '3×4 — done', $text, 'Text outside the address should still be texturized.' );
+ }
+
+ /**
+ * @testdox A queued notice with another address element, such as one from a plugin, still texturizes address content.
+ */
+ public function test_texturizes_address_when_a_queued_notice_has_an_unmarked_address(): void {
+ $this->go_to( get_permalink( self::factory()->post->create( array( 'post_type' => 'page' ) ) ) );
+ wc_add_notice( '<address>1 Main St</address>', 'success' );
+
+ $this->sut->skip_address_texturize_on_order_pages();
+
+ $this->assertStringNotContainsString(
+ "o'neil--shop@48x17.com",
+ $this->texturize_to_text( "<address>o'neil--shop@48x17.com</address>" ),
+ 'Address content should be texturized.'
+ );
+ }
+
+ /**
+ * @testdox A queued notice without an address element still texturizes address content.
+ */
+ public function test_texturizes_address_when_queued_notices_have_no_address_markup(): void {
+ $this->go_to( get_permalink( self::factory()->post->create( array( 'post_type' => 'page' ) ) ) );
+ wc_add_notice( 'Please confirm your address.', 'success' );
+
+ $this->sut->skip_address_texturize_on_order_pages();
+
+ $this->assertStringNotContainsString(
+ "o'neil--shop@48x17.com",
+ $this->texturize_to_text( "<address>o'neil--shop@48x17.com</address>" ),
+ 'Address content should be texturized.'
+ );
+ }
+
+ /**
+ * @testdox Address content is texturized when the WooCommerce session is missing.
+ */
+ public function test_texturizes_address_when_the_session_is_missing(): void {
+ $this->go_to( get_permalink( self::factory()->post->create( array( 'post_type' => 'page' ) ) ) );
+ $session = WC()->session;
+ WC()->session = null;
+
+ try {
+ $this->sut->skip_address_texturize_on_order_pages();
+ $this->assertStringNotContainsString(
+ "o'neil--shop@48x17.com",
+ $this->texturize_to_text( "<address>o'neil--shop@48x17.com</address>" ),
+ 'Address content should be texturized.'
+ );
+ } finally {
+ WC()->session = $session;
+ }
+ }
+
+ /**
+ * @testdox Both Review Order meta lines keep the billing email as entered, and a neighboring paragraph is still texturized.
+ */
+ public function test_review_order_meta_line_survives_texturize_on_block_themes(): void {
+ $this->open_block_theme_email_page( 'review-order' );
+ $this->sut->skip_address_texturize_on_order_pages();
+
+ // The meta line shows the email only to the signed-in customer who owns the order.
+ $customer_id = self::factory()->user->create( array( 'role' => 'customer' ) );
+ wp_set_current_user( $customer_id );
+
+ $order = WC_Helper_Order::create_order( $customer_id );
+ $order->set_billing_email( "o'neil--shop@48x17.com" );
+ $order->set_billing_first_name( 'Pat' );
+ $order->set_billing_last_name( 'Lee' );
+ $order->save();
+
+ foreach ( $order->get_items() as $item ) {
+ if ( $item instanceof \WC_Order_Item_Product ) {
+ wp_update_post(
+ array(
+ 'ID' => $item->get_product_id(),
+ 'comment_status' => 'open',
+ )
+ );
+ }
+ }
+
+ $form = wc_get_template_html( 'order/customer-review-order.php', array( 'order' => $order ) );
+ $empty = wc_get_template_html(
+ 'order/customer-review-order-empty.php',
+ array(
+ 'order' => $order,
+ 'reviewed_count' => 1,
+ )
+ );
+
+ $this->assertStringContainsString( '<address class="woocommerce-breadcrumb woocommerce-review-order__meta">', $form, 'The form meta line should be an address element.' );
+ $this->assertStringContainsString( '<address class="woocommerce-breadcrumb woocommerce-review-order__meta">', $empty, 'The empty-state meta line should be an address element.' );
+ $this->assertStringContainsString( 'woocommerce-review-order__form', $form, 'The form template should render the review form.' );
+ $this->assert_literal_email( wp_kses_post( $form ) . '<p>3x4 -- done</p>' );
+ $this->assert_literal_email( wp_kses_post( $empty ) . '<p>3x4 -- done</p>' );
+ }
+
+ /**
+ * @testdox The My Account verification notice keeps the email and the quotes around it, and neighboring text is still texturized.
+ */
+ public function test_account_verification_notice_survives_texturize_on_block_themes(): void {
+ $notice = $this->resend_as_customer();
+ $this->assertStringContainsString( '<address class="' . TexturizeExclusions::VERIFICATION_EMAIL_CLASS . '">', $notice, 'The account notice should wrap the sentence in a marked address element.' );
+
+ $this->sut->skip_address_texturize_on_order_pages();
+ $html = wc_kses_notice( $notice ) . '<p>3x4 -- done</p>';
+ $this->assert_literal_email( $html );
+ $this->assertStringContainsString( 'to "o\'neil--shop@48x17.com"', $this->texturize_to_text( $html ), 'The quote after the email should stay straight.' );
+ }
+
+ /**
+ * @testdox The guest verification notice keeps the email on the product page it redirects to, and neighboring text is still texturized.
+ */
+ public function test_guest_verification_notice_survives_texturize_on_block_themes(): void {
+ $notice = $this->resend_as_guest();
+
+ $this->sut->skip_address_texturize_on_order_pages();
+ $this->assertStringContainsString( '<address class="' . TexturizeExclusions::VERIFICATION_EMAIL_CLASS . '">', $notice, 'The guest notice should wrap the sentence in a marked address element.' );
+ $this->assert_literal_email( wc_kses_notice( $notice ) . '<p>3x4 -- done</p>' );
+ }
+
+ /**
+ * @testdox Classic themes get verification notices without an address element, since they do not texturize notices.
+ */
+ public function test_classic_themes_get_verification_notices_without_address(): void {
+ switch_theme( 'storefront' );
+ $this->assertFalse( wp_is_block_theme(), 'The test requires a classic theme.' );
+
+ $this->assertStringNotContainsString( '<address', $this->resend_as_customer(), 'The account notice should not use an address element.' );
+ wc_clear_notices();
+ $this->assertStringNotContainsString( '<address', $this->resend_as_guest(), 'The guest notice should not use an address element.' );
+ }
+
+ /**
+ * @testdox Classic themes get the withdrawal and Review Order templates without an address element.
+ */
+ public function test_classic_themes_get_templates_without_address(): void {
+ switch_theme( 'storefront' );
+ $this->assertFalse( wp_is_block_theme(), 'The test requires a classic theme.' );
+
+ $email = "o'neil--shop@48x17.com";
+ $view = new OrderWithdrawalFormView();
+ $data = $this->withdrawal_form_data( $email, 'None' );
+ $order = WC_Helper_Order::create_order();
+
+ $templates = array(
+ 'withdrawal confirmation' => wc_get_template_html(
+ 'myaccount/form-order-withdrawal.php',
+ $view->get_template_args( new OrderWithdrawalFormState( 'confirmation', $data, array() ), 'https://example.test/withdraw/', 'https://example.test/shop/' )
+ ),
+ 'withdrawal review' => wc_get_template_html(
+ 'myaccount/form-order-withdrawal.php',
+ $view->get_template_args( new OrderWithdrawalFormState( 'review', $data, array() ), 'https://example.test/withdraw/', 'https://example.test/shop/' )
+ ),
+ 'review order' => wc_get_template_html( 'order/customer-review-order.php', array( 'order' => $order ) ),
+ 'review order empty' => wc_get_template_html(
+ 'order/customer-review-order-empty.php',
+ array(
+ 'order' => $order,
+ 'reviewed_count' => 1,
+ )
+ ),
+ );
+
+ foreach ( $templates as $name => $html ) {
+ $this->assertStringNotContainsString( '<address', $html, "The {$name} template should not use an address element." );
+ }
+ // Each withdrawal screen has one note without the email, so the email note makes two paragraphs.
+ $note = '<p class="woocommerce-order-withdrawal-content__note">';
+ $this->assertSame( 2, substr_count( $templates['withdrawal confirmation'], $note ), 'The confirmation email note should stay a paragraph.' );
+ $this->assertSame( 2, substr_count( $templates['withdrawal review'], $note ), 'The review email note should stay a paragraph.' );
+ $this->assertStringContainsString( esc_html( $email ), $templates['withdrawal review'], 'The review rows should still show the email.' );
+
+ $meta = '<p class="woocommerce-breadcrumb woocommerce-review-order__meta">';
+ $this->assertStringContainsString( $meta, $templates['review order'], 'The form meta line should stay a paragraph.' );
+ $this->assertStringContainsString( $meta, $templates['review order empty'], 'The empty-state meta line should stay a paragraph.' );
+ }
+
+ /**
+ * @testdox Withdrawal notes and the email review row keep the email as entered, and another row is still texturized.
+ */
+ public function test_withdrawal_email_survives_texturize_on_block_themes(): void {
+ $this->open_block_theme_email_page( 'order-withdrawal' );
+ $this->sut->skip_address_texturize_on_order_pages();
+
+ $email = "o'neil--shop@48x17.com";
+ $view = new OrderWithdrawalFormView();
+ $data = $this->withdrawal_form_data( $email, '3x4 -- done' );
+
+ $confirmation = wc_get_template_html(
+ 'myaccount/form-order-withdrawal.php',
+ $view->get_template_args( new OrderWithdrawalFormState( 'confirmation', $data, array() ), 'https://example.test/withdraw/', 'https://example.test/shop/' )
+ );
+ $review = wc_get_template_html(
+ 'myaccount/form-order-withdrawal.php',
+ $view->get_template_args( new OrderWithdrawalFormState( 'review', $data, array() ), 'https://example.test/withdraw/', 'https://example.test/shop/' )
+ );
+
+ $this->assertStringContainsString( '<address class="woocommerce-order-withdrawal-content__note">', $confirmation, 'The note that contains the email should be an address element.' );
+ $this->assertStringContainsString( '<p class="woocommerce-order-withdrawal-content__note">', $confirmation, 'The note without an email should stay a paragraph.' );
+ $this->assert_literal_email( wp_kses_post( $confirmation ) . '<p>3x4 -- done</p>' );
+
+ $this->assertStringContainsString( '<address>' . esc_html( $email ) . '</address>', $review, 'The email review row should wrap the address element.' );
+ $this->assert_literal_email( wp_kses_post( $review ) );
+ }
+
+ /**
+ * @testdox A withdrawal review row with no key keeps the escaped text path and is still texturized.
+ */
+ public function test_withdrawal_review_row_without_a_key_is_texturized(): void {
+ $this->open_block_theme_email_page( 'order-withdrawal' );
+ $this->sut->skip_address_texturize_on_order_pages();
+
+ $html = wc_get_template_html(
+ 'myaccount/form-order-withdrawal.php',
+ array(
+ 'screen' => 'review',
+ 'data' => array(
+ 'email' => "o'neil--shop@48x17.com",
+ ),
+ 'review_rows' => array(
+ array(
+ 'label' => 'Details',
+ 'value' => '3x4 -- done',
+ ),
+ ),
+ )
+ );
+
+ $text = $this->texturize_to_text( wp_kses_post( $html ) );
+
+ $this->assertStringContainsString( "o'neil--shop@48x17.com", $text, 'The email note should not be texturized.' );
+ $this->assertStringContainsString( '3×4 — done', $text, 'A review row without a key should still be texturized.' );
+ $this->assertStringNotContainsString( '3x4 -- done', $text, 'A review row without a key should still be texturized.' );
+ }
+
+ /**
+ * @testdox Classic themes still texturize address content when a notice contains an address element.
+ */
+ public function test_texturizes_address_on_classic_themes_when_a_notice_contains_address_markup(): void {
+ switch_theme( 'storefront' );
+ $this->assertFalse( wp_is_block_theme(), 'The test requires a classic theme.' );
+ $this->go_to( get_permalink( self::factory()->post->create( array( 'post_type' => 'page' ) ) ) );
+ wc_add_notice( '<address class="' . TexturizeExclusions::VERIFICATION_EMAIL_CLASS . '">kept</address>', 'success' );
+
+ $this->sut->skip_address_texturize_on_order_pages();
+
+ $this->assertStringNotContainsString(
+ "o'neil--shop@48x17.com",
+ $this->texturize_to_text( "<address>o'neil--shop@48x17.com</address>" ),
+ 'Address content should be texturized.'
+ );
+ }
+
/**
* @testdox On the view order page, the customer details template shows the billing email and address as entered, after kses and wptexturize().
*/
@@ -114,6 +459,217 @@ class TexturizeExclusionsTest extends WC_Unit_Test_Case {
$this->assertStringContainsString( '12--14 Main St', $text, 'The billing address should not be texturized.' );
}
+ /**
+ * Resend a pending verification as the signed-in customer and return the queued success notice.
+ *
+ * @return string
+ */
+ private function resend_as_customer(): string {
+ $this->enable_stock_notifications_feature();
+ $capture = static function () {
+ throw new \RuntimeException( 'Redirected.' );
+ };
+ add_filter( 'wp_redirect', $capture );
+
+ try {
+ $this->open_block_theme_email_page( 'stock-notifications' );
+
+ $user_id = self::factory()->user->create( array( 'role' => 'customer' ) );
+ wp_set_current_user( $user_id );
+
+ $product = WC_Helper_Product::create_simple_product();
+ $notification = new Notification();
+ $notification->set_product_id( $product->get_id() );
+ $notification->set_user_id( $user_id );
+ $notification->set_user_email( "o'neil--shop@48x17.com" );
+ $notification->set_status( NotificationStatus::PENDING );
+ $notification->save();
+
+ $service = $this->createMock( NotificationManagementService::class );
+ $service->method( 'resend_verification_email' )->willReturn( true );
+
+ $endpoint = new MyAccountEndpoint();
+ $endpoint->init( $service, new MyAccountView() );
+
+ // phpcs:disable WordPress.Security.NonceVerification.Recommended
+ $_GET = array(
+ MyAccountEndpoint::ACTION_FIELD => MyAccountEndpoint::ACTION_RESEND,
+ 'notification_id' => (string) $notification->get_id(),
+ '_wpnonce' => wp_create_nonce( MyAccountEndpoint::get_nonce_action( MyAccountEndpoint::ACTION_RESEND, $notification->get_id() ) ),
+ );
+ // phpcs:enable WordPress.Security.NonceVerification.Recommended
+
+ try {
+ $endpoint->maybe_handle_action();
+ $this->fail( 'Expected the resend action to redirect.' );
+ } catch ( \RuntimeException $exception ) {
+ $this->assertSame( 'Redirected.', $exception->getMessage() );
+ }
+
+ $notices = wc_get_notices( 'success' );
+ $this->assertCount( 1, $notices, 'The resend should queue one success notice.' );
+
+ return $notices[0]['notice'];
+ } finally {
+ remove_filter( 'wp_redirect', $capture );
+ // phpcs:ignore WordPress.Security.NonceVerification.Recommended
+ $_GET = array();
+ $this->restore_stock_notifications_feature_option();
+ }
+ }
+
+ /**
+ * Resend a pending verification as a guest and return the queued success notice.
+ *
+ * @return string
+ */
+ private function resend_as_guest(): string {
+ wp_set_current_user( 0 );
+ $this->enable_stock_notifications_feature();
+ $capture = static function () {
+ throw new \RuntimeException( 'Redirected.' );
+ };
+ add_filter( 'wp_redirect', $capture );
+
+ try {
+ $this->go_to( get_permalink( self::factory()->post->create( array( 'post_type' => 'page' ) ) ) );
+
+ $product = WC_Helper_Product::create_simple_product();
+ $notification = new Notification();
+ $notification->set_product_id( $product->get_id() );
+ $notification->set_user_email( "o'neil--shop@48x17.com" );
+ $notification->set_status( NotificationStatus::PENDING );
+ $notification->save();
+
+ // phpcs:disable WordPress.Security.NonceVerification.Recommended
+ $_GET[ NotificationManagementService::RESEND_QUERY_ARG ] = (string) $notification->get_id();
+ $_GET['_wpnonce'] = wp_create_nonce( NotificationManagementService::RESEND_NONCE_ACTION . '_' . $notification->get_id() );
+ // phpcs:enable WordPress.Security.NonceVerification.Recommended
+
+ $email_manager = $this->createMock( EmailManager::class );
+ $email_manager->expects( $this->once() )->method( 'send_verify_email' );
+ $service = new NotificationManagementService();
+ $service->init( $email_manager );
+
+ try {
+ $service->maybe_process_resend_request();
+ $this->fail( 'Expected the guest resend to redirect.' );
+ } catch ( \RuntimeException $exception ) {
+ $this->assertSame( 'Redirected.', $exception->getMessage() );
+ }
+
+ $notices = wc_get_notices( 'success' );
+ $this->assertCount( 1, $notices, 'The guest resend should queue one success notice.' );
+
+ return $notices[0]['notice'];
+ } finally {
+ remove_filter( 'wp_redirect', $capture );
+ // phpcs:disable WordPress.Security.NonceVerification.Recommended
+ unset( $_GET[ NotificationManagementService::RESEND_QUERY_ARG ], $_GET['_wpnonce'] );
+ // phpcs:enable WordPress.Security.NonceVerification.Recommended
+ $this->restore_stock_notifications_feature_option();
+ }
+ }
+
+ /**
+ * Form data for a withdrawal screen.
+ *
+ * @param string $email Customer email.
+ * @param string $details Additional details.
+ * @return array<string,string>
+ */
+ private function withdrawal_form_data( string $email, string $details ): array {
+ return array(
+ OrderWithdrawalFormProcessor::FIELD_FIRST_NAME => 'Pat',
+ OrderWithdrawalFormProcessor::FIELD_LAST_NAME => 'Lee',
+ OrderWithdrawalFormProcessor::FIELD_EMAIL => $email,
+ OrderWithdrawalFormProcessor::FIELD_EMAIL_CONFIRMATION => $email,
+ OrderWithdrawalFormProcessor::FIELD_ORDER_NUMBER => '1001',
+ OrderWithdrawalFormProcessor::FIELD_WITHDRAWAL_TYPE => OrderWithdrawalFormProcessor::WITHDRAWAL_TYPE_SPECIFIC,
+ OrderWithdrawalFormProcessor::FIELD_ADDITIONAL_DETAILS => $details,
+ );
+ }
+
+ /**
+ * Assert an email inside the HTML stays literal and a neighboring 3x4 sentence is texturized.
+ *
+ * @param string $html HTML that already includes the neighboring sentence.
+ */
+ private function assert_literal_email( string $html ): void {
+ $text = $this->texturize_to_text( $html );
+
+ $this->assertStringContainsString( "o'neil--shop@48x17.com", $text, 'The email should not be texturized.' );
+ $this->assertStringNotContainsString( '48×17', $text, 'The email should not gain a multiplication sign.' );
+ $this->assertStringContainsString( '3×4 — done', $text, 'Neighboring text should still be texturized.' );
+ $this->assertStringNotContainsString( '3x4 -- done', $text, 'Neighboring text should still be texturized.' );
+ }
+
+ /**
+ * Open a block-theme page that shows a customer email.
+ *
+ * @param string $page review-order, order-withdrawal, or stock-notifications.
+ */
+ private function open_block_theme_email_page( string $page ): void {
+ if ( 'review-order' === $page ) {
+ $this->go_to_review_order_page();
+ return;
+ }
+
+ if ( 'order-withdrawal' === $page ) {
+ update_option( 'woocommerce_feature_order_withdrawal_enabled', 'yes' );
+ wc_get_container()->get( OrderWithdrawalController::class )->register_feature_hooks();
+ $this->go_to_account_endpoint( OrderWithdrawalEndpoint::ENDPOINT_KEY );
+ return;
+ }
+
+ if ( 'stock-notifications' === $page ) {
+ new MyAccountEndpoint();
+ $this->go_to_account_endpoint( MyAccountEndpoint::ENDPOINT );
+ return;
+ }
+
+ $this->fail( 'Unknown email page.' );
+ }
+
+ /**
+ * Load the Review Order page with its order query var set.
+ */
+ private function go_to_review_order_page(): void {
+ global $wp;
+
+ $page_id = self::factory()->post->create( array( 'post_type' => 'page' ) );
+ update_option( 'woocommerce_review_order_page_id', $page_id );
+ $this->go_to( add_query_arg( Endpoint::QUERY_VAR, '15', get_permalink( $page_id ) ) );
+
+ // go_to() only keeps query vars WordPress already lists. The endpoint guard reads this one.
+ if ( ! isset( $wp->query_vars[ Endpoint::QUERY_VAR ] ) ) {
+ $wp->query_vars[ Endpoint::QUERY_VAR ] = '15';
+ }
+ }
+
+ /**
+ * Load a My Account endpoint page.
+ *
+ * is_wc_endpoint_url() reads the slug query var. Rewrite rules set that on a pretty-permalink request. This helper sets it when the query-argument request did not.
+ *
+ * @param string $key Endpoint key passed to is_wc_endpoint_url().
+ */
+ private function go_to_account_endpoint( string $key ): void {
+ global $wp;
+
+ $page_id = self::factory()->post->create( array( 'post_type' => 'page' ) );
+ update_option( 'woocommerce_myaccount_page_id', $page_id );
+
+ $query_vars = WC()->query->get_query_vars();
+ $slug = isset( $query_vars[ $key ] ) && is_string( $query_vars[ $key ] ) && '' !== $query_vars[ $key ] ? $query_vars[ $key ] : $key;
+
+ $this->go_to( add_query_arg( $slug, '', get_permalink( $page_id ) ) );
+
+ if ( ! isset( $wp->query_vars[ $slug ] ) ) {
+ $wp->query_vars[ $slug ] = '';
+ }
+ }
+
/**
* Load an order endpoint page, so the WooCommerce conditional tags match.
*
diff --git a/plugins/woocommerce/tests/php/src/Internal/StockNotifications/Frontend/MyAccountEndpointTests.php b/plugins/woocommerce/tests/php/src/Internal/StockNotifications/Frontend/MyAccountEndpointTests.php
index cb2a344a769..7baaa01c8db 100644
--- a/plugins/woocommerce/tests/php/src/Internal/StockNotifications/Frontend/MyAccountEndpointTests.php
+++ b/plugins/woocommerce/tests/php/src/Internal/StockNotifications/Frontend/MyAccountEndpointTests.php
@@ -667,6 +667,27 @@ class MyAccountEndpointTests extends \WC_Unit_Test_Case {
$this->assertSame( NotificationStatus::ACTIVE, $updated->get_status() );
}
+ /**
+ * @testdox A cancel notice escapes the product name.
+ */
+ public function test_cancel_notice_escapes_the_product_name(): void {
+ $user_id = $this->factory->user->create( array( 'role' => 'customer' ) );
+ \wp_set_current_user( $user_id );
+ $notification = $this->create_notification( $user_id, NotificationStatus::ACTIVE );
+ $product = wc_get_product( $notification->get_product_id() );
+ $this->assertInstanceOf( \WC_Product::class, $product );
+ $product->set_name( 'Lamp & "quoted"' );
+ $product->save();
+
+ $this->simulate_action_request( MyAccountEndpoint::ACTION_CANCEL, $notification->get_id(), true );
+ $this->run_action_expecting_redirect();
+
+ $notices = \wc_get_notices( 'success' );
+ $this->assertCount( 1, $notices, 'Cancelling should queue one success notice.' );
+ $this->assertStringContainsString( 'Lamp & "quoted"', $notices[0]['notice'], 'The product name should be escaped.' );
+ $this->assertStringNotContainsString( 'Lamp & "', $notices[0]['notice'], 'The product name should not be stored raw.' );
+ }
+
/**
* A valid resend link from the owner hands the notification to the service and reports success.
*/