WordPress at Your Fingertips
function is not described

WC_Blocks_Utils::has_block_in_page() public WC 1.0

Check if a given page contains a particular block.

{} It's a method of the class: WC_Blocks_Utils{}

No Hooks.


true|false. Boolean value if the page contains the block or not. Null in case the page does not exist.


$result = WC_Blocks_Utils::has_block_in_page( $page, $block_name );
$page(int|WP_Post) (required)
Page post ID or post object.
$block_name(string) (required)
The name (id) of a block, e.g. woocommerce/cart.

Code of WC_Blocks_Utils::has_block_in_page() WC 5.6.0

public static function has_block_in_page( $page, $block_name ) {
	$page_to_check = get_post( $page );
	if ( null === $page_to_check ) {
		return false;

	$blocks = parse_blocks( $page_to_check->post_content );
	foreach ( $blocks as $block ) {
		if ( $block_name === $block['blockName'] ) {
			return true;

	return false;