Automattic\WooCommerce\Blocks\Templates

SingleProductTemplateCompatibility::wrap_single_product_template()private staticWC 1.0

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() WC 8.9.3

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;
}