Automattic\WooCommerce\EmailEditor\Integrations\WooCommerce\Renderer\Blocks

Product_Collection::render_contentprotectedWC 1.0

Render the product collection block content for email.

Method of the class: Product_Collection{}

No Hooks.

Returns

String.

Usage

// protected - for code of main (parent) or child class
$result = $this->render_content( $block_content, $parsed_block, $rendering_context ): string;
$block_content(string) (required)
Block content.
$parsed_block(array) (required)
Parsed block.
$rendering_context(Rendering_Context) (required)
Rendering context.

Product_Collection::render_content() code WC 10.5.0

protected function render_content( string $block_content, array $parsed_block, Rendering_Context $rendering_context ): string {
	// Create a query for the Product Collection block.
	$query = $this->prepare_and_execute_query( $parsed_block, $rendering_context );

	// Get collection type to pass to child blocks.
	$collection_type = $parsed_block['attrs']['collection'] ?? '';

	$content = '';

	foreach ( $parsed_block['innerBlocks'] as $inner_block ) {
		switch ( $inner_block['blockName'] ) {
			case 'woocommerce/product-template':
				$content .= $this->render_product_template( $inner_block, $query, $collection_type );
				break;
			default:
				$content .= render_block( $inner_block );
				break;
		}
	}

	wp_reset_postdata();

	return $content;
}