Commit 82d9199041a for woocommerce
commit 82d9199041a437775745ce48b8883bcd9b7c20e0
Author: Yuliyan Slavchev <yuliyan.slavchev@gmail.com>
Date: Mon Jun 22 10:43:46 2026 +0300
Fix email editor column percentage widths (#65868)
* Fix email editor column percentage widths
* Add changelog entry
diff --git a/packages/php/email-editor/changelog/stomail-8193-column-width-doesnt-work-in-the-alpha-block-editor b/packages/php/email-editor/changelog/stomail-8193-column-width-doesnt-work-in-the-alpha-block-editor
new file mode 100644
index 00000000000..261640d2137
--- /dev/null
+++ b/packages/php/email-editor/changelog/stomail-8193-column-width-doesnt-work-in-the-alpha-block-editor
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Preserve percentage widths for email editor columns in previews and rendered emails.
diff --git a/packages/php/email-editor/src/Integrations/Core/Renderer/Blocks/class-column.php b/packages/php/email-editor/src/Integrations/Core/Renderer/Blocks/class-column.php
index 221c7776f07..4077292f94a 100644
--- a/packages/php/email-editor/src/Integrations/Core/Renderer/Blocks/class-column.php
+++ b/packages/php/email-editor/src/Integrations/Core/Renderer/Blocks/class-column.php
@@ -121,9 +121,25 @@ class Column extends Abstract_Block_Renderer {
$wrapper_cell_attrs = array(
'class' => $wrapper_classname,
'style' => $wrapper_styles['css'],
- 'width' => Styles_Helper::parse_value( $block_attributes['width'] ),
+ 'width' => $this->get_width_attribute_value( $block_attributes['width'] ),
);
return Table_Wrapper_Helper::render_table_cell( $inner_table, $wrapper_cell_attrs );
}
+
+ /**
+ * Returns a table cell width attribute value.
+ *
+ * @param string $width Column width.
+ * @return string
+ */
+ private function get_width_attribute_value( $width ): string {
+ $parsed_width = Styles_Helper::parse_value( $width );
+
+ if ( is_string( $width ) && preg_match( '/%\s*$/', $width ) ) {
+ return $parsed_width . '%';
+ }
+
+ return (string) $parsed_width;
+ }
}
diff --git a/packages/php/email-editor/tests/integration/Integrations/Core/Renderer/Blocks/Column_Test.php b/packages/php/email-editor/tests/integration/Integrations/Core/Renderer/Blocks/Column_Test.php
index 4ce9cfe0635..dcd5f40a80c 100644
--- a/packages/php/email-editor/tests/integration/Integrations/Core/Renderer/Blocks/Column_Test.php
+++ b/packages/php/email-editor/tests/integration/Integrations/Core/Renderer/Blocks/Column_Test.php
@@ -182,6 +182,29 @@ class Column_Test extends \Email_Editor_Integration_Test_Case {
$this->assertStringContainsString( 'wp-block-column editor-class-1 another-class', $rendered );
}
+ /**
+ * Test it preserves percentage width attributes.
+ */
+ public function testItPreservesPercentageWidthAttributes(): void {
+ $parsed_column = $this->parsed_column;
+ $parsed_column['attrs']['width'] = '33.33%';
+ $rendered = $this->column_renderer->render( '<p>Column content</p>', $parsed_column, $this->rendering_context );
+ $this->checkValidHTML( $rendered );
+ $this->assertStringContainsString( 'width="33.33%"', $rendered );
+ }
+
+ /**
+ * Test it uses numeric width attributes for pixel widths.
+ */
+ public function testItUsesNumericWidthAttributesForPixelWidths(): void {
+ $parsed_column = $this->parsed_column;
+ $parsed_column['attrs']['width'] = '220px';
+ $rendered = $this->column_renderer->render( '<p>Column content</p>', $parsed_column, $this->rendering_context );
+ $this->checkValidHTML( $rendered );
+ $this->assertStringContainsString( 'width="220"', $rendered );
+ $this->assertStringNotContainsString( 'width="220px"', $rendered );
+ }
+
/**
* Test it applies padding-left from email_attrs (set by Spacing_Preprocessor for columns blockGap)
*/