Product_Image
extends Abstract_Product_Block_Renderer
in package
Renders a WooCommerce product image block for email.
Table of Contents
- render() : string
- Render the block.
- add_spacer() : string
- Add a spacer around the block.
- compile_css() : string
- Compile objects containing CSS properties to a string.
- get_product_from_context() : WC_Product|null
- Get product from block context.
- get_styles_from_block() : array<string|int, mixed>
- Wrapper for wp_style_engine_get_styles which ensures all values are returned.
- render_content() : string
- Render the product image block content for email.
- add_image_size_when_missing() : array<string|int, mixed>
- When the width is not set, it's important to get it for the image to be displayed correctly.
- apply_email_wrapper() : string
- Apply email-compatible table wrapper (similar to Image renderer).
- build_image_html() : string
- Build email-compatible image HTML.
- create_overlay_structure() : string
- Create overlay structure for email compatibility.
- extract_image_height() : float
- Extract image height from HTML for positioning calculations.
- extract_image_width() : float
- Extract image width from HTML for positioning calculations.
- get_product_image_data() : array<string|int, mixed>|null
- Get product image data.
- parse_attributes() : array<string|int, mixed>
- Parse block attributes with defaults.
- process_inner_blocks() : array<string|int, mixed>
- Process inner blocks (like sale badges) from block content.
- render_overlay_badge() : string
- Render a sale badge with email-compatible overlay positioning.
- wrap_with_link() : string
- Wrap image with product link.
Methods
render()
Render the block.
public
render(string $block_content, array<string|int, mixed> $parsed_block, Rendering_Context $rendering_context) : string
Parameters
- $block_content : string
-
The block content.
- $parsed_block : array<string|int, mixed>
-
The parsed block.
- $rendering_context : Rendering_Context
-
The rendering context.
Return values
string —add_spacer()
Add a spacer around the block.
protected
add_spacer(string $content, array<string|int, mixed> $email_attrs) : string
Parameters
- $content : string
-
The block content.
- $email_attrs : array<string|int, mixed>
-
The email attributes.
Return values
string —compile_css()
Compile objects containing CSS properties to a string.
protected
compile_css(array<string|int, mixed> ...$styles) : string
Parameters
- $styles : array<string|int, mixed>
-
Style arrays to compile.
Return values
string —get_product_from_context()
Get product from block context.
protected
get_product_from_context(array<string|int, mixed> $parsed_block) : WC_Product|null
Parameters
- $parsed_block : array<string|int, mixed>
-
Parsed block.
Return values
WC_Product|null —get_styles_from_block()
Wrapper for wp_style_engine_get_styles which ensures all values are returned.
protected
get_styles_from_block(array<string|int, mixed> $block_styles[, bool $skip_convert_vars = false ]) : array<string|int, mixed>
Parameters
- $block_styles : array<string|int, mixed>
-
Array of block styles.
- $skip_convert_vars : bool = false
-
If true, --wp_preset--spacing--x type values will be left in the original var:preset:spacing:x format.
Return values
array<string|int, mixed> —render_content()
Render the product image block content for email.
protected
render_content(string $block_content, array<string|int, mixed> $parsed_block, Rendering_Context $rendering_context) : string
Parameters
- $block_content : string
-
Block content.
- $parsed_block : array<string|int, mixed>
-
Parsed block.
- $rendering_context : Rendering_Context
-
Rendering context.
Return values
string —add_image_size_when_missing()
When the width is not set, it's important to get it for the image to be displayed correctly.
private
add_image_size_when_missing(array<string|int, mixed> $parsed_block, Rendering_Context $rendering_context) : array<string|int, mixed>
Based on the email Image renderer logic.
Parameters
- $parsed_block : array<string|int, mixed>
-
Parsed block.
- $rendering_context : Rendering_Context
-
Rendering context.
Return values
array<string|int, mixed> —apply_email_wrapper()
Apply email-compatible table wrapper (similar to Image renderer).
private
apply_email_wrapper(string $image_html, array<string|int, mixed> $parsed_block, Rendering_Context $rendering_context) : string
Parameters
- $image_html : string
-
Image HTML.
- $parsed_block : array<string|int, mixed>
-
Parsed block.
- $rendering_context : Rendering_Context
-
Rendering context.
Return values
string —build_image_html()
Build email-compatible image HTML.
private
build_image_html(array<string|int, mixed> $image_data, array<string|int, mixed> $attributes, Rendering_Context $rendering_context) : string
Parameters
- $image_data : array<string|int, mixed>
-
Image data.
- $attributes : array<string|int, mixed>
-
Block attributes.
- $rendering_context : Rendering_Context
-
Rendering context.
Return values
string —create_overlay_structure()
Create overlay structure for email compatibility.
private
create_overlay_structure(string $image_html, string $badges_html, string $other_content, string $badge_alignment[, WC_Product|null $product = null ][, bool $show_product_link = false ]) : string
Uses Faux Absolute Position with badge-below fallback for better cross-client support.
Parameters
- $image_html : string
-
Image HTML.
- $badges_html : string
-
Badges HTML.
- $other_content : string
-
Other inner content.
- $badge_alignment : string
-
Badge alignment.
- $product : WC_Product|null = null
-
Product object for link.
- $show_product_link : bool = false
-
Whether to show product link.
Return values
string —extract_image_height()
Extract image height from HTML for positioning calculations.
private
extract_image_height(string $image_html) : float
Parameters
- $image_html : string
-
Image HTML.
Return values
float — Image height in pixels.extract_image_width()
Extract image width from HTML for positioning calculations.
private
extract_image_width(string $image_html) : float
Parameters
- $image_html : string
-
Image HTML.
Return values
float — Image width in pixels.get_product_image_data()
Get product image data.
private
get_product_image_data(WC_Product $product, array<string|int, mixed> $attributes) : array<string|int, mixed>|null
Parameters
- $product : WC_Product
-
Product object.
- $attributes : array<string|int, mixed>
-
Parsed attributes.
Return values
array<string|int, mixed>|null —parse_attributes()
Parse block attributes with defaults.
private
parse_attributes(array<string|int, mixed> $attributes) : array<string|int, mixed>
Parameters
- $attributes : array<string|int, mixed>
-
Block attributes.
Return values
array<string|int, mixed> —process_inner_blocks()
Process inner blocks (like sale badges) from block content.
private
process_inner_blocks(array<string|int, mixed> $parsed_block, WC_Product $product, Rendering_Context $rendering_context) : array<string|int, mixed>
Handles special positioning for email compatibility.
Parameters
- $parsed_block : array<string|int, mixed>
-
Parsed block.
- $product : WC_Product
-
Product object.
- $rendering_context : Rendering_Context
-
Rendering context.
Return values
array<string|int, mixed> — Array with 'badges' and 'other_content' keysrender_overlay_badge()
Render a sale badge with email-compatible overlay positioning.
private
render_overlay_badge(array<string|int, mixed> $badge_block, WC_Product $product, Rendering_Context $rendering_context) : string
Parameters
- $badge_block : array<string|int, mixed>
-
Badge block data.
- $product : WC_Product
-
Product object.
- $rendering_context : Rendering_Context
-
Rendering context.
Return values
string —wrap_with_link()
Wrap image with product link.
private
wrap_with_link(string $image_html, WC_Product $product) : string
Parameters
- $image_html : string
-
Image HTML.
- $product : WC_Product
-
Product object.
