Automattic\WooCommerce\Internal\Utilities

BlocksUtil::get_block_from_template_part()public staticWC 1.0

Get all instances of the specified block on a specific template part.

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

No Hooks.

Return

Array. Array of blocks as returned by parse_blocks().

Usage

$result = BlocksUtil::get_block_from_template_part( $block_name, $template_part_slug );
$block_name(string) (required)
The name (id) of a block, e.g. woocommerce/mini-cart.
$template_part_slug(string) (required)
The woo page to search, e.g. header.

Код BlocksUtil::get_block_from_template_part() WC 7.1.0

public static function get_block_from_template_part( $block_name, $template_part_slug ) {
	$template = get_block_template( get_stylesheet() . '//' . $template_part_slug, 'wp_template_part' );
	$blocks   = parse_blocks( $template->content );

	$flatten_blocks = self::flatten_blocks( $blocks );

	return array_values(
		array_filter(
			$flatten_blocks,
			function ( $block ) use ( $block_name ) {
				return ( $block_name === $block['blockName'] );
			}
		)
	);
}