Automattic\WooCommerce\Internal\Utilities
BlocksUtil::get_block_from_template_part
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() BlocksUtil::get block from template part WC 10.7.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' );
if ( ! $template || null === $template->content ) {
return array();
}
$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'] );
}
)
);
}