Fix Classic Template block in Single Product custom templates (https://github.com/woocommerce/woocommerce-blocks/pull/10342)

* Fix Classic Template block in Single Product custom templates

* Update src/BlockTemplatesController.php

Co-authored-by: Tom Cafferkey <tjcafferkey@gmail.com>

---------

Co-authored-by: Tom Cafferkey <tjcafferkey@gmail.com>
This commit is contained in:
Albert Juhé Lluveras 2023-07-27 08:26:30 +02:00 committed by GitHub
parent b5100e9d99
commit 966cf8a4c9
3 changed files with 9 additions and 4 deletions

View File

@ -590,7 +590,13 @@ class BlockTemplatesController {
if (
is_singular( 'product' ) && $this->block_template_is_available( 'single-product' )
) {
$templates = get_block_templates( array( 'slug__in' => array( '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' );

View File

@ -9,7 +9,7 @@ use WC_Shortcode_Checkout;
use WC_Frontend_Scripts;
/**
* Classic Single Product class
* Classic Template class
*
* @internal
*/
@ -91,7 +91,7 @@ class ClassicTemplate extends AbstractDynamicBlock {
return $this->render_order_received();
}
if ( 'single-product' === $attributes['template'] ) {
if ( is_product() ) {
return $this->render_single_product();
}

View File

@ -269,7 +269,6 @@ class SingleProductTemplateCompatibility extends AbstractTemplateCompatibility {
$wrapped_blocks = self::wrap_single_product_template( $template_content );
$template = self::inject_custom_attributes_to_first_and_last_block_single_product_template( $wrapped_blocks );
return self::serialize_blocks( $template );
}
/**