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.
Method of the class: SingleProductTemplateCompatibility{}
No Hooks.
Return
Array
. Wrapped template content inside a div.
Usage
$result = SingleProductTemplateCompatibility::wrap_single_product_template( $template_content );
- $template_content(string) (required)
- Template Content.
SingleProductTemplateCompatibility::wrap_single_product_template() SingleProductTemplateCompatibility::wrap single product template code WC 9.4.2
private static function wrap_single_product_template( $template_content ) { $parsed_blocks = parse_blocks( $template_content ); $grouped_blocks = self::group_blocks( $parsed_blocks ); $wrapped_blocks = array_map( function ( $blocks ) { if ( 'core/template-part' === $blocks[0]['blockName'] ) { return $blocks; } $has_single_product_template_blocks = self::has_single_product_template_blocks( $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; }