Advanced AJAX Product Filters - Version 1.0.3.3

Version Description

  • Enhancement/Fix - Showing products and options now depending on woocommerce_hide_out_of_stock_items option
  • Fix - If in category, only products/options from this category will be shown
Download this release

Release Info

Developer dholovnia
Plugin Icon wp plugin Advanced AJAX Product Filters
Version 1.0.3.3
Comparing to
See all releases

Code changes from version 1.0.3.2 to 1.0.3.3

includes/widget.php CHANGED
@@ -94,24 +94,28 @@ class BeRocket_AAPF_Widget extends WP_Widget {
94
  return true;
95
  }
96
  }
97
-
98
- $terms = get_terms( array( $attribute ), $args = array( 'orderby' => 'name', 'order' => 'ASC' ) );
99
- $args = array(
100
- 'post_type' => 'product',
101
- 'orderby' => "category",
102
- 'order' => 'ASC',
103
- 'ignore_sticky_posts'=> 1
104
- );
105
-
106
- $price_range = array();
107
-
108
- $my_query = new WP_Query($args);
109
- if( $my_query->have_posts() ) {
110
- while ($my_query->have_posts()){
111
- $my_query->the_post();
112
- $meta_values = get_post_meta( $my_query->post->ID, '_price' );
113
- $price_range[] = $meta_values[0];
 
114
  }
 
 
 
115
  }
116
 
117
  $style = $class = '';
@@ -122,7 +126,6 @@ class BeRocket_AAPF_Widget extends WP_Widget {
122
 
123
  if( !$scroll_theme ) $scroll_theme = 'dark';
124
 
125
- set_query_var( 'terms', $terms );
126
  set_query_var( 'operator', $operator );
127
  set_query_var( 'title', $title );
128
  set_query_var( 'class', $class );
@@ -166,6 +169,69 @@ class BeRocket_AAPF_Widget extends WP_Widget {
166
  br_get_template_part('widget_end');
167
  }
168
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
  /**
170
  * Validating and updating widget data
171
  *
94
  return true;
95
  }
96
  }
97
+
98
+ $woocommerce_hide_out_of_stock_items = BeRocket_AAPF_Widget::woocommerce_hide_out_of_stock_items();
99
+ $terms = $sort_terms = array();
100
+
101
+ if( $attribute == 'price' ) {
102
+ $price_range = BeRocket_AAPF_Widget::get_price_range( $wp_query_product_cat, $woocommerce_hide_out_of_stock_items );
103
+ }else{
104
+ $my_query = BeRocket_AAPF_Widget::get_filter_products( $wp_query_product_cat, $woocommerce_hide_out_of_stock_items );
105
+
106
+ if ( $my_query->have_posts() ) {
107
+ while ( $my_query->have_posts() ) {
108
+ $my_query->the_post();
109
+ $t_terms = get_the_terms( $my_query->post->ID, $attribute );
110
+ foreach( $t_terms as $key => $val ){
111
+ $terms[$key] = $val;
112
+ $sort_terms[$key] = $val->name;
113
+ }
114
+ }
115
  }
116
+
117
+ array_multisort( $sort_terms, $terms );
118
+ set_query_var( 'terms', $terms );
119
  }
120
 
121
  $style = $class = '';
126
 
127
  if( !$scroll_theme ) $scroll_theme = 'dark';
128
 
 
129
  set_query_var( 'operator', $operator );
130
  set_query_var( 'title', $title );
131
  set_query_var( 'class', $class );
169
  br_get_template_part('widget_end');
170
  }
171
 
172
+ public static function woocommerce_hide_out_of_stock_items(){
173
+ $hide = get_option( 'woocommerce_hide_out_of_stock_items', null );
174
+
175
+ if ( is_array( $hide ) ) {
176
+ $hide = array_map( 'stripslashes', $hide );
177
+ } elseif ( ! is_null( $hide ) ) {
178
+ $hide = stripslashes( $hide );
179
+ }
180
+
181
+ return $hide;
182
+ }
183
+
184
+ public static function get_price_range( $wp_query_product_cat, $woocommerce_hide_out_of_stock_items ){
185
+ $price_range = array();
186
+ $my_query = BeRocket_AAPF_Widget::get_filter_products( $wp_query_product_cat, $woocommerce_hide_out_of_stock_items );
187
+
188
+ if ( $my_query->have_posts() ) {
189
+ while ( $my_query->have_posts() ) {
190
+ $my_query->the_post();
191
+ $meta_values = get_post_meta( $my_query->post->ID, '_price' );
192
+ if ( $meta_values[0] or $woocommerce_hide_out_of_stock_items != 'yes' ) {
193
+ $price_range[] = $meta_values[0];
194
+ }
195
+ }
196
+ }
197
+
198
+ if ( @ count( $price_range ) < 2 ) {
199
+ return false;
200
+ }else{
201
+ return $price_range;
202
+ }
203
+ }
204
+
205
+ function get_filter_products( $wp_query_product_cat, $woocommerce_hide_out_of_stock_items ) {
206
+ $args = array(
207
+ 'post_type' => 'product',
208
+ 'orderby' => 'category',
209
+ 'order' => 'ASC',
210
+ 'ignore_sticky_posts' => 1
211
+ );
212
+
213
+ if ( $wp_query_product_cat != - 1 ) {
214
+ $args['tax_query'] = array(
215
+ array(
216
+ 'taxonomy' => 'product_cat',
217
+ 'field' => 'slug',
218
+ 'terms' => array( $wp_query_product_cat ),
219
+ )
220
+ );
221
+ }
222
+
223
+ if ( $woocommerce_hide_out_of_stock_items == 'yes' ) {
224
+ $args['meta_query'] = array(
225
+ array(
226
+ 'key' => '_stock_status',
227
+ 'value' => 'instock',
228
+ 'compare' => '='
229
+ )
230
+ );
231
+ }
232
+
233
+ return new WP_Query( $args );
234
+ }
235
  /**
236
  * Validating and updating widget data
237
  *
readme.txt CHANGED
@@ -5,7 +5,7 @@ Donate link: http://berocket.com
5
  Tags: filters, product filters, ajax product filters, advanced product filters, woocommerce filters, woocommerce product filters, woocommerce ajax product filters
6
  Requires at least: 3.9
7
  Tested up to: 4.1
8
- Stable tag: 1.0.3.2
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -86,6 +86,10 @@ WooCommerce AJAX Filters - advanced AJAX product filters plugin for WooCommerce.
86
 
87
  == Changelog ==
88
 
 
 
 
 
89
  = 1.0.3.2 =
90
  * Fix - wrong path was committed in previous version that killed plugin
91
 
5
  Tags: filters, product filters, ajax product filters, advanced product filters, woocommerce filters, woocommerce product filters, woocommerce ajax product filters
6
  Requires at least: 3.9
7
  Tested up to: 4.1
8
+ Stable tag: 1.0.3.3
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
86
 
87
  == Changelog ==
88
 
89
+ = 1.0.3.3 =
90
+ * Enhancement/Fix - Showing products and options now depending on woocommerce_hide_out_of_stock_items option
91
+ * Fix - If in category, only products/options from this category will be shown
92
+
93
  = 1.0.3.2 =
94
  * Fix - wrong path was committed in previous version that killed plugin
95
 
templates/admin.php CHANGED
@@ -24,7 +24,7 @@
24
  </select>
25
  </label>
26
  </p>
27
- <p <? if ($instance['attribute'] == 'pa_lengthcm' or $instance['attribute'] == 'pa_widthcm' or $instance['attribute'] == 'price' ) echo " style='display: none;'"; ?> >
28
  <label>Operator:
29
  <select id="<?php echo $this->get_field_id( 'operator' ); ?>" name="<?php echo $this->get_field_name( 'operator' ); ?>" class="berocket_aapf_widget_admin_operator_select">
30
  <option <?php if ($instance['operator'] == 'AND') echo 'selected'; ?> value="AND">AND</option>
24
  </select>
25
  </label>
26
  </p>
27
+ <p <? if ( $instance['attribute'] == 'price' ) echo " style='display: none;'"; ?> >
28
  <label>Operator:
29
  <select id="<?php echo $this->get_field_id( 'operator' ); ?>" name="<?php echo $this->get_field_name( 'operator' ); ?>" class="berocket_aapf_widget_admin_operator_select">
30
  <option <?php if ($instance['operator'] == 'AND') echo 'selected'; ?> value="AND">AND</option>
woocommerce-filters.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Advanced AJAX Product Filters for WooCommerce
4
  Plugin URI: http://berocket.com/wp-plugins/product-filters
5
  Description: Advanced AJAX Product Filters for WooCommerce
6
- Version: 1.0.3.2
7
  Author: BeRocket
8
  Author URI: http://berocket.com
9
  */
3
  Plugin Name: Advanced AJAX Product Filters for WooCommerce
4
  Plugin URI: http://berocket.com/wp-plugins/product-filters
5
  Description: Advanced AJAX Product Filters for WooCommerce
6
+ Version: 1.0.3.3
7
  Author: BeRocket
8
  Author URI: http://berocket.com
9
  */