WooCommerce Code Reference

BlockRegistry
in package

Product block registration and style registration functionality.

Tags
deprecated
10.9.0

Product editor extension APIs will be removed in WooCommerce 11.0.

Table of Contents

DEPRECATED_SINCE  = '10.9.0'
Version that product editor APIs were deprecated in.
GENERIC_BLOCKS  = array('woocommerce/conditional', 'woocommerce/product-checkbox-field', 'woocommerce/product-collapsible', 'woocommerce/product-radio-field', 'woocommerce/product-pricing-field', 'woocommerce/product-section', 'woocommerce/product-section-description', 'woocommerce/product-subsection', 'woocommerce/product-subsection-description', 'woocommerce/product-details-section-description', 'woocommerce/product-tab', 'woocommerce/product-toggle-field', 'woocommerce/product-taxonomy-field', 'woocommerce/product-text-field', 'woocommerce/product-text-area-field', 'woocommerce/product-number-field', 'woocommerce/product-linked-list-field', 'woocommerce/product-select-field', 'woocommerce/product-notice-field')
Array of all available generic blocks.
GENERIC_BLOCKS_DIR  = 'product-editor/blocks/generic'
Generic blocks directory.
PRODUCT_FIELDS_BLOCKS  = array('woocommerce/product-catalog-visibility-field', 'woocommerce/product-custom-fields', 'woocommerce/product-custom-fields-toggle-field', 'woocommerce/product-description-field', 'woocommerce/product-downloads-field', 'woocommerce/product-images-field', 'woocommerce/product-inventory-email-field', 'woocommerce/product-sku-field', 'woocommerce/product-name-field', 'woocommerce/product-regular-price-field', 'woocommerce/product-sale-price-field', 'woocommerce/product-schedule-sale-fields', 'woocommerce/product-shipping-class-field', 'woocommerce/product-shipping-dimensions-fields', 'woocommerce/product-summary-field', 'woocommerce/product-tag-field', 'woocommerce/product-inventory-quantity-field', 'woocommerce/product-variation-items-field', 'woocommerce/product-password-field', 'woocommerce/product-list-field', 'woocommerce/product-has-variations-notice', 'woocommerce/product-single-variation-notice')
Array of all available product fields blocks.
PRODUCT_FIELDS_BLOCKS_DIR  = 'product-editor/blocks/product-fields'
Product fields blocks directory.
$instance  : BlockRegistry
Singleton instance.
get_instance()  : BlockRegistry
Get the singleton instance.
is_registered()  : bool
Check if a block is registered.
register_block_type_from_metadata()  : WP_Block_Type|false
Register a block type from metadata stored in the block.json file.
register_categories()  : mixed
Register product related block categories.
unregister()  : mixed
Unregister a block.
__construct()  : mixed
Constructor
augment_attributes()  : mixed
Augment the attributes of a block by adding attributes that are used by the product editor.
augment_uses_context()  : mixed
Augment the uses_context of a block by adding attributes that are used by the product editor.
get_file_path()  : mixed
Get a file path for a given block file.
has_role_support()  : mixed
Checks for block attribute role support.
register_block()  : WP_Block_Type|false
Register a single block.
register_block_type_from_metadata_without_deprecation_notice()  : WP_Block_Type|false
Register a block type from metadata without emitting a deprecation notice for internal block registration.
register_product_blocks()  : mixed
Register all the product blocks.
remove_block_prefix()  : string
Get the block name without the "woocommerce/" prefix.

Constants

GENERIC_BLOCKS

Array of all available generic blocks.

public mixed GENERIC_BLOCKS = array('woocommerce/conditional', 'woocommerce/product-checkbox-field', 'woocommerce/product-collapsible', 'woocommerce/product-radio-field', 'woocommerce/product-pricing-field', 'woocommerce/product-section', 'woocommerce/product-section-description', 'woocommerce/product-subsection', 'woocommerce/product-subsection-description', 'woocommerce/product-details-section-description', 'woocommerce/product-tab', 'woocommerce/product-toggle-field', 'woocommerce/product-taxonomy-field', 'woocommerce/product-text-field', 'woocommerce/product-text-area-field', 'woocommerce/product-number-field', 'woocommerce/product-linked-list-field', 'woocommerce/product-select-field', 'woocommerce/product-notice-field')

PRODUCT_FIELDS_BLOCKS

Array of all available product fields blocks.

public mixed PRODUCT_FIELDS_BLOCKS = array('woocommerce/product-catalog-visibility-field', 'woocommerce/product-custom-fields', 'woocommerce/product-custom-fields-toggle-field', 'woocommerce/product-description-field', 'woocommerce/product-downloads-field', 'woocommerce/product-images-field', 'woocommerce/product-inventory-email-field', 'woocommerce/product-sku-field', 'woocommerce/product-name-field', 'woocommerce/product-regular-price-field', 'woocommerce/product-sale-price-field', 'woocommerce/product-schedule-sale-fields', 'woocommerce/product-shipping-class-field', 'woocommerce/product-shipping-dimensions-fields', 'woocommerce/product-summary-field', 'woocommerce/product-tag-field', 'woocommerce/product-inventory-quantity-field', 'woocommerce/product-variation-items-field', 'woocommerce/product-password-field', 'woocommerce/product-list-field', 'woocommerce/product-has-variations-notice', 'woocommerce/product-single-variation-notice')

Properties

Methods

register_block_type_from_metadata()

Register a block type from metadata stored in the block.json file.

public register_block_type_from_metadata(string $file_or_folder) : WP_Block_Type|false
Parameters
$file_or_folder : string

Path to the JSON file with metadata definition for the block or path to the folder where the block.json file is located.

Tags
deprecated
10.9.0

Product editor extension APIs will be removed in WooCommerce 11.0.

Return values
WP_Block_Type|falseThe registered block type on success, or false on failure.

register_categories()

Register product related block categories.

public register_categories(array<string|int, array<string|int, mixed>> $block_categories, WP_Block_Editor_Context $editor_context) : mixed
Parameters
$block_categories : array<string|int, array<string|int, mixed>>

Array of categories for block types.

$editor_context : WP_Block_Editor_Context

The current block editor context.

Return values
mixed

augment_attributes()

Augment the attributes of a block by adding attributes that are used by the product editor.

private augment_attributes(array<string|int, mixed> $attributes) : mixed
Parameters
$attributes : array<string|int, mixed>

Block attributes.

Return values
mixed

augment_uses_context()

Augment the uses_context of a block by adding attributes that are used by the product editor.

private augment_uses_context(array<string|int, mixed> $uses_context) : mixed
Parameters
$uses_context : array<string|int, mixed>

Block uses_context.

Return values
mixed

register_block()

Register a single block.

private register_block(string $block_name, string $block_dir) : WP_Block_Type|false
Parameters
$block_name : string

Block name.

$block_dir : string

Block directory.

Return values
WP_Block_Type|falseThe registered block type on success, or false on failure.

register_block_type_from_metadata_without_deprecation_notice()

Register a block type from metadata without emitting a deprecation notice for internal block registration.

private register_block_type_from_metadata_without_deprecation_notice(string $file_or_folder) : WP_Block_Type|false
Parameters
$file_or_folder : string

Path to the JSON file with metadata definition for the block or path to the folder where the block.json file is located.

Return values
WP_Block_Type|falseThe registered block type on success, or false on failure.