Automattic\WooCommerce\Blocks\Templates
SingleProductTemplateCompatibility::wrap_single_product_template()
For compatibility reason, we need to wrap the Single Product template in a div with specific class. For more details, see https://github.com/woocommerce/woocommerce-blocks/issues/8314.
Метод класса: SingleProductTemplateCompatibility{}
Хуков нет.
Возвращает
Массив
. Wrapped template content inside a div.
Использование
$result = SingleProductTemplateCompatibility::wrap_single_product_template( $template_content );
- $template_content(строка) (обязательный)
- Template Content.
Код SingleProductTemplateCompatibility::wrap_single_product_template() SingleProductTemplateCompatibility::wrap single product template WC 7.7.2
private static function wrap_single_product_template( $template_content ) { $parsed_blocks = parse_blocks( $template_content ); $grouped_blocks = self::group_blocks( $parsed_blocks ); $single_product_template_blocks = array( 'woocommerce/product-image-gallery', 'woocommerce/product-details', 'woocommerce/add-to-cart-form', 'woocommerce/product-meta', 'woocommerce/product-price', 'woocommerce/breadcrumbs' ); $wrapped_blocks = array_map( function( $blocks ) use ( $single_product_template_blocks ) { if ( 'core/template-part' === $blocks[0]['blockName'] ) { return $blocks; } $has_single_product_template_blocks = self::has_single_product_template_blocks( $blocks, $single_product_template_blocks ); if ( $has_single_product_template_blocks ) { $wrapped_block = self::create_wrap_block_group( $blocks ); return array( $wrapped_block[0] ); } return $blocks; }, $grouped_blocks ); return $wrapped_blocks; }