Automattic\WooCommerce\Blocks\BlockTypes
ProductCollection::add_rendering_callback()
Attach the init directive to Product Collection block to call the onRender callback.
Method of the class: ProductCollection{}
No Hooks.
Return
String
. Updated HTML content.
Usage
// private - for code of main (parent) class only $result = $this->add_rendering_callback( $block_content, $collection );
- $block_content(string) (required)
- The HTML content of the block.
- $collection(string) (required)
- Collection type.
ProductCollection::add_rendering_callback() ProductCollection::add rendering callback code WC 9.3.3
private function add_rendering_callback( $block_content, $collection ) { $p = new \WP_HTML_Tag_Processor( $block_content ); // Add `data-init to the product collection block so we trigger JS event on render. if ( $this->is_next_tag_product_collection( $p ) ) { $p->set_attribute( 'data-wc-init', 'callbacks.onRender' ); if ( $collection ) { $p->set_attribute( 'data-wc-context', wp_json_encode( array( 'collection' => $collection, ), JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP ) ); } } return $p->get_updated_html(); }