WC_Blocks_Utils::get_blocks_from_page
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.
Returns
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() WC Blocks Utils::get blocks from page code WC 10.5.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'] );
}
)
);
}