Automattic\WooCommerce\Blocks

BlockTemplatesRegistry::initpublicWC 1.0

Initialization method.

Method of the class: BlockTemplatesRegistry{}

No Hooks.

Returns

null. Nothing (null).

Usage

$BlockTemplatesRegistry = new BlockTemplatesRegistry();
$BlockTemplatesRegistry->init();

BlockTemplatesRegistry::init() code WC 9.9.3

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(),
			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 ( Features::is_enabled( 'blockified-add-to-cart' ) && 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();
	}
	$this->templates = array_merge( $templates, $template_parts );

	// Init all templates.
	foreach ( $this->templates as $template ) {
		$template->init();
	}
}