WC_Blocks_Utils
in package
Blocks Utility class.
Table of Contents
- get_blocks_from_page() : array<string|int, mixed>
- Get all instances of the specified block on a specific woo page (e.g. `cart` or `checkout` page).
- has_block_in_page() : bool
- Check if a given page contains a particular block.
- get_all_blocks_from_page() : array<string|int, mixed>
- Get blocks from a woocommerce page.
Methods
get_blocks_from_page()
Get all instances of the specified block on a specific woo page (e.g. `cart` or `checkout` page).
public
static get_blocks_from_page(string $block_name, string $woo_page_name) : array<string|int, mixed>
Parameters
- $block_name : string
-
The name (id) of a block, e.g.
woocommerce/cart
. - $woo_page_name : string
-
The woo page to search, e.g.
cart
.
Return values
array<string|int, mixed> — Array of blocks as returned by parse_blocks().has_block_in_page()
Check if a given page contains a particular block.
public
static has_block_in_page(int|WP_Post $page, string $block_name) : bool
Parameters
- $page : int|WP_Post
-
Page post ID or post object.
- $block_name : string
-
The name (id) of a block, e.g.
woocommerce/cart
.
Return values
bool — Boolean value if the page contains the block or not. Null in case the page does not exist.get_all_blocks_from_page()
Get blocks from a woocommerce page.
private
static get_all_blocks_from_page(string $woo_page_name) : array<string|int, mixed>
Parameters
- $woo_page_name : string
-
A woocommerce page e.g.
checkout
orcart
.