Automattic\WooCommerce\Blocks\BlockTypes\ProductCollection
Renderer::enhance_product_collection_with_interactivity()
Enhances the Product Collection block with client-side pagination.
This function identifies Product Collection blocks and adds necessary data attributes to enable client-side navigation and animation effects. It also enqueues the Interactivity API runtime.
Method of the class: Renderer{}
No Hooks.
Return
String
. Updated block content with added interactivity attributes.
Usage
$Renderer = new Renderer(); $Renderer->enhance_product_collection_with_interactivity( $block_content, $block );
- $block_content(string) (required)
- The HTML content of the block.
- $block(array) (required)
- Block details, including its attributes.
Renderer::enhance_product_collection_with_interactivity() Renderer::enhance product collection with interactivity code WC 9.6.0
public function enhance_product_collection_with_interactivity( $block_content, $block ) { $is_product_collection_block = $block['attrs']['query']['isProductCollectionBlock'] ?? false; if ( $is_product_collection_block ) { // Enqueue the Interactivity API runtime and set the namespace. wp_enqueue_script( 'wc-interactivity' ); $p = new \WP_HTML_Tag_Processor( $block_content ); if ( $this->is_next_tag_product_collection( $p ) ) { $this->set_product_collection_namespace( $p ); } // Check if dimensions need to be set and handle accordingly. $this->handle_block_dimensions( $p, $block ); $block_content = $p->get_updated_html(); $collection = $block['attrs']['collection'] ?? ''; $block_content = $this->add_rendering_callback( $block_content, $collection ); $is_enhanced_pagination_enabled = ! ( $block['attrs']['forcePageReload'] ?? false ); if ( $is_enhanced_pagination_enabled ) { $block_content = $this->enable_client_side_navigation( $block_content ); } } return $block_content; }