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 7.1.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',
	];

	return array(
		// Ignoring the warning of not using meta queries.
		// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
		'meta_query' => array(
			'relation' => 'AND',
			$max_price_query,
			$min_price_query,
		),
	);
}