WooCommerce Code Reference

Init
in package

Loads assets related to the product block editor.

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.
EDITOR_CONTEXT_NAME  = 'woocommerce/edit-product'
The context name used to identify the editor.
$product_templates  : array<string|int, mixed>
Registered product templates.
$redirection_controller  : RedirectionController
Redirection controller.
$supported_product_types  : array<string|int, mixed>
Supported product types.
__construct()  : mixed
Constructor
add_user_data_fields()  : array<string|int, mixed>
Adds fields so that we can store user preferences for the variations block.
dequeue_conflicting_styles()  : mixed
Dequeue conflicting styles.
enable_rest_api_for_product_variation()  : array<string|int, mixed>
Enables variation post type in REST API.
enqueue_scripts()  : mixed
Enqueue scripts needed for the product form block editor.
enqueue_styles()  : mixed
Enqueue styles needed for the rich text editor.
get_block_types()  : array<string|int, mixed>
Filters woocommerce block types.
possibly_add_template_id()  : mixed
Adds the product template ID to the product if it doesn't exist.
register_layout_templates()  : mixed
Register layout templates.
register_metadata_attribute()  : array<string|int, mixed>
Registers the metadata block attribute for all block types.
register_product_templates()  : mixed
Register product templates.
register_user_metas()  : mixed
Register user metas.
set_current_screen_to_block_editor_if_wc_admin()  : mixed
Sets the current screen to the block editor if a wc-admin page.
update_edit_product_link()  : string
Update the edit product links when the new experience is enabled.
create_default_product_template_by_custom_product_type()  : array<string|int, mixed>
Create default product template by custom product type if it does not have a template associated yet.
get_default_product_templates()  : array<string|int, mixed>
Get default product templates.
get_product_editor_settings()  : mixed
Get the product editor settings.

Constants

Properties

Methods

add_user_data_fields()

Adds fields so that we can store user preferences for the variations block.

public add_user_data_fields(array<string|int, mixed> $user_data_fields) : array<string|int, mixed>
Parameters
$user_data_fields : array<string|int, mixed>

User data fields.

Return values
array<string|int, mixed>

enable_rest_api_for_product_variation()

Enables variation post type in REST API.

public enable_rest_api_for_product_variation(array<string|int, mixed> $args) : array<string|int, mixed>
Parameters
$args : array<string|int, mixed>

Array of post type arguments.

Return values
array<string|int, mixed>Array of post type arguments.

get_block_types()

Filters woocommerce block types.

public get_block_types(array<string|int, string> $block_types) : array<string|int, mixed>
Parameters
$block_types : array<string|int, string>

Array of woocommerce block types.

Return values
array<string|int, mixed>

possibly_add_template_id()

Adds the product template ID to the product if it doesn't exist.

public possibly_add_template_id(WP_REST_Response $response, WC_Product $product) : mixed
Parameters
$response : WP_REST_Response

The response object.

$product : WC_Product

The product.

Return values
mixed

register_metadata_attribute()

Registers the metadata block attribute for all block types.

public register_metadata_attribute(array<string|int, mixed> $args) : array<string|int, mixed>

This is a fallback/temporary solution until the Gutenberg core version registers the metadata attribute.

Parameters
$args : array<string|int, mixed>

Array of arguments for registering a block type.

Tags
see
https://github.com/WordPress/gutenberg/blob/6aaa3686ae67adc1a6a6b08096d3312859733e1b/lib/compat/wordpress-6.5/blocks.php#L27-L47

To do: Remove this method once the Gutenberg core version registers the metadata attribute.

Return values
array<string|int, mixed>$args

set_current_screen_to_block_editor_if_wc_admin()

Sets the current screen to the block editor if a wc-admin page.

public set_current_screen_to_block_editor_if_wc_admin() : mixed
Return values
mixed

Update the edit product links when the new experience is enabled.

public update_edit_product_link(string $link, int $post_id) : string
Parameters
$link : string

The edit link.

$post_id : int

Post ID.

Return values
string

create_default_product_template_by_custom_product_type()

Create default product template by custom product type if it does not have a template associated yet.

private create_default_product_template_by_custom_product_type(array<string|int, mixed> $templates) : array<string|int, mixed>
Parameters
$templates : array<string|int, mixed>

The registered product templates.

Return values
array<string|int, mixed>The new templates.

get_default_product_templates()

Get default product templates.

private get_default_product_templates() : array<string|int, mixed>
Return values
array<string|int, mixed>The default templates.