Automattic\WooCommerce\Blocks\BlockTypes
ProductFilterRating::get_dropdown_props()
Get the dropdown props.
Метод класса: ProductFilterRating{}
Хуков нет.
Возвращает
Массив<Массив-key,
. array>
Использование
// private - только в коде основоного (родительского) класса $result = $this->get_dropdown_props( $rating_counts, $selected_ratings_query, $show_counts, $select_type );
- $rating_counts(разное) (обязательный)
- The rating counts.
- $selected_ratings_query(разное) (обязательный)
- The url query param for selected ratings.
- $show_counts(true|false) (обязательный)
- Whether to show the counts.
- $select_type(строка) (обязательный)
- The select type. (single|multiple).
Код ProductFilterRating::get_dropdown_props() ProductFilterRating::get dropdown props WC 9.3.3
private function get_dropdown_props( $rating_counts, $selected_ratings_query, $show_counts, $select_type ) { $ratings_array = explode( ',', $selected_ratings_query ); $placeholder_text = 'single' === $select_type ? __( 'Select a rating', 'woocommerce' ) : __( 'Select ratings', 'woocommerce' ); $selected_items = array_reduce( $rating_counts, function( $carry, $rating ) use ( $ratings_array, $show_counts ) { if ( in_array( (string) $rating['rating'], $ratings_array, true ) ) { $count = $rating['count']; $count_label = $show_counts ? "($count)" : ''; $rating_str = (string) $rating['rating']; $carry[] = array( /* translators: %d is referring to the average rating value. Example: Rated 4 out of 5. */ 'label' => sprintf( __( 'Rated %d out of 5', 'woocommerce' ), $rating_str ) . ' ' . $count_label, 'value' => $rating['rating'], ); } return $carry; }, array() ); return array( 'items' => array_map( function ( $rating ) use ( $show_counts ) { $count = $rating['count']; $count_label = $show_counts ? "($count)" : ''; $rating_str = (string) $rating['rating']; return array( /* translators: %d is referring to the average rating value. Example: Rated 4 out of 5. */ 'label' => sprintf( __( 'Rated %d out of 5', 'woocommerce' ), $rating_str ) . ' ' . $count_label, 'value' => $rating['rating'], ); }, $rating_counts ), 'select_type' => $select_type, 'selected_items' => $selected_items, 'action' => "{$this->get_full_block_name()}::actions.onDropdownChange", 'placeholder' => $placeholder_text, ); }