Automattic\WooCommerce\Blocks\BlockTypes

ProductQuery::get_filter_by_rating_query()privateWC 1.0

Return a query that filters products by rating.

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

Хуков нет.

Возвращает

Массив.

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

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

Код ProductQuery::get_filter_by_rating_query() WC 7.3.0

private function get_filter_by_rating_query() {
	$filter_rating_values = get_query_var( RatingFilter::RATING_QUERY_VAR );
	if ( empty( $filter_rating_values ) ) {
		return array();
	}

	$parsed_filter_rating_values = explode( ',', $filter_rating_values );
	$product_visibility_terms    = wc_get_product_visibility_term_ids();

	if ( empty( $parsed_filter_rating_values ) || empty( $product_visibility_terms ) ) {
		return array();
	}

	$rating_terms = array_map(
		function( $rating ) use ( $product_visibility_terms ) {
			return $product_visibility_terms[ 'rated-' . $rating ];
		},
		$parsed_filter_rating_values
	);

	return array(
		'tax_query' => array(
			array(
				'field'         => 'term_taxonomy_id',
				'taxonomy'      => 'product_visibility',
				'terms'         => $rating_terms,
				'operator'      => 'IN',
				'rating_filter' => true,
			),
		),
	);
}