Automattic\WooCommerce\Blocks

BlockTemplatesController::render_block_template()publicWC 1.0

Renders the default block template from Woo Blocks if no theme templates exist.

Метод класса: BlockTemplatesController{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

$BlockTemplatesController = new BlockTemplatesController();
$BlockTemplatesController->render_block_template();

Код BlockTemplatesController::render_block_template() WC 8.7.0

public function render_block_template() {
	if ( is_embed() || ! BlockTemplateUtils::supports_block_templates() ) {
		return;
	}

	if (
		is_singular( 'product' ) && $this->block_template_is_available( 'single-product' )
	) {
		global $post;

		$valid_slugs = [ 'single-product' ];
		if ( 'product' === $post->post_type && $post->post_name ) {
			$valid_slugs[] = 'single-product-' . $post->post_name;
		}
		$templates = get_block_templates( array( 'slug__in' => $valid_slugs ) );

		if ( isset( $templates[0] ) && BlockTemplateUtils::template_has_legacy_template_block( $templates[0] ) ) {
			add_filter( 'woocommerce_disable_compatibility_layer', '__return_true' );
		}

		if ( ! BlockTemplateUtils::theme_has_template( 'single-product' ) ) {
			add_filter( 'woocommerce_has_block_template', '__return_true', 10, 0 );
		}
	} elseif (
		( is_product_taxonomy() && is_tax( 'product_cat' ) ) && $this->block_template_is_available( 'taxonomy-product_cat' )
	) {
		$templates = get_block_templates( array( 'slug__in' => array( 'taxonomy-product_cat' ) ) );

		if ( isset( $templates[0] ) && BlockTemplateUtils::template_has_legacy_template_block( $templates[0] ) ) {
			add_filter( 'woocommerce_disable_compatibility_layer', '__return_true' );
		}

		if ( ! BlockTemplateUtils::theme_has_template( 'taxonomy-product_cat' ) ) {
			add_filter( 'woocommerce_has_block_template', '__return_true', 10, 0 );
		}
	} elseif (
		( is_product_taxonomy() && is_tax( 'product_tag' ) ) && $this->block_template_is_available( 'taxonomy-product_tag' )
	) {
		$templates = get_block_templates( array( 'slug__in' => array( 'taxonomy-product_tag' ) ) );

		if ( isset( $templates[0] ) && BlockTemplateUtils::template_has_legacy_template_block( $templates[0] ) ) {
			add_filter( 'woocommerce_disable_compatibility_layer', '__return_true' );
		}

		if ( ! BlockTemplateUtils::theme_has_template( 'taxonomy-product_tag' ) ) {
			add_filter( 'woocommerce_has_block_template', '__return_true', 10, 0 );
		}
	} elseif ( is_post_type_archive( 'product' ) && is_search() ) {
		$templates = get_block_templates( array( 'slug__in' => array( ProductSearchResultsTemplate::SLUG ) ) );

		if ( isset( $templates[0] ) && BlockTemplateUtils::template_has_legacy_template_block( $templates[0] ) ) {
			add_filter( 'woocommerce_disable_compatibility_layer', '__return_true' );
		}

		if ( ! BlockTemplateUtils::theme_has_template( ProductSearchResultsTemplate::SLUG ) ) {
			add_filter( 'woocommerce_has_block_template', '__return_true', 10, 0 );
		}
	} elseif (
		( is_post_type_archive( 'product' ) || is_page( wc_get_page_id( 'shop' ) ) ) && $this->block_template_is_available( 'archive-product' )
	) {
		$templates = get_block_templates( array( 'slug__in' => array( 'archive-product' ) ) );

		if ( isset( $templates[0] ) && BlockTemplateUtils::template_has_legacy_template_block( $templates[0] ) ) {
			add_filter( 'woocommerce_disable_compatibility_layer', '__return_true' );
		}

		if ( ! BlockTemplateUtils::theme_has_template( 'archive-product' ) ) {
			add_filter( 'woocommerce_has_block_template', '__return_true', 10, 0 );
		}
	} elseif (
		is_cart() &&
		! BlockTemplateUtils::theme_has_template( CartTemplate::get_slug() ) && $this->block_template_is_available( CartTemplate::get_slug() )
	) {
		add_filter( 'woocommerce_has_block_template', '__return_true', 10, 0 );
	} elseif (
		is_checkout() &&
		! BlockTemplateUtils::theme_has_template( CheckoutTemplate::get_slug() ) && $this->block_template_is_available( CheckoutTemplate::get_slug() )
	) {
		add_filter( 'woocommerce_has_block_template', '__return_true', 10, 0 );
	} else {
		$queried_object = get_queried_object();
		if ( is_null( $queried_object ) ) {
			return;
		}

		if ( isset( $queried_object->taxonomy ) && taxonomy_is_product_attribute( $queried_object->taxonomy ) && $this->block_template_is_available( ProductAttributeTemplate::SLUG )
		) {
			$templates = get_block_templates( array( 'slug__in' => array( ProductAttributeTemplate::SLUG ) ) );

			if ( isset( $templates[0] ) && BlockTemplateUtils::template_has_legacy_template_block( $templates[0] ) ) {
				add_filter( 'woocommerce_disable_compatibility_layer', '__return_true' );
			}

			if ( ! BlockTemplateUtils::theme_has_template( ProductAttributeTemplate::SLUG ) ) {
				add_filter( 'woocommerce_has_block_template', '__return_true', 10, 0 );
			}
		}
	}
}