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

widget


Description Description

Outputs the widget front-end HTML


Top ↑

Parameters Parameters

$args

(array) (Required)

$instance

(array) (Required)


Top ↑

Return Return

(void)


Top ↑

Source Source

File: includes/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">', $instance['orientation'] );
		if( ! empty( $title ) ) {
			printf(
				'<div class="price-title">%s%s%s</div>',
				$args['before_title'],
				$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 = ($instance['display_type'] == 'buttons') ? ' 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>',
				remove_query_arg('max_price'),
				__( 'Remove', 'inventory-presser' ),
				number_format( (int) $_GET['max_price'], 0, '.', ',' ),
				__( 'Price Filter', 'inventory-presser' )
			);
		}

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