Advanced Woo Search - Version 2.42

Version Description

( 2021-12-07 ) = * Add - Support for Basel theme * Add - Support for Rey theme * Update - FacetWP plugin integration * Update - Number of search results per page option * Fix - Bug with search page query detection

Download this release

Release Info

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

Code changes from version 2.41 to 2.42

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: 2.41
7
  Author: ILLID
8
  Author URI: https://advanced-woo-search.com/
9
  Text Domain: advanced-woo-search
@@ -96,7 +96,7 @@ final class AWS_Main {
96
  */
97
  private function define_constants() {
98
 
99
- $this->define( 'AWS_VERSION', '2.41' );
100
 
101
  $this->define( 'AWS_DIR', plugin_dir_path( AWS_FILE ) );
102
  $this->define( 'AWS_URL', plugin_dir_url( AWS_FILE ) );
3
  /*
4
  Plugin Name: Advanced Woo Search
5
  Description: Advance ajax WooCommerce product search.
6
+ Version: 2.42
7
  Author: ILLID
8
  Author URI: https://advanced-woo-search.com/
9
  Text Domain: advanced-woo-search
96
  */
97
  private function define_constants() {
98
 
99
+ $this->define( 'AWS_VERSION', '2.42' );
100
 
101
  $this->define( 'AWS_DIR', plugin_dir_path( AWS_FILE ) );
102
  $this->define( 'AWS_URL', plugin_dir_url( AWS_FILE ) );
includes/class-aws-integrations.php CHANGED
@@ -151,6 +151,11 @@ if ( ! class_exists( 'AWS_Integrations' ) ) :
151
  add_action( 'wp_head', array( $this, 'aurum_wp_head' ) );
152
  }
153
 
 
 
 
 
 
154
  if ( 'Woostify' === $this->current_theme ) {
155
  add_filter( 'aws_searchbox_markup', array( $this, 'woostify_aws_searchbox_markup' ), 1 );
156
  }
@@ -187,6 +192,11 @@ if ( ! class_exists( 'AWS_Integrations' ) ) :
187
  add_action( 'wp_head', array( $this, 'botiga_wp_head' ) );
188
  }
189
 
 
 
 
 
 
190
  }
191
 
192
  add_action( 'wp_head', array( $this, 'head_js_integration' ) );
@@ -239,13 +249,6 @@ if ( ! class_exists( 'AWS_Integrations' ) ) :
239
  add_filter( 'woodmart_shop_page_link', array( $this, 'woodmart_shop_page_link' ), 9999 );
240
  }
241
 
242
- // FacetWP plugin
243
- if ( class_exists( 'FacetWP' ) ) {
244
- add_filter( 'facetwp_filtered_post_ids', array( $this, 'facetwp_filtered_post_ids' ), 1 );
245
- add_filter( 'aws_searchpage_enabled', array( $this, 'facetwp_aws_searchpage_enabled' ), 1 );
246
- add_filter( 'aws_search_page_custom_data', array( $this, 'facetwp_aws_search_page_custom_data' ), 1 );
247
- }
248
-
249
  // Product Visibility by User Role for WooCommerce plugin
250
  if ( class_exists( 'Alg_WC_PVBUR' ) ) {
251
  add_filter( 'aws_search_results_products', array( $this, 'pvbur_aws_search_results_products' ), 1 );
@@ -359,6 +362,11 @@ if ( ! class_exists( 'AWS_Integrations' ) ) :
359
  include_once( AWS_DIR . '/includes/modules/class-aws-woobewoo-filters.php' );
360
  }
361
 
 
 
 
 
 
362
  if ( class_exists( 'WC_PPC_Util' ) || class_exists( '\Barn2\Plugin\WC_Protected_Categories\Util' ) ) {
363
  include_once( AWS_DIR . '/includes/modules/class-aws-barn2-protected-categories.php' );
364
  }
@@ -1113,6 +1121,40 @@ if ( ! class_exists( 'AWS_Integrations' ) ) :
1113
 
1114
  }
1115
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1116
  /*
1117
  * Woostify theme markup for seamless integration
1118
  */
@@ -1372,6 +1414,64 @@ if ( ! class_exists( 'AWS_Integrations' ) ) :
1372
  </style>
1373
  <?php }
1374
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1375
  /*
1376
  * Exclude product categories
1377
  */
@@ -1572,6 +1672,10 @@ if ( ! class_exists( 'AWS_Integrations' ) ) :
1572
  $selectors[] = '.search-form-inner form';
1573
  }
1574
 
 
 
 
 
1575
  // WCFM - WooCommerce Multivendor Marketplace
1576
  if ( class_exists( 'WCFMmp' ) ) {
1577
  $selectors[] = '#wcfmmp-store .woocommerce-product-search';
@@ -1865,36 +1969,6 @@ if ( ! class_exists( 'AWS_Integrations' ) ) :
1865
  return $link;
1866
  }
1867
 
1868
- /*
1869
- * FacetWP check for active filters
1870
- */
1871
- public function facetwp_filtered_post_ids( $post_ids ) {
1872
- if ( isset( $_GET['type_aws'] ) && isset( $_GET['s'] ) && ! empty( $post_ids ) ) {
1873
- $this->data['facetwp'] = true;
1874
- }
1875
- return $post_ids;
1876
- }
1877
-
1878
- /*
1879
- * Disable AWS search if FacetWP is active
1880
- */
1881
- public function facetwp_aws_searchpage_enabled( $enabled ) {
1882
- if ( isset( $this->data['facetwp'] ) && $this->data['facetwp'] ) {
1883
- $enabled = false;
1884
- }
1885
- return $enabled;
1886
- }
1887
-
1888
- /*
1889
- * FacetWP - Update search page query
1890
- */
1891
- public function facetwp_aws_search_page_custom_data( $data ) {
1892
- if ( isset( $this->data['facetwp'] ) && $this->data['facetwp'] ) {
1893
- $data['force_ids'] = true;
1894
- }
1895
- return $data;
1896
- }
1897
-
1898
  /*
1899
  * Product Visibility by User Role for WooCommerce plugin hide products for certain users
1900
  */
151
  add_action( 'wp_head', array( $this, 'aurum_wp_head' ) );
152
  }
153
 
154
+ if ( 'Basel' === $this->current_theme ) {
155
+ add_filter( 'aws_js_seamless_searchbox_markup', array( $this, 'basel_seamless_searchbox_markup' ), 1 );
156
+ add_action( 'wp_head', array( $this, 'basel_wp_head' ) );
157
+ }
158
+
159
  if ( 'Woostify' === $this->current_theme ) {
160
  add_filter( 'aws_searchbox_markup', array( $this, 'woostify_aws_searchbox_markup' ), 1 );
161
  }
192
  add_action( 'wp_head', array( $this, 'botiga_wp_head' ) );
193
  }
194
 
195
+ if ( 'Rey' === $this->current_theme ) {
196
+ add_action( 'reycore/search_panel/after_search_form', array( $this, 'rey_search_panel' ) );
197
+ add_action( 'wp_head', array( $this, 'rey_wp_head' ) );
198
+ }
199
+
200
  }
201
 
202
  add_action( 'wp_head', array( $this, 'head_js_integration' ) );
249
  add_filter( 'woodmart_shop_page_link', array( $this, 'woodmart_shop_page_link' ), 9999 );
250
  }
251
 
 
 
 
 
 
 
 
252
  // Product Visibility by User Role for WooCommerce plugin
253
  if ( class_exists( 'Alg_WC_PVBUR' ) ) {
254
  add_filter( 'aws_search_results_products', array( $this, 'pvbur_aws_search_results_products' ), 1 );
362
  include_once( AWS_DIR . '/includes/modules/class-aws-woobewoo-filters.php' );
363
  }
364
 
365
+ // FacetWP plugin
366
+ if ( class_exists( 'FacetWP' ) ) {
367
+ include_once( AWS_DIR . '/includes/modules/class-aws-facetwp.php' );
368
+ }
369
+
370
  if ( class_exists( 'WC_PPC_Util' ) || class_exists( '\Barn2\Plugin\WC_Protected_Categories\Util' ) ) {
371
  include_once( AWS_DIR . '/includes/modules/class-aws-barn2-protected-categories.php' );
372
  }
1121
 
1122
  }
1123
 
1124
+ /*
1125
+ * Basel theme markup for seamless js integration
1126
+ */
1127
+ public function basel_seamless_searchbox_markup( $markup ) {
1128
+ $markup = str_replace( '</form>', '<div class="searchform basel-ajax-search" style="opacity:0;visibility:hidden;"></div></form>', $markup );
1129
+ return $markup;
1130
+ }
1131
+
1132
+ /*
1133
+ * Basel theme styles
1134
+ */
1135
+ public function basel_wp_head() { ?>
1136
+
1137
+ <style>
1138
+ .basel-search-full-screen .basel-search-wrapper .aws-container {
1139
+ margin: 20px 0 0;
1140
+ }
1141
+ .basel-search-full-screen .basel-search-inner .basel-close-search {
1142
+ height: 60px;
1143
+ top: 90px;
1144
+ z-index: 9999;
1145
+ }
1146
+ .secondary-header #searchform {
1147
+ display: none;
1148
+ }
1149
+ .secondary-header .aws-container,
1150
+ .secondary-header .aws-container .aws-search-form,
1151
+ .secondary-header .aws-container {
1152
+ background: transparent;
1153
+ }
1154
+ </style>
1155
+
1156
+ <?php }
1157
+
1158
  /*
1159
  * Woostify theme markup for seamless integration
1160
  */
1414
  </style>
1415
  <?php }
1416
 
1417
+ /*
1418
+ * Rey theme add search form
1419
+ */
1420
+ public function rey_search_panel() {
1421
+ $output = aws_get_search_form( false );
1422
+ echo $output;
1423
+ }
1424
+
1425
+ /*
1426
+ * Rey theme search form styles
1427
+ */
1428
+ public function rey_wp_head() { ?>
1429
+ <style>
1430
+ .rey-searchPanel-inner > form,
1431
+ .rey-searchPanel-inner .rey-searchResults,
1432
+ .rey-searchPanel-inner .rey-lineLoader,
1433
+ .rey-inlineSearch-wrapper > form,
1434
+ .rey-searchPanel-inner .aws-container .aws-search-form .aws-form-btn {
1435
+ display: none !important;
1436
+ }
1437
+ .rey-searchPanel-inner .aws-container .aws-search-field {
1438
+ width: 100%;
1439
+ }
1440
+ .rey-searchPanel-inner .aws-container .aws-search-field:focus {
1441
+ background: transparent;
1442
+ }
1443
+ </style>
1444
+
1445
+
1446
+ <script>
1447
+
1448
+ window.addEventListener('load', function() {
1449
+
1450
+ function aws_results_layout( styles, options ) {
1451
+ var form = options.form;
1452
+ if ( options.form.closest('.rey-searchPanel-inner').length > 0 ) {
1453
+ var containerWidth = form.find('.aws-search-form').outerWidth();
1454
+ var offset = form.find('.aws-search-form').offset();
1455
+ var bodyPosition = jQuery('body').css('position');
1456
+ var bodyOffset = jQuery('body').offset();
1457
+ if ( bodyPosition === 'relative' || bodyPosition === 'absolute' || bodyPosition === 'fixed' ) {
1458
+ styles.left = offset.left - bodyOffset.left;
1459
+ } else {
1460
+ styles.left = offset.left;
1461
+ }
1462
+ if ( containerWidth ) {
1463
+ styles.width = containerWidth;
1464
+ }
1465
+ }
1466
+ return styles;
1467
+ }
1468
+ AwsHooks.add_filter( "aws_results_layout", aws_results_layout );
1469
+ }, false);
1470
+
1471
+ </script>
1472
+
1473
+ <?php }
1474
+
1475
  /*
1476
  * Exclude product categories
1477
  */
1672
  $selectors[] = '.search-form-inner form';
1673
  }
1674
 
1675
+ if ( 'Basel' === $this->current_theme ) {
1676
+ $selectors[] = '.basel-search-wrapper #searchform, .secondary-header #searchform';
1677
+ }
1678
+
1679
  // WCFM - WooCommerce Multivendor Marketplace
1680
  if ( class_exists( 'WCFMmp' ) ) {
1681
  $selectors[] = '#wcfmmp-store .woocommerce-product-search';
1969
  return $link;
1970
  }
1971
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1972
  /*
1973
  * Product Visibility by User Role for WooCommerce plugin hide products for certain users
1974
  */
includes/class-aws-search-page.php CHANGED
@@ -85,14 +85,12 @@ if ( ! class_exists( 'AWS_Search_Page' ) ) :
85
  add_action( 'et_pb_shop_before_print_shop', array( $this, 'et_pb_shop_before_print_shop' ) );
86
  add_action( 'et_pb_shop_after_print_shop', array( $this, 'et_pb_shop_after_print_shop' ) );
87
 
88
- // FacetWP support
89
- add_filter( 'facetwp_pre_filtered_post_ids', array( $this, 'facetwp_pre_filtered_post_ids' ), 10, 2 );
90
-
91
  // Total number of search results
92
  add_filter( 'aws_page_results', array( $this, 'aws_page_results' ), 1 );
93
 
94
  // Number of search results per page
95
  add_filter( 'aws_posts_per_page', array( $this, 'aws_posts_per_page' ), 1 );
 
96
 
97
  // Change default search page query
98
  add_filter( 'aws_search_page_custom_data', array( $this, 'aws_search_page_custom_data' ), 1 );
@@ -153,9 +151,9 @@ if ( ! class_exists( 'AWS_Search_Page' ) ) :
153
  */
154
  $this->data = apply_filters( 'aws_search_page_custom_data', $this->data, $query, $posts );
155
 
156
- $post_type_product = ( $query->get( 'post_type' ) && is_string( $query->get( 'post_type' ) ) && $query->get( 'post_type' ) === 'product' ) ? true : false;
157
 
158
- if ( $post_type_product && isset( $_GET['type_aws'] ) && isset( $query->query_vars['s'] ) && $query->query &&
159
  ( ( isset( $this->data['force_ids'] ) && $this->data['force_ids'] ) || ( isset( $this->data['is_elementor'] ) && $this->data['is_elementor'] ) || ( isset( $this->data['is_divi_s_page'] ) && $this->data['is_divi_s_page'] ) )
160
  )
161
  {
@@ -284,9 +282,9 @@ if ( ! class_exists( 'AWS_Search_Page' ) ) :
284
  */
285
  public function filter_found_posts( $found_posts, $query ) {
286
 
287
- $post_type_product = ( $query->get( 'post_type' ) && is_string( $query->get( 'post_type' ) ) && $query->get( 'post_type' ) === 'product' ) ? true : false;
288
 
289
- if ( $post_type_product && isset( $_GET['type_aws'] ) && isset( $this->data['all_products'] ) && $this->data['all_products'] && isset( $query->query_vars['nopaging'] ) && ! $query->query_vars['nopaging'] &&
290
  ( ( isset( $this->data['force_ids'] ) && $this->data['force_ids'] ) || ( isset( $this->data['is_elementor'] ) && $this->data['is_elementor'] ) || ( isset( $this->data['is_divi_s_page'] ) && $this->data['is_divi_s_page'] ) )
291
  ) {
292
  $found_posts = count( $this->data['all_products'] );
@@ -296,23 +294,6 @@ if ( ! class_exists( 'AWS_Search_Page' ) ) :
296
 
297
  }
298
 
299
- /*
300
- * FacetWP add unfiltered products IDs
301
- */
302
- public function facetwp_pre_filtered_post_ids( $post_ids, $obj ) {
303
- if ( isset( $_GET['type_aws'] ) && isset( $_GET['s'] ) ) {
304
- $search_res = $this->search( $obj->query, $obj->query_args['posts_per_page'], $obj->query_args['paged'] );
305
- if ( $search_res ) {
306
- $products_ids = array();
307
- foreach ( $search_res['all'] as $product ) {
308
- $products_ids[] = $product['id'];
309
- }
310
- $post_ids = $products_ids;
311
- }
312
- }
313
- return $post_ids;
314
- }
315
-
316
  /**
317
  * Perform the search.
318
  *
@@ -321,7 +302,7 @@ if ( ! class_exists( 'AWS_Search_Page' ) ) :
321
  * @param int $paged
322
  * @return array | bool
323
  */
324
- private function search( $query, $posts_per_page, $paged = 1 ) {
325
 
326
  if ( ! did_action( 'woocommerce_init' ) || ! did_action( 'woocommerce_after_register_taxonomy' ) || ! did_action( 'woocommerce_after_register_post_type' ) ) {
327
  return false;
@@ -487,7 +468,7 @@ if ( ! class_exists( 'AWS_Search_Page' ) ) :
487
  private function aws_searchpage_enabled( $query ) {
488
  $enabled = true;
489
 
490
- $post_type_product = ( $query->get( 'post_type' ) && is_string( $query->get( 'post_type' ) ) && $query->get( 'post_type' ) === 'product' ) ? true :
491
  ( ( isset( $_GET['post_type'] ) && $_GET['post_type'] === 'product' ) ? true : false );
492
 
493
  if ( ( isset( $query->query_vars['s'] ) && ! isset( $_GET['type_aws'] ) ) ||
@@ -613,6 +594,15 @@ if ( ! class_exists( 'AWS_Search_Page' ) ) :
613
  return $num;
614
  }
615
 
 
 
 
 
 
 
 
 
 
616
  /*
617
  * Change default search page query
618
  */
85
  add_action( 'et_pb_shop_before_print_shop', array( $this, 'et_pb_shop_before_print_shop' ) );
86
  add_action( 'et_pb_shop_after_print_shop', array( $this, 'et_pb_shop_after_print_shop' ) );
87
 
 
 
 
88
  // Total number of search results
89
  add_filter( 'aws_page_results', array( $this, 'aws_page_results' ), 1 );
90
 
91
  // Number of search results per page
92
  add_filter( 'aws_posts_per_page', array( $this, 'aws_posts_per_page' ), 1 );
93
+ add_filter( 'woocommerce_product_query', array( $this, 'woocommerce_product_query' ), 1 );
94
 
95
  // Change default search page query
96
  add_filter( 'aws_search_page_custom_data', array( $this, 'aws_search_page_custom_data' ), 1 );
151
  */
152
  $this->data = apply_filters( 'aws_search_page_custom_data', $this->data, $query, $posts );
153
 
154
+ $post_type_product = $query->get( 'post_type' ) && ( ( is_string( $query->get( 'post_type' ) ) && ( $query->get( 'post_type' ) === 'product' ) ) || ( is_array( $query->get( 'post_type' ) ) && in_array( 'product', $query->get( 'post_type' ) ) ) );
155
 
156
+ if ( ( $query->is_main_query() || $query->is_search() || isset( $query->query_vars['s'] ) ) && $post_type_product && isset( $_GET['type_aws'] ) && $query->query &&
157
  ( ( isset( $this->data['force_ids'] ) && $this->data['force_ids'] ) || ( isset( $this->data['is_elementor'] ) && $this->data['is_elementor'] ) || ( isset( $this->data['is_divi_s_page'] ) && $this->data['is_divi_s_page'] ) )
158
  )
159
  {
282
  */
283
  public function filter_found_posts( $found_posts, $query ) {
284
 
285
+ $post_type_product = $query->get( 'post_type' ) && ( ( is_string( $query->get( 'post_type' ) ) && ( $query->get( 'post_type' ) === 'product' ) ) || ( is_array( $query->get( 'post_type' ) ) && in_array( 'product', $query->get( 'post_type' ) ) ) );
286
 
287
+ if ( ( $query->is_main_query() || $query->is_search() || isset( $query->query_vars['s'] ) ) && $post_type_product && isset( $_GET['type_aws'] ) && isset( $this->data['all_products'] ) && $this->data['all_products'] && isset( $query->query_vars['nopaging'] ) && ! $query->query_vars['nopaging'] &&
288
  ( ( isset( $this->data['force_ids'] ) && $this->data['force_ids'] ) || ( isset( $this->data['is_elementor'] ) && $this->data['is_elementor'] ) || ( isset( $this->data['is_divi_s_page'] ) && $this->data['is_divi_s_page'] ) )
289
  ) {
290
  $found_posts = count( $this->data['all_products'] );
294
 
295
  }
296
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
297
  /**
298
  * Perform the search.
299
  *
302
  * @param int $paged
303
  * @return array | bool
304
  */
305
+ public function search( $query, $posts_per_page, $paged = 1 ) {
306
 
307
  if ( ! did_action( 'woocommerce_init' ) || ! did_action( 'woocommerce_after_register_taxonomy' ) || ! did_action( 'woocommerce_after_register_post_type' ) ) {
308
  return false;
468
  private function aws_searchpage_enabled( $query ) {
469
  $enabled = true;
470
 
471
+ $post_type_product = ( $query->get( 'post_type' ) && ( ( is_string( $query->get( 'post_type' ) ) && ( $query->get( 'post_type' ) === 'product' ) ) || ( is_array( $query->get( 'post_type' ) ) && in_array( 'product', $query->get( 'post_type' ) ) ) ) ) ? true :
472
  ( ( isset( $_GET['post_type'] ) && $_GET['post_type'] === 'product' ) ? true : false );
473
 
474
  if ( ( isset( $query->query_vars['s'] ) && ! isset( $_GET['type_aws'] ) ) ||
594
  return $num;
595
  }
596
 
597
+ /*
598
+ * Number of search results per page
599
+ */
600
+ public function woocommerce_product_query( $query ) {
601
+ if ( $this->aws_searchpage_enabled( $query ) && $query->get( 'posts_per_page' ) ) {
602
+ $query->set( 'posts_per_page', $this->aws_posts_per_page( $query->get( 'posts_per_page' ) ) );
603
+ }
604
+ }
605
+
606
  /*
607
  * Change default search page query
608
  */
includes/modules/class-aws-facetwp.php ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * FacetWP integration
5
+ */
6
+
7
+ if (!defined('ABSPATH')) {
8
+ exit; // Exit if accessed directly.
9
+ }
10
+
11
+ if (!class_exists('AWS_FacetWP')) :
12
+
13
+ /**
14
+ * Class for main plugin functions
15
+ */
16
+ class AWS_FacetWP {
17
+
18
+ /**
19
+ * @var AWS_FacetWP The single instance of the class
20
+ */
21
+ protected static $_instance = null;
22
+
23
+ private $data = array();
24
+
25
+ /**
26
+ * Main AWS_FacetWP Instance
27
+ *
28
+ * Ensures only one instance of AWS_FacetWP is loaded or can be loaded.
29
+ *
30
+ * @static
31
+ * @return AWS_FacetWP - Main instance
32
+ */
33
+ public static function instance()
34
+ {
35
+ if (is_null(self::$_instance)) {
36
+ self::$_instance = new self();
37
+ }
38
+ return self::$_instance;
39
+ }
40
+
41
+ /**
42
+ * Constructor
43
+ */
44
+ public function __construct() {
45
+
46
+ add_filter( 'facetwp_pre_filtered_post_ids', array( $this, 'facetwp_pre_filtered_post_ids' ), 10, 2 );
47
+ add_filter( 'facetwp_filtered_post_ids', array( $this, 'facetwp_filtered_post_ids' ), 1 );
48
+ add_filter( 'aws_searchpage_enabled', array( $this, 'aws_searchpage_enabled' ), 1 );
49
+ add_filter( 'aws_search_page_custom_data', array( $this, 'aws_search_page_custom_data' ), 1 );
50
+ add_filter( 'posts_pre_query', array( $this, 'posts_pre_query' ), 9999, 2 );
51
+
52
+ }
53
+
54
+ /*
55
+ * FacetWP add unfiltered products IDs
56
+ */
57
+ public function facetwp_pre_filtered_post_ids( $post_ids, $obj ) {
58
+ if ( class_exists( 'AWS_Search_Page' ) && isset( $_GET['type_aws'] ) && isset( $_GET['s'] ) ) {
59
+ $search_res = AWS_Search_Page::factory()->search( $obj->query, $obj->query_args['posts_per_page'], $obj->query_args['paged'] );
60
+ if ( $search_res ) {
61
+ $products_ids = array();
62
+ foreach ( $search_res['all'] as $product ) {
63
+ $products_ids[] = $product['id'];
64
+ }
65
+ $post_ids = $products_ids;
66
+ }
67
+ }
68
+ return $post_ids;
69
+ }
70
+
71
+ /*
72
+ * FacetWP check for active filters
73
+ */
74
+ public function facetwp_filtered_post_ids( $post_ids ) {
75
+ if ( isset( $_GET['type_aws'] ) && isset( $_GET['s'] ) && ! empty( $post_ids ) ) {
76
+ $this->data['facetwp'] = true;
77
+ $this->data['filtered_post_ids'] = $post_ids;
78
+ }
79
+ return $post_ids;
80
+ }
81
+
82
+ /*
83
+ * Disable AWS search if FacetWP is active
84
+ */
85
+ public function aws_searchpage_enabled( $enabled ) {
86
+ if ( isset( $this->data['facetwp'] ) && $this->data['facetwp'] ) {
87
+ $enabled = false;
88
+ }
89
+ return $enabled;
90
+ }
91
+
92
+ /*
93
+ * FacetWP - Update search page query
94
+ */
95
+ public function aws_search_page_custom_data( $data ) {
96
+ if ( isset( $this->data['facetwp'] ) && $this->data['facetwp'] ) {
97
+ $data['force_ids'] = true;
98
+ }
99
+ return $data;
100
+ }
101
+
102
+ /*
103
+ * Update posts query
104
+ */
105
+ public function posts_pre_query( $posts, $query ) {
106
+ if ( ( $query->is_main_query() || $query->is_search() || isset( $query->query_vars['s'] ) ) && isset( $this->data['filtered_post_ids'] ) && ! empty( $this->data['filtered_post_ids'] ) ) {
107
+ $posts = $this->data['filtered_post_ids'];
108
+ }
109
+ return $posts;
110
+ }
111
+
112
+ }
113
+
114
+ endif;
115
+
116
+ AWS_FacetWP::instance();
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.8
7
- Stable tag: 2.41
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -167,6 +167,13 @@ Yep. This plugin is always compatible with the latest version of Woocommerce?
167
 
168
  == Changelog ==
169
 
 
 
 
 
 
 
 
170
  = 2.41 ( 2021-11-22 ) =
171
  * Add - Support for WooCommerce Protected Categories plugin
172
  * Fix - JS seamless integration issue
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.8
7
+ Stable tag: 2.42
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
167
 
168
  == Changelog ==
169
 
170
+ = 2.42 ( 2021-12-07 ) =
171
+ * Add - Support for Basel theme
172
+ * Add - Support for Rey theme
173
+ * Update - FacetWP plugin integration
174
+ * Update - Number of search results per page option
175
+ * Fix - Bug with search page query detection
176
+
177
  = 2.41 ( 2021-11-22 ) =
178
  * Add - Support for WooCommerce Protected Categories plugin
179
  * Fix - JS seamless integration issue