Automattic\WooCommerce\Internal\Utilities

BlocksUtil::get_blocks_from_widget_area()public staticWC 1.0

Get all instances of the specified block from the widget area.

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

Хуков нет.

Возвращает

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

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

$result = BlocksUtil::get_blocks_from_widget_area( $block_name );
$block_name(массив) (обязательный)
The name (id) of a block, e.g. woocommerce/mini-cart.

Код BlocksUtil::get_blocks_from_widget_area() WC 6.6.1

public static function get_blocks_from_widget_area( $block_name ) {
	return array_reduce(
		get_option( 'widget_block' ),
		function ( $acc, $block ) use ( $block_name ) {
			$parsed_blocks = ! empty( $block ) && is_array( $block ) ? parse_blocks( $block['content'] ) : array();
			if ( ! empty( $parsed_blocks ) && $block_name === $parsed_blocks[0]['blockName'] ) {
				array_push( $acc, $parsed_blocks[0] );
				return $acc;
			}
			return $acc;
		},
		array()
	);
}