Advanced Woo Search - Version 1.74

Version Description

  • Fix - Issue with not working search page when using Elementor page builder
  • Fix - Issue with not working search page when using Divi page builder
  • Update - Order by statement for products
Download this release

Release Info

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

Code changes from version 1.73 to 1.74

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.73
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.73' );
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.74
7
  Author: ILLID
8
  Author URI: https://advanced-woo-search.com/
9
  Text Domain: aws
16
  exit;
17
  }
18
 
19
+ define( 'AWS_VERSION', '1.74' );
20
 
21
 
22
  define( 'AWS_DIR', dirname( __FILE__ ) );
includes/class-aws-search-page.php CHANGED
@@ -23,6 +23,8 @@ if ( ! class_exists( 'AWS_Search_Page' ) ) :
23
 
24
  private $posts_by_query = array();
25
 
 
 
26
  /**
27
  * Return a singleton instance of the current class
28
  *
@@ -58,12 +60,19 @@ if ( ! class_exists( 'AWS_Search_Page' ) ) :
58
  // Add header
59
  add_action( 'pre_get_posts', array( $this, 'action_pre_get_posts' ), 5 );
60
 
 
 
 
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' ) );
66
 
 
 
 
 
67
  }
68
 
69
  /**
@@ -82,25 +91,13 @@ if ( ! class_exists( 'AWS_Search_Page' ) ) :
82
  $new_posts = array();
83
 
84
  $search_query = $query->query_vars['s'];
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();
105
 
106
  $post_array = (array) $post_array;
@@ -159,6 +156,38 @@ if ( ! class_exists( 'AWS_Search_Page' ) ) :
159
 
160
  }
161
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162
  /**
163
  * Filter the posts array to contain ES query results in EP_Post form. Pull previously queried posts.
164
  *
@@ -204,6 +233,36 @@ if ( ! class_exists( 'AWS_Search_Page' ) ) :
204
  }
205
  }
206
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
207
  /**
208
  * Remove the found_rows from the SQL Query
209
  *
@@ -219,6 +278,36 @@ if ( ! class_exists( 'AWS_Search_Page' ) ) :
219
  return '';
220
  }
221
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
222
  /*
223
  * Update links for WooCommerce filter widgets
224
  */
@@ -241,6 +330,19 @@ if ( ! class_exists( 'AWS_Search_Page' ) ) :
241
 
242
  }
243
 
 
 
 
 
 
 
 
 
 
 
 
 
 
244
  /**
245
  * Check if we should override default search query
246
  *
23
 
24
  private $posts_by_query = array();
25
 
26
+ private $data = array();
27
+
28
  /**
29
  * Return a singleton instance of the current class
30
  *
60
  // Add header
61
  add_action( 'pre_get_posts', array( $this, 'action_pre_get_posts' ), 5 );
62
 
63
+ // Overwrite query
64
+ add_action( 'pre_get_posts', array( $this, 'pre_get_posts_overwrite' ), 999 );
65
+
66
  // Nukes the FOUND_ROWS() database query
67
  add_filter( 'found_posts_query', array( $this, 'filter_found_posts_query' ), 5, 2 );
68
 
69
  // Update filters links
70
  add_filter( 'woocommerce_layered_nav_link', array( $this, 'woocommerce_layered_nav_link' ) );
71
 
72
+ add_filter( 'posts_pre_query', array( $this, 'posts_pre_query' ), 10, 2 );
73
+
74
+ add_filter( 'body_class', array( $this, 'body_class' ), 999 );
75
+
76
  }
77
 
78
  /**
91
  $new_posts = array();
92
 
93
  $search_query = $query->query_vars['s'];
94
+ $search_res = $this->search( $search_query, $query );
 
95
  $posts_per_page = apply_filters( 'aws_posts_per_page', $query->get( 'posts_per_page' ) );
 
 
 
 
 
 
96
 
97
+ $query->found_posts = count( $search_res['all'] );
98
+ $query->max_num_pages = ceil( count( $search_res['all'] ) / $posts_per_page );
99
 
100
+ foreach ( $search_res['products'] as $post_array ) {
 
 
 
 
 
101
  $post = new stdClass();
102
 
103
  $post_array = (array) $post_array;
156
 
157
  }
158
 
159
+ /**
160
+ * Filter the posts array.
161
+ *
162
+ * @param array $posts
163
+ * @param object $query
164
+ * @return array|null
165
+ */
166
+ public function posts_pre_query( $posts, $query ) {
167
+
168
+ if ( isset( $_GET['type_aws'] ) && isset( $query->query_vars['s'] ) && $query->query && isset( $query->query['fields'] ) && $query->query['fields'] == 'ids' &&
169
+ isset( $this->data['is_elementor'] ) && $this->data['is_elementor'] )
170
+ {
171
+
172
+ $products_ids = array();
173
+ $posts_per_page = apply_filters( 'aws_posts_per_page', $query->get( 'posts_per_page' ) );
174
+ $search_query = $_GET['s'];
175
+
176
+ $search_res = $this->search( $search_query, $query );
177
+
178
+ $query->found_posts = count( $search_res['all'] );
179
+ $query->max_num_pages = ceil( count( $search_res['all'] ) / $posts_per_page );
180
+
181
+ foreach ( $search_res['products'] as $product ) {
182
+ $products_ids[] = $product['id'];
183
+ }
184
+
185
+ $posts = $products_ids;
186
+
187
+ }
188
+ return $posts;
189
+ }
190
+
191
  /**
192
  * Filter the posts array to contain ES query results in EP_Post form. Pull previously queried posts.
193
  *
233
  }
234
  }
235
 
236
+ /**
237
+ * Make necessary changes in main query.
238
+ *
239
+ * @param $query
240
+ */
241
+ public function pre_get_posts_overwrite( $query ) {
242
+ if ( ! $this->aws_searchpage_enabled( $query ) ) {
243
+ return;
244
+ }
245
+
246
+ // Divi builder fix
247
+ if ( defined( 'ET_CORE' ) && $GLOBALS && isset( $GLOBALS['et_builder_used_in_wc_shop'] ) && $GLOBALS['et_builder_used_in_wc_shop'] ) {
248
+
249
+ $GLOBALS['et_builder_used_in_wc_shop'] = false;
250
+
251
+ $query->set( 'page_id', 0 );
252
+ $query->set( 'post_type', 'product' );
253
+ $query->set( 'posts_per_page', apply_filters( 'aws_posts_per_page', get_option( 'posts_per_page' ) ) );
254
+ $query->set( 'wc_query', 'product_query' );
255
+ $query->set( 'meta_query', array() );
256
+
257
+ $query->is_singular = false;
258
+ $query->is_page = false;
259
+ $query->is_post_type_archive = true;
260
+ $query->is_archive = true;
261
+
262
+ }
263
+
264
+ }
265
+
266
  /**
267
  * Remove the found_rows from the SQL Query
268
  *
278
  return '';
279
  }
280
 
281
+ /**
282
+ * Perform the search.
283
+ *
284
+ * @param string $s
285
+ * @param object $query
286
+ * @return array
287
+ */
288
+ private function search( $s, $query ) {
289
+
290
+ $posts_array = (array) aws_search( $s );
291
+ $posts_per_page = apply_filters( 'aws_posts_per_page', $query->get( 'posts_per_page' ) );
292
+ $post_array_products = $posts_array['products'];
293
+
294
+ // Filter and order output
295
+ if ( $post_array_products && is_array( $post_array_products ) && ! empty( $post_array_products ) ) {
296
+ $post_array_products = AWS()->order( $post_array_products, $query );
297
+ }
298
+
299
+ $paged = $query->query_vars['paged'] ? $query->query_vars['paged'] : 1;
300
+ $offset = ( $paged > 1 ) ? $paged * $posts_per_page - $posts_per_page : 0;
301
+
302
+ $products = array_slice( $post_array_products, $offset, $posts_per_page );
303
+
304
+ return array(
305
+ 'all' => $post_array_products,
306
+ 'products' => $products
307
+ );
308
+
309
+ }
310
+
311
  /*
312
  * Update links for WooCommerce filter widgets
313
  */
330
 
331
  }
332
 
333
+ /*
334
+ * Check some strings inside body classes
335
+ */
336
+ function body_class( $classes ) {
337
+ foreach( $classes as $class ) {
338
+ if ( strpos( $class, 'elementor-page-' ) !== false ) {
339
+ $this->data['is_elementor'] = true;
340
+ break;
341
+ }
342
+ }
343
+ return $classes;
344
+ }
345
+
346
  /**
347
  * Check if we should override default search query
348
  *
includes/class-aws-search.php CHANGED
@@ -430,7 +430,7 @@ if ( ! class_exists( 'AWS_Search' ) ) :
430
  {$query['lang']}
431
  GROUP BY ID
432
  ORDER BY
433
- relevance DESC
434
  LIMIT 0, {$results_num}
435
  ";
436
 
@@ -806,7 +806,7 @@ if ( ! class_exists( 'AWS_Search' ) ) :
806
  AND count > 0
807
  {$excludes}
808
  GROUP BY term_id
809
- ORDER BY relevance DESC
810
  LIMIT 0, {$terms_number}";
811
 
812
  $sql = trim( preg_replace( '/\s+/', ' ', $sql ) );
430
  {$query['lang']}
431
  GROUP BY ID
432
  ORDER BY
433
+ relevance DESC, id DESC
434
  LIMIT 0, {$results_num}
435
  ";
436
 
806
  AND count > 0
807
  {$excludes}
808
  GROUP BY term_id
809
+ ORDER BY relevance DESC, term_id DESC
810
  LIMIT 0, {$terms_number}";
811
 
812
  $sql = trim( preg_replace( '/\s+/', ' ', $sql ) );
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.2
7
- Stable tag: 1.73
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -103,6 +103,11 @@ Yep. This plugin is always compatible with the latest version of Woocommerce?
103
 
104
  == Changelog ==
105
 
 
 
 
 
 
106
  = 1.73 =
107
  * Add - Relevance search for terms
108
  * Dev – Add aws_search_terms_number filter
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.2
7
+ Stable tag: 1.74
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
103
 
104
  == Changelog ==
105
 
106
+ = 1.74 =
107
+ * Fix - Issue with not working search page when using Elementor page builder
108
+ * Fix - Issue with not working search page when using Divi page builder
109
+ * Update - Order by statement for products
110
+
111
  = 1.73 =
112
  * Add - Relevance search for terms
113
  * Dev – Add aws_search_terms_number filter