Automattic\WooCommerce\Blocks\BlockTypes
MiniCart::render_template_part_contents
Render Mini-Cart template contents while removing legacy saved wrappers.
Method of the class: MiniCart{}
No Hooks.
Returns
string. The rendered template contents.
Usage
// private - for code of main (parent) class only $result = $this->render_template_part_contents( $template_contents );
- $template_contents(string) (required)
- The template contents to render.
MiniCart::render_template_part_contents() MiniCart::render template part contents code WC 11.2.2
private function render_template_part_contents( $template_contents ) {
$process_legacy_wrappers = function ( $parsed_block ) {
if ( 'woocommerce/mini-cart-contents' !== ( $parsed_block['blockName'] ?? null ) ) {
return $parsed_block;
}
$processed_blocks = parse_blocks(
$this->process_template_contents( serialize_block( $parsed_block ) )
);
return $processed_blocks[0] ?? $parsed_block;
};
add_filter( 'render_block_data', $process_legacy_wrappers, 10, 1 );
try {
return do_blocks( $template_contents );
} finally {
remove_filter( 'render_block_data', $process_legacy_wrappers, 10 );
}
}