Automattic\WooCommerce\Blocks\BlockTypes

ProductCollection::enhance_product_collection_with_interactivity()publicWC 1.0

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.

Метод класса: ProductCollection{}

Хуков нет.

Возвращает

Строку. Updated block content with added interactivity attributes.

Использование

$ProductCollection = new ProductCollection();
$ProductCollection->enhance_product_collection_with_interactivity( $block_content, $block );
$block_content(строка) (обязательный)
The HTML content of the block.
$block(массив) (обязательный)
Block details, including its attributes.

Код ProductCollection::enhance_product_collection_with_interactivity() WC 9.4.2

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 );
		}
		$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;
}