Automattic\WooCommerce\Blocks\Templates

SingleProductTemplateCompatibility::add_compatibility_layer()public staticWC 1.0

Add compatibility layer to the first and last block of the Single Product Template.

Method of the class: SingleProductTemplateCompatibility{}

No Hooks.

Return

String.

Usage

$result = SingleProductTemplateCompatibility::add_compatibility_layer( $template_content );
$template_content(string) (required)
Template.

SingleProductTemplateCompatibility::add_compatibility_layer() code WC 8.9.0

public static function add_compatibility_layer( $template_content ) {
	$parsed_blocks = parse_blocks( $template_content );

	if ( ! self::has_single_product_template_blocks( $parsed_blocks ) ) {
		$template = self::inject_custom_attributes_to_first_and_last_block_single_product_template( $parsed_blocks );
		return self::serialize_blocks( $template );
	}

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