Advanced Woo Search - Version 2.04

Version Description

  • Add - Add BeRocket WooCommerce AJAX Products Filter plugin support
  • Add - Add WCFM - WooCommerce Multivendor Marketplace plugin support for users search
  • Dev - Add aws_products_search_page_filtered filter
  • Dev - Add aws_search_page_filters filter
Download this release

Release Info

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

Code changes from version 2.03 to 2.04

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.03
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', '2.03' );
20
 
21
 
22
  define( 'AWS_DIR', dirname( __FILE__ ) );
3
  /*
4
  Plugin Name: Advanced Woo Search
5
  Description: Advance ajax WooCommerce product search.
6
+ Version: 2.04
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', '2.04' );
20
 
21
 
22
  define( 'AWS_DIR', dirname( __FILE__ ) );
includes/class-aws-helpers.php CHANGED
@@ -823,6 +823,59 @@ if ( ! class_exists( 'AWS_Helpers' ) ) :
823
 
824
  }
825
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
826
  }
827
 
828
  endif;
823
 
824
  }
825
 
826
+ /**
827
+ * Filter search page results by taxonomies
828
+ * @param array $product_terms Available product terms
829
+ * @param array $filter_terms Filter terms
830
+ * @param string $operator Operator
831
+ * @return bool $skip
832
+ */
833
+ static public function page_filter_tax( $product_terms, $filter_terms, $operator = 'OR' ) {
834
+
835
+ $skip = true;
836
+
837
+ if ( $filter_terms && is_array( $filter_terms ) && ! empty( $filter_terms ) ) {
838
+
839
+ if ( $operator === 'AND' ) {
840
+
841
+ $has_all = true;
842
+
843
+ foreach( $filter_terms as $term ) {
844
+ if ( array_search( $term, $product_terms ) === false ) {
845
+ $has_all = false;
846
+ break;
847
+ }
848
+ }
849
+
850
+ if ( $has_all ) {
851
+ $skip = false;
852
+ }
853
+
854
+ }
855
+
856
+ if ( $operator === 'IN' || $operator === 'OR' ) {
857
+
858
+ $has_all = false;
859
+
860
+ foreach( $filter_terms as $term ) {
861
+ if ( array_search( $term, $product_terms ) !== false ) {
862
+ $has_all = true;
863
+ break;
864
+ }
865
+ }
866
+
867
+ if ( $has_all ) {
868
+ $skip = false;
869
+ }
870
+
871
+ }
872
+
873
+ }
874
+
875
+ return $skip;
876
+
877
+ }
878
+
879
  }
880
 
881
  endif;
includes/class-aws-integrations.php CHANGED
@@ -169,6 +169,11 @@ if ( ! class_exists( 'AWS_Integrations' ) ) :
169
  // WP all import finish
170
  add_action( 'pmxi_after_xml_import', array( $this, 'pmxi_after_xml_import' ) );
171
 
 
 
 
 
 
172
  }
173
 
174
  /**
@@ -1085,6 +1090,43 @@ if ( ! class_exists( 'AWS_Integrations' ) ) :
1085
  }
1086
  }
1087
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1088
  }
1089
 
1090
  endif;
169
  // WP all import finish
170
  add_action( 'pmxi_after_xml_import', array( $this, 'pmxi_after_xml_import' ) );
171
 
172
+ // BeRocket WooCommerce AJAX Products Filter
173
+ if ( defined( 'BeRocket_AJAX_filters_version' ) ) {
174
+ add_filter( 'aws_search_page_filters', array( $this, 'berocket_search_page_filters' ) );
175
+ }
176
+
177
  }
178
 
179
  /**
1090
  }
1091
  }
1092
 
1093
+ /*
1094
+ * BeRocket WooCommerce AJAX Products Filter
1095
+ */
1096
+ public function berocket_search_page_filters( $filters ) {
1097
+
1098
+ if ( isset( $_GET['filters'] ) ) {
1099
+
1100
+ $get_filters = explode( '|', $_GET['filters'] );
1101
+
1102
+ foreach( $get_filters as $get_filter ) {
1103
+
1104
+ if ( $get_filter === '_stock_status[1]' ) {
1105
+ $filters['in_status'] = true;
1106
+ } elseif ( $get_filter === '_stock_status[2]' ) {
1107
+ $filters['in_status'] = false;
1108
+ } elseif ( $get_filter === '_sale[1]' ) {
1109
+ $filters['on_sale'] = true;
1110
+ } elseif ( $get_filter === '_sale[2]' ) {
1111
+ $filters['on_sale'] = false;
1112
+ } elseif( preg_match( '/([\w]+)\[(.+?)\]/', $get_filter, $matches ) ) {
1113
+ $taxonomy = $matches[1];
1114
+ $operator = strpos( $matches[2], '-' ) !== false ? 'OR' : 'AND';
1115
+ $explode_char = strpos( $matches[2], '-' ) !== false ? '-' : '+';
1116
+ $filters['tax'][$taxonomy] = array(
1117
+ 'terms' => explode( $explode_char, $matches[2] ),
1118
+ 'operator' => $operator
1119
+ );
1120
+ }
1121
+
1122
+ }
1123
+
1124
+ }
1125
+
1126
+ return $filters;
1127
+
1128
+ }
1129
+
1130
  }
1131
 
1132
  endif;
includes/class-aws-order.php CHANGED
@@ -39,12 +39,7 @@ if ( ! class_exists( 'AWS_Order' ) ) :
39
  private function filter_results( $query ) {
40
 
41
  $new_products = array();
42
-
43
- $price_min = false;
44
- $price_max = false;
45
- $rating = false;
46
- $brand = false;
47
-
48
  $attr_filter = array();
49
 
50
  if ( isset( $query->query_vars['meta_query'] ) ) {
@@ -53,27 +48,27 @@ if ( ! class_exists( 'AWS_Order' ) ) :
53
  if ( isset( $meta_query['price_filter'] ) && isset( $meta_query['price_filter']['value'] ) ) {
54
  $price_values = $meta_query['price_filter']['value'];
55
  if ( isset( $price_values[0] ) && isset( $price_values[1] ) ) {
56
- $price_min = $price_values[0];
57
- $price_max = $price_values[1];
58
  }
59
  }
60
 
61
  }
62
 
63
- if ( ! $price_min && isset( $_GET['min_price'] ) ) {
64
- $price_min = sanitize_text_field( $_GET['min_price'] );
65
  }
66
 
67
- if ( ! $price_max && isset( $_GET['max_price'] ) ) {
68
- $price_max = sanitize_text_field( $_GET['max_price'] );
69
  }
70
 
71
  if ( isset( $_GET['rating_filter'] ) && $_GET['rating_filter'] ) {
72
- $rating = explode( ',', sanitize_text_field( $_GET['rating_filter'] ) );
73
  }
74
 
75
  if ( isset( $_GET['filtering'] ) && $_GET['filtering'] && isset( $_GET['filter_product_brand'] ) ) {
76
- $brand = explode( ',', sanitize_text_field( $_GET['filter_product_brand'] ) );
77
  }
78
 
79
  if ( isset( $query->query_vars['tax_query'] ) ) {
@@ -92,32 +87,53 @@ if ( ! class_exists( 'AWS_Order' ) ) :
92
 
93
  }
94
 
 
 
 
 
 
 
 
 
 
95
  foreach( $this->products as $post_array ) {
96
 
97
- if ( ( $price_min || $price_min == '0' ) && $price_max ) {
 
 
 
 
 
 
 
 
 
 
 
 
98
  if ( isset( $post_array['f_price'] ) && $post_array['f_price'] ) {
99
- if ( $post_array['f_price'] > $price_max || $post_array['f_price'] < $price_min ) {
100
  continue;
101
  }
102
  }
103
  }
104
 
105
- if ( $rating && is_array( $rating ) ) {
106
  if ( isset( $post_array['f_rating'] ) ) {
107
- if ( array_search( floor( $post_array['f_rating'] ), $rating ) === false ) {
108
  continue;
109
  }
110
  }
111
  }
112
 
113
- if ( $brand && is_array( $brand ) ) {
114
 
115
  $skip = true;
116
  $p_brands = get_the_terms( $post_array['id'], 'product_brand' );
117
 
118
  if ( ! is_wp_error( $p_brands ) && ! empty( $p_brands ) ) {
119
  foreach ( $p_brands as $p_brand ) {
120
- if ( in_array( $p_brand->term_id, $brand ) ) {
121
  $skip = false;
122
  break;
123
  }
@@ -130,7 +146,44 @@ if ( ! class_exists( 'AWS_Order' ) ) :
130
 
131
  }
132
 
133
- if ( $attr_filter && ! empty( $attr_filter ) ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134
 
135
  $product = wc_get_product( $post_array['id'] );
136
  $attributes = $product->get_attributes();
@@ -149,7 +202,7 @@ if ( ! class_exists( 'AWS_Order' ) ) :
149
 
150
  if ( ! is_wp_error( $product_terms ) && ! empty( $product_terms ) ) {
151
  foreach ( $product_terms as $product_term ) {
152
- $product_terms_array[$product_term->slug] = $product_term->slug;
153
  }
154
  }
155
 
@@ -160,52 +213,16 @@ if ( ! class_exists( 'AWS_Order' ) ) :
160
 
161
  if ( $product_terms_array ) {
162
 
 
163
  foreach( $attr_filter as $attr_filter_name => $attr_filter_object ) {
164
 
165
- $skip = true;
166
- $attr_filter_operator = $attr_filter_object['operator'];
167
  $attr_filter_terms = $attr_filter_object['terms'];
168
 
169
- if ( $attr_filter_terms && is_array( $attr_filter_terms ) && ! empty( $attr_filter_terms ) ) {
170
-
171
- if ( $attr_filter_operator === 'AND' ) {
172
-
173
- $has_all = true;
174
-
175
- foreach( $attr_filter_terms as $term ) {
176
- if ( ! isset( $product_terms_array[$term] ) ) {
177
- $has_all = false;
178
- break;
179
- }
180
- }
181
-
182
- if ( $has_all ) {
183
- $skip = false;
184
- }
185
-
186
- }
187
-
188
- if ( $attr_filter_operator === 'IN' || $attr_filter_operator === 'OR' ) {
189
-
190
- $has_all = false;
191
-
192
- foreach( $attr_filter_terms as $term ) {
193
- if ( isset( $product_terms_array[$term] ) ) {
194
- $has_all = true;
195
- break;
196
- }
197
- }
198
-
199
- if ( $has_all ) {
200
- $skip = false;
201
- }
202
-
203
- }
204
-
205
- if ( $skip ) {
206
- break;
207
- }
208
 
 
 
209
  }
210
 
211
  }
@@ -224,7 +241,12 @@ if ( ! class_exists( 'AWS_Order' ) ) :
224
 
225
  }
226
 
227
- $this->products = $new_products;
 
 
 
 
 
228
 
229
  }
230
 
39
  private function filter_results( $query ) {
40
 
41
  $new_products = array();
42
+ $filters = array();
 
 
 
 
 
43
  $attr_filter = array();
44
 
45
  if ( isset( $query->query_vars['meta_query'] ) ) {
48
  if ( isset( $meta_query['price_filter'] ) && isset( $meta_query['price_filter']['value'] ) ) {
49
  $price_values = $meta_query['price_filter']['value'];
50
  if ( isset( $price_values[0] ) && isset( $price_values[1] ) ) {
51
+ $filters['price_min'] = $price_values[0];
52
+ $filters['price_max'] = $price_values[1];
53
  }
54
  }
55
 
56
  }
57
 
58
+ if ( ! isset( $filters['price_min'] ) && isset( $_GET['min_price'] ) ) {
59
+ $filters['price_min'] = sanitize_text_field( $_GET['min_price'] );
60
  }
61
 
62
+ if ( ! isset( $filters['price_max'] ) && isset( $_GET['max_price'] ) ) {
63
+ $filters['price_max'] = sanitize_text_field( $_GET['max_price'] );
64
  }
65
 
66
  if ( isset( $_GET['rating_filter'] ) && $_GET['rating_filter'] ) {
67
+ $filters['rating'] = explode( ',', sanitize_text_field( $_GET['rating_filter'] ) );
68
  }
69
 
70
  if ( isset( $_GET['filtering'] ) && $_GET['filtering'] && isset( $_GET['filter_product_brand'] ) ) {
71
+ $filters['brand'] = explode( ',', sanitize_text_field( $_GET['filter_product_brand'] ) );
72
  }
73
 
74
  if ( isset( $query->query_vars['tax_query'] ) ) {
87
 
88
  }
89
 
90
+
91
+ /**
92
+ * Filter available search page filters before apply
93
+ * @since 2.04
94
+ * @param array $filters Filters
95
+ */
96
+ $filters = apply_filters( 'aws_search_page_filters', $filters );
97
+
98
+
99
  foreach( $this->products as $post_array ) {
100
 
101
+ if ( isset( $filters['in_status'] ) ) {
102
+ if ( $post_array['f_stock'] !== $filters['in_status'] ) {
103
+ continue;
104
+ }
105
+ }
106
+
107
+ if ( isset( $filters['on_sale'] ) ) {
108
+ if ( $post_array['f_sale'] !== $filters['on_sale'] ) {
109
+ continue;
110
+ }
111
+ }
112
+
113
+ if ( isset( $filters['price_min'] ) && isset( $filters['price_max'] ) ) {
114
  if ( isset( $post_array['f_price'] ) && $post_array['f_price'] ) {
115
+ if ( $post_array['f_price'] > $filters['price_max'] || $post_array['f_price'] < $filters['price_min'] ) {
116
  continue;
117
  }
118
  }
119
  }
120
 
121
+ if ( isset( $filters['rating'] ) && is_array( $filters['rating'] ) ) {
122
  if ( isset( $post_array['f_rating'] ) ) {
123
+ if ( array_search( floor( $post_array['f_rating'] ), $filters['rating'] ) === false ) {
124
  continue;
125
  }
126
  }
127
  }
128
 
129
+ if ( isset( $filters['brand'] ) && is_array( $filters['brand'] ) ) {
130
 
131
  $skip = true;
132
  $p_brands = get_the_terms( $post_array['id'], 'product_brand' );
133
 
134
  if ( ! is_wp_error( $p_brands ) && ! empty( $p_brands ) ) {
135
  foreach ( $p_brands as $p_brand ) {
136
+ if ( in_array( $p_brand->term_id, $filters['brand'] ) ) {
137
  $skip = false;
138
  break;
139
  }
146
 
147
  }
148
 
149
+ if ( isset( $filters['tax'] ) && is_array( $filters['tax'] ) ) {
150
+
151
+ $skip = true;
152
+
153
+ foreach( $filters['tax'] as $taxonomy => $taxonomy_terms ) {
154
+
155
+ $terms = get_the_terms( $post_array['id'], $taxonomy );
156
+ $operator = isset( $taxonomy_terms['operator'] ) ? $taxonomy_terms['operator'] : 'OR';
157
+ $term_arr = array();
158
+
159
+ if ( ! is_wp_error( $terms ) && ! empty( $terms ) ) {
160
+ foreach ( $terms as $term ) {
161
+ $term_arr[] = $term->term_id;
162
+ }
163
+ } elseif( strpos( $taxonomy, 'pa_' ) !== 0 ) {
164
+ $terms = get_the_terms( $post_array['id'], 'pa_' . $taxonomy );
165
+ if ( ! is_wp_error( $terms ) && ! empty( $terms ) ) {
166
+ foreach ( $terms as $term ) {
167
+ $term_arr[] = $term->term_id;
168
+ }
169
+ }
170
+ }
171
+
172
+ $skip = AWS_Helpers::page_filter_tax( $term_arr, $taxonomy_terms['terms'], $operator );
173
+
174
+ if ( $skip ) {
175
+ break;
176
+ }
177
+
178
+ }
179
+
180
+ if ( $skip ) {
181
+ continue;
182
+ }
183
+
184
+ }
185
+
186
+ if ( $attr_filter && ! empty( $attr_filter ) && is_array( $attr_filter ) ) {
187
 
188
  $product = wc_get_product( $post_array['id'] );
189
  $attributes = $product->get_attributes();
202
 
203
  if ( ! is_wp_error( $product_terms ) && ! empty( $product_terms ) ) {
204
  foreach ( $product_terms as $product_term ) {
205
+ $product_terms_array[] = $product_term->slug;
206
  }
207
  }
208
 
213
 
214
  if ( $product_terms_array ) {
215
 
216
+
217
  foreach( $attr_filter as $attr_filter_name => $attr_filter_object ) {
218
 
219
+ $operator = $attr_filter_object['operator'];
 
220
  $attr_filter_terms = $attr_filter_object['terms'];
221
 
222
+ $skip = AWS_Helpers::page_filter_tax( $product_terms_array, $attr_filter_terms, $operator );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
223
 
224
+ if ( $skip ) {
225
+ break;
226
  }
227
 
228
  }
241
 
242
  }
243
 
244
+ /**
245
+ * Filter search results after search page filters applied
246
+ * @since 2.04
247
+ * @param array $new_products Products
248
+ */
249
+ $this->products = apply_filters( 'aws_products_search_page_filtered', $new_products );
250
 
251
  }
252
 
includes/class-aws-search.php CHANGED
@@ -609,6 +609,9 @@ if ( ! class_exists( 'AWS_Search' ) ) :
609
  $f_reviews = $product->get_review_count();
610
  }
611
 
 
 
 
612
  // $categories = $product->get_categories( ',' );
613
  // $tags = $product->get_tags( ',' );
614
 
@@ -635,6 +638,8 @@ if ( ! class_exists( 'AWS_Search' ) ) :
635
  'f_price' => $f_price,
636
  'f_rating' => $f_rating,
637
  'f_reviews' => $f_reviews,
 
 
638
  'post_data' => $post_data
639
  );
640
 
609
  $f_reviews = $product->get_review_count();
610
  }
611
 
612
+ $f_stock = $product->is_in_stock();
613
+ $f_sale = $product->is_on_sale();
614
+
615
  // $categories = $product->get_categories( ',' );
616
  // $tags = $product->get_tags( ',' );
617
 
638
  'f_price' => $f_price,
639
  'f_rating' => $f_rating,
640
  'f_reviews' => $f_reviews,
641
+ 'f_stock' => $f_stock,
642
+ 'f_sale' => $f_sale,
643
  'post_data' => $post_data
644
  );
645
 
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.4
7
- Stable tag: 2.03
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -54,6 +54,7 @@ Additional features available only in PRO plugin version.
54
  * Product **attributes** search ( including custom attributes)
55
  * Product **custom taxonomies** search
56
  * Product **custom fields** search
 
57
  * **Advanced settings page** with lot of options
58
  * **Exclude/include** spicific products by its ids, taxonomies or attributes from search results
59
  * Ability to specify **source of image** for search results: featured image, gallery, product content, product short description or set default image if there is no other images
@@ -104,6 +105,12 @@ Yep. This plugin is always compatible with the latest version of Woocommerce?
104
 
105
  == Changelog ==
106
 
 
 
 
 
 
 
107
  = 2.03 =
108
  * Add - Seamless integration for Elementor plugin search module
109
  * Add - Widget for Elementor plugin
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.4
7
+ Stable tag: 2.04
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
54
  * Product **attributes** search ( including custom attributes)
55
  * Product **custom taxonomies** search
56
  * Product **custom fields** search
57
+ * **Users** search
58
  * **Advanced settings page** with lot of options
59
  * **Exclude/include** spicific products by its ids, taxonomies or attributes from search results
60
  * Ability to specify **source of image** for search results: featured image, gallery, product content, product short description or set default image if there is no other images
105
 
106
  == Changelog ==
107
 
108
+ = 2.04 =
109
+ * Add - Add BeRocket WooCommerce AJAX Products Filter plugin support
110
+ * Add - Add WCFM - WooCommerce Multivendor Marketplace plugin support for users search
111
+ * Dev - Add aws_products_search_page_filtered filter
112
+ * Dev - Add aws_search_page_filters filter
113
+
114
  = 2.03 =
115
  * Add - Seamless integration for Elementor plugin search module
116
  * Add - Widget for Elementor plugin