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{}

Хуков нет.

Возвращает

Массив. Array of blocks as returned by parse_blocks().

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

$result = BlocksUtil::get_block_from_template_part( $block_name, $template_part_slug );
$block_name(строка) (обязательный)
The name (id) of a block, e.g. woocommerce/mini-cart.
$template_part_slug(строка) (обязательный)
The woo page to search, e.g. header.

Код BlocksUtil::get_block_from_template_part() WC 6.6.1

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'] );
			}
		)
	);
}