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:
parent
b5100e9d99
commit
966cf8a4c9
|
@ -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' );
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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 );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue