Advanced AJAX Product Filters - Version 1.3.3.1

Version Description

  • Fix - WooCommerce Shortcode with multiple categories
  • Fix - Incorrect recount terms on some sites
Download this release

Release Info

Developer RazyRx
Plugin Icon wp plugin Advanced AJAX Product Filters
Version 1.3.3.1
Comparing to
See all releases

Code changes from version 1.3.3 to 1.3.3.1

includes/addons/woocommerce-variation.php CHANGED
@@ -35,7 +35,7 @@ class BeRocket_AAPF_compat_woocommerce_variation {
35
  $outofstock = wc_get_product_visibility_term_ids();
36
  if( empty($outofstock['outofstock']) ) {
37
  $outofstock = get_term_by( 'slug', 'outofstock', 'product_visibility' );
38
- $outofstock = $outofstock->term_id;
39
  } else {
40
  $outofstock = $outofstock['outofstock'];
41
  }
@@ -66,28 +66,20 @@ class BeRocket_AAPF_compat_woocommerce_variation {
66
  $current_attributes = array_unique($current_attributes);
67
  $current_terms = implode('", "', $current_terms);
68
  $current_attributes = implode('", "', $current_attributes);
69
- $query = sprintf( '
70
- SELECT filtered_post.id, filtered_post.out_of_stock, COUNT(filtered_post.ID) as post_count FROM
71
- (
72
- SELECT filtered_post.*, max_filtered_post.max_meta_count, stock_table.out_of_stock_init as out_of_stock FROM
73
- (
74
  SELECT %1$s.id as var_id, %1$s.post_parent as ID, COUNT(%1$s.id) as meta_count FROM %1$s
75
  INNER JOIN %2$s AS pf1 ON (%1$s.ID = pf1.post_id)
76
  WHERE %1$s.post_type = "product_variation"
77
  AND %1$s.post_status != "trash"
78
  AND pf1.meta_key IN ("%4$s") AND pf1.meta_value IN ("%5$s")
79
- GROUP BY %1$s.id
80
- ) as filtered_post
 
 
 
81
  INNER JOIN
82
  (
83
- SELECT ID, MAX(meta_count) as max_meta_count FROM
84
- (
85
- SELECT %1$s.id as var_id, %1$s.post_parent as ID, COUNT(%1$s.id) as meta_count FROM %1$s
86
- INNER JOIN %2$s AS pf1 ON (%1$s.ID = pf1.post_id)
87
- WHERE %1$s.post_type = "product_variation"
88
- AND pf1.meta_key IN ("%4$s") AND pf1.meta_value IN ("%5$s")
89
- GROUP BY %1$s.id
90
- ) as max_filtered_post
91
  GROUP BY ID
92
  ) as max_filtered_post ON max_filtered_post.ID = filtered_post.ID AND max_filtered_post.max_meta_count = filtered_post.meta_count
93
  LEFT JOIN
35
  $outofstock = wc_get_product_visibility_term_ids();
36
  if( empty($outofstock['outofstock']) ) {
37
  $outofstock = get_term_by( 'slug', 'outofstock', 'product_visibility' );
38
+ $outofstock = $outofstock->term_taxonomy_id;
39
  } else {
40
  $outofstock = $outofstock['outofstock'];
41
  }
66
  $current_attributes = array_unique($current_attributes);
67
  $current_terms = implode('", "', $current_terms);
68
  $current_attributes = implode('", "', $current_attributes);
69
+ $query_filtered_posts = '
 
 
 
 
70
  SELECT %1$s.id as var_id, %1$s.post_parent as ID, COUNT(%1$s.id) as meta_count FROM %1$s
71
  INNER JOIN %2$s AS pf1 ON (%1$s.ID = pf1.post_id)
72
  WHERE %1$s.post_type = "product_variation"
73
  AND %1$s.post_status != "trash"
74
  AND pf1.meta_key IN ("%4$s") AND pf1.meta_value IN ("%5$s")
75
+ GROUP BY %1$s.id';
76
+ $query = sprintf( '
77
+ SELECT filtered_post.id, filtered_post.out_of_stock, COUNT(filtered_post.ID) as post_count FROM
78
+ (
79
+ SELECT filtered_post.*, max_filtered_post.max_meta_count, stock_table.out_of_stock_init as out_of_stock FROM ('.$query_filtered_posts.') as filtered_post
80
  INNER JOIN
81
  (
82
+ SELECT ID, MAX(meta_count) as max_meta_count FROM ('.$query_filtered_posts.') as max_filtered_post
 
 
 
 
 
 
 
83
  GROUP BY ID
84
  ) as max_filtered_post ON max_filtered_post.ID = filtered_post.ID AND max_filtered_post.max_meta_count = filtered_post.meta_count
85
  LEFT JOIN
includes/functions.php CHANGED
@@ -2205,14 +2205,19 @@ if ( ! function_exists( 'br_filters_query' ) ) {
2205
  }
2206
 
2207
  if( ! function_exists('berocket_add_filter_to_link') ) {
2208
- function berocket_add_filter_to_link($attribute = '', $values = array(), $operator = 'OR', $remove_attribute = FALSE) {
2209
  if( ! is_array($values) ) {
2210
  $values = array($values);
2211
  }
2212
  $options = BeRocket_AAPF::get_aapf_option();
2213
 
2214
- $current_url = "//" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
2215
- $filters = (empty($_GET['filters']) ? '' : $_GET['filters']);
 
 
 
 
 
2216
  $current_url = remove_query_arg('filters', $current_url);
2217
  if( strpos($current_url, '?') === FALSE ) {
2218
  $url_string = $current_url;
2205
  }
2206
 
2207
  if( ! function_exists('berocket_add_filter_to_link') ) {
2208
+ function berocket_add_filter_to_link($attribute = '', $values = array(), $operator = 'OR', $remove_attribute = FALSE, $current_url = FALSE) {
2209
  if( ! is_array($values) ) {
2210
  $values = array($values);
2211
  }
2212
  $options = BeRocket_AAPF::get_aapf_option();
2213
 
2214
+ if( $current_url === FALSE ) {
2215
+ $current_url = "//" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
2216
+ $filters = (empty($_GET['filters']) ? '' : $_GET['filters']);
2217
+ } else {
2218
+ parse_str(parse_url($current_url, PHP_URL_QUERY), $filters);
2219
+ $filters = br_get_value_from_array($filters, 'filters');
2220
+ }
2221
  $current_url = remove_query_arg('filters', $current_url);
2222
  if( strpos($current_url, '?') === FALSE ) {
2223
  $url_string = $current_url;
includes/widget.php CHANGED
@@ -860,7 +860,7 @@ class BeRocket_AAPF_Widget extends WP_Widget {
860
  $set_query_var_title['widget_id'] = ( $this->id ? $this->id : $widget_id );
861
  $set_query_var_title['widget_id_number'] = ( $this->number ? $this->number : $widget_id_number );
862
  $set_query_var_title['slug_urls'] = ! empty($br_options['slug_urls']);
863
- $set_query_var_title['date_style'] = berocket_isset($date_style);
864
  set_query_var( 'berocket_query_var_title', $set_query_var_title );
865
 
866
  // widget title and start tag ( <ul> ) can be found in templates/widget_start.php
@@ -1395,7 +1395,7 @@ if( BeRocket_AAPF::$debug_mode ) {
1395
  }
1396
  }
1397
  $queried_object = $wp_query->get_queried_object_id();
1398
- if( ! empty($queried_object) ) {
1399
  $query_object = $wp_query->get_queried_object();
1400
  if( ! empty($query_object->taxonomy) && ! empty($query_object->slug) ) {
1401
  $tax_query[ $query_object->taxonomy ] = array(
@@ -1520,7 +1520,7 @@ if( BeRocket_AAPF::$debug_mode ) {
1520
  }
1521
  }
1522
  $queried_object = $wp_query->get_queried_object_id();
1523
- if( ! empty($queried_object) ) {
1524
  $query_object = $wp_query->get_queried_object();
1525
  if( ! empty($query_object->taxonomy) && ! empty($query_object->slug) ) {
1526
  $tax_query[ $query_object->taxonomy ] = array(
@@ -1718,7 +1718,7 @@ if( BeRocket_AAPF::$debug_mode ) {
1718
  );
1719
  }
1720
  $queried_object = $wp_query->get_queried_object_id();
1721
- if( ! empty($queried_object) ) {
1722
  $query_object = $wp_query->get_queried_object();
1723
  if( ! empty($query_object->taxonomy) && ! empty($query_object->slug) ) {
1724
  $tax_query[ $query_object->taxonomy ] = array(
@@ -1735,7 +1735,7 @@ if( BeRocket_AAPF::$debug_mode ) {
1735
  $tax_query_sql = $tax_query->get_sql( $wpdb->posts, 'ID' );
1736
  unset($tax_query);
1737
  if( ! empty($re) && ! is_wp_error($re) ) {
1738
- $term_ids = wp_list_pluck( $re, 'term_id' );
1739
  }
1740
  if( empty($term_ids) || ! is_array($term_ids) || ! count($term_ids) ) {
1741
  $terms = array();
@@ -1776,6 +1776,10 @@ if( BeRocket_AAPF::$debug_mode ) {
1776
  }
1777
  $wpdb->query( 'SET SESSION group_concat_max_len = 1000000' );
1778
  $results = $wpdb->get_results( $query );
 
 
 
 
1779
  $results_pid = wp_list_pluck( $results, 'PID', 'term_count_id' );
1780
  $results = wp_list_pluck( $results, 'term_count', 'term_count_id' );
1781
  $term_count = array();
@@ -2035,7 +2039,7 @@ if( BeRocket_AAPF::$debug_mode ) {
2035
  }
2036
 
2037
  $queried_object = $wp_query->get_queried_object_id();
2038
- if ( ! empty($queried_object) ) {
2039
  $query_object = $wp_query->get_queried_object();
2040
  if ( ! empty($query_object->taxonomy) && ! empty($query_object->slug) ) {
2041
  $tax_query[ $query_object->taxonomy ] = array(
@@ -2058,7 +2062,7 @@ if( BeRocket_AAPF::$debug_mode ) {
2058
  $meta_query_sql = $meta_query->get_sql( 'post', $wpdb->posts, 'ID' );
2059
  $tax_query_sql = $tax_query->get_sql( $wpdb->posts, 'ID' );
2060
  if( ! empty($re) && count($re)) {
2061
- $term_ids = wp_list_pluck( $re, 'term_id' );
2062
 
2063
  // Generate query
2064
  $query = array();
@@ -2160,6 +2164,10 @@ if( BeRocket_AAPF::$debug_mode ) {
2160
  $term_recount_log['query_2'] = $query;
2161
  }
2162
  $results = $wpdb->get_results( $query );
 
 
 
 
2163
  $results_pid = wp_list_pluck( $results, 'PID', 'term_count_id' );
2164
  $results = wp_list_pluck( $results, 'term_count', 'term_count_id' );
2165
  }
860
  $set_query_var_title['widget_id'] = ( $this->id ? $this->id : $widget_id );
861
  $set_query_var_title['widget_id_number'] = ( $this->number ? $this->number : $widget_id_number );
862
  $set_query_var_title['slug_urls'] = ! empty($br_options['slug_urls']);
863
+ $set_query_var_title = apply_filters('berocket_aapf_query_var_title_filter', $set_query_var_title, $instance, $br_options);
864
  set_query_var( 'berocket_query_var_title', $set_query_var_title );
865
 
866
  // widget title and start tag ( <ul> ) can be found in templates/widget_start.php
1395
  }
1396
  }
1397
  $queried_object = $wp_query->get_queried_object_id();
1398
+ if( ! empty($queried_object) && empty($br_wc_query) ) {
1399
  $query_object = $wp_query->get_queried_object();
1400
  if( ! empty($query_object->taxonomy) && ! empty($query_object->slug) ) {
1401
  $tax_query[ $query_object->taxonomy ] = array(
1520
  }
1521
  }
1522
  $queried_object = $wp_query->get_queried_object_id();
1523
+ if( ! empty($queried_object) && empty($br_wc_query) ) {
1524
  $query_object = $wp_query->get_queried_object();
1525
  if( ! empty($query_object->taxonomy) && ! empty($query_object->slug) ) {
1526
  $tax_query[ $query_object->taxonomy ] = array(
1718
  );
1719
  }
1720
  $queried_object = $wp_query->get_queried_object_id();
1721
+ if( ! empty($queried_object) && empty($br_wc_query) ) {
1722
  $query_object = $wp_query->get_queried_object();
1723
  if( ! empty($query_object->taxonomy) && ! empty($query_object->slug) ) {
1724
  $tax_query[ $query_object->taxonomy ] = array(
1735
  $tax_query_sql = $tax_query->get_sql( $wpdb->posts, 'ID' );
1736
  unset($tax_query);
1737
  if( ! empty($re) && ! is_wp_error($re) ) {
1738
+ $term_ids = wp_list_pluck( $re, 'term_taxonomy_id' );
1739
  }
1740
  if( empty($term_ids) || ! is_array($term_ids) || ! count($term_ids) ) {
1741
  $terms = array();
1776
  }
1777
  $wpdb->query( 'SET SESSION group_concat_max_len = 1000000' );
1778
  $results = $wpdb->get_results( $query );
1779
+ $term_to_taxonomy = wp_list_pluck( $re, 'term_id', 'term_taxonomy_id' );
1780
+ foreach($results as &$results_convert) {
1781
+ $results_convert->term_count_id = $term_to_taxonomy[$results_convert->term_count_id];
1782
+ }
1783
  $results_pid = wp_list_pluck( $results, 'PID', 'term_count_id' );
1784
  $results = wp_list_pluck( $results, 'term_count', 'term_count_id' );
1785
  $term_count = array();
2039
  }
2040
 
2041
  $queried_object = $wp_query->get_queried_object_id();
2042
+ if ( ! empty($queried_object) && empty($br_wc_query) ) {
2043
  $query_object = $wp_query->get_queried_object();
2044
  if ( ! empty($query_object->taxonomy) && ! empty($query_object->slug) ) {
2045
  $tax_query[ $query_object->taxonomy ] = array(
2062
  $meta_query_sql = $meta_query->get_sql( 'post', $wpdb->posts, 'ID' );
2063
  $tax_query_sql = $tax_query->get_sql( $wpdb->posts, 'ID' );
2064
  if( ! empty($re) && count($re)) {
2065
+ $term_ids = wp_list_pluck( $re, 'term_taxonomy_id' );
2066
 
2067
  // Generate query
2068
  $query = array();
2164
  $term_recount_log['query_2'] = $query;
2165
  }
2166
  $results = $wpdb->get_results( $query );
2167
+ $term_to_taxonomy = wp_list_pluck( $re, 'term_id', 'term_taxonomy_id' );
2168
+ foreach($results as &$results_convert) {
2169
+ $results_convert->term_count_id = $term_to_taxonomy[$results_convert->term_count_id];
2170
+ }
2171
  $results_pid = wp_list_pluck( $results, 'PID', 'term_count_id' );
2172
  $results = wp_list_pluck( $results, 'term_count', 'term_count_id' );
2173
  }
js/admin.js CHANGED
@@ -330,6 +330,8 @@ var berocket_admin_filter_types_by_attr = {
330
  && filter_type != 'product_cat'
331
  && filter_type != 'tag' )
332
  || type != 'select' ) );
 
 
333
  if ( type == 'color' || type == 'image' ) {
334
  var tax_color_name;
335
  if ( filter_type == 'attribute' ) {
330
  && filter_type != 'product_cat'
331
  && filter_type != 'tag' )
332
  || type != 'select' ) );
333
+ berocket_aapf_show_hide( $('.br_aapf_date_style_select', $parent),
334
+ ( filter_type != 'date' ) );
335
  if ( type == 'color' || type == 'image' ) {
336
  var tax_color_name;
337
  if ( filter_type == 'attribute' ) {
main.php CHANGED
@@ -1283,6 +1283,7 @@ jQuery(document).on('change', '.br_selected_area_show', br_selected_area_show);
1283
  $out['class'] = (empty($out['class']) ? '' : $out['class'] . ' ') . 'berocket_aapf_false';
1284
  }
1285
  if( $atts['berocket_aapf'] == 'true' || $atts['berocket_aapf'] == '1' ) {
 
1286
  $out['berocket_aapf'] = true;
1287
  $out['class'] = (empty($out['class']) ? '' : $out['class'] . ' ') . 'berocket_aapf_true';
1288
  }
@@ -1681,6 +1682,9 @@ jQuery(document).on('change', '.br_selected_area_show', br_selected_area_show);
1681
  }
1682
  $query_vars['post__not_in'] = array_merge($query_vars['post__not_in'], apply_filters('berocket_add_out_of_stock_variable', array(), $custom_terms, berocket_isset($_POST['limits_arr'])));
1683
  $query_vars['post__in'] = apply_filters( 'loop_shop_post_in', $query_vars['post__in']);
 
 
 
1684
  $query_vars['berocket_filtered'] = true;
1685
  global $br_wc_query;
1686
  $br_wc_query = $query_vars;
@@ -1747,7 +1751,6 @@ jQuery(document).on('change', '.br_selected_area_show', br_selected_area_show);
1747
  $query->set( $args_field, $variable );
1748
  }
1749
  }
1750
-
1751
  $query->set('berocket_filtered', true);
1752
 
1753
  //THIS CAN BE NEW FIX FOR SORTING, BUT NOT SURE
1283
  $out['class'] = (empty($out['class']) ? '' : $out['class'] . ' ') . 'berocket_aapf_false';
1284
  }
1285
  if( $atts['berocket_aapf'] == 'true' || $atts['berocket_aapf'] == '1' ) {
1286
+ $out['cache'] = false;
1287
  $out['berocket_aapf'] = true;
1288
  $out['class'] = (empty($out['class']) ? '' : $out['class'] . ' ') . 'berocket_aapf_true';
1289
  }
1682
  }
1683
  $query_vars['post__not_in'] = array_merge($query_vars['post__not_in'], apply_filters('berocket_add_out_of_stock_variable', array(), $custom_terms, berocket_isset($_POST['limits_arr'])));
1684
  $query_vars['post__in'] = apply_filters( 'loop_shop_post_in', $query_vars['post__in']);
1685
+ if ( br_woocommerce_version_check('3.6') && ! empty($_POST['price']) ) {
1686
+ $query_vars['berocket_price'] = $_POST['price'];
1687
+ }
1688
  $query_vars['berocket_filtered'] = true;
1689
  global $br_wc_query;
1690
  $br_wc_query = $query_vars;
1751
  $query->set( $args_field, $variable );
1752
  }
1753
  }
 
1754
  $query->set('berocket_filtered', true);
1755
 
1756
  //THIS CAN BE NEW FIX FOR SORTING, BUT NOT SURE
readme.txt CHANGED
@@ -5,7 +5,7 @@ Donate link: https://berocket.com/product/woocommerce-ajax-products-filter?utm_s
5
  Tags: filters, product filters, ajax product filters, ajax filter, ajax filter widget, color filter, size filter, product onsale filter, product preview, product category filter, product reset filter, product sort by filter, stock filter, product tag filter, price range filter, price box filter, advanced product filters, woocommerce filters, woocommerce product filters, woocommerce products filter, woocommerce ajax product filters, widget, plugin, woocommerce item filters, filters plugin, ajax filters plugin, filter woocommerce products, filter woocommerce products plugin, wc filters, wc filters products, wc products filters, wc ajax products filters, wc product filters, wc advanced product filters, woocommerce layered nav, woocommerce layered navigation, ajax filtered nav, ajax filtered navigation, price filter, ajax price filter, woocommerce product sorting, sidebar filter, sidebar ajax filter, taxonomy filter, category filter, attribute filter, attributes filter, woocommerce product sort, ajax products filter plugin for woocommerce, rocket, berocket, berocket woocommerce ajax products filter
6
  Requires at least: 4.0
7
  Tested up to: 5.2.2
8
- Stable tag: 1.3.3
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -184,6 +184,10 @@ You can try this plugin's admin side [here](https://berocket.com/product/woocomm
184
 
185
  == Changelog ==
186
 
 
 
 
 
187
  = 1.3.3 =
188
  * Enhancement - Filtering speed optimization
189
  * Enhancement - Multiple WooCommerce shortcode can work correct
5
  Tags: filters, product filters, ajax product filters, ajax filter, ajax filter widget, color filter, size filter, product onsale filter, product preview, product category filter, product reset filter, product sort by filter, stock filter, product tag filter, price range filter, price box filter, advanced product filters, woocommerce filters, woocommerce product filters, woocommerce products filter, woocommerce ajax product filters, widget, plugin, woocommerce item filters, filters plugin, ajax filters plugin, filter woocommerce products, filter woocommerce products plugin, wc filters, wc filters products, wc products filters, wc ajax products filters, wc product filters, wc advanced product filters, woocommerce layered nav, woocommerce layered navigation, ajax filtered nav, ajax filtered navigation, price filter, ajax price filter, woocommerce product sorting, sidebar filter, sidebar ajax filter, taxonomy filter, category filter, attribute filter, attributes filter, woocommerce product sort, ajax products filter plugin for woocommerce, rocket, berocket, berocket woocommerce ajax products filter
6
  Requires at least: 4.0
7
  Tested up to: 5.2.2
8
+ Stable tag: 1.3.3.1
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
184
 
185
  == Changelog ==
186
 
187
+ = 1.3.3.1 =
188
+ * Fix - WooCommerce Shortcode with multiple categories
189
+ * Fix - Incorrect recount terms on some sites
190
+
191
  = 1.3.3 =
192
  * Enhancement - Filtering speed optimization
193
  * Enhancement - Multiple WooCommerce shortcode can work correct
woocommerce-filters.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: Advanced AJAX Product Filters for WooCommerce
4
  * Plugin URI: https://wordpress.org/plugins/woocommerce-ajax-filters/?utm_source=free_plugin&utm_medium=plugins&utm_campaign=ajax_filters
5
  * Description: Unlimited AJAX products filters to make your shop perfect
6
- * Version: 1.3.3
7
  * Author: BeRocket
8
  * Requires at least: 4.0
9
  * Author URI: https://berocket.com?utm_source=free_plugin&utm_medium=plugins&utm_campaign=ajax_filters
@@ -11,6 +11,6 @@
11
  * Domain Path: /languages/
12
  * WC tested up to: 3.6.5
13
  */
14
- define( "BeRocket_AJAX_filters_version", '1.3.3' );
15
  define( "BeRocket_AJAX_filters_file", __FILE__ );
16
  include_once('main.php');
3
  * Plugin Name: Advanced AJAX Product Filters for WooCommerce
4
  * Plugin URI: https://wordpress.org/plugins/woocommerce-ajax-filters/?utm_source=free_plugin&utm_medium=plugins&utm_campaign=ajax_filters
5
  * Description: Unlimited AJAX products filters to make your shop perfect
6
+ * Version: 1.3.3.1
7
  * Author: BeRocket
8
  * Requires at least: 4.0
9
  * Author URI: https://berocket.com?utm_source=free_plugin&utm_medium=plugins&utm_campaign=ajax_filters
11
  * Domain Path: /languages/
12
  * WC tested up to: 3.6.5
13
  */
14
+ define( "BeRocket_AJAX_filters_version", '1.3.3.1' );
15
  define( "BeRocket_AJAX_filters_file", __FILE__ );
16
  include_once('main.php');