Automattic\WooCommerce\Blocks\BlockTypes

ProductFilterRating::prepare_selected_filters()publicWC 1.0

Prepare the active filter items.

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

Хуков нет.

Возвращает

Массив. Active filters items.

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

$ProductFilterRating = new ProductFilterRating();
$ProductFilterRating->prepare_selected_filters( $items, $params );
$items(массив) (обязательный)
The active filter items.
$params(массив) (обязательный)
The query param parsed from the URL.

Код ProductFilterRating::prepare_selected_filters() WC 9.8.4

public function prepare_selected_filters( $items, $params ) {
	if ( empty( $params[ self::RATING_FILTER_QUERY_VAR ] ) ) {
		return $items;
	}

	$active_ratings = array_filter(
		explode( ',', $params[ self::RATING_FILTER_QUERY_VAR ] )
	);

	if ( empty( $active_ratings ) ) {
		return $items;
	}

	foreach ( $active_ratings as $rating ) {
		$items[] = array(
			'type'  => 'rating',
			'value' => $rating,
			/* translators: %s is referring to rating value. Example: Rated 4 out of 5. */
			'label' => sprintf( __( 'Rating: Rated %d out of 5', 'woocommerce' ), $rating ),
		);
	}

	return $items;
}