WordPress at Your Fingertips
function is not described


BlockTemplateUtils::create_new_block_template_object() public WC 1.0

Build a new template object so that we can make Woo Blocks default templates available in the current theme should they not have any.

{} It's a method of the class: BlockTemplateUtils{}

No Hooks.


Object. Block template object.


$result = BlockTemplateUtils::create_new_block_template_object( $template_file, $template_type, $template_slug, $template_is_from_theme );
$template_file(string) (required)
Block template file path.
$template_type(string) (required)
wp_template or wp_template_part.
$template_slug(string) (required)
Block template slug e.g. single-product.
If the block template file is being loaded from the current theme instead of Woo Blocks.
Default: false

Code of BlockTemplateUtils::create_new_block_template_object() WC 6.1.1

public static function create_new_block_template_object( $template_file, $template_type, $template_slug, $template_is_from_theme = false ) {
	$theme_name = wp_get_theme()->get( 'TextDomain' );

	$new_template_item = array(
		'slug'        => $template_slug,
		'id'          => $template_is_from_theme ? $theme_name . '//' . $template_slug : self::PLUGIN_SLUG . '//' . $template_slug,
		'path'        => $template_file,
		'type'        => $template_type,
		'theme'       => $template_is_from_theme ? $theme_name : self::PLUGIN_SLUG,
		// Plugin was agreed as a valid source value despite existing inline docs at the time of creating: https://github.com/WordPress/gutenberg/issues/36597#issuecomment-976232909.
		'source'      => $template_is_from_theme ? 'theme' : 'plugin',
		'title'       => self::convert_slug_to_title( $template_slug ),
		'description' => '',
		'post_types'  => array(), // Don't appear in any Edit Post template selector dropdown.

	return (object) $new_template_item;