Commit 23571ed3c90 for woocommerce
commit 23571ed3c90d888e12ee7a834f1065b7dab8eb19
Author: Yuliyan Slavchev <yuliyan.slavchev@gmail.com>
Date: Tue Aug 11 17:07:47 2026 +0300
Email editor: Center table header cells by default (#67443)
diff --git a/packages/php/email-editor/changelog/fix-wooplug-7408-table-header-alignment b/packages/php/email-editor/changelog/fix-wooplug-7408-table-header-alignment
new file mode 100644
index 00000000000..4c4bb499e0f
--- /dev/null
+++ b/packages/php/email-editor/changelog/fix-wooplug-7408-table-header-alignment
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Center table header cells in rendered emails when no alignment is set, so they match the editor canvas instead of falling back to left.
diff --git a/packages/php/email-editor/src/Integrations/Core/Renderer/Blocks/class-table.php b/packages/php/email-editor/src/Integrations/Core/Renderer/Blocks/class-table.php
index 8398f83f7d4..bf02373cf00 100644
--- a/packages/php/email-editor/src/Integrations/Core/Renderer/Blocks/class-table.php
+++ b/packages/php/email-editor/src/Integrations/Core/Renderer/Blocks/class-table.php
@@ -366,6 +366,11 @@ class Table extends Abstract_Block_Renderer {
return 'left';
}
+ // Header cells fall back to center, which is what the browser stylesheet gives them in the editor.
+ if ( 'TH' === $html->get_tag() ) {
+ return 'center';
+ }
+
return $rendering_context->get_default_text_align();
}
diff --git a/packages/php/email-editor/tests/integration/Integrations/Core/Renderer/Blocks/Table_Test.php b/packages/php/email-editor/tests/integration/Integrations/Core/Renderer/Blocks/Table_Test.php
index 27fe1ea6d4f..84b8fedd5a8 100644
--- a/packages/php/email-editor/tests/integration/Integrations/Core/Renderer/Blocks/Table_Test.php
+++ b/packages/php/email-editor/tests/integration/Integrations/Core/Renderer/Blocks/Table_Test.php
@@ -631,6 +631,46 @@ class Table_Test extends \Email_Editor_Integration_Test_Case {
$this->assertStringContainsString( 'text-align: right;', $rendered );
}
+ /**
+ * Test it centers header cells without alignment, like the editor does, while body cells stay left.
+ */
+ public function testItCentersHeaderCellsWithoutExplicitAlignment(): void {
+ $parsed_table = $this->parsed_table;
+ unset( $parsed_table['attrs']['textAlign'] );
+ $parsed_table['innerHTML'] = $this->simple_table_content;
+
+ $rendered = $this->table_renderer->render( $this->simple_table_content, $parsed_table, $this->rendering_context );
+
+ $html = new \WP_HTML_Tag_Processor( $rendered );
+
+ $this->assertTrue( $html->next_tag( array( 'tag_name' => 'TH' ) ) );
+ $this->assertStringContainsString( 'text-align: center;', (string) $html->get_attribute( 'style' ) );
+
+ $this->assertTrue( $html->next_tag( array( 'tag_name' => 'TD' ) ) );
+ $this->assertStringContainsString( 'text-align: left;', (string) $html->get_attribute( 'style' ) );
+ }
+
+ /**
+ * Test it keeps explicit header cell alignment instead of the centered fallback.
+ */
+ public function testItPreservesExplicitHeaderCellAlignment(): void {
+ $content = '<table><thead><tr><th class="has-text-align-right">Header</th><th data-align="left">Header 2</th></tr></thead></table>';
+
+ $parsed_table = $this->parsed_table;
+ unset( $parsed_table['attrs']['textAlign'] );
+ $parsed_table['innerHTML'] = $content;
+
+ $rendered = $this->table_renderer->render( $content, $parsed_table, $this->rendering_context );
+
+ $html = new \WP_HTML_Tag_Processor( $rendered );
+
+ $this->assertTrue( $html->next_tag( array( 'tag_name' => 'TH' ) ) );
+ $this->assertStringContainsString( 'text-align: right;', (string) $html->get_attribute( 'style' ) );
+
+ $this->assertTrue( $html->next_tag( array( 'tag_name' => 'TH' ) ) );
+ $this->assertStringContainsString( 'text-align: left;', (string) $html->get_attribute( 'style' ) );
+ }
+
/**
* Test it applies fixed table layout when has-fixed-layout class is present
*/