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

Product_Collection::render_product_templateprivateWC 1.0

Render the product template block.

Method of the class: Product_Collection{}

No Hooks.

Returns

String.

Usage

// private - for code of main (parent) class only
$result = $this->render_product_template( $inner_block, $query, $collection_type, $columns, $rendering_context ): string;
$inner_block(array) (required)
Inner block data.
$query(WP_Query) (required)
WP_Query object.
$collection_type(string) (required)
Collection type identifier.
$columns(int) (required)
Number of columns for the grid layout.
$rendering_context(Rendering_Context) (required)
Rendering context.

Product_Collection::render_product_template() code WC 10.8.1

private function render_product_template( array $inner_block, \WP_Query $query, string $collection_type, int $columns, Rendering_Context $rendering_context ): string {
	if ( ! $query->have_posts() ) {
		return $this->render_no_results_message();
	}

	$posts       = $query->get_posts();
	$total_count = count( $posts );

	if ( 0 === $total_count ) {
		return $this->render_no_results_message();
	}

	$products = array_filter(
		array_map(
			function ( $post ) {
				return $post instanceof \WP_Post ? wc_get_product( $post->ID ) : null;
			},
			$posts
		)
	);
	return $this->render_product_grid( $products, $inner_block, $collection_type, $columns, $rendering_context );
}