Automattic\WooCommerce\Blocks\BlockTypes

ProductFilterPrice::register_active_filters_data()publicWC 1.0

Register the active filters data.

Method of the class: ProductFilterPrice{}

No Hooks.

Return

Array. Active filters data.

Usage

$ProductFilterPrice = new ProductFilterPrice();
$ProductFilterPrice->register_active_filters_data( $data, $params );
$data(array) (required)
The active filters data.
$params(array) (required)
The query param parsed from the URL.

ProductFilterPrice::register_active_filters_data() code WC 8.9.0

public function register_active_filters_data( $data, $params ) {
	$min_price           = intval( $params[ self::MIN_PRICE_QUERY_VAR ] ?? 0 );
	$max_price           = intval( $params[ self::MAX_PRICE_QUERY_VAR ] ?? 0 );
	$formatted_min_price = $min_price ? wp_strip_all_tags( wc_price( $min_price, array( 'decimals' => 0 ) ) ) : null;
	$formatted_max_price = $max_price ? wp_strip_all_tags( wc_price( $max_price, array( 'decimals' => 0 ) ) ) : null;

	if ( ! $formatted_min_price && ! $formatted_max_price ) {
		return $data;
	}

	if ( $formatted_min_price && $formatted_max_price ) {
		$title = sprintf(
			/* translators: %1$s and %2$s are the formatted minimum and maximum prices respectively. */
			__( 'Between %1$s and %2$s', 'woocommerce' ),
			$formatted_min_price,
			$formatted_max_price
		);
	}

	if ( ! $formatted_min_price ) {
		/* translators: %s is the formatted maximum price. */
		$title = sprintf( __( 'Up to %s', 'woocommerce' ), $formatted_max_price );
	}

	if ( ! $formatted_max_price ) {
		/* translators: %s is the formatted minimum price. */
		$title = sprintf( __( 'From %s', 'woocommerce' ), $formatted_min_price );
	}

	$data['price'] = array(
		'type'  => __( 'Price', 'woocommerce' ),
		'items' => array(
			array(
				'title'      => $title,
				'attributes' => array(
					'data-wc-on--click' => "{$this->get_full_block_name()}::actions.reset",
				),
			),
		),
	);

	return $data;
}