Inventory_Presser_Maximum_Price_Filter::widget( array $args, array $instance )

Outputs the widget front-end HTML


Parameters

$args

(array) (Required)

$instance

(array) (Required)


Return

(void)


Source

File: includes/widget/class-widget-maximum-price-filter.php

	public function widget( $args, $instance ) {

		// Need the stylesheet for this content.
		wp_enqueue_style( 'invp-maximum-price-filters' );

		$reset_link_only = ( isset( $instance['cb_reset_link_only'] ) && $instance['cb_reset_link_only'] == 'true' );

		if ( $reset_link_only && ! isset( $_GET['max_price'] ) ) {
			return;
		}

		echo $args['before_widget'] ?? '';

		$title = apply_filters( 'widget_title', $instance['title'] ?? '' );

		printf( '<div class="price-filter price-filter-%s">', esc_attr( $instance['orientation'] ?? '' ) );
		if ( ! empty( $title ) ) {
			printf(
				'<div class="price-title">%s%s%s</div>',
				$args['before_title'] ?? '',
				esc_html( $title ),
				$args['after_title'] ?? ''
			);
		}

		if ( ! $reset_link_only ) {

			$price_points = ( isset( $instance['prices'] ) && is_array( $instance['prices'] ) ) ? $instance['prices'] : $this->price_defaults;

			$base_link = add_query_arg(
				array(
					'orderby' => apply_filters( 'invp_prefix_meta_key', 'price' ),
					'order'   => 'DESC',
				),
				get_post_type_archive_link( INVP::POST_TYPE )
			);

			$class_string = ( 'buttons' === $instance['display_type'] ?? '' ) ? ' class="_button _button-med"' : ' class="price-filter-text"';

			foreach ( $price_points as $price_point ) {
				$this_link = add_query_arg( 'max_price', $price_point, $base_link );
				printf(
					'<div><a href="%s"%s><span class="dashicons dashicons-arrow-down-alt"></span>&nbsp;$%s</a></div>',
					$this_link,
					$class_string,
					number_format( $price_point, 0, '.', ',' )
				);
			}
		}

		if ( isset( $_GET['max_price'] ) ) {
			printf(
				'<div><a href="%s">%s $%s %s</a></div>',
				esc_attr( remove_query_arg( 'max_price' ) ),
				esc_html__( 'Remove', 'inventory-presser' ),
				number_format( (int) $_GET['max_price'], 0, '.', ',' ),
				esc_html__( 'Price Filter', 'inventory-presser' )
			);
		}

		echo '</div>' . $args['after_widget'] ?? '';
	}