WooCommerce Code Reference

Product_Collection extends Abstract_Product_Block_Renderer
in package

Renders a product collection 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 collection block content for email.
build_attribute_query()  : array<string|int, mixed>
Build attribute query from woocommerceAttributes block attributes.
build_tax_query()  : array<string|int, mixed>
Build tax query from taxQuery block attributes.
get_cart_contents_product_ids()  : array<string|int, mixed>
Get cart contents product IDs for email rendering.
get_collection_specific_product_ids()  : array<string|int, mixed>
Get specific product IDs for collection types that need them (upsell, cross-sell, related, cart-contents).
get_cross_sell_product_ids()  : array<string|int, mixed>
Get cross-sell product IDs.
get_product_references_for_collection()  : array<string|int, mixed>
Get product references for collections (handles different contexts).
get_related_product_ids()  : array<string|int, mixed>
Get related product IDs.
get_sample_product_ids_for_preview()  : array<string|int, mixed>
Get sample product IDs for preview emails.
get_upsell_product_ids()  : array<string|int, mixed>
Get upsell product IDs.
get_user_cart_product_ids_from_context()  : array<string|int, mixed>
Get cart product IDs from rendering context using user ID or email.
is_all_stock_statuses()  : bool
Check if all stock statuses are selected (meaning no filtering needed).
prepare_and_execute_query()  : WP_Query
Prepare and execute a query for the Product Collection block using the original QueryBuilder.
render_no_results_message()  : string
Render a no results message.
render_product_content()  : string
Render default product content when no inner blocks are present.
render_product_grid()  : string
Render product grid using HTML table structure for email compatibility.
render_product_template()  : string
Render the product template block.

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>

get_cart_contents_product_ids()

Get cart contents product IDs for email rendering.

private get_cart_contents_product_ids(array<string|int, mixed> $parsed_block, Rendering_Context $rendering_context) : array<string|int, mixed>
Parameters
$parsed_block : array<string|int, mixed>

Parsed block data.

$rendering_context : Rendering_Context

Rendering context.

Return values
array<string|int, mixed>Array of cart product IDs or sample products for preview.

get_collection_specific_product_ids()

Get specific product IDs for collection types that need them (upsell, cross-sell, related, cart-contents).

private get_collection_specific_product_ids(string $collection, array<string|int, mixed> $parsed_block, Rendering_Context $rendering_context) : array<string|int, mixed>
Parameters
$collection : string

Collection type.

$parsed_block : array<string|int, mixed>

Parsed block data.

$rendering_context : Rendering_Context

Rendering context.

Return values
array<string|int, mixed>Array of product IDs or empty array.

get_product_references_for_collection()

Get product references for collections (handles different contexts).

private get_product_references_for_collection(array<string|int, mixed> $parsed_block) : array<string|int, mixed>
Parameters
$parsed_block : array<string|int, mixed>

Parsed block data.

Return values
array<string|int, mixed>Array of product IDs or empty array.

prepare_and_execute_query()

Prepare and execute a query for the Product Collection block using the original QueryBuilder.

private prepare_and_execute_query(array<string|int, mixed> $parsed_block, Rendering_Context $rendering_context) : WP_Query
Parameters
$parsed_block : array<string|int, mixed>

Parsed block data.

$rendering_context : Rendering_Context

Rendering context.

Return values
WP_Query

render_product_content()

Render default product content when no inner blocks are present.

private render_product_content(WC_Product|null $product, array<string|int, mixed> $template_block, string $collection_type) : string
Parameters
$product : WC_Product|null

Product object.

$template_block : array<string|int, mixed>

Inner block data.

$collection_type : string

Collection type identifier.

Return values
string

render_product_grid()

Render product grid using HTML table structure for email compatibility.

private render_product_grid(array<string|int, mixed> $products, array<string|int, mixed> $inner_block, string $collection_type) : string
Parameters
$products : array<string|int, mixed>

Array of WC_Product objects.

$inner_block : array<string|int, mixed>

Inner block data.

$collection_type : string

Collection type identifier.

Return values
string