Automattic\WooCommerce\EmailEditor\Integrations\WooCommerce\Renderer\Blocks
Product_Collection::render_product_grid
Render product grid using HTML table structure for email compatibility.
Method of the class: Product_Collection{}
No Hooks.
Returns
String.
Usage
// private - for code of main (parent) class only $result = $this->render_product_grid( $products, $inner_block, $collection_type, $columns, $rendering_context ): string;
- $products(array) (required)
- Array of WC_Product objects.
- $inner_block(array) (required)
- Inner block data.
- $collection_type(string) (required)
- Collection type identifier.
- $columns(int) (required)
- Number of columns for the grid layout.
- $rendering_context(Rendering_Context) (required)
- Rendering context.
Product_Collection::render_product_grid() Product Collection::render product grid code WC 10.8.1
private function render_product_grid( array $products, array $inner_block, string $collection_type, int $columns, Rendering_Context $rendering_context ): string {
// Limit columns to max 2 for email compatibility.
$columns = min( max( $columns, 1 ), 2 );
// Get the block gap from theme styles to match the editor spacing.
$theme_styles = $rendering_context->get_theme_styles();
$block_gap = $theme_styles['spacing']['blockGap'] ?? '16px';
if ( 1 === $columns ) {
// Single column layout - render products vertically.
$content = '';
$index = 0;
foreach ( $products as $product ) {
// For the first product, use the original email_attrs.
// For subsequent products, add margin-top for spacing between items.
$email_attrs = $inner_block['email_attrs'] ?? array();
if ( $index > 0 && ! isset( $email_attrs['margin-top'] ) ) {
$email_attrs['margin-top'] = $block_gap;
}
$content .= $this->add_spacer(
$this->render_product_content( $product, $inner_block, $collection_type ),
$email_attrs
);
++$index;
}
return $content;
}
// Two-column layout using HTML tables for email compatibility.
// Wrap with add_spacer to match single-column spacing behavior.
return $this->add_spacer(
$this->render_two_column_grid( $products, $inner_block, $collection_type, $rendering_context, $block_gap ),
$inner_block['email_attrs'] ?? array()
);
}