WooCommerce Code Reference

Templates
in package

Templates class.

Table of Contents

$post_types  : array<string|int, mixed>
The post type.
$template_directory  : string
The template directory.
$template_prefix  : string
The plugin slug.
$templates_registry  : Templates_Registry
The templates registry.
__construct()  : mixed
Constructor of the class.
add_theme_templates()  : array<string|int, mixed>
This is need to enable saving post – template association.
get_block_template()  : WP_Block_Template|null
Get a block template by ID.
get_post_types()  : array<string|int, mixed>
This is a callback function for adding post_types property to templates rest api response.
initialize()  : void
Initializes the class.
register_post_types_to_api()  : void
Register post_types property to the templates rest api response.
register_templates()  : Templates_Registry
Register the templates via register_block_template

Properties

Methods

add_theme_templates()

This is need to enable saving post – template association.

public add_theme_templates(array<string|int, mixed> $templates, string $theme, WP_Post $post, string $post_type) : array<string|int, mixed>

When a theme doesn't support block_templates feature the association is not saved, because templates registered via register_block_template are not added to the list of available templates. https://github.com/WordPress/wordpress-develop/blob/cdc2f255acce57372b849d6278c4156e1056c749/src/wp-includes/class-wp-theme.php#L1355

This function ensures that the email templates are in the list which is used for checking if the template can be saved in the association. See https://github.com/WordPress/wordpress-develop/blob/cdc2f255acce57372b849d6278c4156e1056c749/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php#L1595-L1599

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

The templates.

$theme : string

The theme.

$post : WP_Post

The post.

$post_type : string

The post type.

Return values
array<string|int, mixed>

get_post_types()

This is a callback function for adding post_types property to templates rest api response.

public get_post_types(array<string|int, mixed> $response_object) : array<string|int, mixed>
Parameters
$response_object : array<string|int, mixed>

The rest API response object.

Return values
array<string|int, mixed>

register_post_types_to_api()

Register post_types property to the templates rest api response.

public register_post_types_to_api() : void

There is a PR that adds the property into the core https://github.com/WordPress/wordpress-develop/pull/7530 Until it is merged, we need to add it manually.

Return values
void