WooCommerce Code Reference

Renderer
in package

Renderer class.

Handles rendering of the block and adds interactivity.

Table of Contents

$parsed_block  : array<string|int, mixed>
The Block with its attributes before it gets rendered
$render_state  : array<string|int, mixed>
The render state of the product collection block.
__construct()  : mixed
Constructor.
add_navigation_link_directives()  : mixed
Add interactive links to all anchors inside the Query Pagination block.
enhance_product_collection_with_interactivity()  : string
Enhances the Product Collection block with client-side pagination.
handle_rendering()  : string
Handle the rendering of the block.
provide_location_context_for_inner_blocks()  : array<string|int, mixed>
Provides the location context to each inner block of the product collection block.
set_parsed_block()  : mixed
Set the parsed block.
get_list_styles()  : string
Get the styles for the list element (fixed width).
render_interactivity_notices_region()  : string
Render interactivity API powered notices that can be added client-side. This reuses classes from the woocommerce/store-notices block to ensure style consistency.
add_store_notices_fallback()  : string
Add a fallback store notices div to the block content.
get_location_context()  : array<string|int, mixed>
Get the global location context.
handle_block_dimensions()  : mixed
Handle block dimensions if width type is set to 'fixed'.
reset_render_state()  : mixed
Reset the render state.
set_fixed_width_style()  : mixed
Set the style attribute for fixed width.
should_prevent_render()  : bool
Check if the block should be prevented from rendering.

Properties

Methods

Add interactive links to all anchors inside the Query Pagination block.

public add_navigation_link_directives(string $block_content, array<string|int, mixed> $block, WP_Block $instance) : mixed

This enabled client-side navigation for the product collection block.

Parameters
$block_content : string

The block content.

$block : array<string|int, mixed>

The full block, including name and attributes.

$instance : WP_Block

The block instance.

Return values
mixed

enhance_product_collection_with_interactivity()

Enhances the Product Collection block with client-side pagination.

public enhance_product_collection_with_interactivity(string $block_content, array<string|int, mixed> $block) : string

This function identifies Product Collection blocks and adds necessary data attributes to enable client-side navigation. It also enqueues the Interactivity API runtime.

Parameters
$block_content : string

The HTML content of the block.

$block : array<string|int, mixed>

Block details, including its attributes.

Return values
stringUpdated block content with added interactivity attributes.

handle_rendering()

Handle the rendering of the block.

public handle_rendering(string $block_content, array<string|int, mixed> $block) : string
Parameters
$block_content : string

The block content about to be rendered.

$block : array<string|int, mixed>

The block being rendered.

Return values
string

provide_location_context_for_inner_blocks()

Provides the location context to each inner block of the product collection block.

public provide_location_context_for_inner_blocks(array<string|int, mixed> $context) : array<string|int, mixed>

Hint: Only blocks using the 'query' context will be affected.

The sourceData structure depends on the context type as follows:

  • site: [ ]
  • order: [ 'orderId' => int ]
  • cart: [ 'productIds' => int[] ]
  • archive: [ 'taxonomy' => string, 'termId' => int ]
  • product: [ 'productId' => int ]
Parameters
$context : array<string|int, mixed>

The block context.

Tags
example

array( 'type' => 'product', 'sourceData' => array( 'productId' => 123 ), )

Return values
array<string|int, mixed>$context { The block context including the product collection location context. @type array $productCollectionLocation { @type string $type The context type. Possible values are 'site', 'order', 'cart', 'archive', 'product'. @type array $sourceData The context source data. Can be the product ID of the viewed product, the order ID of the current order viewed, etc. See structure above for more details. } }

get_list_styles()

Get the styles for the list element (fixed width).

protected get_list_styles(string $fixed_width) : string
Parameters
$fixed_width : string

Fixed width value.

Return values
string

render_interactivity_notices_region()

Render interactivity API powered notices that can be added client-side. This reuses classes from the woocommerce/store-notices block to ensure style consistency.

protected render_interactivity_notices_region() : string
Return values
stringThe rendered store notices HTML.

add_store_notices_fallback()

Add a fallback store notices div to the block content.

private add_store_notices_fallback(string $block_content) : string
Parameters
$block_content : string

The block content.

Return values
stringThe updated block content.

handle_block_dimensions()

Handle block dimensions if width type is set to 'fixed'.

private handle_block_dimensions(WP_HTML_Tag_Processor $p, array<string|int, mixed> $block) : mixed
Parameters
$p : WP_HTML_Tag_Processor

The HTML tag processor.

$block : array<string|int, mixed>

The block details.

Return values
mixed

set_fixed_width_style()

Set the style attribute for fixed width.

private set_fixed_width_style(WP_HTML_Tag_Processor $p, string $fixed_width) : mixed
Parameters
$p : WP_HTML_Tag_Processor

The HTML tag processor.

$fixed_width : string

The fixed width value.

Return values
mixed