/lib/widgets/class-ss-wc-widget-layered-nav-filters.php
https://gitlab.com/aristath/shoestrap-3-woocommerce-child · PHP · 103 lines · 61 code · 19 blank · 23 comment · 11 complexity · 9fbce16be2b7c9ace1350ab96486aa66 MD5 · raw file
- <?php
- /**
- * Layered Navigation Fitlers Widget
- *
- * @author WooThemes
- * @category Widgets
- * @package WooCommerce/Widgets
- * @version 2.0.1
- * @extends WC_Widget
- */
- if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
- class SS_WC_Widget_Layered_Nav_Filters extends WC_Widget {
- /**
- * Constructor
- */
- public function __construct() {
- $this->widget_cssclass = 'woocommerce widget_layered_nav_filters';
- $this->widget_description = __( 'Shows active layered nav filters so users can see and deactivate them.', 'woocommerce' );
- $this->widget_id = 'woocommerce_layered_nav_filters';
- $this->widget_name = __( 'WooCommerce Layered Nav Filters', 'woocommerce' );
- $this->settings = array(
- 'title' => array(
- 'type' => 'text',
- 'std' => __( 'Active Filters', 'woocommerce' ),
- 'label' => __( 'Title', 'woocommerce' )
- )
- );
- parent::__construct();
- }
- /**
- * widget function.
- *
- * @see WP_Widget
- * @access public
- * @param array $args
- * @param array $instance
- * @return void
- */
- public function widget( $args, $instance ) {
- global $_chosen_attributes, $woocommerce;
- extract( $args );
- if ( ! is_post_type_archive( 'product' ) && ! is_tax( get_object_taxonomies( 'product' ) ) )
- return;
- $current_term = is_tax() ? get_queried_object()->term_id : '';
- $current_tax = is_tax() ? get_queried_object()->taxonomy : '';
- $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
- // Price
- $min_price = isset( $_GET['min_price'] ) ? esc_attr( $_GET['min_price'] ) : 0;
- $max_price = isset( $_GET['max_price'] ) ? esc_attr( $_GET['max_price'] ) : 0;
- if ( count( $_chosen_attributes ) > 0 || $min_price > 0 || $max_price > 0 ) {
- echo $before_widget;
- if ( $title ) {
- echo $before_title . $title . $after_title;
- }
- // Attributes
- if (!is_null($_chosen_attributes)){
- foreach ( $_chosen_attributes as $taxonomy => $data ) {
- 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 ) );
- $link = remove_query_arg( 'filter_' . $taxonomy_filter );
- if ( sizeof( $new_filter ) > 0 )
- $link = add_query_arg( 'filter_' . $taxonomy_filter, implode( ',', $new_filter ), $link );
- echo '<a class="chosen label primary label-default" title="' . __( 'Remove filter', 'woocommerce' ) . '" href="' . esc_url( $link ) . '">' . $term->name . ' <i class="el-icon-remove"></i></a> ';
- }
- }
- }
- if ( $min_price ) {
- $link = remove_query_arg( 'min_price' );
- echo '<a class="chosen label primary label-default" title="' . __( 'Remove filter', 'woocommerce' ) . '" href="' . esc_url( $link ) . '">' . __( 'Min', 'woocommerce' ) . ' ' . wc_price( $min_price ) . ' <i class="el-icon-remove"></i></a> ';
- }
- if ( $max_price ) {
- $link = remove_query_arg( 'max_price' );
- echo '<a class="chosen label primary label-default" title="' . __( 'Remove filter', 'woocommerce' ) . '" href="' . esc_url( $link ) . '">' . __( 'Max', 'woocommerce' ) . ' ' . wc_price( $max_price ) . ' <i class="el-icon-remove"></i></a> ';
- }
- echo $after_widget;
- }
- }
- }
- unregister_widget( 'WC_Widget_Layered_Nav_Filters' );
- register_widget( 'SS_WC_Widget_Layered_Nav_Filters' );