Advanced Woo Search - Version 1.64

Version Description

  • Fix issue with Polylang plugin support
  • Fix filters for search results page
  • Add aws_title_search_result filter
  • Add aws_excerpt_search_result filter
Download this release

Release Info

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

Code changes from version 1.63 to 1.64

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.63
7
  Author: ILLID
8
  Author URI: https://advanced-woo-search.com/
9
  Text Domain: aws
@@ -16,7 +16,7 @@ if ( ! defined( 'ABSPATH' ) ) {
16
  exit;
17
  }
18
 
19
- define( 'AWS_VERSION', '1.63' );
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.64
7
  Author: ILLID
8
  Author URI: https://advanced-woo-search.com/
9
  Text Domain: aws
16
  exit;
17
  }
18
 
19
+ define( 'AWS_VERSION', '1.64' );
20
 
21
 
22
  define( 'AWS_DIR', dirname( __FILE__ ) );
assets/js/common.js CHANGED
@@ -512,6 +512,25 @@
512
  }, 1000);
513
  } );
514
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
515
  });
516
 
517
 
512
  }, 1000);
513
  } );
514
 
515
+ // Search results filters fix
516
+ var $filters_widget = $('.woocommerce.widget_layered_nav_filters');
517
+ var searchQuery = window.location.search;
518
+
519
+ if ( $filters_widget.length > 0 && searchQuery ) {
520
+ if ( searchQuery.indexOf('type_aws=true') !== -1 ) {
521
+ var $filterLinks = $filters_widget.find('ul li.chosen a');
522
+ if ( $filterLinks.length > 0 ) {
523
+ var addQuery = '&type_aws=true';
524
+ $filterLinks.each( function() {
525
+ var filterLink = $(this).attr("href");
526
+ if ( filterLink && filterLink.indexOf('post_type=product') !== -1 ) {
527
+ $(this).attr( "href", filterLink + addQuery );
528
+ }
529
+ });
530
+ }
531
+ }
532
+ }
533
+
534
  });
535
 
536
 
includes/class-aws-order.php CHANGED
@@ -16,47 +16,197 @@ if ( ! class_exists( 'AWS_Order' ) ) :
16
  */
17
  private $products = array();
18
 
19
- /**
20
- * @var AWS_Order Order by value
21
- */
22
- private $order_by = null;
23
-
24
  /**
25
  * Constructor
26
  */
27
  public function __construct( $products, $query ) {
28
 
29
- if ( isset( $query->query['orderby'] ) ) {
30
 
31
- $order_by = $query->query['orderby'];
 
32
 
33
- } else {
 
 
 
34
 
35
- $order_by = $query->query_vars['orderby'];
36
 
37
- if ( $order_by === 'meta_value_num' ) {
38
- $order_by = 'price';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  }
40
 
41
- if ( isset( $query->query_vars['order'] ) ) {
42
- $order_by = $order_by . '-' . strtolower( $query->query_vars['order'] );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  }
44
 
45
  }
46
 
47
- $this->products = $products;
48
- $this->order_by = $order_by;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
 
50
- $this->order();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
 
52
  }
53
 
54
  /*
55
  * Sort products
56
  */
57
- private function order() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
 
59
- switch( $this->order_by ) {
60
 
61
  case 'price':
62
  case 'price-asc':
16
  */
17
  private $products = array();
18
 
 
 
 
 
 
19
  /**
20
  * Constructor
21
  */
22
  public function __construct( $products, $query ) {
23
 
24
+ $this->products = $products;
25
 
26
+ // Filter
27
+ $this->filter_results( $query );
28
 
29
+ // Order
30
+ if ( $query->query && ( isset( $query->query['orderby'] ) || isset( $query->query_vars['orderby'] ) ) ) {
31
+ $this->order( $query );
32
+ }
33
 
34
+ }
35
 
36
+ /*
37
+ * Filter search results
38
+ */
39
+ private function filter_results( $query ) {
40
+
41
+ $new_products = array();
42
+
43
+ $price_min = false;
44
+ $price_max = false;
45
+ $rating = false;
46
+
47
+ $attr_filter = array();
48
+
49
+ if ( isset( $query->query_vars['meta_query'] ) ) {
50
+ $meta_query = $query->query_vars['meta_query'];
51
+
52
+ if ( isset( $meta_query['price_filter'] ) && isset( $meta_query['price_filter']['value'] ) ) {
53
+ $price_values = $meta_query['price_filter']['value'];
54
+ if ( isset( $price_values[0] ) && isset( $price_values[1] ) ) {
55
+ $price_min = $price_values[0];
56
+ $price_max = $price_values[1];
57
+ }
58
  }
59
 
60
+ }
61
+
62
+ if ( isset( $_GET['rating_filter'] ) && $_GET['rating_filter'] ) {
63
+ $rating = explode( ',', $_GET['rating_filter'] );
64
+ }
65
+
66
+ if ( isset( $query->query_vars['tax_query'] ) ) {
67
+ $tax_query = $query->query_vars['tax_query'];
68
+
69
+ if ( $tax_query && is_array( $tax_query ) && ! empty( $tax_query ) ) {
70
+ foreach( $tax_query as $taxonomy_query ) {
71
+ if ( is_array( $taxonomy_query ) ) {
72
+ if ( isset( $taxonomy_query['taxonomy'] ) && strpos( $taxonomy_query['taxonomy'], 'pa_' ) === 0 ) {
73
+ $tax_name = $taxonomy_query['taxonomy'];
74
+ $attr_filter[$tax_name] = $taxonomy_query;
75
+ }
76
+ }
77
+ }
78
  }
79
 
80
  }
81
 
82
+ foreach( $this->products as $post_array ) {
83
+
84
+ if ( $price_min && $price_max ) {
85
+ if ( isset( $post_array['f_price'] ) && $post_array['f_price'] ) {
86
+ if ( $post_array['f_price'] > $price_max || $post_array['f_price'] < $price_min ) {
87
+ continue;
88
+ }
89
+ }
90
+ }
91
+
92
+ if ( $rating && is_array( $rating ) ) {
93
+ if ( isset( $post_array['f_rating'] ) ) {
94
+ if ( array_search( floor( $post_array['f_rating'] ), $rating ) === false ) {
95
+ continue;
96
+ }
97
+ }
98
+ }
99
+
100
+ if ( $attr_filter && ! empty( $attr_filter ) ) {
101
+
102
+ $product = wc_get_product( $post_array['id'] );
103
+ $attributes = $product->get_attributes();
104
+ $skip = true;
105
+
106
+ if ( $attributes && ! empty( $attributes ) ) {
107
+ foreach( $attributes as $attr_name => $attribute_object ) {
108
+ if ( $attribute_object ) {
109
+ if ( ( is_object( $attribute_object ) && method_exists( $attribute_object, 'is_taxonomy' ) && $attribute_object->is_taxonomy() ) ||
110
+ ( is_array( $attribute_object ) && isset( $attribute_object['is_taxonomy'] ) && $attribute_object['is_taxonomy'] )
111
+ ) {
112
+ if ( isset( $attr_filter[$attr_name] ) ) {
113
+ $product_terms = wp_get_object_terms( $post_array['id'], $attr_name );
114
+
115
+ if ( ! is_wp_error( $product_terms ) && ! empty( $product_terms ) ) {
116
+
117
+ $product_terms_array = array();
118
+
119
+ foreach ( $product_terms as $product_term ) {
120
+ $product_terms_array[$product_term->slug] = $product_term->slug;
121
+ }
122
+
123
+ $operator = $attr_filter[$attr_name]['operator'];
124
+ $terms = $attr_filter[$attr_name]['terms'];
125
 
126
+ if ( $terms && is_array( $terms ) && ! empty( $terms ) ) {
127
+
128
+ if ( $operator === 'AND' ) {
129
+
130
+ $has_all = true;
131
+
132
+ foreach( $terms as $term ) {
133
+ if ( ! isset( $product_terms_array[$term] ) ) {
134
+ $has_all = false;
135
+ break;
136
+ }
137
+ }
138
+
139
+ if ( $has_all ) {
140
+ $skip = false;
141
+ }
142
+
143
+ }
144
+
145
+ if ( $operator === 'IN' || $operator === 'OR' ) {
146
+
147
+ $has_all = false;
148
+
149
+ foreach( $terms as $term ) {
150
+ if ( isset( $product_terms_array[$term] ) ) {
151
+ $has_all = true;
152
+ break;
153
+ }
154
+ }
155
+
156
+ if ( $has_all ) {
157
+ $skip = false;
158
+ }
159
+
160
+ }
161
+
162
+ }
163
+
164
+ }
165
+
166
+ }
167
+ }
168
+ }
169
+ }
170
+ }
171
+
172
+ if ( $skip ) {
173
+ continue;
174
+ }
175
+
176
+ }
177
+
178
+ $new_products[] = $post_array;
179
+
180
+ }
181
+
182
+ $this->products = $new_products;
183
 
184
  }
185
 
186
  /*
187
  * Sort products
188
  */
189
+ private function order( $query ) {
190
+
191
+ if ( isset( $query->query['orderby'] ) ) {
192
+
193
+ $order_by = $query->query['orderby'];
194
+
195
+ } else {
196
+
197
+ $order_by = $query->query_vars['orderby'];
198
+
199
+ if ( $order_by === 'meta_value_num' ) {
200
+ $order_by = 'price';
201
+ }
202
+
203
+ if ( isset( $query->query_vars['order'] ) ) {
204
+ $order_by = $order_by . '-' . strtolower( $query->query_vars['order'] );
205
+ }
206
+
207
+ }
208
 
209
+ switch( $order_by ) {
210
 
211
  case 'price':
212
  case 'price-asc':
includes/class-aws-search-page.php CHANGED
@@ -61,6 +61,9 @@ if ( ! class_exists( 'AWS_Search_Page' ) ) :
61
  // Nukes the FOUND_ROWS() database query
62
  add_filter( 'found_posts_query', array( $this, 'filter_found_posts_query' ), 5, 2 );
63
 
 
 
 
64
  }
65
 
66
  /**
@@ -82,25 +85,20 @@ if ( ! class_exists( 'AWS_Search_Page' ) ) :
82
 
83
  $posts_array = (array) aws_search( $search_query );
84
  $posts_per_page = apply_filters( 'aws_posts_per_page', $query->get( 'posts_per_page' ) );
 
 
 
 
 
 
85
 
86
- $query->found_posts = count( $posts_array['products'] );
87
- $query->max_num_pages = ceil( count( $posts_array['products'] ) / $posts_per_page );
88
 
89
  $paged = $query->query_vars['paged'] ? $query->query_vars['paged'] : 1;
90
  $offset = ( $paged > 1 ) ? $paged * $posts_per_page - $posts_per_page : 0;
91
 
92
- if ( $query->query && ( isset( $query->query['orderby'] ) || isset( $query->query_vars['orderby'] ) ) ) {
93
-
94
- if ( isset( $posts_array['products'] ) && ! empty( $posts_array['products'] ) ) {
95
-
96
- $posts_array['products'] = AWS()->order( $posts_array['products'], $query );
97
-
98
- }
99
-
100
- }
101
-
102
- $products = array_slice( $posts_array['products'], $offset, $posts_per_page );
103
-
104
 
105
  foreach ( $products as $post_array ) {
106
  $post = new stdClass();
@@ -221,6 +219,25 @@ if ( ! class_exists( 'AWS_Search_Page' ) ) :
221
  return '';
222
  }
223
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
224
  /**
225
  * Check if we should override default search query
226
  *
61
  // Nukes the FOUND_ROWS() database query
62
  add_filter( 'found_posts_query', array( $this, 'filter_found_posts_query' ), 5, 2 );
63
 
64
+ // Update filters links
65
+ add_filter( 'woocommerce_layered_nav_link', array( $this, 'woocommerce_layered_nav_link' ), 10, 3 );
66
+
67
  }
68
 
69
  /**
85
 
86
  $posts_array = (array) aws_search( $search_query );
87
  $posts_per_page = apply_filters( 'aws_posts_per_page', $query->get( 'posts_per_page' ) );
88
+ $post_array_products = $posts_array['products'];
89
+
90
+ // Filter and order output
91
+ if ( $post_array_products && is_array( $post_array_products ) && ! empty( $post_array_products ) ) {
92
+ $post_array_products = AWS()->order( $post_array_products, $query );
93
+ }
94
 
95
+ $query->found_posts = count( $post_array_products );
96
+ $query->max_num_pages = ceil( count( $post_array_products ) / $posts_per_page );
97
 
98
  $paged = $query->query_vars['paged'] ? $query->query_vars['paged'] : 1;
99
  $offset = ( $paged > 1 ) ? $paged * $posts_per_page - $posts_per_page : 0;
100
 
101
+ $products = array_slice( $post_array_products, $offset, $posts_per_page );
 
 
 
 
 
 
 
 
 
 
 
102
 
103
  foreach ( $products as $post_array ) {
104
  $post = new stdClass();
219
  return '';
220
  }
221
 
222
+ /*
223
+ * Update links for WooCommerce filter widgets
224
+ */
225
+ public function woocommerce_layered_nav_link( $link, $term, $taxonomy ) {
226
+
227
+ $first_char = '&';
228
+
229
+ if ( strpos( $link, '?' ) === false ) {
230
+ $first_char = '?';
231
+ }
232
+
233
+ if ( isset( $_GET['type_aws'] ) && strpos( $link, 'type_aws' ) === false ) {
234
+ $link = $link . $first_char . 'type_aws=true';
235
+ }
236
+
237
+ return $link;
238
+
239
+ }
240
+
241
  /**
242
  * Check if we should override default search query
243
  *
includes/class-aws-search.php CHANGED
@@ -587,6 +587,9 @@ if ( ! class_exists( 'AWS_Search' ) ) :
587
  // $categories = $product->get_categories( ',' );
588
  // $tags = $product->get_tags( ',' );
589
 
 
 
 
590
  $new_result = array(
591
  'id' => $post_id,
592
  'title' => $title,
587
  // $categories = $product->get_categories( ',' );
588
  // $tags = $product->get_tags( ',' );
589
 
590
+ $title = apply_filters( 'aws_title_search_result', $title, $post_id, $product );
591
+ $excerpt = apply_filters( 'aws_excerpt_search_result', $excerpt, $post_id, $product );
592
+
593
  $new_result = array(
594
  'id' => $post_id,
595
  'title' => $title,
includes/class-aws-table.php CHANGED
@@ -98,6 +98,7 @@ if ( ! class_exists( 'AWS_Table' ) ) :
98
  'no_found_rows' => 1,
99
  'orderby' => 'ID',
100
  'order' => 'DESC',
 
101
  );
102
 
103
 
@@ -228,6 +229,7 @@ if ( ! class_exists( 'AWS_Table' ) ) :
228
  'no_found_rows' => 1,
229
  'orderby' => 'ID',
230
  'order' => 'DESC',
 
231
  );
232
 
233
 
@@ -706,7 +708,8 @@ if ( ! class_exists( 'AWS_Table' ) ) :
706
  'post_status' => 'publish',
707
  'suppress_filters' => false,
708
  'no_found_rows' => 1,
709
- 'include' => $product_id
 
710
  ) );
711
 
712
  $this->fill_table( $posts );
98
  'no_found_rows' => 1,
99
  'orderby' => 'ID',
100
  'order' => 'DESC',
101
+ 'lang' => ''
102
  );
103
 
104
 
229
  'no_found_rows' => 1,
230
  'orderby' => 'ID',
231
  'order' => 'DESC',
232
+ 'lang' => ''
233
  );
234
 
235
 
708
  'post_status' => 'publish',
709
  'suppress_filters' => false,
710
  'no_found_rows' => 1,
711
+ 'include' => $product_id,
712
+ 'lang' => ''
713
  ) );
714
 
715
  $this->fill_table( $posts );
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: Mihail Barinov
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=GSE37FC4Y7CEY
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.0
7
- Stable tag: 1.63
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -101,6 +101,12 @@ Yep. This plugin is always compatible with the latest version of Woocommerce?
101
 
102
  == Changelog ==
103
 
 
 
 
 
 
 
104
  = 1.63 =
105
  * Update porto theme support
106
  * Add aws_search_tax_results filter
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=GSE37FC4Y7CEY
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.1
7
+ Stable tag: 1.64
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
101
 
102
  == Changelog ==
103
 
104
+ = 1.64 =
105
+ * Fix issue with Polylang plugin support
106
+ * Fix filters for search results page
107
+ * Add aws_title_search_result filter
108
+ * Add aws_excerpt_search_result filter
109
+
110
  = 1.63 =
111
  * Update porto theme support
112
  * Add aws_search_tax_results filter