Advanced Woo Search - Version 1.91

Version Description

  • Add - aws_terms_search_query filter
  • Add - aws_search_terms_description filter
  • Add - Support for Elementor pop-up templates
  • Fix - taxonomies search with special characters bug
  • Fix - bug with search results page cache
  • Update - aws_searchbox_markup filter new parameter
Download this release

Release Info

Developer Mihail Barinov
Plugin Icon 128x128 Advanced Woo Search
Version 1.91
Comparing to
See all releases

Code changes from version 1.90 to 1.91

advanced-woo-search.php CHANGED
@@ -3,7 +3,7 @@
3
  /*
4
  Plugin Name: Advanced Woo Search
5
  Description: Advance ajax WooCommerce product search.
6
- Version: 1.90
7
  Author: ILLID
8
  Author URI: https://advanced-woo-search.com/
9
  Text Domain: advanced-woo-search
@@ -16,7 +16,7 @@ if ( ! defined( 'ABSPATH' ) ) {
16
  exit;
17
  }
18
 
19
- define( 'AWS_VERSION', '1.90' );
20
 
21
 
22
  define( 'AWS_DIR', dirname( __FILE__ ) );
3
  /*
4
  Plugin Name: Advanced Woo Search
5
  Description: Advance ajax WooCommerce product search.
6
+ Version: 1.91
7
  Author: ILLID
8
  Author URI: https://advanced-woo-search.com/
9
  Text Domain: advanced-woo-search
16
  exit;
17
  }
18
 
19
+ define( 'AWS_VERSION', '1.91' );
20
 
21
 
22
  define( 'AWS_DIR', dirname( __FILE__ ) );
assets/js/common.js CHANGED
@@ -128,7 +128,9 @@
128
  html += '<span class="aws_result_content">';
129
  html += '<span class="aws_result_title">';
130
  html += taxitem.name;
131
- html += '<span class="aws_result_count">&nbsp;(' + taxitem.count + ')</span>';
 
 
132
  html += '</span>';
133
  html += '</span>';
134
  html += '</a>';
128
  html += '<span class="aws_result_content">';
129
  html += '<span class="aws_result_title">';
130
  html += taxitem.name;
131
+ if ( taxitem.count ) {
132
+ html += '<span class="aws_result_count">&nbsp;(' + taxitem.count + ')</span>';
133
+ }
134
  html += '</span>';
135
  html += '</span>';
136
  html += '</a>';
includes/class-aws-helpers.php CHANGED
@@ -712,6 +712,79 @@ if ( ! class_exists( 'AWS_Helpers' ) ) :
712
 
713
  }
714
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
715
  }
716
 
717
  endif;
712
 
713
  }
714
 
715
+ /*
716
+ * Get taxonomies search array
717
+ *
718
+ * @return array Terms
719
+ */
720
+ static public function get_tax_search_array( $search_terms ) {
721
+
722
+ global $wpdb;
723
+
724
+ $search_array = array();
725
+
726
+ foreach ( $search_terms as $search_term ) {
727
+
728
+ $search_term_len = strlen( $search_term );
729
+
730
+ $search_term_norm = AWS_Plurals::singularize( $search_term );
731
+
732
+ if ( $search_term_norm && $search_term_len > 3 && strlen( $search_term_norm ) > 2 ) {
733
+ $search_term = $search_term_norm;
734
+ }
735
+
736
+ $like = '%' . $wpdb->esc_like($search_term) . '%';
737
+
738
+ $search_array[] = $wpdb->prepare('( name LIKE %s )', $like);
739
+
740
+ if ( $terms_desc_search = apply_filters( 'aws_search_terms_description', false ) ) {
741
+ $search_array[] = $wpdb->prepare('( description LIKE %s )', $like);
742
+ }
743
+
744
+ }
745
+
746
+ return $search_array;
747
+
748
+ }
749
+
750
+ /*
751
+ * Get taxonomies relevance array
752
+ *
753
+ * @return array Relevance array
754
+ */
755
+ static public function get_tax_relevance_array( $search_terms ) {
756
+
757
+ global $wpdb;
758
+
759
+ $relevance_array = array();
760
+
761
+ foreach ( $search_terms as $search_term ) {
762
+
763
+ $search_term_len = strlen( $search_term );
764
+
765
+ $relevance = 40 + 2 * $search_term_len;
766
+
767
+ $search_term_norm = AWS_Plurals::singularize( $search_term );
768
+
769
+ if ( $search_term_norm && $search_term_len > 3 && strlen( $search_term_norm ) > 2 ) {
770
+ $search_term = $search_term_norm;
771
+ }
772
+
773
+ $like = '%' . $wpdb->esc_like($search_term) . '%';
774
+
775
+ $relevance_array[] = $wpdb->prepare( "( case when ( name LIKE %s ) then {$relevance} else 0 end )", $like );
776
+
777
+ if ( $terms_desc_search = apply_filters( 'aws_search_terms_description', false ) ) {
778
+ $relevance_desc = 10 + 2 * $search_term_len;
779
+ $relevance_array[] = $wpdb->prepare( "( case when ( description LIKE %s ) then {$relevance_desc} else 0 end )", $like );
780
+ }
781
+
782
+ }
783
+
784
+ return $relevance_array;
785
+
786
+ }
787
+
788
  }
789
 
790
  endif;
includes/class-aws-integrations.php CHANGED
@@ -100,6 +100,11 @@ if ( ! class_exists( 'AWS_Integrations' ) ) :
100
  add_action( 'wp_head', array( $this, 'avada_head_action' ) );
101
  }
102
 
 
 
 
 
 
103
  }
104
 
105
  // Wholesale plugin hide certain products
@@ -480,6 +485,27 @@ if ( ! class_exists( 'AWS_Integrations' ) ) :
480
 
481
  <?php }
482
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
483
  /*
484
  * Porto theme seamless integration
485
  */
100
  add_action( 'wp_head', array( $this, 'avada_head_action' ) );
101
  }
102
 
103
+ // Elementor pro
104
+ if ( defined( 'ELEMENTOR_PRO_VERSION' ) ) {
105
+ add_action( 'wp_footer', array( $this, 'elementor_pro_popup' ) );
106
+ }
107
+
108
  }
109
 
110
  // Wholesale plugin hide certain products
485
 
486
  <?php }
487
 
488
+ /*
489
+ * Elementor popup search form init
490
+ */
491
+ public function elementor_pro_popup() { ?>
492
+
493
+ <script>
494
+ window.addEventListener('load', function() {
495
+ if (window.jQuery) {
496
+ jQuery( document ).on( 'elementor/popup/show', function() {
497
+ window.setTimeout(function(){
498
+ jQuery('.elementor-container .aws-container').each( function() {
499
+ jQuery(this).aws_search();
500
+ });
501
+ }, 1000);
502
+ } );
503
+ }
504
+ }, false);
505
+ </script>
506
+
507
+ <?php }
508
+
509
  /*
510
  * Porto theme seamless integration
511
  */
includes/class-aws-markup.php CHANGED
@@ -123,7 +123,7 @@ if ( ! class_exists( 'AWS_Markup' ) ) :
123
  $markup .= '</form>';
124
  $markup .= '</div>';
125
 
126
- return apply_filters( 'aws_searchbox_markup', $markup );
127
 
128
  }
129
 
123
  $markup .= '</form>';
124
  $markup .= '</div>';
125
 
126
+ return apply_filters( 'aws_searchbox_markup', $markup, $params );
127
 
128
  }
129
 
includes/class-aws-search-page.php CHANGED
@@ -289,11 +289,19 @@ if ( ! class_exists( 'AWS_Search_Page' ) ) :
289
  */
290
  private function search( $s, $query ) {
291
 
292
- if ( isset( $this->data['search_res'] ) ) {
293
- return $this->data['search_res'];
 
 
 
 
 
 
 
 
 
294
  }
295
 
296
- $posts_array = (array) aws_search( $s );
297
  $posts_per_page = apply_filters( 'aws_posts_per_page', $query->get( 'posts_per_page' ) );
298
  $post_array_products = $posts_array['products'];
299
 
@@ -313,12 +321,12 @@ if ( ! class_exists( 'AWS_Search_Page' ) ) :
313
 
314
  $this->data['all_products'] = $post_array_products;
315
 
316
- $this->data['search_res'] = array(
317
  'all' => $post_array_products,
318
  'products' => $products
319
  );
320
 
321
- return $this->data['search_res'];
322
 
323
  }
324
 
289
  */
290
  private function search( $s, $query ) {
291
 
292
+ $hash = spl_object_hash( $query );
293
+
294
+ if ( isset( $this->data['search_res'][$hash] ) ) {
295
+ return $this->data['search_res'][$hash];
296
+ }
297
+
298
+ if ( isset( $this->data['search_res']['s'] ) ) {
299
+ $posts_array = $this->data['search_res']['s'];
300
+ } else {
301
+ $posts_array = (array) aws_search( $s );
302
+ $this->data['search_res']['s'] = $posts_array;
303
  }
304
 
 
305
  $posts_per_page = apply_filters( 'aws_posts_per_page', $query->get( 'posts_per_page' ) );
306
  $post_array_products = $posts_array['products'];
307
 
321
 
322
  $this->data['all_products'] = $post_array_products;
323
 
324
+ $this->data['search_res'][$hash] = array(
325
  'all' => $post_array_products,
326
  'products' => $products
327
  );
328
 
329
+ return $this->data['search_res'][$hash];
330
 
331
  }
332
 
includes/class-aws-search.php CHANGED
@@ -767,14 +767,15 @@ if ( ! class_exists( 'AWS_Search' ) ) :
767
  global $wpdb;
768
 
769
  $result_array = array();
770
- $search_array = array();
771
- $relevance_array = array();
772
  $excludes = '';
773
  $search_query = '';
774
  $relevance_query = '';
 
 
775
 
776
  $filtered_terms = $this->data['search_terms'];
777
- $filtered_terms[] = $this->data['s_nonormalize'];
 
778
 
779
  /**
780
  * Max number of terms to show
@@ -785,21 +786,39 @@ if ( ! class_exists( 'AWS_Search' ) ) :
785
 
786
  if ( $filtered_terms && ! empty( $filtered_terms ) ) {
787
 
788
- foreach ( $filtered_terms as $search_term ) {
789
 
790
- $search_term_len = strlen( $search_term );
791
- $relevance = 40 + 2 * $search_term_len;
792
- $search_term_norm = AWS_Plurals::singularize( $search_term );
793
 
794
- if ( $search_term_norm && $search_term_len > 3 && strlen( $search_term_norm ) > 2 ) {
795
- $search_term = $search_term_norm;
796
- }
 
 
 
 
 
 
 
 
797
 
798
- $like = '%' . $wpdb->esc_like($search_term) . '%';
799
- $search_array[] = $wpdb->prepare('( name LIKE %s )', $like);
800
 
801
- $relevance_array[] = $wpdb->prepare( "( case when ( name LIKE %s ) then {$relevance} else 0 end )", $like );
 
 
 
 
 
 
 
 
 
 
802
 
 
 
803
  }
804
 
805
  } else {
@@ -814,7 +833,7 @@ if ( ! class_exists( 'AWS_Search' ) ) :
814
  $relevance_query = '0';
815
  }
816
 
817
- $search_query .= sprintf( ' AND ( %s )', implode( ' OR ', $search_array ) );
818
 
819
  /**
820
  * Exclude certain terms from search
@@ -849,6 +868,15 @@ if ( ! class_exists( 'AWS_Search' ) ) :
849
 
850
  $sql = trim( preg_replace( '/\s+/', ' ', $sql ) );
851
 
 
 
 
 
 
 
 
 
 
852
  $search_results = $wpdb->get_results( $sql );
853
 
854
  if ( ! empty( $search_results ) && !is_wp_error( $search_results ) ) {
767
  global $wpdb;
768
 
769
  $result_array = array();
 
 
770
  $excludes = '';
771
  $search_query = '';
772
  $relevance_query = '';
773
+ $s_string_with_chars = $this->data['s_nonormalize'];
774
+ $search_string_unfiltered = '';
775
 
776
  $filtered_terms = $this->data['search_terms'];
777
+
778
+ $filtered_terms_full = $wpdb->prepare( '( name LIKE %s )', '%' . $wpdb->esc_like( $s_string_with_chars ) . '%' );
779
 
780
  /**
781
  * Max number of terms to show
786
 
787
  if ( $filtered_terms && ! empty( $filtered_terms ) ) {
788
 
789
+ $search_array = AWS_Helpers::get_tax_search_array( $filtered_terms );
790
 
791
+ $relevance_array = AWS_Helpers::get_tax_relevance_array( $filtered_terms );
 
 
792
 
793
+ // Search terms with special chars
794
+ $no_normalized_str = $s_string_with_chars;
795
+
796
+ $no_normalized_str = AWS_Helpers::html2txt( $no_normalized_str );
797
+ $no_normalized_str = trim( $no_normalized_str );
798
+
799
+ $no_normalized_str = strtr( $no_normalized_str, AWS_Helpers::get_diacritic_chars() );
800
+
801
+ if ( function_exists( 'mb_strtolower' ) ) {
802
+ $no_normalized_str = mb_strtolower( $no_normalized_str );
803
+ }
804
 
805
+ $search_array_chars = array_unique( explode( ' ', $no_normalized_str ) );
806
+ $search_array_chars = AWS_Helpers::filter_stopwords( $search_array_chars );
807
 
808
+ if ( $search_array_chars ) {
809
+ foreach ( $search_array_chars as $search_array_chars_index => $search_array_chars_term ) {
810
+ if ( array_search( $search_array_chars_term, $filtered_terms ) ) {
811
+ unset( $search_array_chars[$search_array_chars_index] );
812
+ }
813
+ }
814
+ }
815
+
816
+ if ( count( $search_array_chars ) === 1 && $search_array_chars[0] === $s_string_with_chars ) {
817
+ $search_array_chars = array();
818
+ }
819
 
820
+ if ( $search_array_chars ) {
821
+ $search_string_unfiltered = sprintf( 'OR ( %s )', implode( ' OR ', AWS_Helpers::get_tax_search_array( $search_array_chars ) ) );
822
  }
823
 
824
  } else {
833
  $relevance_query = '0';
834
  }
835
 
836
+ $search_query .= sprintf( ' AND ( ( %s ) OR %s %s )', implode( ' OR ', $search_array ), $filtered_terms_full, $search_string_unfiltered );
837
 
838
  /**
839
  * Exclude certain terms from search
868
 
869
  $sql = trim( preg_replace( '/\s+/', ' ', $sql ) );
870
 
871
+ /**
872
+ * Filter terms search query
873
+ * @since 1.91
874
+ * @param string $sql Sql query
875
+ * @param string $taxonomy Taxonomy name
876
+ * @param string $search_query Search query
877
+ */
878
+ $sql = apply_filters( 'aws_terms_search_query', $sql, $taxonomy, $search_query );
879
+
880
  $search_results = $wpdb->get_results( $sql );
881
 
882
  if ( ! empty( $search_results ) && !is_wp_error( $search_results ) ) {
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
4
  Tags: widget, plugin, woocommerce, search, product search, woocommerce search, ajax search, live search, custom search, ajax, shortcode, better search, relevance search, relevant search, search by sku, search plugin, shop, store, wordpress search, wp ajax search, wp search, wp search plugin, sidebar, ecommerce, merketing, products, category search, instant-search, search highlight, woocommerce advanced search, woocommerce live search, WooCommerce Plugin, woocommerce product search
5
  Requires at least: 4.0
6
  Tested up to: 5.3
7
- Stable tag: 1.90
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -104,6 +104,14 @@ Yep. This plugin is always compatible with the latest version of Woocommerce?
104
 
105
  == Changelog ==
106
 
 
 
 
 
 
 
 
 
107
  = 1.90 =
108
  * Update - Search query fix
109
 
4
  Tags: widget, plugin, woocommerce, search, product search, woocommerce search, ajax search, live search, custom search, ajax, shortcode, better search, relevance search, relevant search, search by sku, search plugin, shop, store, wordpress search, wp ajax search, wp search, wp search plugin, sidebar, ecommerce, merketing, products, category search, instant-search, search highlight, woocommerce advanced search, woocommerce live search, WooCommerce Plugin, woocommerce product search
5
  Requires at least: 4.0
6
  Tested up to: 5.3
7
+ Stable tag: 1.91
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
104
 
105
  == Changelog ==
106
 
107
+ = 1.91 =
108
+ * Add - aws_terms_search_query filter
109
+ * Add - aws_search_terms_description filter
110
+ * Add - Support for Elementor pop-up templates
111
+ * Fix - taxonomies search with special characters bug
112
+ * Fix - bug with search results page cache
113
+ * Update - aws_searchbox_markup filter new parameter
114
+
115
  = 1.90 =
116
  * Update - Search query fix
117