Commit 2ed9badecf1 for woocommerce

commit 2ed9badecf1eebf497cd5679047cc0a139b1ae41
Author: Alex <361918+alex02@users.noreply.github.com>
Date:   Thu Nov 26 14:09:31 2026 +0200

    Keep apostrophes in plain-text emails (#71185)

    The plain email templates escape text with esc_html(), which turns an apostrophe into &#039;. The single-quote rule in WC_Email::$plain_search did not match the decimal or hexadecimal apostrophe codes, so the catch-all rule for unknown entities removed them: "Your order's complete" was sent as "Your orders complete". The rule now also matches &#39;, &#039; and &#x27;, and turns them into an apostrophe, as it already did for &rsquo;.

    Fixes #71183

    Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

diff --git a/plugins/woocommerce/changelog/fix-plain-email-apostrophes b/plugins/woocommerce/changelog/fix-plain-email-apostrophes
new file mode 100644
index 00000000000..5ba9bdb0a84
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-plain-email-apostrophes
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Keep apostrophes in plain-text emails instead of removing them.
diff --git a/plugins/woocommerce/includes/emails/class-wc-email.php b/plugins/woocommerce/includes/emails/class-wc-email.php
index e285c73cc5b..367f97cafdd 100644
--- a/plugins/woocommerce/includes/emails/class-wc-email.php
+++ b/plugins/woocommerce/includes/emails/class-wc-email.php
@@ -206,7 +206,7 @@ class WC_Email extends WC_Settings_API {
 		"/\r/",                                                  // Non-legal carriage return.
 		'/&(nbsp|#0*160);/i',                                    // Non-breaking space.
 		'/&(quot|rdquo|ldquo|#0*8220|#0*8221|#0*147|#0*148);/i', // Double quotes.
-		'/&(apos|rsquo|lsquo|#0*8216|#0*8217);/i',               // Single quotes.
+		'/&(apos|rsquo|lsquo|#0*39|#x0*27|#0*8216|#0*8217);/i',  // Single quotes.
 		'/&gt;/i',                                               // Greater-than.
 		'/&lt;/i',                                               // Less-than.
 		'/&#0*38;/i',                                            // Ampersand.
diff --git a/plugins/woocommerce/tests/php/includes/emails/class-wc-email-test.php b/plugins/woocommerce/tests/php/includes/emails/class-wc-email-test.php
index 55975594c5f..f8fc8ade91f 100644
--- a/plugins/woocommerce/tests/php/includes/emails/class-wc-email-test.php
+++ b/plugins/woocommerce/tests/php/includes/emails/class-wc-email-test.php
@@ -254,6 +254,52 @@ class WC_Email_Test extends \WC_Unit_Test_Case {
 		$this->assertFalse( ( new $class_name() )->supports_cc_bcc() );
 	}

+	/**
+	 * @testdox Plain-text emails keep an apostrophe that the template escaped in the heading.
+	 *
+	 * @testWith ["Your order's complete"]
+	 *           ["L'été est là"]
+	 *
+	 * @param string $heading Email heading with an apostrophe.
+	 */
+	public function test_plain_email_keeps_apostrophe_in_heading( string $heading ): void {
+		$email             = new WC_Email_Customer_Completed_Order();
+		$email->object     = WC_Helper_Order::create_order();
+		$email->email_type = 'plain';
+		add_filter(
+			'woocommerce_email_heading_customer_completed_order',
+			function () use ( $heading ) {
+				return $heading;
+			}
+		);
+
+		$this->assertStringContainsString( str_replace( "'", '&#039;', $heading ), $email->get_content_plain(), 'Fixture: the plain template must escape the apostrophe' );
+		$this->assertStringContainsString( $heading, $email->get_content() );
+	}
+
+	/**
+	 * @testdox The plain-text rules turn decimal and hexadecimal apostrophe codes into an apostrophe.
+	 *
+	 * @testWith ["&#39;"]
+	 *           ["&#x27;"]
+	 *
+	 * @param string $code Apostrophe character reference.
+	 */
+	public function test_plain_text_rules_turn_numeric_apostrophe_codes_into_apostrophe( string $code ): void {
+		$email = new WC_Email_Customer_Completed_Order();
+
+		$this->assertSame( "Your order's complete", preg_replace( $email->plain_search, $email->plain_replace, "Your order{$code}s complete" ) );
+	}
+
+	/**
+	 * @testdox The plain-text rules still turn &rsquo; into an apostrophe.
+	 */
+	public function test_plain_text_rules_turn_rsquo_into_apostrophe(): void {
+		$email = new WC_Email_Customer_Completed_Order();
+
+		$this->assertSame( "Your order's complete", preg_replace( $email->plain_search, $email->plain_replace, 'Your order&rsquo;s complete' ) );
+	}
+
 	/**
 	 * Create an email that opts out of Cc/Bcc support.
 	 *