Automattic\WooCommerce\EmailEditor\Integrations\WooCommerce\Renderer\Blocks

Product_Image::add_image_size_when_missing │ private │ WC 1.0

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() code WC 11.1.2

private function add_image_size_when_missing( array $parsed_block, Rendering_Context $rendering_context ): array {
	if ( isset( $parsed_block['attrs']['width'] ) ) {
		return $parsed_block;
	}

	$align = $parsed_block['attrs']['align'] ?? '';

	// For full-width alignment, use the full layout content size (ignoring padding).
	if ( 'full' === $align ) {
		$layout_settings                = $rendering_context->get_theme_settings()['layout'] ?? array();
		$parsed_block['attrs']['width'] = $layout_settings['contentSize'] ?? '100%';
		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;
}