Automattic\WooCommerce\Blocks\BlockTypes

RelatedProducts::is_related_products_block()privateWC 1.0

Determines whether the block is a related products block.

Method of the class: RelatedProducts{}

No Hooks.

Return

true|false. Whether the block is a related products block.

Usage

// private - for code of main (parent) class only
$result = $this->is_related_products_block( $parsed_block, $rendered_block );
$parsed_block(array) (required)
The parsed block.
$rendered_block(array)
The rendered block.
Default: null

RelatedProducts::is_related_products_block() code WC 9.6.0

private function is_related_products_block( $parsed_block, $rendered_block = null ) {
	$is_product_collection_block = $rendered_block->context['query']['isProductCollectionBlock'] ?? false;
	if ( ProductQuery::is_woocommerce_variation( $parsed_block ) && isset( $parsed_block['attrs']['namespace'] ) && 'woocommerce/related-products' === $parsed_block['attrs']['namespace'] && ! $is_product_collection_block ) {
		return true;
	}

	return false;
}