Automattic\WooCommerce\Blocks\BlockTypes

ProductQuery::update_rest_query()publicWC 1.0

Update the query for the product query block in Editor.

Method of the class: ProductQuery{}

No Hooks.

Return

null. Nothing (null).

Usage

$ProductQuery = new ProductQuery();
$ProductQuery->update_rest_query( $args, $request ): array;
$args(array) (required)
Query args.
$request(WP_REST_Request) (required)
Request.

ProductQuery::update_rest_query() code WC 9.4.2

public function update_rest_query( $args, $request ): array {
	$woo_attributes      = $request->get_param( '__woocommerceAttributes' );
	$is_valid_attributes = is_array( $woo_attributes );
	$orderby             = $request->get_param( 'orderby' );
	$woo_stock_status    = $request->get_param( '__woocommerceStockStatus' );
	$on_sale             = $request->get_param( '__woocommerceOnSale' ) === 'true';

	$on_sale_query    = $on_sale ? $this->get_on_sale_products_query() : [];
	$orderby_query    = $orderby ? $this->get_custom_orderby_query( $orderby ) : [];
	$attributes_query = $is_valid_attributes ? $this->get_product_attributes_query( $woo_attributes ) : [];
	$stock_query      = is_array( $woo_stock_status ) ? $this->get_stock_status_query( $woo_stock_status ) : [];
	$visibility_query = is_array( $woo_stock_status ) ? $this->get_product_visibility_query( $stock_query ) : [];
	$tax_query        = $is_valid_attributes ? $this->merge_tax_queries( $attributes_query, $visibility_query ) : [];

	return array_merge( $args, $on_sale_query, $orderby_query, $stock_query, $tax_query );
}