Automattic\WooCommerce\Blocks\BlockTypes

ProductFilterRating::get_rating_items()privateWC 1.0

Get the Rating list items.

Method of the class: ProductFilterRating{}

No Hooks.

Return

Array. The rating items.

Usage

// private - for code of main (parent) class only
$result = $this->get_rating_items( $ratings, $selected, $with_counts );
$ratings(array) (required)
- The rating counts.
$selected(array) (required)
- an array of selected ratings.
$with_counts(true|false) (required)
- Whether to show the counts.

ProductFilterRating::get_rating_items() code WC 9.6.1

private function get_rating_items( $ratings, $selected, $with_counts ) {
	return array_map(
		function ( $rating ) use ( $selected, $with_counts ) {
			$value       = (string) $rating['rating'];
			$count_label = $with_counts ? "({$rating['count']})" : '';

			$aria_label = sprintf(
				/* translators: %1$d is referring to rating value. Example: Rated 4 out of 5. */
				__( 'Rated %s out of 5', 'woocommerce' ),
				$value,
			);

			return array(
				'id'         => 'rating-' . $value,
				'selected'   => in_array( $value, $selected, true ),
				'label'      => $this->render_rating_label( (int) $value, $count_label ),
				'aria_label' => $aria_label,
				'value'      => $value,
			);
		},
		$ratings
	);
}