Automattic\WooCommerce\Blocks\BlockTypes

ProductFilterRating::register_active_filters_data()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::register_active_filters_data() WC 9.7.1

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;
}

/**
 * Include and render the block.
 *
 * @param array    $attributes Block attributes. Default empty array.
 * @param string   $content    Block content. Default empty string.
 * @param WP_Block $block      Block instance.
 * @return string Rendered block type output.
 */
protected function render( $attributes, $content, $block ) {