Automattic\WooCommerce\Blocks\BlockTypes

ProductQuery::get_filter_by_price_query()privateWC 1.0

Return a query that filters products by price.

Метод класса: ProductQuery{}

Хуков нет.

Возвращает

Массив.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->get_filter_by_price_query();

Код ProductQuery::get_filter_by_price_query() WC 8.7.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,
			),
		),
	);
}