plugins/woocommerce/src/Admin/BlockTemplates/README.md
The Automattic\WooCommerce\Admin\BlockTemplates namespace contains interfaces for working with block templates.
Objects that implement the interfaces and fire the hooks in this namespace are instantiated using more specific APIs, such as:
Please see the documentation for those APIs for more information on how to do this.
Note: In order to use these interface type definitions, you will need to import them. For example to import the BlockInterface:
use Automattic\WooCommerce\Admin\BlockTemplates\BlockInterface;
woocommerce_block_template_area_{template_area}_after_add_block_{block_id}Fires after a specific block is added to any template in a specific area.
The dynamic portion of the hook name, $template_area, refers to the area of the template the block was added to.
The dynamic portion of the hook name, $block_id, refers to the ID of the block that was added.
BlockInterface $blockThe block that was added.
woocommerce_block_template_after_add_blockFires after a block is added to a template.
Unless you need to perform an action after any block is added to any template, you should use the more specific woocommerce_block_template_area_{template_area}_after_add_block_{block_id} hook instead for better performance.
BlockInterface $blockThe block that was added.
woocommerce_block_template_area_{template_area}_after_remove_block_{block_id}Fires after a specific block is removed from any template in a specific area.
The dynamic portion of the hook name, $template_area, refers to the area of the template the block was removed from.
The dynamic portion of the hook name, $block_id, refers to the ID of the block that was removed.
BlockInterface $blockThe block that was removed.
woocommerce_block_template_after_remove_blockFires after a block is removed from a template.
Unless you need to perform an action after any block is removed from any template, you should use the more specific woocommerce_block_template_area_{template_area}_after_remove_block_{block_id} hook instead for better performance.
BlockInterface $blockThe block that was removed.
All block templates implement this interface.
get_id(): stringGet the template ID.
get_title(): stringGet the template title.
get_description(): stringGet the template description.
get_area(): stringGet the template area.
get_block( string $block_id ): ?BlockInterfaceGet a block by ID.
remove_block( string $block_id )Removes a block from the template.
remove_blocks()Removes all blocks from the template.
get_formatted_template(): arrayGet the formatted template.
get_block( string $block_id ): ?BlockInterfaceGet a block by ID.
remove_block( string $block_id )Removes a block from the template.
remove_blocks()Removes all blocks from the template.
&get_root_template(): BlockTemplateInterfaceGet the root template that the block belongs to.
get_formatted_template(): arrayGet the block configuration as a formatted template.
get_block( string $block_id ): ?BlockInterfaceGet a block by ID.
remove_block( string $block_id )Removes a block from the container.
remove_blocks()Removes all blocks from the container.
&get_root_template(): BlockTemplateInterfaceGet the root template that the container belongs to.
get_formatted_template(): arrayGet the container as a formatted template.
get_name(): stringGet the block name.
get_id(): stringGet the block ID.
get_order(): intGet the block order.
set_order( int $order )Set the block order.
get_attributes(): arrayGet the block attributes as a key/value array.
set_attributes( array $attributes )Set the block attributes as a key/value array.
&get_parent(): ContainerInterfaceGet the parent container that the block belongs to.
&get_root_template(): BlockTemplateInterfaceGet the root template that the block belongs to.
remove()Removes the block from its parent. When a block is removed from its parent, it is detached from both the parent and the root template.
is_detached(): boolCheck if the block is detached from its parent or root template. A detached block is no longer a part of the template and will not be included in the formatted template.
add_hide_condition( string $expression ): stringAdds a hide condition to the block. The hide condition is a JavaScript-like expression that is evaluated at runtime on the client to determine if the block should be hidden.
See @woocommerce/expression-evaluation for more information on the expression syntax.
remove_hide_condition( string $key )Removes a hide condition from the block, referenced by the key returned from add_hide_condition().
get_hide_conditions(): arrayGet the hide conditions for the block.
add_disable_condition( string $expression ): stringAdds a disable condition to the block. Similar to add_hide_condition(), but the block is shown as disabled instead of hidden.
remove_disable_condition( string $key )Removes a disable condition from the block, referenced by the key returned from add_disable_condition().
get_disable_conditions(): arrayGet the disable conditions for the block.
get_formatted_template(): arrayGet the block configuration as a formatted template.