2012-10-14 12:06:37 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Layered Navigation Fitlers Widget
|
|
|
|
*
|
|
|
|
* @author WooThemes
|
|
|
|
* @category Widgets
|
|
|
|
* @package WooCommerce/Widgets
|
2012-12-03 19:19:58 +00:00
|
|
|
* @version 2.0.0
|
2012-10-14 12:06:37 +00:00
|
|
|
* @extends WP_Widget
|
|
|
|
*/
|
2012-10-15 10:57:58 +00:00
|
|
|
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
|
|
|
|
2012-12-31 18:25:09 +00:00
|
|
|
class WC_Widget_Layered_Nav_Filters extends WP_Widget {
|
2012-10-14 12:06:37 +00:00
|
|
|
|
|
|
|
var $woo_widget_cssclass;
|
|
|
|
var $woo_widget_description;
|
|
|
|
var $woo_widget_idbase;
|
|
|
|
var $woo_widget_name;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* constructor
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2012-12-31 18:25:09 +00:00
|
|
|
function WC_Widget_Layered_Nav_Filters() {
|
2012-10-14 12:06:37 +00:00
|
|
|
|
|
|
|
/* Widget variable settings. */
|
2012-11-15 17:46:24 +00:00
|
|
|
$this->woo_widget_cssclass = 'woocommerce widget_layered_nav_filters';
|
2012-10-14 12:06:37 +00:00
|
|
|
$this->woo_widget_description = __( 'Shows active layered nav filters so users can see and deactivate them.', 'woocommerce' );
|
|
|
|
$this->woo_widget_idbase = 'woocommerce_layered_nav_filters';
|
|
|
|
$this->woo_widget_name = __( 'WooCommerce Layered Nav Filters', 'woocommerce' );
|
|
|
|
|
|
|
|
/* Widget settings. */
|
|
|
|
$widget_ops = array( 'classname' => $this->woo_widget_cssclass, 'description' => $this->woo_widget_description );
|
|
|
|
|
|
|
|
/* Create the widget. */
|
|
|
|
$this->WP_Widget( 'woocommerce_layered_nav_filters', $this->woo_widget_name, $widget_ops );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* widget function.
|
|
|
|
*
|
|
|
|
* @see WP_Widget
|
|
|
|
* @access public
|
|
|
|
* @param array $args
|
|
|
|
* @param array $instance
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function widget( $args, $instance ) {
|
|
|
|
global $_chosen_attributes, $woocommerce, $_attributes_array;
|
2012-11-27 16:22:47 +00:00
|
|
|
|
2012-10-14 12:06:37 +00:00
|
|
|
extract( $args );
|
|
|
|
|
2012-12-13 12:25:46 +00:00
|
|
|
if ( ! is_post_type_archive( 'product' ) && is_array( $_attributes_array ) && ! is_tax( array_merge( $_attributes_array, array( 'product_cat', 'product_tag' ) ) ) )
|
2012-10-14 12:06:37 +00:00
|
|
|
return;
|
2012-11-27 16:22:47 +00:00
|
|
|
|
2012-10-14 12:06:37 +00:00
|
|
|
$current_term = $_attributes_array && is_tax( $_attributes_array ) ? get_queried_object()->term_id : '';
|
|
|
|
$current_tax = $_attributes_array && is_tax( $_attributes_array ) ? get_queried_object()->taxonomy : '';
|
2012-11-27 16:22:47 +00:00
|
|
|
|
2012-12-26 16:08:25 +00:00
|
|
|
$title = ( ! isset( $instance['title'] ) ) ? __( 'Active filters', 'woocommerce' ) : $instance['title'];
|
2012-12-26 15:59:11 +00:00
|
|
|
$title = apply_filters( 'widget_title', $title, $instance, $this->id_base);
|
2012-11-27 16:22:47 +00:00
|
|
|
|
2012-10-14 12:06:37 +00:00
|
|
|
// Price
|
2013-01-12 13:03:19 +00:00
|
|
|
$min_price = isset( $_GET['min_price'] ) ? esc_attr( $_GET['min_price'] ) : 0;
|
|
|
|
$max_price = isset( $_GET['max_price'] ) ? esc_attr( $_GET['max_price'] ) : 0;
|
2012-11-27 16:22:47 +00:00
|
|
|
|
2013-01-12 13:03:19 +00:00
|
|
|
if ( count( $_chosen_attributes ) > 0 || $min_price > 0 || $max_price > 0 ) {
|
2012-11-27 16:22:47 +00:00
|
|
|
|
2012-12-26 15:59:11 +00:00
|
|
|
echo $before_widget;
|
|
|
|
if ( $title ) {
|
|
|
|
echo $before_title . $title . $after_title;
|
|
|
|
}
|
2012-10-14 12:06:37 +00:00
|
|
|
|
|
|
|
echo "<ul>";
|
2012-11-27 16:22:47 +00:00
|
|
|
|
2012-10-14 12:06:37 +00:00
|
|
|
// Attributes
|
|
|
|
foreach ( $_chosen_attributes as $taxonomy => $data ) {
|
2012-11-27 16:22:47 +00:00
|
|
|
|
2012-10-14 12:06:37 +00:00
|
|
|
foreach ( $data['terms'] as $term_id ) {
|
|
|
|
$term = get_term( $term_id, $taxonomy );
|
|
|
|
$taxonomy_filter = str_replace( 'pa_', '', $taxonomy );
|
|
|
|
$current_filter = ! empty( $_GET[ 'filter_' . $taxonomy_filter ] ) ? $_GET[ 'filter_' . $taxonomy_filter ] : '';
|
|
|
|
$new_filter = array_map( 'absint', explode( ',', $current_filter ) );
|
|
|
|
$new_filter = array_diff( $new_filter, array( $term_id ) );
|
2012-11-27 16:22:47 +00:00
|
|
|
|
2012-10-14 12:06:37 +00:00
|
|
|
$link = remove_query_arg( 'filter_' . $taxonomy_filter );
|
2012-11-27 16:22:47 +00:00
|
|
|
|
2012-10-14 12:06:37 +00:00
|
|
|
if ( sizeof( $new_filter ) > 0 )
|
|
|
|
$link = add_query_arg( 'filter_' . $taxonomy_filter, implode( ',', $new_filter ), $link );
|
2012-11-27 16:22:47 +00:00
|
|
|
|
2012-12-19 10:58:27 +00:00
|
|
|
echo '<li class="chosen"><a title="' . __( 'Remove filter', 'woocommerce' ) . '" href="' . $link . '">' . $term->name . '</a></li>';
|
2012-10-14 12:06:37 +00:00
|
|
|
}
|
|
|
|
}
|
2012-11-27 16:22:47 +00:00
|
|
|
|
2013-01-12 13:03:19 +00:00
|
|
|
if ( $min_price ) {
|
2012-10-14 12:06:37 +00:00
|
|
|
$link = remove_query_arg( 'min_price' );
|
2013-01-12 13:03:19 +00:00
|
|
|
echo '<li class="chosen"><a title="' . __( 'Remove filter', 'woocommerce' ) . '" href="' . $link . '">' . __( 'Min', 'woocommerce' ) . ' ' . woocommerce_price( $min_price ) . '</a></li>';
|
2012-10-14 12:06:37 +00:00
|
|
|
}
|
2012-11-27 16:22:47 +00:00
|
|
|
|
2013-01-12 13:03:19 +00:00
|
|
|
if ( $max_price ) {
|
2012-10-14 12:06:37 +00:00
|
|
|
$link = remove_query_arg( 'max_price' );
|
2013-01-12 13:03:19 +00:00
|
|
|
echo '<li class="chosen"><a title="' . __( 'Remove filter', 'woocommerce' ) . '" href="' . $link . '">' . __( 'Max', 'woocommerce' ) . ' ' . woocommerce_price( $max_price ) . '</a></li>';
|
2012-10-14 12:06:37 +00:00
|
|
|
}
|
2012-11-27 16:22:47 +00:00
|
|
|
|
2012-10-14 12:06:37 +00:00
|
|
|
echo "</ul>";
|
|
|
|
|
|
|
|
echo $after_widget;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|