Automattic\WooCommerce\Blocks\BlockTypes\ProductCollection

Renderer::add_rendering_callback()privateWC 1.0

Attach the init directive to Product Collection block to call the onRender callback.

Method of the class: Renderer{}

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.

Renderer::add_rendering_callback() code WC 9.6.0

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'
		);
		$p->set_attribute(
			'data-wc-context',
			$collection ? wp_json_encode(
				array( 'collection' => $collection ),
				JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP
			) : '{}'
		);
	}

	return $p->get_updated_html();
}