Automattic\WooCommerce\Blocks\Utils

BlockTemplateUtils::create_new_block_template_object()public staticWC 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.

Method of the class: BlockTemplateUtils{}

No Hooks.

Return

Object. Block template object.

Usage

$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.
$template_is_from_theme(true|false)
If the block template file is being loaded from the current theme instead of Woo Blocks.
Default: false

BlockTemplateUtils::create_new_block_template_object() code WC 9.4.2

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::get_block_template_title( $template_slug ),
		'description' => self::get_block_template_description( $template_slug ),
		'post_types'  => array(), // Don't appear in any Edit Post template selector dropdown.
	);

	return (object) $new_template_item;
}