Automattic\WooCommerce\Blocks
BlockTemplatesRegistry::init
Initialization method.
Method of the class: BlockTemplatesRegistry{}
No Hooks.
Returns
null. Nothing (null).
Usage
$BlockTemplatesRegistry = new BlockTemplatesRegistry(); $BlockTemplatesRegistry->init();
BlockTemplatesRegistry::init() BlockTemplatesRegistry::init code WC 10.7.0
public function init() {
if ( BlockTemplateUtils::supports_block_templates( 'wp_template' ) ) {
$templates = array(
ProductCatalogTemplate::SLUG => new ProductCatalogTemplate(),
ProductCategoryTemplate::SLUG => new ProductCategoryTemplate(),
ProductTagTemplate::SLUG => new ProductTagTemplate(),
ProductAttributeTemplate::SLUG => new ProductAttributeTemplate(),
ProductBrandTemplate::SLUG => new ProductBrandTemplate(),
ProductSearchResultsTemplate::SLUG => new ProductSearchResultsTemplate(),
CartTemplate::SLUG => new CartTemplate(),
CheckoutTemplate::SLUG => new CheckoutTemplate(),
OrderConfirmationTemplate::SLUG => new OrderConfirmationTemplate(),
SingleProductTemplate::SLUG => new SingleProductTemplate(),
);
} else {
$templates = array();
}
if ( Features::is_enabled( 'launch-your-store' ) ) {
$templates[ ComingSoonTemplate::SLUG ] = new ComingSoonTemplate();
}
if ( BlockTemplateUtils::supports_block_templates( 'wp_template_part' ) ) {
$template_parts = array(
MiniCartTemplate::SLUG => new MiniCartTemplate(),
CheckoutHeaderTemplate::SLUG => new CheckoutHeaderTemplate(),
);
if ( wp_is_block_theme() ) {
$product_types = wc_get_product_types();
if ( count( $product_types ) > 0 ) {
add_filter( 'default_wp_template_part_areas', array( $this, 'register_add_to_cart_with_options_template_part_area' ), 10, 1 );
if ( array_key_exists( ProductType::SIMPLE, $product_types ) ) {
$template_parts[ SimpleProductAddToCartWithOptionsTemplate::SLUG ] = new SimpleProductAddToCartWithOptionsTemplate();
}
if ( array_key_exists( ProductType::EXTERNAL, $product_types ) ) {
$template_parts[ ExternalProductAddToCartWithOptionsTemplate::SLUG ] = new ExternalProductAddToCartWithOptionsTemplate();
}
if ( array_key_exists( ProductType::VARIABLE, $product_types ) ) {
$template_parts[ VariableProductAddToCartWithOptionsTemplate::SLUG ] = new VariableProductAddToCartWithOptionsTemplate();
}
if ( array_key_exists( ProductType::GROUPED, $product_types ) ) {
$template_parts[ GroupedProductAddToCartWithOptionsTemplate::SLUG ] = new GroupedProductAddToCartWithOptionsTemplate();
}
}
}
} else {
$template_parts = array();
}
// Init all templates.
foreach ( $templates as $template ) {
$template->init();
// Taxonomy templates are registered automatically by WordPress and
// are made available through the Add Template menu.
if ( ! $template->is_taxonomy_template ) {
$directory = BlockTemplateUtils::get_templates_directory( 'wp_template' );
$template_file_path = $directory . '/' . $template::SLUG . '.html';
register_block_template(
'woocommerce//' . $template::SLUG,
array(
'title' => $template->get_template_title(),
'description' => $template->get_template_description(),
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
'content' => file_get_contents( $template_file_path ),
)
);
}
}
foreach ( $template_parts as $template_part ) {
$template_part->init();
}
$this->templates = array_merge( $templates, $template_parts );
}