Automattic\WooCommerce\EmailEditor\Integrations\WooCommerce\Renderer\Blocks
Product_Image::add_image_size_when_missing
When the width is not set, it's important to get it for the image to be displayed correctly. Based on the email Image renderer logic.
Method of the class: Product_Image{}
No Hooks.
Returns
Array.
Usage
// private - for code of main (parent) class only $result = $this->add_image_size_when_missing( $parsed_block, $rendering_context ): array;
- $parsed_block(array) (required)
- Parsed block.
- $rendering_context(Rendering_Context) (required)
- Rendering context.
Product_Image::add_image_size_when_missing() Product Image::add image size when missing code WC 10.7.0
private function add_image_size_when_missing( array $parsed_block, Rendering_Context $rendering_context ): array {
if ( isset( $parsed_block['attrs']['width'] ) ) {
return $parsed_block;
}
if ( ! isset( $parsed_block['email_attrs']['width'] ) ) {
$parsed_block['attrs']['width'] = '100%';
return $parsed_block;
}
// Use the email_attrs width if set (e.g., for multi-column layouts),
// otherwise fall back to the rendering context layout width.
$parsed_block['attrs']['width'] = $parsed_block['email_attrs']['width'];
return $parsed_block;
}