From 278f0ec0db10be7d1f8f898b5019753fc475669f Mon Sep 17 00:00:00 2001 From: Luigi Teschio Date: Fri, 2 Jun 2023 15:59:20 +0200 Subject: [PATCH] Blockified Single Product Template: avoid to add another group block on the editor side when the user creates a template for a specific product (https://github.com/woocommerce/woocommerce-blocks/pull/9699) * Blockified Single Product Template: avoid to add another group block on the editor side when the user creates a template for a specific product * improve comment --- plugins/woocommerce-blocks/src/BlockTemplatesController.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/woocommerce-blocks/src/BlockTemplatesController.php b/plugins/woocommerce-blocks/src/BlockTemplatesController.php index df06d5faf16..e0904954735 100644 --- a/plugins/woocommerce-blocks/src/BlockTemplatesController.php +++ b/plugins/woocommerce-blocks/src/BlockTemplatesController.php @@ -324,8 +324,10 @@ class BlockTemplatesController { } if ( str_contains( $template->slug, 'single-product' ) ) { - if ( ! is_admin() && ! BlockTemplateUtils::template_has_legacy_template_block( $template ) ) { - + // We don't want to add the compatibility layer on the Editor Side. + // The second condition is necessary to not apply the compatibility layer on the REST API. Gutenberg uses the REST API to clone the template. + // More details: https://github.com/woocommerce/woocommerce-blocks/issues/9662. + if ( ( ! is_admin() && ! ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ) && ! BlockTemplateUtils::template_has_legacy_template_block( $template ) ) { $new_content = SingleProductTemplateCompatibility::add_compatibility_layer( $template->content ); $template->content = $new_content; }