Commit e99a7b30c93 for woocommerce
commit e99a7b30c9382567efa1a57ae606a123dd1b0af1
Author: Yuliyan Slavchev <yuliyan.slavchev@gmail.com>
Date: Fri Oct 23 12:12:45 2026 +0300
Keep editor heading alignment in sent block emails (#69996)
* Keep editor heading alignment in sent block emails
* Strip heading alignment inside media queries in block emails
diff --git a/plugins/woocommerce/changelog/wooprd-3551-block-email-heading-alignment b/plugins/woocommerce/changelog/wooprd-3551-block-email-heading-alignment
new file mode 100644
index 00000000000..dcb864e0a83
--- /dev/null
+++ b/plugins/woocommerce/changelog/wooprd-3551-block-email-heading-alignment
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Keep the heading alignment set in the email editor in sent block emails, instead of forcing headings to the left.
diff --git a/plugins/woocommerce/src/Internal/EmailEditor/WooContentProcessor.php b/plugins/woocommerce/src/Internal/EmailEditor/WooContentProcessor.php
index 8e35380aef0..2fb40477a0e 100644
--- a/plugins/woocommerce/src/Internal/EmailEditor/WooContentProcessor.php
+++ b/plugins/woocommerce/src/Internal/EmailEditor/WooContentProcessor.php
@@ -56,12 +56,24 @@ class WooContentProcessor {
* because the email editor theme controls all typography via theme.json. Leaving these in
* the WooCommerce CSS would override the editor's heading sizes and weights.
*
+ * Text alignment is stripped from the plain heading rules so headings keep the alignment
+ * set in the editor instead of being forced to the left.
+ *
* @since 10.8.0
* @param string $css CSS.
* @return string
*/
public function prepare_css( string $css ): string {
remove_filter( 'woocommerce_email_styles', array( $this, 'prepare_css' ) );
+
+ // Remove text-align from the plain h1-h6 rules. They force headings to the left (right in RTL),
+ // which overrides the alignment set in the editor.
+ $css = (string) preg_replace_callback(
+ '/(^|[{}])(\s*h[1-6]\s*\{)([^}]*)/',
+ fn( array $matches ): string => $matches[1] . $matches[2] . preg_replace( '/text-align\s*:\s*[^;]+;/', '', $matches[3] ),
+ $css
+ );
+
// Remove typography declarations from WooCommerce CSS.
// The email editor theme.json controls all typography; WC CSS would override it.
return (string) preg_replace(
diff --git a/plugins/woocommerce/tests/php/src/Internal/EmailEditor/WooContentProcessorTest.php b/plugins/woocommerce/tests/php/src/Internal/EmailEditor/WooContentProcessorTest.php
index b267b2738f5..6c42415c0d3 100644
--- a/plugins/woocommerce/tests/php/src/Internal/EmailEditor/WooContentProcessorTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/EmailEditor/WooContentProcessorTest.php
@@ -40,6 +40,27 @@ class WooContentProcessorTest extends \WC_Unit_Test_Case {
$this->assertStringContainsString( 'margin', $result, 'Non-typography properties should be preserved' );
}
+ /**
+ * @testdox Should strip text alignment from heading rules only.
+ */
+ public function test_prepare_css_strips_text_align_from_headings(): void {
+ $css = "h1 { text-align: left; margin: 0; }\nh2 {\n\ttext-align: left;\n}\nh3 { text-align: right; }\n.text-align-right { text-align: right; }\n#body_content_inner { text-align: left; }";
+
+ $result = $this->woo_content_processor->prepare_css( $css );
+
+ $this->assertDoesNotMatchRegularExpression( '/h[1-3]\s*\{[^}]*text-align/', $result, 'Headings should not have text-align' );
+ $this->assertStringContainsString( 'margin: 0;', $result, 'Other heading properties should be preserved' );
+ $this->assertStringContainsString( '.text-align-right { text-align: right; }', $result, 'Alignment classes should be preserved' );
+ $this->assertStringContainsString( '#body_content_inner { text-align: left; }', $result, 'Other rules should be preserved' );
+
+ $media_css = '@media screen and (max-width: 600px) { h1 { text-align: left; margin: 0; } h2 { text-align: left; } }';
+
+ $result = $this->woo_content_processor->prepare_css( $media_css );
+
+ $this->assertStringNotContainsString( 'text-align', $result, 'Headings inside media queries should not have text-align' );
+ $this->assertStringContainsString( 'margin: 0;', $result, 'Other heading properties inside media queries should be preserved' );
+ }
+
/**
* @testdox Should return WooCommerce content styles with correct order totals CSS.
*/