Automattic\WooCommerce\Blocks\Templates
SingleProductTemplate::render_block_template()
Renders the default block template from Woo Blocks if no theme templates exist.
Method of the class: SingleProductTemplate{}
No Hooks.
Return
null
. Nothing (null).
Usage
$SingleProductTemplate = new SingleProductTemplate(); $SingleProductTemplate->render_block_template();
SingleProductTemplate::render_block_template() SingleProductTemplate::render block template code WC 9.4.2
public function render_block_template() { if ( ! is_embed() && is_singular( 'product' ) ) { global $post; $compatibility_layer = new SingleProductTemplateCompatibility(); $compatibility_layer->init(); $valid_slugs = array( self::SLUG ); $single_product_slug = 'product' === $post->post_type && $post->post_name ? 'single-product-' . $post->post_name : ''; if ( $single_product_slug ) { $valid_slugs[] = 'single-product-' . $post->post_name; } $templates = get_block_templates( array( 'slug__in' => $valid_slugs ) ); if ( count( $templates ) === 0 ) { return; } // Use the first template by default. $template = $templates[0]; // Check if there is a template matching the slug `single-product-{post_name}`. if ( count( $valid_slugs ) > 1 && count( $templates ) > 1 ) { foreach ( $templates as $t ) { if ( $single_product_slug === $t->slug ) { $template = $t; break; } } } if ( isset( $template ) && BlockTemplateUtils::template_has_legacy_template_block( $template ) ) { add_filter( 'woocommerce_disable_compatibility_layer', '__return_true' ); } add_filter( 'woocommerce_has_block_template', '__return_true', 10, 0 ); } }