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_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_collection_specific_product_ids() : array<string|int, mixed>
- Get specific product IDs for collection types that need them (upsell, cross-sell, related).
- 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_upsell_product_ids() : array<string|int, mixed>
- Get upsell product IDs.
- 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
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 collection 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 —build_attribute_query()
Build attribute query from woocommerceAttributes block attributes.
private
build_attribute_query(array<string|int, mixed> $attributes) : array<string|int, mixed>
Parameters
- $attributes : array<string|int, mixed>
-
Attribute filters from block attributes.
Return values
array<string|int, mixed> —build_tax_query()
Build tax query from taxQuery block attributes.
private
build_tax_query(array<string|int, mixed> $tax_query_input) : array<string|int, mixed>
Parameters
- $tax_query_input : array<string|int, mixed>
-
Tax query input from block attributes.
Return values
array<string|int, mixed> —get_collection_specific_product_ids()
Get specific product IDs for collection types that need them (upsell, cross-sell, related).
private
get_collection_specific_product_ids(string $collection, array<string|int, mixed> $parsed_block) : array<string|int, mixed>
Parameters
- $collection : string
-
Collection type.
- $parsed_block : array<string|int, mixed>
-
Parsed block data.
Return values
array<string|int, mixed> — Array of product IDs or empty array.get_cross_sell_product_ids()
Get cross-sell product IDs.
private
get_cross_sell_product_ids(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 cross-sell product IDs.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.get_related_product_ids()
Get related product IDs.
private
get_related_product_ids(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 related product IDs.get_upsell_product_ids()
Get upsell product IDs.
private
get_upsell_product_ids(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 upsell product IDs.is_all_stock_statuses()
Check if all stock statuses are selected (meaning no filtering needed).
private
is_all_stock_statuses(array<string|int, mixed> $stock_status) : bool
Parameters
- $stock_status : array<string|int, mixed>
-
Stock status values from block attributes.
Return values
bool —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) : WP_Query
Parameters
- $parsed_block : array<string|int, mixed>
-
Parsed block data.
Return values
WP_Query —render_no_results_message()
Render a no results message.
private
render_no_results_message() : string
Return values
string —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
Parameters
- $product : WC_Product|null
-
Product object.
- $template_block : array<string|int, mixed>
-
Inner block data.
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
Parameters
- $products : array<string|int, mixed>
-
Array of WC_Product objects.
- $inner_block : array<string|int, mixed>
-
Inner block data.
Return values
string —render_product_template()
Render the product template block.
private
render_product_template(array<string|int, mixed> $inner_block, WP_Query $query) : string
Parameters
- $inner_block : array<string|int, mixed>
-
Inner block data.
- $query : WP_Query
-
WP_Query object.
