Automattic\WooCommerce\Blocks\BlockTypes
ProductQuery::get_filter_by_price_query
Return a query that filters products by price.
Method of the class: ProductQuery{}
No Hooks.
Returns
Array.
Usage
// private - for code of main (parent) class only $result = $this->get_filter_by_price_query();
ProductQuery::get_filter_by_price_query() ProductQuery::get filter by price query code WC 10.5.0
private function get_filter_by_price_query() {
$min_price = get_query_var( PriceFilter::MIN_PRICE_QUERY_VAR );
$max_price = get_query_var( PriceFilter::MAX_PRICE_QUERY_VAR );
$max_price_query = empty( $max_price ) ? array() : [
'key' => '_price',
'value' => $max_price,
'compare' => '<=',
'type' => 'numeric',
];
$min_price_query = empty( $min_price ) ? array() : [
'key' => '_price',
'value' => $min_price,
'compare' => '>=',
'type' => 'numeric',
];
if ( empty( $min_price_query ) && empty( $max_price_query ) ) {
return array();
}
return array(
'meta_query' => array(
array(
'relation' => 'AND',
$max_price_query,
$min_price_query,
),
),
);
}