WC_Blocks_Utils::get_blocks_from_page()public staticWC 1.0

Get all instances of the specified block on a specific woo page (e.g. cart or checkout page).

Method of the class: WC_Blocks_Utils{}

No Hooks.

Return

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

Usage

$result = WC_Blocks_Utils::get_blocks_from_page( $block_name, $woo_page_name );
$block_name(string) (required)
The name (id) of a block, e.g. woocommerce/cart.
$woo_page_name(string) (required)
The woo page to search, e.g. cart.

WC_Blocks_Utils::get_blocks_from_page() code WC 8.7.0

public static function get_blocks_from_page( $block_name, $woo_page_name ) {
	$page_blocks = self::get_all_blocks_from_page( $woo_page_name );

	// Get any instances of the specified block.
	return array_values(
		array_filter(
			$page_blocks,
			function ( $block ) use ( $block_name ) {
				return ( $block_name === $block['blockName'] );
			}
		)
	);
}