Advanced Woo Search - Version 2.22

Version Description

( 2021-02-19 ) = * Add - Support for WOOF - WooCommerce Products Filter plugin * Fix - Search form widget layout * Dev - Add aws_search_page_query filter

Download this release

Release Info

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

Code changes from version 2.21 to 2.22

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.21
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.21' );
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.22
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.22' );
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
@@ -276,6 +276,11 @@ if ( ! class_exists( 'AWS_Integrations' ) ) :
276
  AWS_WCFM::instance();
277
  }
278
 
 
 
 
 
 
279
  }
280
 
281
  /*
276
  AWS_WCFM::instance();
277
  }
278
 
279
+ // WOOF - WooCommerce Products Filter
280
+ if ( defined( 'WOOF_PLUGIN_NAME' ) ) {
281
+ include_once( AWS_DIR . '/includes/modules/class-aws-woof-filter.php' );
282
+ }
283
+
284
  }
285
 
286
  /*
includes/class-aws-search-page.php CHANGED
@@ -104,10 +104,9 @@ if ( ! class_exists( 'AWS_Search_Page' ) ) :
104
  }
105
 
106
  $new_posts = array();
107
- $search_query = $query->query_vars['s'] ? $query->query_vars['s'] : $_GET['s'];
108
  $posts_per_page = apply_filters( 'aws_posts_per_page', $query->get( 'posts_per_page' ) );
109
  $paged = $query->query_vars['paged'] ? $query->query_vars['paged'] : 1;
110
- $search_res = $this->search( $search_query, $query, $posts_per_page, $paged );
111
 
112
  $query->found_posts = count( $search_res['all'] );
113
  $query->max_num_pages = ceil( count( $search_res['all'] ) / $posts_per_page );
@@ -206,9 +205,8 @@ if ( ! class_exists( 'AWS_Search_Page' ) ) :
206
  $products_ids = array();
207
  $posts_per_page = apply_filters( 'aws_posts_per_page', $query->get( 'posts_per_page' ) );
208
  $paged = $query->query_vars['paged'] ? $query->query_vars['paged'] : 1;
209
- $search_query = $_GET['s'];
210
 
211
- $search_res = $this->search( $search_query, $query, $posts_per_page, $paged );
212
 
213
  $query->found_posts = count( $search_res['all'] );
214
  $query->max_num_pages = ceil( count( $search_res['all'] ) / $posts_per_page );
@@ -341,8 +339,7 @@ if ( ! class_exists( 'AWS_Search_Page' ) ) :
341
  */
342
  public function facetwp_pre_filtered_post_ids( $post_ids, $obj ) {
343
  if ( isset( $_GET['type_aws'] ) && isset( $_GET['s'] ) ) {
344
- $search_query = $_GET['s'];
345
- $search_res = $this->search( $search_query, $obj->query, $obj->query_args['posts_per_page'], $obj->query_args['paged'] );
346
  $products_ids = array();
347
  foreach ( $search_res['all'] as $product ) {
348
  $products_ids[] = $product['id'];
@@ -355,13 +352,14 @@ if ( ! class_exists( 'AWS_Search_Page' ) ) :
355
  /**
356
  * Perform the search.
357
  *
358
- * @param string $s
359
  * @param object $query
360
  * @param int $posts_per_page
361
  * @param int $paged
362
  * @return array
363
  */
364
- private function search( $s, $query, $posts_per_page, $paged = 1 ) {
 
 
365
 
366
  $hash = hash( 'md2', $s );
367
 
@@ -535,6 +533,27 @@ if ( ! class_exists( 'AWS_Search_Page' ) ) :
535
  return apply_filters( 'aws_searchpage_enabled', $enabled, $query );
536
  }
537
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
538
  }
539
 
540
 
104
  }
105
 
106
  $new_posts = array();
 
107
  $posts_per_page = apply_filters( 'aws_posts_per_page', $query->get( 'posts_per_page' ) );
108
  $paged = $query->query_vars['paged'] ? $query->query_vars['paged'] : 1;
109
+ $search_res = $this->search( $query, $posts_per_page, $paged );
110
 
111
  $query->found_posts = count( $search_res['all'] );
112
  $query->max_num_pages = ceil( count( $search_res['all'] ) / $posts_per_page );
205
  $products_ids = array();
206
  $posts_per_page = apply_filters( 'aws_posts_per_page', $query->get( 'posts_per_page' ) );
207
  $paged = $query->query_vars['paged'] ? $query->query_vars['paged'] : 1;
 
208
 
209
+ $search_res = $this->search( $query, $posts_per_page, $paged );
210
 
211
  $query->found_posts = count( $search_res['all'] );
212
  $query->max_num_pages = ceil( count( $search_res['all'] ) / $posts_per_page );
339
  */
340
  public function facetwp_pre_filtered_post_ids( $post_ids, $obj ) {
341
  if ( isset( $_GET['type_aws'] ) && isset( $_GET['s'] ) ) {
342
+ $search_res = $this->search( $obj->query, $obj->query_args['posts_per_page'], $obj->query_args['paged'] );
 
343
  $products_ids = array();
344
  foreach ( $search_res['all'] as $product ) {
345
  $products_ids[] = $product['id'];
352
  /**
353
  * Perform the search.
354
  *
 
355
  * @param object $query
356
  * @param int $posts_per_page
357
  * @param int $paged
358
  * @return array
359
  */
360
+ private function search( $query, $posts_per_page, $paged = 1 ) {
361
+
362
+ $s = $this->get_search_query( $query );
363
 
364
  $hash = hash( 'md2', $s );
365
 
533
  return apply_filters( 'aws_searchpage_enabled', $enabled, $query );
534
  }
535
 
536
+ /**
537
+ * Get current page search query
538
+ *
539
+ * @param object|bool $query
540
+ * @return string
541
+ */
542
+ private function get_search_query( $query = false ) {
543
+
544
+ $search_query = isset( $_GET['s'] ) ? $_GET['s'] : ( ( is_object( $query ) && $query->query_vars['s'] ) ? $query->query_vars['s'] : '' );
545
+
546
+ /**
547
+ * Filter search query string for search results page
548
+ * @since 2.22
549
+ * @param string $search_query Search query string
550
+ * @param object|bool $query Search query object
551
+ */
552
+
553
+ return apply_filters( 'aws_search_page_query', $search_query, $query );
554
+
555
+ }
556
+
557
  }
558
 
559
 
includes/modules/class-aws-woof-filter.php ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * AWS plugin WOOF - WooCommerce Products Filter integration
5
+ */
6
+
7
+ if (!defined('ABSPATH')) {
8
+ exit; // Exit if accessed directly.
9
+ }
10
+
11
+ if (!class_exists('AWS_Woof_Filter_Init')) :
12
+
13
+ /**
14
+ * Class for main plugin functions
15
+ */
16
+ class AWS_Woof_Filter_Init {
17
+
18
+ /**
19
+ * @var AWS_Woof_Filter_Init The single instance of the class
20
+ */
21
+ protected static $_instance = null;
22
+
23
+ /**
24
+ * Main AWS_Woof_Filter_Init Instance
25
+ *
26
+ * Ensures only one instance of AWS_Woof_Filter_Init is loaded or can be loaded.
27
+ *
28
+ * @static
29
+ * @return AWS_Woof_Filter_Init - Main instance
30
+ */
31
+ public static function instance()
32
+ {
33
+ if (is_null(self::$_instance)) {
34
+ self::$_instance = new self();
35
+ }
36
+ return self::$_instance;
37
+ }
38
+
39
+ /**
40
+ * Constructor
41
+ */
42
+ public function __construct() {
43
+
44
+ add_filter( 'aws_search_page_filters', array( $this, 'woof_search_page_filters' ) );
45
+
46
+ add_filter( 'aws_searchpage_enabled', array( $this, 'woof_searchpage_enabled' ) );
47
+
48
+ add_filter( 'aws_search_page_query', array( $this, 'woof_aws_searchpage_query' ) );
49
+
50
+ add_filter( 'woof_text_search_like_option', array( $this, 'woof_text_search_like_option' ) );
51
+
52
+ add_filter( 'woof_get_request_data', array( $this, 'woof_get_request_data' ), 999 );
53
+
54
+ }
55
+
56
+ /*
57
+ * Filter products
58
+ */
59
+ public function woof_search_page_filters( $filters ) {
60
+
61
+ if ( isset( $_GET['swoof'] ) || isset( $_GET['woof_text'] ) ) {
62
+ foreach ( $_GET as $key => $param ) {
63
+
64
+ if ( $key === 'product_cat' || $key === 'product_tag' || strpos($key, 'pa_') !== false ) {
65
+
66
+ $slugs_arr = explode(',', $param);
67
+ $term_ids = array();
68
+
69
+ if ( $slugs_arr ) {
70
+ foreach( $slugs_arr as $slug ) {
71
+ $term = get_term_by('slug', $slug, $key );
72
+ if ( $term ) {
73
+ $term_ids[] = $term->term_id;
74
+ }
75
+ }
76
+ }
77
+
78
+ $operator = 'OR';
79
+ $filters['tax'][$key] = array(
80
+ 'terms' => $term_ids,
81
+ 'operator' => $operator
82
+ );
83
+ }
84
+
85
+ }
86
+ }
87
+
88
+ return $filters;
89
+
90
+ }
91
+
92
+ /*
93
+ * Enable aws search
94
+ */
95
+ public function woof_searchpage_enabled( $enabled ) {
96
+ if ( isset( $_GET['post_type'] ) && $_GET['post_type'] === 'product' && isset( $_GET['type_aws'] ) && isset( $_GET['woof_text'] ) ) {
97
+ return true;
98
+ }
99
+ return $enabled;
100
+ }
101
+
102
+ /*
103
+ * WOOF - WooCommerce Products Filter: set search query string
104
+ */
105
+ public function woof_aws_searchpage_query( $search_query ) {
106
+ if ( ! $search_query && isset( $_GET['woof_text'] ) ) {
107
+ return $_GET['woof_text'];
108
+ }
109
+ return $search_query;
110
+ }
111
+
112
+ /*
113
+ * Enable text search feature
114
+ */
115
+ public function woof_text_search_like_option( $enable ) {
116
+ if ( isset( $_GET['post_type'] ) && $_GET['post_type'] === 'product' && isset( $_GET['type_aws'] ) ) {
117
+ return true;
118
+ }
119
+ return $enable;
120
+ }
121
+
122
+ /*
123
+ * Add woof_text query if it is not exists
124
+ */
125
+ public function woof_get_request_data( $request ) {
126
+ if ( isset( $_GET['post_type'] ) && $_GET['post_type'] === 'product' && isset( $_GET['type_aws'] ) && isset( $_GET['s'] ) && ! isset( $_GET['woof_text'] ) ) {
127
+ $request['woof_text'] = $request['s'];
128
+ }
129
+ return $request;
130
+ }
131
+
132
+
133
+ }
134
+
135
+
136
+ endif;
137
+
138
+ AWS_Woof_Filter_Init::instance();
includes/widget.php CHANGED
@@ -32,8 +32,9 @@ class AWS_Widget extends WP_Widget {
32
  $this->id_base
33
  );
34
 
 
 
35
  if ( $title ) {
36
- echo $before_widget;
37
  echo $before_title;
38
  echo $title;
39
  echo $after_title;
32
  $this->id_base
33
  );
34
 
35
+ echo $before_widget;
36
+
37
  if ( $title ) {
 
38
  echo $before_title;
39
  echo $title;
40
  echo $after_title;
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.6
7
- Stable tag: 2.21
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -166,6 +166,11 @@ Yep. This plugin is always compatible with the latest version of Woocommerce?
166
 
167
  == Changelog ==
168
 
 
 
 
 
 
169
  = 2.21 ( 2021-02-15 ) =
170
  * Add - Plugin search form module for Gutenberg
171
  * Add - Label element for search form
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.7
7
+ Stable tag: 2.22
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
166
 
167
  == Changelog ==
168
 
169
+ = 2.22 ( 2021-02-19 ) =
170
+ * Add - Support for WOOF - WooCommerce Products Filter plugin
171
+ * Fix - Search form widget layout
172
+ * Dev - Add aws_search_page_query filter
173
+
174
  = 2.21 ( 2021-02-15 ) =
175
  * Add - Plugin search form module for Gutenberg
176
  * Add - Label element for search form