Advanced AJAX Product Filters - Version 1.3.3

Version Description

  • Enhancement - Filtering speed optimization
  • Enhancement - Multiple WooCommerce shortcode can work correct
  • Enhancement - Database query optimization and less query count
Download this release

Release Info

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

Code changes from version 1.3.2.8 to 1.3.3

Files changed (5) hide show
  1. includes/widget.php +29 -17
  2. js/widget.min.js +64 -21
  3. main.php +26 -66
  4. readme.txt +6 -1
  5. woocommerce-filters.php +2 -2
includes/widget.php CHANGED
@@ -860,6 +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( 'berocket_query_var_title', $set_query_var_title );
864
 
865
  // widget title and start tag ( <ul> ) can be found in templates/widget_start.php
@@ -1743,18 +1744,22 @@ if( BeRocket_AAPF::$debug_mode ) {
1743
 
1744
  // Generate query
1745
  $query = array();
1746
- $query['select'] = "SELECT COUNT( DISTINCT {$wpdb->posts}.ID ) as term_count, GROUP_CONCAT({$wpdb->posts}.ID SEPARATOR ',') as PID, terms.term_id as term_count_id";
 
 
 
 
 
 
1747
  $query['from'] = "FROM {$wpdb->posts}";
1748
  $query['join'] = "
1749
  INNER JOIN {$wpdb->term_relationships} AS term_relationships ON {$wpdb->posts}.ID = term_relationships.object_id
1750
- INNER JOIN {$wpdb->term_taxonomy} AS term_taxonomy USING( term_taxonomy_id )
1751
- INNER JOIN {$wpdb->terms} AS terms USING( term_id )
1752
  " . $tax_query_sql['join'] . $meta_query_sql['join'];
1753
  $query['where'] = "
1754
  WHERE {$wpdb->posts}.post_type IN ( 'product' )
1755
  AND " . br_select_post_status() . "
1756
  " . $tax_query_sql['where'] . $meta_query_sql['where'] . "
1757
- AND terms.term_id IN (" . implode( ',', array_map( 'absint', $term_ids ) ) . ")
1758
  ";
1759
 
1760
  br_where_search( $query );
@@ -1762,13 +1767,14 @@ if( BeRocket_AAPF::$debug_mode ) {
1762
  $query['join'] = $query['join']." INNER JOIN {$wpdb->prefix}icl_translations as wpml_lang ON ( {$wpdb->posts}.ID = wpml_lang.element_id )";
1763
  $query['where'] = $query['where']." AND wpml_lang.language_code = '".ICL_LANGUAGE_CODE."' AND wpml_lang.element_type = 'post_product'";
1764
  }
1765
- $query['group_by'] = "GROUP BY terms.term_id";
1766
  $query = apply_filters( 'woocommerce_get_filtered_term_product_counts_query', $query );
1767
  $query = apply_filters( 'berocket_posts_clauses_recount', $query );
1768
  $query = implode( ' ', $query );
1769
  if( BeRocket_AAPF::$debug_mode ) {
1770
  $term_recount_log['query_1'] = $query;
1771
  }
 
1772
  $results = $wpdb->get_results( $query );
1773
  $results_pid = wp_list_pluck( $results, 'PID', 'term_count_id' );
1774
  $results = wp_list_pluck( $results, 'term_count', 'term_count_id' );
@@ -1986,7 +1992,13 @@ if( BeRocket_AAPF::$debug_mode ) {
1986
  }
1987
  }
1988
 
1989
- if ( $count_filtering ) {
 
 
 
 
 
 
1990
  if ( class_exists('WP_Meta_Query') && class_exists('WP_Tax_Query') ) {
1991
  if ( $has_new_function ) {
1992
  $tax_query = WC_Query::get_main_tax_query();
@@ -2050,18 +2062,22 @@ if( BeRocket_AAPF::$debug_mode ) {
2050
 
2051
  // Generate query
2052
  $query = array();
2053
- $query['select'] = "SELECT COUNT( DISTINCT {$wpdb->posts}.ID ) as term_count, GROUP_CONCAT(DISTINCT {$wpdb->posts}.ID SEPARATOR ',') as PID, terms.term_id as term_count_id";
 
 
 
 
 
 
2054
  $query['from'] = "FROM {$wpdb->posts}";
2055
  $query['join'] = "
2056
  INNER JOIN {$wpdb->term_relationships} AS term_relationships ON {$wpdb->posts}.ID = term_relationships.object_id
2057
- INNER JOIN {$wpdb->term_taxonomy} AS term_taxonomy USING( term_taxonomy_id )
2058
- INNER JOIN {$wpdb->terms} AS terms USING( term_id )
2059
  " . $tax_query_sql['join'] . $meta_query_sql['join'];
2060
  $query['where'] = "
2061
  WHERE {$wpdb->posts}.post_type IN ( 'product' )
2062
  AND " . br_select_post_status() . "
2063
  " . $tax_query_sql['where'] . $meta_query_sql['where'] . "
2064
- AND terms.term_id IN (" . implode( ',', array_map( 'absint', $term_ids ) ) . ")
2065
  ";
2066
  if( defined( 'WCML_VERSION' ) && defined('ICL_LANGUAGE_CODE') ) {
2067
  $query['join'] = $query['join']." INNER JOIN {$wpdb->prefix}icl_translations as wpml_lang ON ( {$wpdb->posts}.ID = wpml_lang.element_id )";
@@ -2071,13 +2087,9 @@ if( BeRocket_AAPF::$debug_mode ) {
2071
  if( ! empty($post__in) ) {
2072
  $query['where'] .= " AND {$wpdb->posts}.ID IN (\"" . implode('","', $post__in) . "\")";
2073
  }
2074
- if( function_exists('wc_get_product_visibility_term_ids') ) {
2075
- $product_visibility_term_ids = wc_get_product_visibility_term_ids();
2076
- $query['where'] .= " AND ( {$wpdb->posts}.ID NOT IN (SELECT object_id FROM {$wpdb->term_relationships} WHERE term_taxonomy_id='" . $product_visibility_term_ids['exclude-from-catalog'] . "') ) ";
2077
- }
2078
 
2079
  $query['where'] .= $old_join_posts;
2080
- $query['group_by'] = "GROUP BY terms.term_id";
2081
  if( ! empty($br_options['out_of_stock_variable_reload']) ) {
2082
  $new_post_terms = berocket_isset($_POST['terms']);
2083
  $new_post_limits = berocket_isset($_POST['limits_arr']);
@@ -2104,13 +2116,13 @@ if( BeRocket_AAPF::$debug_mode ) {
2104
  $limit_post__term_id_without_product = array();
2105
  foreach($limit_post__not_in as $terms_id => $limit_post) {
2106
  if( is_array($limit_post) && count($limit_post) ) {
2107
- $limit_post__not_in_where_array[$terms_id] = "({$wpdb->posts}.ID NOT IN (\"" . implode('","', $limit_post) . "\") AND terms.term_id = {$terms_id})";
2108
  } else {
2109
  $limit_post__term_id_without_product[] = $terms_id;
2110
  }
2111
  }
2112
  if( count($limit_post__term_id_without_product) ) {
2113
- $limit_post__not_in_where_array[] = "(terms.term_id IN (".implode(', ', $limit_post__term_id_without_product)."))";
2114
  }
2115
  $limit_post__not_in_where = implode(' OR ', $limit_post__not_in_where_array);
2116
  }
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
1744
 
1745
  // Generate query
1746
  $query = array();
1747
+ $query['select'] = "SELECT COUNT( DISTINCT {$wpdb->posts}.ID ) as term_count";
1748
+ if( $taxonomy == 'product_cat' ) {
1749
+ $query['select'] .= ", GROUP_CONCAT(DISTINCT {$wpdb->posts}.ID SEPARATOR ',') as PID";
1750
+ } else {
1751
+ $query['select'] .= ", '' as PID";
1752
+ }
1753
+ $query['select'] .= ", term_relationships.term_taxonomy_id as term_count_id";
1754
  $query['from'] = "FROM {$wpdb->posts}";
1755
  $query['join'] = "
1756
  INNER JOIN {$wpdb->term_relationships} AS term_relationships ON {$wpdb->posts}.ID = term_relationships.object_id
 
 
1757
  " . $tax_query_sql['join'] . $meta_query_sql['join'];
1758
  $query['where'] = "
1759
  WHERE {$wpdb->posts}.post_type IN ( 'product' )
1760
  AND " . br_select_post_status() . "
1761
  " . $tax_query_sql['where'] . $meta_query_sql['where'] . "
1762
+ AND term_relationships.term_taxonomy_id IN (" . implode( ',', array_map( 'absint', $term_ids ) ) . ")
1763
  ";
1764
 
1765
  br_where_search( $query );
1767
  $query['join'] = $query['join']." INNER JOIN {$wpdb->prefix}icl_translations as wpml_lang ON ( {$wpdb->posts}.ID = wpml_lang.element_id )";
1768
  $query['where'] = $query['where']." AND wpml_lang.language_code = '".ICL_LANGUAGE_CODE."' AND wpml_lang.element_type = 'post_product'";
1769
  }
1770
+ $query['group_by'] = "GROUP BY term_relationships.term_taxonomy_id";
1771
  $query = apply_filters( 'woocommerce_get_filtered_term_product_counts_query', $query );
1772
  $query = apply_filters( 'berocket_posts_clauses_recount', $query );
1773
  $query = implode( ' ', $query );
1774
  if( BeRocket_AAPF::$debug_mode ) {
1775
  $term_recount_log['query_1'] = $query;
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' );
1992
  }
1993
  }
1994
 
1995
+ if (
1996
+ ( ! $hide_empty
1997
+ || apply_filters( 'berocket_aapf_is_filtered_page_check', ! empty($_GET['filters']), 'get_filter_args', $wp_query )
1998
+ || ( ! empty($br_options['out_of_stock_variable_reload']) && ! empty($br_options['out_of_stock_variable']) )
1999
+ || is_filtered()
2000
+ ) && $count_filtering
2001
+ ) {
2002
  if ( class_exists('WP_Meta_Query') && class_exists('WP_Tax_Query') ) {
2003
  if ( $has_new_function ) {
2004
  $tax_query = WC_Query::get_main_tax_query();
2062
 
2063
  // Generate query
2064
  $query = array();
2065
+ $query['select'] = "SELECT COUNT( DISTINCT {$wpdb->posts}.ID ) as term_count";
2066
+ if( $taxonomy == 'product_cat' ) {
2067
+ $query['select'] .= ", GROUP_CONCAT(DISTINCT {$wpdb->posts}.ID SEPARATOR ',') as PID";
2068
+ } else {
2069
+ $query['select'] .= ", '' as PID";
2070
+ }
2071
+ $query['select'] .= ", term_relationships.term_taxonomy_id as term_count_id";
2072
  $query['from'] = "FROM {$wpdb->posts}";
2073
  $query['join'] = "
2074
  INNER JOIN {$wpdb->term_relationships} AS term_relationships ON {$wpdb->posts}.ID = term_relationships.object_id
 
 
2075
  " . $tax_query_sql['join'] . $meta_query_sql['join'];
2076
  $query['where'] = "
2077
  WHERE {$wpdb->posts}.post_type IN ( 'product' )
2078
  AND " . br_select_post_status() . "
2079
  " . $tax_query_sql['where'] . $meta_query_sql['where'] . "
2080
+ AND term_relationships.term_taxonomy_id IN (" . implode( ',', array_map( 'absint', $term_ids ) ) . ")
2081
  ";
2082
  if( defined( 'WCML_VERSION' ) && defined('ICL_LANGUAGE_CODE') ) {
2083
  $query['join'] = $query['join']." INNER JOIN {$wpdb->prefix}icl_translations as wpml_lang ON ( {$wpdb->posts}.ID = wpml_lang.element_id )";
2087
  if( ! empty($post__in) ) {
2088
  $query['where'] .= " AND {$wpdb->posts}.ID IN (\"" . implode('","', $post__in) . "\")";
2089
  }
 
 
 
 
2090
 
2091
  $query['where'] .= $old_join_posts;
2092
+ $query['group_by'] = "GROUP BY term_relationships.term_taxonomy_id";
2093
  if( ! empty($br_options['out_of_stock_variable_reload']) ) {
2094
  $new_post_terms = berocket_isset($_POST['terms']);
2095
  $new_post_limits = berocket_isset($_POST['limits_arr']);
2116
  $limit_post__term_id_without_product = array();
2117
  foreach($limit_post__not_in as $terms_id => $limit_post) {
2118
  if( is_array($limit_post) && count($limit_post) ) {
2119
+ $limit_post__not_in_where_array[$terms_id] = "({$wpdb->posts}.ID NOT IN (\"" . implode('","', $limit_post) . "\") AND term_relationships.term_taxonomy_id = {$terms_id})";
2120
  } else {
2121
  $limit_post__term_id_without_product[] = $terms_id;
2122
  }
2123
  }
2124
  if( count($limit_post__term_id_without_product) ) {
2125
+ $limit_post__not_in_where_array[] = "(term_relationships.term_taxonomy_id IN (".implode(', ', $limit_post__term_id_without_product)."))";
2126
  }
2127
  $limit_post__not_in_where = implode(' OR ', $limit_post__not_in_where_array);
2128
  }
js/widget.min.js CHANGED
@@ -25,16 +25,29 @@ var berocket_aapf_widget_product_filters = [],
25
  $(document).on('change', '.br_date_filter', function() {
26
  var $berocket_aapf_widget = $(this).parents('.berocket_aapf_widget');
27
  var $date_info = $berocket_aapf_widget.find('.berocket_date_picker');
28
- var value = $(this).val();
29
  value = value.replace(/\//g, '');
30
  if( $(this).is('.br_start_date')) {
31
- $date_info.data('value_1', $(this).val());
32
  $date_info.data('value1', value);
33
  } else {
34
- $date_info.data('value_2', $(this).val());
35
  $date_info.data('value2', value);
36
  }
37
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  if( $(the_ajax_script.products_holder_id).is('.wf-container') ) {
39
  berocket_replace_only_html = true;
40
  }
@@ -596,10 +609,10 @@ var berocket_aapf_widget_product_filters = [],
596
  is_product_table = true;
597
  }
598
  }
 
599
  if( is_product_table ) {
600
  $data = $(data);
601
  berocket_aapf_attribute_data.jquery = $data;
602
- $('.hide_products').removeClass('hide_products');
603
  } else {
604
  if( the_ajax_script.ajax_request_load && the_ajax_script.ajax_request_load_style == 'jquery' ) {
605
  $data = $(data);
@@ -615,7 +628,22 @@ var berocket_aapf_widget_product_filters = [],
615
  args_ajax.no_products = the_ajax_script.no_products;
616
  }
617
  } else {
618
- args_ajax.products = $data.find(the_ajax_script.products_holder_id).prop('outerHTML');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
619
  }
620
  result = afterAjaxLoad(args_ajax);
621
  berocket_aapf_attribute_data.jquery = $data;
@@ -727,28 +755,43 @@ var berocket_aapf_widget_product_filters = [],
727
  }
728
  }
729
  } else {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
730
  if ( typeof args.no_products != 'undefined' ) {
731
  if( berocket_child_no_products ) {
732
  args.no_products = berocket_child_no_products;
733
  }
734
- if ( $(the_ajax_script.products_holder_id).length > 0 ) {
735
- $(the_ajax_script.products_holder_id).html(args.no_products).removeClass('hide_products');
736
  } else if ( $('div.woocommerce').length > 0 ) {
737
  $('div.woocommerce').html(args.no_products);
738
  }
739
  } else {
740
  var $products = $(args.products);
741
  if ( $products.length > 0 ) {
742
- if ( $(the_ajax_script.products_holder_id).length > 0 ) {
743
  if( berocket_replace_only_html ) {
744
- $(the_ajax_script.products_holder_id).removeClass('hide_products').html($products.html());
745
- if( typeof($(the_ajax_script.products_holder_id).isotope) == 'function' ) {
746
- $(the_ajax_script.products_holder_id).isotope( 'reloadItems' );
747
- $(the_ajax_script.products_holder_id).isotope();
748
  }
749
  jQuery(document).trigger('berocket_aapf_time_to_fix_products_style');
750
  } else {
751
- $(the_ajax_script.products_holder_id).replaceWith($products);
752
  }
753
  } else {
754
  if ( $('div.woocommerce').length > 0 ) {
@@ -757,14 +800,14 @@ var berocket_aapf_widget_product_filters = [],
757
  }
758
  } else {
759
  if ( $products.find(the_ajax_script.products_holder_id).length > 0 ) {
760
- if ( $(the_ajax_script.products_holder_id).length > 0 ) {
761
- $(the_ajax_script.products_holder_id).html($products.find(the_ajax_script.products_holder_id).html()).removeClass('hide_products');
762
  } else if ( $('div.woocommerce').length > 0 ) {
763
  $('div.woocommerce').html($products.find(the_ajax_script.products_holder_id).prop('outerHTML'));
764
  }
765
  } else {
766
- if ( $(the_ajax_script.products_holder_id).length > 0 ) {
767
- $(the_ajax_script.products_holder_id).html(the_ajax_script.no_products).removeClass('hide_products');
768
  } else if ( $('div.woocommerce').length > 0 ) {
769
  $('div.woocommerce').html('');
770
  }
@@ -1649,8 +1692,8 @@ var berocket_aapf_widget_product_filters = [],
1649
  } else if ( el_type == 'slider' ) {
1650
  $slider = $('#'+el_id).closest('li').find('.berocket_filter_slider');
1651
 
1652
- val1 = parseFloat($slider.data('min'));
1653
- val2 = parseFloat($slider.data('max'));
1654
 
1655
  ui = {handle:$slider.children(), values:[val1,val2]};
1656
  $slider.slider( "values", [ val1, val2 ] ).trigger('slide', ui);
@@ -1659,8 +1702,8 @@ var berocket_aapf_widget_product_filters = [],
1659
  } else if ( el_type == '_date' ) {
1660
  $date = $('.'+el_id+'.berocket_date_picker');
1661
 
1662
- val1 = $date.data('min');
1663
- val2 = $date.data('max');
1664
 
1665
  berocket_unselect_all = true;
1666
  $('.'+el_id+'.br_start_date').val(val1).trigger('change');
25
  $(document).on('change', '.br_date_filter', function() {
26
  var $berocket_aapf_widget = $(this).parents('.berocket_aapf_widget');
27
  var $date_info = $berocket_aapf_widget.find('.berocket_date_picker');
28
+ var value = berocket_convert_date_to_date_picker($(this).datepicker( "getDate" ));
29
  value = value.replace(/\//g, '');
30
  if( $(this).is('.br_start_date')) {
31
+ $date_info.data('value_1', $(this).val());
32
  $date_info.data('value1', value);
33
  } else {
34
+ $date_info.data('value_2', $(this).val());
35
  $date_info.data('value2', value);
36
  }
37
  });
38
+ function berocket_convert_date_to_date_picker(date) {
39
+ var mm = date.getMonth();
40
+ mm++;
41
+ if( mm < 10 ) {
42
+ mm = '0'+mm;
43
+ }
44
+ var dd = date.getDate();
45
+ if( dd < 10 ) {
46
+ dd = '0'+dd;
47
+ }
48
+ var yy = date.getFullYear();
49
+ return mm+'/'+dd+'/'+yy;
50
+ }
51
  if( $(the_ajax_script.products_holder_id).is('.wf-container') ) {
52
  berocket_replace_only_html = true;
53
  }
609
  is_product_table = true;
610
  }
611
  }
612
+ $('.hide_products').removeClass('hide_products');
613
  if( is_product_table ) {
614
  $data = $(data);
615
  berocket_aapf_attribute_data.jquery = $data;
 
616
  } else {
617
  if( the_ajax_script.ajax_request_load && the_ajax_script.ajax_request_load_style == 'jquery' ) {
618
  $data = $(data);
628
  args_ajax.no_products = the_ajax_script.no_products;
629
  }
630
  } else {
631
+ var $block_products_holder_id;
632
+ if( $data.find(the_ajax_script.products_holder_id).length > 1 ) {
633
+ $data.find(the_ajax_script.products_holder_id).each(function () {
634
+ if( $(this).is('.berocket_aapf_true') || $(this).parents('.berocket_aapf_true').length || $(this).find('.berocket_aapf_true').length ) {
635
+ $block_products_holder_id = $(this);
636
+ return false;
637
+ }
638
+ if( typeof($block_products_holder_id) == 'undefined' && ! $(this).is('.berocket_aapf_false') && $(this).parents('.berocket_aapf_false').length && $(this).find('.berocket_aapf_false').length ) {
639
+ $block_products_holder_id = $(this);
640
+ }
641
+ });
642
+ }
643
+ if( typeof($block_products_holder_id) == 'undefined' ) {
644
+ $block_products_holder_id = $data.find(the_ajax_script.products_holder_id);
645
+ }
646
+ args_ajax.products = $block_products_holder_id.prop('outerHTML');
647
  }
648
  result = afterAjaxLoad(args_ajax);
649
  berocket_aapf_attribute_data.jquery = $data;
755
  }
756
  }
757
  } else {
758
+ var $block_products_holder_id;
759
+ if( $(the_ajax_script.products_holder_id).length > 1 ) {
760
+ $(the_ajax_script.products_holder_id).each(function () {
761
+ if( $(this).is('.berocket_aapf_true') || $(this).parents('.berocket_aapf_true').length || $(this).find('.berocket_aapf_true').length ) {
762
+ $block_products_holder_id = $(this);
763
+ return false;
764
+ }
765
+ if( typeof($block_products_holder_id) == 'undefined' && ! $(this).is('.berocket_aapf_false') && $(this).parents('.berocket_aapf_false').length && $(this).find('.berocket_aapf_false').length ) {
766
+ $block_products_holder_id = $(this);
767
+ }
768
+ });
769
+ }
770
+ if( typeof($block_products_holder_id) == 'undefined' ) {
771
+ $block_products_holder_id = $(the_ajax_script.products_holder_id);
772
+ }
773
  if ( typeof args.no_products != 'undefined' ) {
774
  if( berocket_child_no_products ) {
775
  args.no_products = berocket_child_no_products;
776
  }
777
+ if ( $block_products_holder_id.length > 0 ) {
778
+ $block_products_holder_id.html(args.no_products);
779
  } else if ( $('div.woocommerce').length > 0 ) {
780
  $('div.woocommerce').html(args.no_products);
781
  }
782
  } else {
783
  var $products = $(args.products);
784
  if ( $products.length > 0 ) {
785
+ if ( $block_products_holder_id.length > 0 ) {
786
  if( berocket_replace_only_html ) {
787
+ $block_products_holder_id.html($products.html());
788
+ if( typeof($block_products_holder_id.isotope) == 'function' ) {
789
+ $block_products_holder_id.isotope( 'reloadItems' );
790
+ $block_products_holder_id.isotope();
791
  }
792
  jQuery(document).trigger('berocket_aapf_time_to_fix_products_style');
793
  } else {
794
+ $block_products_holder_id.replaceWith($products);
795
  }
796
  } else {
797
  if ( $('div.woocommerce').length > 0 ) {
800
  }
801
  } else {
802
  if ( $products.find(the_ajax_script.products_holder_id).length > 0 ) {
803
+ if ( $block_products_holder_id.length > 0 ) {
804
+ $block_products_holder_id.html($products.find(the_ajax_script.products_holder_id).html());
805
  } else if ( $('div.woocommerce').length > 0 ) {
806
  $('div.woocommerce').html($products.find(the_ajax_script.products_holder_id).prop('outerHTML'));
807
  }
808
  } else {
809
+ if ( $block_products_holder_id.length > 0 ) {
810
+ $block_products_holder_id.html(the_ajax_script.no_products);
811
  } else if ( $('div.woocommerce').length > 0 ) {
812
  $('div.woocommerce').html('');
813
  }
1692
  } else if ( el_type == 'slider' ) {
1693
  $slider = $('#'+el_id).closest('li').find('.berocket_filter_slider');
1694
 
1695
+ var val1 = parseFloat($slider.data('min'));
1696
+ var val2 = parseFloat($slider.data('max'));
1697
 
1698
  ui = {handle:$slider.children(), values:[val1,val2]};
1699
  $slider.slider( "values", [ val1, val2 ] ).trigger('slide', ui);
1702
  } else if ( el_type == '_date' ) {
1703
  $date = $('.'+el_id+'.berocket_date_picker');
1704
 
1705
+ var val1 = $date.data('min');
1706
+ var val2 = $date.data('max');
1707
 
1708
  berocket_unselect_all = true;
1709
  $('.'+el_id+'.br_start_date').val(val1).trigger('change');
main.php CHANGED
@@ -1277,8 +1277,15 @@ jQuery(document).on('change', '.br_selected_area_show', br_selected_area_show);
1277
  add_filter( 'shortcode_atts_products', array($this, 'shortcode_atts_products'), 10, 3);
1278
  }
1279
  function shortcode_atts_products($out, $pairs, $atts) {
1280
- if( ! empty($atts['berocket_aapf']) && $atts['berocket_aapf'] == 'true' ) {
1281
- $out['berocket_aapf'] = true;
 
 
 
 
 
 
 
1282
  }
1283
  return $out;
1284
  }
@@ -1577,6 +1584,9 @@ jQuery(document).on('change', '.br_selected_area_show', br_selected_area_show);
1577
  return ob_get_clean();
1578
  }
1579
  public function woocommerce_shortcode_products_query( $query_vars, $atts = array(), $name = 'products' ) {
 
 
 
1580
  if( apply_filters('berocket_aapf_wcshortcode_is_filtering', ( (! is_shop() && ! is_product_taxonomy() && ! is_product_category() && ! is_product_tag()) || ! empty($atts['berocket_aapf']) ), $query_vars, $atts, $name ) ) {
1581
  $query_vars = $this->woocommerce_filter_query_vars($query_vars, $atts, $name);
1582
  }
@@ -1588,24 +1598,26 @@ jQuery(document).on('change', '.br_selected_area_show', br_selected_area_show);
1588
  }
1589
  }
1590
  public function price_filter_post_clauses( $args, $wp_query ) {
1591
- if( empty($wp_query->query_vars['berocket_filtered']) || empty($_POST['price']) ) {
1592
  return $args;
1593
  }
1594
  return $this->add_price_to_post_clauses($args);
1595
  }
1596
  public function add_price_to_post_clauses($args) {
1597
- global $wpdb;
 
1598
 
1599
- if ( ! strstr( $args['join'], 'wc_product_meta_lookup' ) ) {
1600
- $args['join'] .= " LEFT JOIN {$wpdb->wc_product_meta_lookup} wc_product_meta_lookup ON {$wpdb->posts}.ID = wc_product_meta_lookup.product_id ";
1601
- }
1602
- $min = isset( $_POST['price'][0] ) ? floatval( $_POST['price'][0] ) : 0;
1603
- $max = isset( $_POST['price'][1] ) ? floatval( $_POST['price'][1] ) : 9999999999;
1604
- $args['where'] .= $wpdb->prepare(
1605
- ' AND wc_product_meta_lookup.min_price >= %f AND wc_product_meta_lookup.max_price <= %f ',
1606
- $min,
1607
- $max
1608
- );
 
1609
  return $args;
1610
  }
1611
  public function woocommerce_filter_query_vars( $query_vars, $atts = array(), $name = 'products' ) {
@@ -2515,58 +2527,6 @@ jQuery(document).on('change', '.br_selected_area_show', br_selected_area_show);
2515
  $md5 = $md5 . br_get_value_from_array($options, 'purge_cache_time');
2516
  return $md5;
2517
  }
2518
- public function fix_WC_outofstock($variation_id) {
2519
- $product = wc_get_product($variation_id);
2520
- $this->update_visibility($product, true);
2521
- }
2522
-
2523
- /**
2524
- * Update visibility terms based on props.
2525
- *
2526
- * @since 3.0.0
2527
- *
2528
- * @param WC_Product $product Product object.
2529
- * @param bool $force Force update. Used during create.
2530
- */
2531
- protected function update_visibility( &$product, $force = false ) {
2532
- $changes = $product->get_changes();
2533
-
2534
- if ( $force || array_intersect( array( 'stock_status' ), array_keys( $changes ) ) ) {
2535
- $terms = array();
2536
-
2537
- if ( 'outofstock' === $product->get_stock_status() ) {
2538
- $terms[] = 'outofstock';
2539
- }
2540
-
2541
- wp_set_post_terms( $product->get_id(), $terms, 'product_visibility', false );
2542
- }
2543
- }
2544
-
2545
- public function as_schedule_WC_outofstock() {
2546
- $variation_ids = wp_parse_id_list(
2547
- get_posts(
2548
- array(
2549
- 'post_type' => 'product_variation',
2550
- 'fields' => 'ids',
2551
- 'post_status' => array( 'any', 'trash', 'auto-draft' ),
2552
- 'numberposts' => -1, // phpcs:ignore WordPress.VIP.PostsPerPage.posts_per_page_numberposts
2553
- )
2554
- )
2555
- );
2556
- foreach($variation_ids as $variation_id) {
2557
- if( function_exists('as_schedule_single_action') ) {
2558
- as_schedule_single_action( time(), 'berocket_fix_WC_outofstock', array($variation_id), 'BeRocket' );
2559
- }
2560
- }
2561
- }
2562
- public function sanitize_option( $input ) {
2563
- $input = parent::sanitize_option( $input );
2564
- $option = $this->get_option();
2565
- if( br_get_value_from_array($input, 'purge_cache_time') != br_get_value_from_array($option, 'purge_cache_time') ) {
2566
- $this->as_schedule_WC_outofstock();
2567
- }
2568
- return $input;
2569
- }
2570
  public function option_page_capability($capability = '') {
2571
  return 'manage_berocket_aapf';
2572
  }
1277
  add_filter( 'shortcode_atts_products', array($this, 'shortcode_atts_products'), 10, 3);
1278
  }
1279
  function shortcode_atts_products($out, $pairs, $atts) {
1280
+ if( ! empty($atts['berocket_aapf']) ) {
1281
+ if( $atts['berocket_aapf'] == 'false' || $atts['berocket_aapf'] == '0' ) {
1282
+ $out['berocket_aapf'] = false;
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
+ }
1289
  }
1290
  return $out;
1291
  }
1584
  return ob_get_clean();
1585
  }
1586
  public function woocommerce_shortcode_products_query( $query_vars, $atts = array(), $name = 'products' ) {
1587
+ if( isset($atts['berocket_aapf']) && $atts['berocket_aapf'] === false ) {
1588
+ return $query_vars;
1589
+ }
1590
  if( apply_filters('berocket_aapf_wcshortcode_is_filtering', ( (! is_shop() && ! is_product_taxonomy() && ! is_product_category() && ! is_product_tag()) || ! empty($atts['berocket_aapf']) ), $query_vars, $atts, $name ) ) {
1591
  $query_vars = $this->woocommerce_filter_query_vars($query_vars, $atts, $name);
1592
  }
1598
  }
1599
  }
1600
  public function price_filter_post_clauses( $args, $wp_query ) {
1601
+ if( empty($wp_query->query_vars['berocket_filtered']) ) {
1602
  return $args;
1603
  }
1604
  return $this->add_price_to_post_clauses($args);
1605
  }
1606
  public function add_price_to_post_clauses($args) {
1607
+ if( ! empty($_POST['price']) ) {
1608
+ global $wpdb;
1609
 
1610
+ if ( ! strstr( $args['join'], 'wc_product_meta_lookup' ) ) {
1611
+ $args['join'] .= " LEFT JOIN {$wpdb->wc_product_meta_lookup} wc_product_meta_lookup ON {$wpdb->posts}.ID = wc_product_meta_lookup.product_id ";
1612
+ }
1613
+ $min = isset( $_POST['price'][0] ) ? floatval( $_POST['price'][0] ) : 0;
1614
+ $max = isset( $_POST['price'][1] ) ? floatval( $_POST['price'][1] ) : 9999999999;
1615
+ $args['where'] .= $wpdb->prepare(
1616
+ ' AND wc_product_meta_lookup.min_price >= %f AND wc_product_meta_lookup.max_price <= %f ',
1617
+ $min,
1618
+ $max
1619
+ );
1620
+ }
1621
  return $args;
1622
  }
1623
  public function woocommerce_filter_query_vars( $query_vars, $atts = array(), $name = 'products' ) {
2527
  $md5 = $md5 . br_get_value_from_array($options, 'purge_cache_time');
2528
  return $md5;
2529
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2530
  public function option_page_capability($capability = '') {
2531
  return 'manage_berocket_aapf';
2532
  }
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.2.8
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -184,6 +184,11 @@ You can try this plugin's admin side [here](https://berocket.com/product/woocomm
184
 
185
  == Changelog ==
186
 
 
 
 
 
 
187
  = 1.3.2.8 =
188
  * Enhancement - Price slider speed woocommerce 3.6
189
  * Enhancement - WooCommerce shortcode add no products message
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
 
185
  == Changelog ==
186
 
187
+ = 1.3.3 =
188
+ * Enhancement - Filtering speed optimization
189
+ * Enhancement - Multiple WooCommerce shortcode can work correct
190
+ * Enhancement - Database query optimization and less query count
191
+
192
  = 1.3.2.8 =
193
  * Enhancement - Price slider speed woocommerce 3.6
194
  * Enhancement - WooCommerce shortcode add no products message
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.2.8
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.2.8' );
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
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' );
15
  define( "BeRocket_AJAX_filters_file", __FILE__ );
16
  include_once('main.php');