Advanced AJAX Product Filters - Version 1.1.3

Version Description

  • Enhancement - load only products from last AJAX request
  • Enhancement - Uses HTML for widgets from theme
  • Enhancement/Fix - Attributes page support
  • Fix - Hash links didn't works with plugin
  • Fix - Widgets don't display on page with latest version of WooCommerce
  • Fix - Remove PHP errors
Download this release

Release Info

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

Code changes from version 1.1.2 to 1.1.3

README.md CHANGED
@@ -4,8 +4,8 @@ Contributors: dholovnia, berocket
4
  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, widget, plugin
6
  Requires at least: 4.0
7
- Tested up to: 4.3.1
8
- Stable tag: 1.1.2
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -139,14 +139,13 @@ http://woocommerce-product-filter.berocket.com
139
 
140
  == Changelog ==
141
 
142
- = 1.1.1.1 =
143
- * Fix - fixes for the bugs from the support forum
144
-
145
- = 1.1.1 =
146
- * Fix - most of the bugs for almost a month period
147
-
148
- = 1.1.0.8 =
149
- * Fix - removing PHP 5.5 code
150
 
151
  = 1.1.0.7 =
152
  * Enhancement - Option to hide selected values and/or without products. Add at the bottom button to show them
4
  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, widget, plugin
6
  Requires at least: 4.0
7
+ Tested up to: 4.4
8
+ Stable tag: 1.1.3
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
139
 
140
  == Changelog ==
141
 
142
+ = 1.1.3 =
143
+ * Enhancement - load only products from last AJAX request
144
+ * Enhancement - Uses HTML for widgets from theme
145
+ * Enhancement/Fix - Attributes page support
146
+ * Fix - Hash links didn't works with plugin
147
+ * Fix - Widgets don't display on page with latest version of WooCommerce
148
+ * Fix - Remove PHP errors
 
149
 
150
  = 1.1.0.7 =
151
  * Enhancement - Option to hide selected values and/or without products. Add at the bottom button to show them
css/widget.css CHANGED
@@ -43,6 +43,10 @@ ul.products.hide_products li{
43
  background-position: -14px 0;
44
  }
45
 
 
 
 
 
46
  .berocket_aapf_widget-title{
47
  margin-bottom: 5px;
48
  font-size: 14px;
@@ -50,6 +54,7 @@ ul.products.hide_products li{
50
 
51
  ul.berocket_aapf_widget{
52
  margin-bottom: 30px;
 
53
  }
54
 
55
  ul.berocket_aapf_widget .berocket_widget_show_values{
@@ -103,7 +108,7 @@ ul.berocket_aapf_widget li{
103
  ul.berocket_aapf_widget li > span{
104
  display: block;
105
  cursor: pointer;
106
- height: 20px;
107
  }
108
 
109
  ul.berocket_aapf_widget li > span:hover{
43
  background-position: -14px 0;
44
  }
45
 
46
+ .berocket_aapf_widget .berocket_label_widgets{
47
+ display: inline;
48
+ }
49
+
50
  .berocket_aapf_widget-title{
51
  margin-bottom: 5px;
52
  font-size: 14px;
54
 
55
  ul.berocket_aapf_widget{
56
  margin-bottom: 30px;
57
+ margin-right: 1em;
58
  }
59
 
60
  ul.berocket_aapf_widget .berocket_widget_show_values{
108
  ul.berocket_aapf_widget li > span{
109
  display: block;
110
  cursor: pointer;
111
+ line-height: 1.1em;
112
  }
113
 
114
  ul.berocket_aapf_widget li > span:hover{
includes/widget.php CHANGED
@@ -22,6 +22,7 @@ class BeRocket_AAPF_Widget extends WP_Widget {
22
  * Constructor
23
  */
24
  function BeRocket_AAPF_Widget() {
 
25
  /* Widget settings. */
26
  $widget_ops = array( 'classname' => 'widget_berocket_aapf', 'description' => __('Add Filters to Products page', BeRocket_AJAX_domain) );
27
 
@@ -75,6 +76,11 @@ class BeRocket_AAPF_Widget extends WP_Widget {
75
  $current_language = '';
76
  }
77
 
 
 
 
 
 
78
  wp_localize_script(
79
  'berocket_aapf_widget-script',
80
  'the_ajax_script',
@@ -84,6 +90,7 @@ class BeRocket_AAPF_Widget extends WP_Widget {
84
  'current_page_url' => preg_replace( "~paged?/[0-9]+/?~", "", home_url( $wp->request ) ),
85
  'ajaxurl' => admin_url( 'admin-ajax.php' ),
86
  'product_cat' => $wp_query_product_cat,
 
87
  'products_holder_id' => @ $br_options['products_holder_id'],
88
  'control_sorting' => @ $br_options['control_sorting'],
89
  'seo_friendly_urls' => @ $br_options['seo_friendly_urls'],
@@ -106,7 +113,9 @@ class BeRocket_AAPF_Widget extends WP_Widget {
106
 
107
  if ( $widget_type == 'update_button' ) {
108
  set_query_var( 'title', apply_filters( 'berocket_aapf_widget_title', $title ) );
 
109
  br_get_template_part( 'widget_update_button' );
 
110
  return '';
111
  }
112
 
@@ -199,6 +208,8 @@ class BeRocket_AAPF_Widget extends WP_Widget {
199
  set_query_var( 'hide_o_value', @ $br_options['hide_value']['o'] );
200
  set_query_var( 'hide_sel_value', @ $br_options['hide_value']['sel'] );
201
 
 
 
202
  // widget title and start tag ( <ul> ) can be found in templates/widget_start.php
203
  br_get_template_part('widget_start');
204
 
@@ -277,6 +288,7 @@ class BeRocket_AAPF_Widget extends WP_Widget {
277
  br_get_template_part( $type );
278
 
279
  br_get_template_part('widget_end');
 
280
  }
281
 
282
  public static function woocommerce_hide_out_of_stock_items(){
@@ -324,6 +336,7 @@ class BeRocket_AAPF_Widget extends WP_Widget {
324
 
325
  public static function get_attribute_values( $taxonomy = '', $order_by = 'id', $hide_empty = false ) {
326
  if ( ! $taxonomy ) return array();
 
327
  if( $hide_empty ) {
328
  global $wp_query, $post;
329
  $terms = array();
@@ -335,6 +348,8 @@ class BeRocket_AAPF_Widget extends WP_Widget {
335
  $q_args['taxonomy'] = '';
336
  $q_args['term'] = '';
337
  $q_args['meta_query'] = '';
 
 
338
  $q_args['fields'] = 'ids';
339
  $paged = 1;
340
  do{
@@ -526,6 +541,12 @@ class BeRocket_AAPF_Widget extends WP_Widget {
526
  $args['posts_per_page'] = apply_filters( 'loop_shop_per_page', $default_posts_per_page );
527
  unset( $default_posts_per_page );
528
 
 
 
 
 
 
 
529
  $wp_query = new WP_Query( $args );
530
 
531
  // here we get max products to know if current page is not too big
22
  * Constructor
23
  */
24
  function BeRocket_AAPF_Widget() {
25
+ global $wp_version;
26
  /* Widget settings. */
27
  $widget_ops = array( 'classname' => 'widget_berocket_aapf', 'description' => __('Add Filters to Products page', BeRocket_AJAX_domain) );
28
 
76
  $current_language = '';
77
  }
78
 
79
+ $product_taxonomy = '-1';
80
+ if ( is_product_taxonomy() ) {
81
+ $product_taxonomy = $wp_query->query_vars['taxonomy'].'|'.$wp_query->query_vars['term'];
82
+ }
83
+
84
  wp_localize_script(
85
  'berocket_aapf_widget-script',
86
  'the_ajax_script',
90
  'current_page_url' => preg_replace( "~paged?/[0-9]+/?~", "", home_url( $wp->request ) ),
91
  'ajaxurl' => admin_url( 'admin-ajax.php' ),
92
  'product_cat' => $wp_query_product_cat,
93
+ 'product_taxonomy' => $product_taxonomy,
94
  'products_holder_id' => @ $br_options['products_holder_id'],
95
  'control_sorting' => @ $br_options['control_sorting'],
96
  'seo_friendly_urls' => @ $br_options['seo_friendly_urls'],
113
 
114
  if ( $widget_type == 'update_button' ) {
115
  set_query_var( 'title', apply_filters( 'berocket_aapf_widget_title', $title ) );
116
+ echo $before_widget;
117
  br_get_template_part( 'widget_update_button' );
118
+ echo $after_widget;
119
  return '';
120
  }
121
 
208
  set_query_var( 'hide_o_value', @ $br_options['hide_value']['o'] );
209
  set_query_var( 'hide_sel_value', @ $br_options['hide_value']['sel'] );
210
 
211
+ echo $before_widget;
212
+
213
  // widget title and start tag ( <ul> ) can be found in templates/widget_start.php
214
  br_get_template_part('widget_start');
215
 
288
  br_get_template_part( $type );
289
 
290
  br_get_template_part('widget_end');
291
+ echo $after_widget;
292
  }
293
 
294
  public static function woocommerce_hide_out_of_stock_items(){
336
 
337
  public static function get_attribute_values( $taxonomy = '', $order_by = 'id', $hide_empty = false ) {
338
  if ( ! $taxonomy ) return array();
339
+ $re = array();
340
  if( $hide_empty ) {
341
  global $wp_query, $post;
342
  $terms = array();
348
  $q_args['taxonomy'] = '';
349
  $q_args['term'] = '';
350
  $q_args['meta_query'] = '';
351
+ $q_args['attribute'] = '';
352
+ $q_args['title'] = '';
353
  $q_args['fields'] = 'ids';
354
  $paged = 1;
355
  do{
541
  $args['posts_per_page'] = apply_filters( 'loop_shop_per_page', $default_posts_per_page );
542
  unset( $default_posts_per_page );
543
 
544
+ if( isset($_POST['product_taxonomy']) && $_POST['product_taxonomy'] != '-1' && strpos( $_POST['product_taxonomy'], '|' ) !== FALSE ) {
545
+ $product_taxonomy = explode( '|', $_POST['product_taxonomy'] );
546
+ $args['taxonomy'] = $product_taxonomy[0];
547
+ $args['term'] = $product_taxonomy[1];
548
+ }
549
+
550
  $wp_query = new WP_Query( $args );
551
 
552
  // here we get max products to know if current page is not too big
js/widget.min.js CHANGED
@@ -9,7 +9,9 @@
9
  berocket_aapf_widget_wait_for_button = false,
10
  berocket_aapf_widget_selected_filters = [],
11
  berocket_aapf_widget_first_page_jump = true,
12
- berocket_aapf_widget_scroll_shop_top = the_ajax_script.scroll_shop_top;
 
 
13
 
14
  if( $('.woocommerce-pagination').hasClass('.woocommerce-pagination') ){
15
  woocommerce_pagination_page = parseInt( $('.woocommerce-pagination .current').first().text() );
@@ -156,7 +158,13 @@
156
  if( the_ajax_script.user_func != null )
157
  berocket_fire( the_ajax_script.user_func.before_update );
158
 
159
- $(the_ajax_script.products_holder_id).addClass('hide_products').append('<div class="berocket_aapf_widget_loading" />');
 
 
 
 
 
 
160
 
161
  update_data_containers();
162
  update_selected_area();
@@ -167,6 +175,7 @@
167
  price: berocket_aapf_widget_product_price_limit,
168
  limits: berocket_aapf_widget_product_limits,
169
  product_cat: the_ajax_script.product_cat,
 
170
  action: 'berocket_aapf_listener',
171
  orderby: $('.woocommerce-ordering select.orderby').val()
172
  };
@@ -233,7 +242,9 @@
233
  {
234
  new_args = args;
235
  }
236
- $.post(url, new_args, function (data) {
 
 
237
  $('.woocommerce-result-count').remove();
238
  $('.woocommerce-pagination').remove();
239
  $('form.woocommerce-ordering').remove();
@@ -618,12 +629,12 @@
618
 
619
  function load_hash_test() {
620
  hash = location.hash;
621
- if( location.hash != "")
622
- location.hash = "";
623
  test_loc = location.href;
624
  reload = false;
625
  var filtersRegex = /filters=\((.*)\)/;
626
  if( ( filters_hash = filtersRegex.exec(hash) ) != null ) {
 
 
627
  if( test_loc.indexOf('?') != -1 ) {
628
  href_param = test_loc.split('?');
629
  if(href_param[1].indexOf('filters=') != -1) {
@@ -643,6 +654,8 @@ function load_hash_test() {
643
  }
644
  var filtersRegex = /paged=([0-9]+)/;
645
  if( ( filters_hash = filtersRegex.exec(hash) ) != null ) {
 
 
646
  if( test_loc.indexOf('?') != -1 ) {
647
  href_param = test_loc.split('?');
648
  if(href_param[1].indexOf('paged=') != -1) {
9
  berocket_aapf_widget_wait_for_button = false,
10
  berocket_aapf_widget_selected_filters = [],
11
  berocket_aapf_widget_first_page_jump = true,
12
+ berocket_aapf_widget_scroll_shop_top = the_ajax_script.scroll_shop_top,
13
+ berocket_last_ajax_request = null,
14
+ berocket_last_ajax_request_id = 1;
15
 
16
  if( $('.woocommerce-pagination').hasClass('.woocommerce-pagination') ){
17
  woocommerce_pagination_page = parseInt( $('.woocommerce-pagination .current').first().text() );
158
  if( the_ajax_script.user_func != null )
159
  berocket_fire( the_ajax_script.user_func.before_update );
160
 
161
+
162
+ if ( berocket_last_ajax_request == null ) {
163
+ $(the_ajax_script.products_holder_id).addClass('hide_products').append('<div class="berocket_aapf_widget_loading" />');
164
+ } else {
165
+ berocket_last_ajax_request.abort();
166
+ berocket_last_ajax_request = null;
167
+ }
168
 
169
  update_data_containers();
170
  update_selected_area();
175
  price: berocket_aapf_widget_product_price_limit,
176
  limits: berocket_aapf_widget_product_limits,
177
  product_cat: the_ajax_script.product_cat,
178
+ product_taxonomy: the_ajax_script.product_taxonomy,
179
  action: 'berocket_aapf_listener',
180
  orderby: $('.woocommerce-ordering select.orderby').val()
181
  };
242
  {
243
  new_args = args;
244
  }
245
+ var berocket_this_ajax_request = berocket_last_ajax_request = $.post(url, new_args, function (data) {
246
+ berocket_last_ajax_request = null;
247
+ berocket_last_ajax_request_id = 1;
248
  $('.woocommerce-result-count').remove();
249
  $('.woocommerce-pagination').remove();
250
  $('form.woocommerce-ordering').remove();
629
 
630
  function load_hash_test() {
631
  hash = location.hash;
 
 
632
  test_loc = location.href;
633
  reload = false;
634
  var filtersRegex = /filters=\((.*)\)/;
635
  if( ( filters_hash = filtersRegex.exec(hash) ) != null ) {
636
+ if( location.hash != "")
637
+ location.hash = "";
638
  if( test_loc.indexOf('?') != -1 ) {
639
  href_param = test_loc.split('?');
640
  if(href_param[1].indexOf('filters=') != -1) {
654
  }
655
  var filtersRegex = /paged=([0-9]+)/;
656
  if( ( filters_hash = filtersRegex.exec(hash) ) != null ) {
657
+ if( location.hash != "")
658
+ location.hash = "";
659
  if( test_loc.indexOf('?') != -1 ) {
660
  href_param = test_loc.split('?');
661
  if(href_param[1].indexOf('paged=') != -1) {
readme.txt CHANGED
@@ -4,8 +4,8 @@ Contributors: dholovnia, berocket
4
  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, widget, plugin
6
  Requires at least: 4.0
7
- Tested up to: 4.3.1
8
- Stable tag: 1.1.2
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -139,14 +139,13 @@ http://woocommerce-product-filter.berocket.com
139
 
140
  == Changelog ==
141
 
142
- = 1.1.1.1 =
143
- * Fix - fixes for the bugs from the support forum
144
-
145
- = 1.1.1 =
146
- * Fix - most of the bugs for almost a month period
147
-
148
- = 1.1.0.8 =
149
- * Fix - removing PHP 5.5 code
150
 
151
  = 1.1.0.7 =
152
  * Enhancement - Option to hide selected values and/or without products. Add at the bottom button to show them
4
  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, widget, plugin
6
  Requires at least: 4.0
7
+ Tested up to: 4.4
8
+ Stable tag: 1.1.3
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
139
 
140
  == Changelog ==
141
 
142
+ = 1.1.3 =
143
+ * Enhancement - load only products from last AJAX request
144
+ * Enhancement - Uses HTML for widgets from theme
145
+ * Enhancement/Fix - Attributes page support
146
+ * Fix - Hash links didn't works with plugin
147
+ * Fix - Widgets don't display on page with latest version of WooCommerce
148
+ * Fix - Remove PHP errors
 
149
 
150
  = 1.1.0.7 =
151
  * Enhancement - Option to hide selected values and/or without products. Add at the bottom button to show them
templates/widget_end.php CHANGED
@@ -1 +1,2 @@
1
- </ul>
 
1
+ </ul>
2
+ </div>
templates/widget_start.php CHANGED
@@ -1,2 +1,3 @@
1
- <?php if ( @ $title ) { ?><h3 class="widget-title berocket_aapf_widget-title <?php echo $css_class ?>"><span><?php echo $title ?></span></h3><?php } ?>
2
- <ul class='berocket_aapf_widget <?php echo $class ?> <?php echo $css_class ?>' <?php echo $style ?> data-scroll_theme='<?php echo $scroll_theme ?>'>
 
1
+ <div class="berocket_aapf_widget-wrapper">
2
+ <?php if ( @ $title ) { ?><h3 class="widget-title berocket_aapf_widget-title <?php echo $css_class ?>"><span><?php echo $title ?></span></h3><?php } ?>
3
+ <ul class='berocket_aapf_widget <?php echo $class ?> <?php echo $css_class ?>' <?php echo $style ?> data-scroll_theme='<?php echo $scroll_theme ?>'>
woocommerce-filters.php CHANGED
@@ -3,12 +3,12 @@
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.1.2
7
  * Author: BeRocket
8
  * Author URI: http://berocket.com
9
  */
10
 
11
- define( "BeRocket_AJAX_filters_version", '1.1.1' );
12
  define( "BeRocket_AJAX_domain", 'BRaapf' );
13
 
14
  define( "AAPF_TEMPLATE_PATH", plugin_dir_path( __FILE__ ) . "templates/" );
@@ -45,7 +45,6 @@ class BeRocket_AAPF {
45
  add_action( 'init', array( __CLASS__, 'init' ) );
46
 
47
  add_shortcode( 'br_filters', array( __CLASS__, 'shortcode' ) );
48
- add_filter( 'loop_shop_per_page', array( __CLASS__, 'loop_shop_per_page' ), 99 );
49
 
50
  if( @ $_GET['filters'] and ! @ defined( 'DOING_AJAX' ) ) {
51
  add_filter( 'pre_get_posts', array( __CLASS__, 'apply_user_filters' ) );
@@ -137,9 +136,10 @@ class BeRocket_AAPF {
137
 
138
  public static function apply_user_filters( $query ) {
139
  if( $query->is_main_query() and
140
- ( is_shop() or $query->get( 'post_type' ) == 'product' or $query->get( 'product_cat' ) )
141
  or
142
  $query->is_page() && 'page' == get_option( 'show_on_front' ) && $query->get('page_id') == wc_get_page_id('shop')
 
143
  ) {
144
  br_aapf_args_converter();
145
  $args = br_aapf_args_parser();
@@ -353,10 +353,6 @@ class BeRocket_AAPF {
353
  delete_option( 'br_filters_options' );
354
  }
355
 
356
- public static function loop_shop_per_page() {
357
- return get_option( 'posts_per_page' );
358
- }
359
-
360
  public static function WPML_fix() {
361
  global $sitepress;
362
  if ( method_exists( $sitepress, 'switch_lang' ) && isset( $_POST['current_language'] ) && $_POST['current_language'] !== $sitepress->get_default_language() ) {
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.1.3
7
  * Author: BeRocket
8
  * Author URI: http://berocket.com
9
  */
10
 
11
+ define( "BeRocket_AJAX_filters_version", '1.1.3' );
12
  define( "BeRocket_AJAX_domain", 'BRaapf' );
13
 
14
  define( "AAPF_TEMPLATE_PATH", plugin_dir_path( __FILE__ ) . "templates/" );
45
  add_action( 'init', array( __CLASS__, 'init' ) );
46
 
47
  add_shortcode( 'br_filters', array( __CLASS__, 'shortcode' ) );
 
48
 
49
  if( @ $_GET['filters'] and ! @ defined( 'DOING_AJAX' ) ) {
50
  add_filter( 'pre_get_posts', array( __CLASS__, 'apply_user_filters' ) );
136
 
137
  public static function apply_user_filters( $query ) {
138
  if( $query->is_main_query() and
139
+ ( ( is_shop() or $query->get( 'post_type' ) == 'product' or $query->get( 'product_cat' ) )
140
  or
141
  $query->is_page() && 'page' == get_option( 'show_on_front' ) && $query->get('page_id') == wc_get_page_id('shop')
142
+ or is_product_taxonomy() )
143
  ) {
144
  br_aapf_args_converter();
145
  $args = br_aapf_args_parser();
353
  delete_option( 'br_filters_options' );
354
  }
355
 
 
 
 
 
356
  public static function WPML_fix() {
357
  global $sitepress;
358
  if ( method_exists( $sitepress, 'switch_lang' ) && isset( $_POST['current_language'] ) && $_POST['current_language'] !== $sitepress->get_default_language() ) {