Automattic\WooCommerce\Blocks\BlockTypes
ProductFilterRating::prepare_selected_filters
Prepare the active filter items.
Method of the class: ProductFilterRating{}
No Hooks.
Returns
Array. Active filters items.
Usage
$ProductFilterRating = new ProductFilterRating(); $ProductFilterRating->prepare_selected_filters( $items, $params );
- $items(array) (required)
- The active filter items.
- $params(array) (required)
- The query param parsed from the URL.
ProductFilterRating::prepare_selected_filters() ProductFilterRating::prepare selected filters code WC 10.8.1
public function prepare_selected_filters( $items, $params ) {
if ( empty( $params[ self::RATING_FILTER_QUERY_VAR ] ) ) {
return $items;
}
$active_ratings = array_map( 'absint', explode( ',', $params[ self::RATING_FILTER_QUERY_VAR ] ) );
$active_ratings = array_filter(
$active_ratings,
function ( $rating ) {
return $rating > 0 && $rating < 6;
}
);
$active_ratings = array_unique( $active_ratings );
if ( empty( $active_ratings ) ) {
return $items;
}
foreach ( $active_ratings as $rating ) {
$items[] = array(
'type' => 'rating',
'value' => (string) $rating,
/* translators: %s is referring to rating value. Example: Rated 4 out of 5. */
'activeLabel' => sprintf( __( 'Rating: Rated %d out of 5', 'woocommerce' ), $rating ),
);
}
return $items;
}