Advanced Woo Search - Version 2.37

Version Description

( 2021-10-11 ) = * Add - Support for B2BKing plugin * Update - Hide out-of-stock items by default if corresponding WC option is enabled * Update - Tested with WC 5.7

Download this release

Release Info

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

Code changes from version 2.36 to 2.37

advanced-woo-search.php CHANGED
@@ -3,12 +3,12 @@
3
  /*
4
  Plugin Name: Advanced Woo Search
5
  Description: Advance ajax WooCommerce product search.
6
- Version: 2.36
7
  Author: ILLID
8
  Author URI: https://advanced-woo-search.com/
9
  Text Domain: advanced-woo-search
10
  WC requires at least: 3.0.0
11
- WC tested up to: 5.6.0
12
  */
13
 
14
 
@@ -96,7 +96,7 @@ final class AWS_Main {
96
  */
97
  private function define_constants() {
98
 
99
- $this->define( 'AWS_VERSION', '2.36' );
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.37
7
  Author: ILLID
8
  Author URI: https://advanced-woo-search.com/
9
  Text Domain: advanced-woo-search
10
  WC requires at least: 3.0.0
11
+ WC tested up to: 5.7.0
12
  */
13
 
14
 
96
  */
97
  private function define_constants() {
98
 
99
+ $this->define( 'AWS_VERSION', '2.37' );
100
 
101
  $this->define( 'AWS_DIR', plugin_dir_path( AWS_FILE ) );
102
  $this->define( 'AWS_URL', plugin_dir_url( AWS_FILE ) );
includes/admin/class-aws-admin-options.php CHANGED
@@ -180,6 +180,8 @@ if ( ! class_exists( 'AWS_Admin_Options' ) ) :
180
  */
181
  static public function include_options() {
182
 
 
 
183
  $options = array();
184
 
185
  $options['general'][] = array(
@@ -591,7 +593,7 @@ if ( ! class_exists( 'AWS_Admin_Options' ) ) :
591
  "name" => __( "Show out-of-stock", "advanced-woo-search" ),
592
  "desc" => __( "Show out-of-stock products in search", "advanced-woo-search" ),
593
  "id" => "outofstock",
594
- "value" => 'true',
595
  "type" => "radio",
596
  'choices' => array(
597
  'true' => __( 'Show', 'advanced-woo-search' ),
180
  */
181
  static public function include_options() {
182
 
183
+ $show_out_of_stock = 'yes' === get_option( 'woocommerce_hide_out_of_stock_items' ) ? 'false' : 'true';
184
+
185
  $options = array();
186
 
187
  $options['general'][] = array(
593
  "name" => __( "Show out-of-stock", "advanced-woo-search" ),
594
  "desc" => __( "Show out-of-stock products in search", "advanced-woo-search" ),
595
  "id" => "outofstock",
596
+ "value" => $show_out_of_stock,
597
  "type" => "radio",
598
  'choices' => array(
599
  'true' => __( 'Show', 'advanced-woo-search' ),
includes/class-aws-integrations.php CHANGED
@@ -326,6 +326,11 @@ if ( ! class_exists( 'AWS_Integrations' ) ) :
326
  include_once( AWS_DIR . '/includes/modules/class-aws-wholesale.php' );
327
  }
328
 
 
 
 
 
 
329
  // Advanced Woo Labels plugin
330
  if ( function_exists( 'AWL' ) || function_exists( 'AWL_PRO' ) ) {
331
  include_once( AWS_DIR . '/includes/modules/class-aws-awl.php' );
326
  include_once( AWS_DIR . '/includes/modules/class-aws-wholesale.php' );
327
  }
328
 
329
+ // B2BKing plugin
330
+ if ( class_exists( 'B2bking' ) ) {
331
+ include_once( AWS_DIR . '/includes/modules/class-aws-b2bking.php' );
332
+ }
333
+
334
  // Advanced Woo Labels plugin
335
  if ( function_exists( 'AWL' ) || function_exists( 'AWL_PRO' ) ) {
336
  include_once( AWS_DIR . '/includes/modules/class-aws-awl.php' );
includes/modules/class-aws-b2bking.php ADDED
@@ -0,0 +1,394 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * B2BKing plugin support
4
+ */
5
+
6
+ if ( ! defined( 'ABSPATH' ) ) {
7
+ exit; // Exit if accessed directly.
8
+ }
9
+
10
+ if ( ! class_exists( 'AWS_B2BKing' ) ) :
11
+
12
+ /**
13
+ * Class
14
+ */
15
+ class AWS_B2BKing {
16
+
17
+ /**
18
+ * Main AWS_B2BKing Instance
19
+ *
20
+ * Ensures only one instance of AWS_B2BKing is loaded or can be loaded.
21
+ *
22
+ * @static
23
+ * @return AWS_B2BKing - Main instance
24
+ */
25
+ protected static $_instance = null;
26
+
27
+ /**
28
+ * Main AWS_B2BKing Instance
29
+ *
30
+ * Ensures only one instance of AWS_B2BKing is loaded or can be loaded.
31
+ *
32
+ * @static
33
+ * @return AWS_B2BKing - Main instance
34
+ */
35
+ public static function instance() {
36
+ if ( is_null( self::$_instance ) ) {
37
+ self::$_instance = new self();
38
+ }
39
+ return self::$_instance;
40
+ }
41
+
42
+ /**
43
+ * Constructor
44
+ */
45
+ public function __construct() {
46
+
47
+ // Hide all products for guests
48
+ if ( ! is_user_logged_in() && get_option('b2bking_guest_access_restriction_setting', 'hide_prices') === 'hide_website') {
49
+ add_filter( 'aws_search_query_string', array( $this, 'sql_hide_results' ), 1 );
50
+ add_filter( 'aws_terms_search_query', array( $this, 'sql_hide_results' ), 1 );
51
+ }
52
+
53
+ // Products visibility
54
+ if ( ( intval( get_option( 'b2bking_all_products_visible_all_users_setting', 1 ) ) !== 1 ) ) {
55
+ add_filter( 'aws_search_query_array', array( $this, 'products_filter' ), 1 );
56
+ add_filter( 'aws_terms_search_query', array( $this, 'terms_filter' ), 1, 2 );
57
+ }
58
+
59
+ }
60
+
61
+ /*
62
+ * Hide all products
63
+ */
64
+ public function sql_hide_results( $sql ) {
65
+
66
+ global $wpdb;
67
+
68
+ $table_name = $wpdb->prefix . AWS_INDEX_TABLE_NAME;
69
+
70
+ $sql = "SELECT * FROM {$table_name} WHERE 1=2";
71
+
72
+ return $sql;
73
+
74
+ }
75
+
76
+ /*
77
+ * Include only visible products
78
+ */
79
+ public function products_filter( $query ) {
80
+
81
+ $products_ids = $this->b2bking_get_all_visible_products();
82
+
83
+ if ( ! empty( $products_ids ) ) {
84
+ $query['exclude_products'] .= sprintf( ' AND ( id IN ( %s ) )', implode( ',', $products_ids ) );
85
+ }
86
+
87
+ return $query;
88
+
89
+ }
90
+
91
+ public function terms_filter( $sql, $taxonomy ) {
92
+
93
+ if ( array_search( 'product_cat', $taxonomy ) !== false ) {
94
+
95
+ $categories_ids = $this->b2bking_get_all_visible_categories();
96
+
97
+ if ( ! empty( $categories_ids ) ) {
98
+ global $wpdb;
99
+ $sql_terms = sprintf( " AND $wpdb->term_taxonomy.term_id IN ( %s )", implode( ',', $categories_ids ) );
100
+ $sql = str_replace( 'WHERE 1 = 1', 'WHERE 1 = 1 ' . $sql_terms, $sql );
101
+ }
102
+
103
+ }
104
+
105
+ return $sql;
106
+
107
+ }
108
+
109
+ /*
110
+ * Get all visible products IDs
111
+ */
112
+ private function b2bking_get_all_visible_products() {
113
+
114
+ $allTheIDs = array();
115
+
116
+ if (intval(get_option( 'b2bking_all_products_visible_all_users_setting', 1 )) !== 1){
117
+
118
+ if ( get_option( 'b2bking_plugin_status_setting', 'b2b' ) !== 'disabled' ){
119
+
120
+ $user_is_b2b = get_user_meta( get_current_user_id(), 'b2bking_b2buser', true );
121
+
122
+ // if user logged in and is b2b
123
+ if (is_user_logged_in() && ($user_is_b2b === 'yes')){
124
+ // Get current user's data: group, id, login, etc
125
+ $currentuserid = get_current_user_id();
126
+ $account_type = get_user_meta($currentuserid,'b2bking_account_type', true);
127
+ if ($account_type === 'subaccount'){
128
+ // for all intents and purposes set current user as the subaccount parent
129
+ $parent_user_id = get_user_meta($currentuserid, 'b2bking_account_parent', true);
130
+ $currentuserid = $parent_user_id;
131
+ }
132
+ $currentuser = get_user_by('id', $currentuserid);
133
+ $currentuserlogin = $currentuser -> user_login;
134
+ $currentusergroupidnr = get_user_meta( $currentuserid, 'b2bking_customergroup', true );
135
+ // if user is b2c
136
+ } else if (is_user_logged_in() && ($user_is_b2b !== 'yes')){
137
+ $currentuserlogin = 'b2c';
138
+ $currentusergroupidnr = 'b2c';
139
+ } else {
140
+ $currentuserlogin = 0;
141
+ $currentusergroupidnr = 0;
142
+ }
143
+ /*
144
+ *
145
+ * There are 2 separate queries that need to be made:
146
+ * 1. Query of all Categories visible to the USER AND all Categories visible to the USER'S GROUP
147
+ * 2. Query of all Products set to Manual visibility mode, visible to the user or the user's group
148
+ *
149
+ */
150
+
151
+ // Build Visible Categories for the 1st Query
152
+ $visiblecategories = array();
153
+ $hiddencategories = array();
154
+
155
+ $terms = get_terms( array(
156
+ 'taxonomy' => 'product_cat',
157
+ 'fields' => 'ids',
158
+ 'hide_empty' => false
159
+ ) );
160
+
161
+ foreach ($terms as $term){
162
+
163
+ /*
164
+ * If category is visible to GROUP OR category is visible to USER
165
+ * Push category into visible categories array
166
+ */
167
+
168
+ // first check group
169
+ $group_meta = get_term_meta( $term, 'b2bking_group_'.$currentusergroupidnr, true );
170
+ if (intval($group_meta) === 1){
171
+ array_push($visiblecategories, $term);
172
+ // else check user
173
+ } else {
174
+ $userlistcommas = get_term_meta( $term, 'b2bking_category_users_textarea', true );
175
+ $userarray = explode(',', $userlistcommas);
176
+ $visible = 'no';
177
+ foreach ($userarray as $user){
178
+ if (trim($user) === $currentuserlogin){
179
+ array_push($visiblecategories, $term);
180
+ $visible = 'yes';
181
+ break;
182
+ }
183
+ }
184
+ if ($visible === 'no'){
185
+ array_push($hiddencategories, $term);
186
+ }
187
+ }
188
+ }
189
+
190
+
191
+ $product_category_visibility_array = array(
192
+ 'taxonomy' => 'product_cat',
193
+ 'field' => 'term_id',
194
+ 'terms' => $visiblecategories,
195
+ 'operator' => 'IN'
196
+ );
197
+
198
+ // if user has enabled "hidden has priority", override setting
199
+ if (intval(get_option( 'b2bking_hidden_has_priority_setting', 0 )) === 1){
200
+ $product_category_visibility_array = array(
201
+ 'taxonomy' => 'product_cat',
202
+ 'field' => 'term_id',
203
+ 'terms' => $hiddencategories,
204
+ 'operator' => 'NOT IN'
205
+ );
206
+ }
207
+
208
+ /* Get all items that do not have manual visibility set up */
209
+ // get all products ids
210
+ if (intval(get_option( 'b2bking_product_visibility_cache_setting', 0 )) === 1){
211
+ $items_not_manual_visibility_array = get_transient('b2bking_not_manual_visibility_array');
212
+ } else {
213
+ $items_not_manual_visibility_array = false;
214
+ }
215
+
216
+ if (!$items_not_manual_visibility_array){
217
+ $all_prods = new WP_Query(array(
218
+ 'posts_per_page' => -1,
219
+ 'post_type' => 'product',
220
+ 'fields' => 'ids'));
221
+ $all_prod_ids = $all_prods->posts;
222
+
223
+ // get all products with manual visibility ids
224
+ $all_prods_manual = new WP_Query(array(
225
+ 'posts_per_page' => -1,
226
+ 'post_type' => 'product',
227
+ 'fields' => 'ids',
228
+ 'meta_query'=> array(
229
+ 'relation' => 'AND',
230
+ array(
231
+ 'key' => 'b2bking_product_visibility_override',
232
+ 'value' => 'manual',
233
+ )
234
+ )));
235
+ $all_prod_manual_ids = $all_prods_manual->posts;
236
+ // get the difference
237
+ $items_not_manual_visibility_array = array_diff($all_prod_ids,$all_prod_manual_ids);
238
+ set_transient('b2bking_not_manual_visibility_array', $items_not_manual_visibility_array);
239
+ }
240
+
241
+ // Build first query
242
+ $queryAparams = array(
243
+ 'posts_per_page' => -1,
244
+ 'post_type' => 'product',
245
+ 'fields' => 'ids',
246
+ 'tax_query' => array(
247
+ $product_category_visibility_array
248
+ ),
249
+ 'post__in' => $items_not_manual_visibility_array,
250
+ );
251
+
252
+ // Build 2nd query: all manual visibility products with USER OR USER GROUP visibility
253
+ $queryBparams = array(
254
+ 'posts_per_page' => -1,
255
+ 'post_type' => 'product',
256
+ 'fields' => 'ids',
257
+ 'meta_query'=> array(
258
+ 'relation' => 'AND',
259
+ array(
260
+ 'relation' => 'OR',
261
+ array(
262
+ 'key' => 'b2bking_group_'.$currentusergroupidnr,
263
+ 'value' => '1'
264
+ ),
265
+ array(
266
+ 'key' => 'b2bking_user_'.$currentuserlogin,
267
+ 'value' => '1'
268
+ )
269
+ ),
270
+ array(
271
+ 'key' => 'b2bking_product_visibility_override',
272
+ 'value' => 'manual',
273
+ )
274
+ ));
275
+
276
+
277
+ // if caching is enabled
278
+ if (intval(get_option( 'b2bking_product_visibility_cache_setting', 0 )) === 1){
279
+
280
+ // cache query results
281
+ if (!get_transient('b2bking_user_'.get_current_user_id().'_visibility')){
282
+ $queryA = new WP_Query($queryAparams);
283
+ $queryB = new WP_Query($queryBparams);
284
+ // Merge the 2 queries in an IDs array
285
+ $allTheIDs = array_merge($queryA->posts,$queryB->posts);
286
+ set_transient('b2bking_user_'.get_current_user_id().'_visibility', $allTheIDs);
287
+ } else {
288
+ $allTheIDs = get_transient('b2bking_user_'.get_current_user_id().'_visibility');
289
+ }
290
+
291
+ } else {
292
+ $queryA = new WP_Query($queryAparams);
293
+ $queryB = new WP_Query($queryBparams);
294
+ // Merge the 2 queries in an IDs array
295
+ $allTheIDs = array_merge($queryA->posts,$queryB->posts);
296
+ }
297
+
298
+
299
+ }
300
+ }
301
+
302
+ return $allTheIDs;
303
+
304
+ }
305
+
306
+ /*
307
+ * Get all visible categories terms IDs
308
+ */
309
+ private function b2bking_get_all_visible_categories() {
310
+
311
+ $visiblecategories = array();
312
+ $hiddencategories = array();
313
+
314
+ if (intval(get_option( 'b2bking_all_products_visible_all_users_setting', 1 )) !== 1){
315
+
316
+ if ( get_option( 'b2bking_plugin_status_setting', 'b2b' ) !== 'disabled' ){
317
+
318
+ if ( $visiblecategories_transient = get_transient('b2bking_user_'.get_current_user_id().'_cat_visibility' ) ) {
319
+ return $visiblecategories_transient;
320
+ }
321
+
322
+ $user_is_b2b = get_user_meta( get_current_user_id(), 'b2bking_b2buser', true );
323
+
324
+ // if user logged in and is b2b
325
+ if (is_user_logged_in() && ($user_is_b2b === 'yes')){
326
+ // Get current user's data: group, id, login, etc
327
+ $currentuserid = get_current_user_id();
328
+ $account_type = get_user_meta($currentuserid,'b2bking_account_type', true);
329
+ if ($account_type === 'subaccount'){
330
+ // for all intents and purposes set current user as the subaccount parent
331
+ $parent_user_id = get_user_meta($currentuserid, 'b2bking_account_parent', true);
332
+ $currentuserid = $parent_user_id;
333
+ }
334
+ $currentuser = get_user_by('id', $currentuserid);
335
+ $currentuserlogin = $currentuser -> user_login;
336
+ $currentusergroupidnr = get_user_meta( $currentuserid, 'b2bking_customergroup', true );
337
+ // if user is b2c
338
+ } else if (is_user_logged_in() && ($user_is_b2b !== 'yes')){
339
+ $currentuserlogin = 'b2c';
340
+ $currentusergroupidnr = 'b2c';
341
+ } else {
342
+ $currentuserlogin = 0;
343
+ $currentusergroupidnr = 0;
344
+ }
345
+
346
+ $terms = get_terms( array(
347
+ 'taxonomy' => 'product_cat',
348
+ 'fields' => 'ids',
349
+ 'hide_empty' => false
350
+ ) );
351
+
352
+ foreach ($terms as $term){
353
+
354
+ /*
355
+ * If category is visible to GROUP OR category is visible to USER
356
+ * Push category into visible categories array
357
+ */
358
+
359
+ // first check group
360
+ $group_meta = get_term_meta( $term, 'b2bking_group_'.$currentusergroupidnr, true );
361
+ if (intval($group_meta) === 1){
362
+ array_push($visiblecategories, $term);
363
+ // else check user
364
+ } else {
365
+ $userlistcommas = get_term_meta( $term, 'b2bking_category_users_textarea', true );
366
+ $userarray = explode(',', $userlistcommas);
367
+ $visible = 'no';
368
+ foreach ($userarray as $user){
369
+ if (trim($user) === $currentuserlogin){
370
+ array_push($visiblecategories, $term);
371
+ $visible = 'yes';
372
+ break;
373
+ }
374
+ }
375
+ if ($visible === 'no'){
376
+ array_push($hiddencategories, $term);
377
+ }
378
+ }
379
+ }
380
+
381
+ set_transient('b2bking_user_'.get_current_user_id().'_cat_visibility', $visiblecategories, 600 );
382
+
383
+ }
384
+ }
385
+
386
+ return $visiblecategories;
387
+
388
+ }
389
+
390
+ }
391
+
392
+ endif;
393
+
394
+ AWS_B2BKing::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.36
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -167,6 +167,11 @@ Yep. This plugin is always compatible with the latest version of Woocommerce?
167
 
168
  == Changelog ==
169
 
 
 
 
 
 
170
  = 2.36 ( 2021-09-21 ) =
171
  * Update - Woodmart theme support. Update search results page pagination links
172
  * Update - Avada theme support. Set number of products per search results page
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.37
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
167
 
168
  == Changelog ==
169
 
170
+ = 2.37 ( 2021-10-11 ) =
171
+ * Add - Support for B2BKing plugin
172
+ * Update - Hide out-of-stock items by default if corresponding WC option is enabled
173
+ * Update - Tested with WC 5.7
174
+
175
  = 2.36 ( 2021-09-21 ) =
176
  * Update - Woodmart theme support. Update search results page pagination links
177
  * Update - Avada theme support. Set number of products per search results page