Automattic\WooCommerce\Blocks\BlockTypes

ProductQuery::build_query()publicWC 1.0

Return a custom query based on attributes, filters and global WP_Query.

Method of the class: ProductQuery{}

No Hooks.

Return

Array.

Usage

$ProductQuery = new ProductQuery();
$ProductQuery->build_query( $query, $block );
$query(WP_Query) (required)
The WordPress Query.
$block(WP_Block)
The block being rendered.
Default: null

ProductQuery::build_query() code WC 9.8.2

public function build_query( $query, $block = null ) {
	$parsed_block                = $this->parsed_block;
	$is_product_collection_block = $block->context['query']['isProductCollectionBlock'] ?? false;
	if ( ! $this->is_woocommerce_variation( $parsed_block ) || $is_product_collection_block ) {
		return $query;
	}

	$common_query_values = array(
		'meta_query'     => array(),
		'posts_per_page' => $query['posts_per_page'],
		'orderby'        => $query['orderby'],
		'order'          => $query['order'],
		'offset'         => $query['offset'],
		'post__in'       => array(),
		'post_status'    => ProductStatus::PUBLISH,
		'post_type'      => 'product',
		'tax_query'      => array(),
	);

	$handpicked_products = isset( $parsed_block['attrs']['query']['include'] ) ?
		$parsed_block['attrs']['query']['include'] : $common_query_values['post__in'];

	$merged_query = $this->merge_queries(
		$common_query_values,
		$this->get_global_query( $parsed_block ),
		$this->get_custom_orderby_query( $query['orderby'] ),
		$this->get_queries_by_custom_attributes( $parsed_block ),
		$this->get_queries_by_applied_filters(),
		$this->get_filter_by_taxonomies_query( $query ),
		$this->get_filter_by_keyword_query( $query )
	);

	return $this->filter_query_to_only_include_ids( $merged_query, $handpicked_products );
}