WooCommerce Code Reference

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_inner_content()  : string
Extract inner content from a wrapper element.
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

get_inner_content()

Extract inner content from a wrapper element.

protected get_inner_content(string $block_content[, string $tag_name = 'div' ]) : string

Removes the outer wrapper element (e.g., div) and returns only the inner HTML content. This is useful when you need to strip the wrapper and use only the inner content.

Parameters
$block_content : string

Block content with wrapper element.

$tag_name : string = 'div'

Tag name of the wrapper element (default: 'div').

Return values
stringInner content without the wrapper element, or original content if wrapper not found.

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>

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

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' keys

render_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