Advanced Woo Search - Version 2.41

Version Description

( 2021-11-22 ) = * Add - Support for WooCommerce Protected Categories plugin * Fix - JS seamless integration issue

Download this release

Release Info

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

Code changes from version 2.40 to 2.41

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.40
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.40' );
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.41
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.41' );
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
@@ -64,15 +64,6 @@ if ( ! class_exists( 'AWS_Integrations' ) ) :
64
  add_action( 'aws_search_start', array( $this, 'b2b_set_filter' ) );
65
  }
66
 
67
- // Protected categories
68
- if ( class_exists( 'WC_PPC_Util' )
69
- && method_exists( 'WC_PPC_Util', 'showing_protected_categories' )
70
- && method_exists( 'WC_PPC_Util', 'to_category_visibilities' )
71
- && method_exists( 'WC_PPC_Util', 'get_product_categories' )
72
- ) {
73
- add_action( 'aws_search_start', array( $this, 'wc_ppc_set_filter' ) );
74
- }
75
-
76
  if ( function_exists( 'dfrapi_currency_code_to_sign' ) ) {
77
  add_filter( 'woocommerce_currency_symbol', array( $this, 'dfrapi_set_currency_symbol_filter' ), 10, 2 );
78
  }
@@ -368,6 +359,10 @@ if ( ! class_exists( 'AWS_Integrations' ) ) :
368
  include_once( AWS_DIR . '/includes/modules/class-aws-woobewoo-filters.php' );
369
  }
370
 
 
 
 
 
371
  }
372
 
373
  /*
@@ -438,57 +433,6 @@ if ( ! class_exists( 'AWS_Integrations' ) ) :
438
 
439
  }
440
 
441
- /*
442
- * Protected categories plugin
443
- */
444
- public function wc_ppc_set_filter() {
445
-
446
- $hidden_categories = array();
447
- $show_protected = WC_PPC_Util::showing_protected_categories();
448
-
449
- // Get all the product categories, and check which are hidden.
450
- foreach ( WC_PPC_Util::to_category_visibilities( WC_PPC_Util::get_product_categories() ) as $category ) {
451
- if ( $category->is_private() || ( ! $show_protected && $category->is_protected() ) ) {
452
- $hidden_categories[] = $category->term_id;
453
- }
454
- }
455
-
456
- if ( $hidden_categories && ! empty( $hidden_categories ) ) {
457
-
458
- foreach( $hidden_categories as $hidden_category ) {
459
- $this->data['exclude_categories'][] = $hidden_category;
460
- }
461
-
462
- $args = array(
463
- 'posts_per_page' => -1,
464
- 'fields' => 'ids',
465
- 'post_type' => 'product',
466
- 'post_status' => 'publish',
467
- 'ignore_sticky_posts' => true,
468
- 'suppress_filters' => true,
469
- 'tax_query' => array(
470
- array(
471
- 'taxonomy' => 'product_cat',
472
- 'field' => 'id',
473
- 'terms' => $hidden_categories
474
- )
475
- )
476
- );
477
-
478
- $exclude_products = get_posts( $args );
479
-
480
- if ( $exclude_products && count( $exclude_products ) > 0 ) {
481
-
482
- foreach( $exclude_products as $exclude_product ) {
483
- $this->data['exclude_products'][] = $exclude_product;
484
- }
485
-
486
- }
487
-
488
- }
489
-
490
- }
491
-
492
  /*
493
  * Datafeedr WooCommerce Importer plugin
494
  */
@@ -1684,8 +1628,14 @@ if ( ! class_exists( 'AWS_Integrations' ) ) :
1684
 
1685
  window.setTimeout(function(){
1686
  jQuery('.aws-js-seamless').each( function() {
1687
- if ( typeof aws_search !== 'undefined' ) {
1688
  jQuery(this).aws_search();
 
 
 
 
 
 
1689
  }
1690
  });
1691
  }, 1000);
64
  add_action( 'aws_search_start', array( $this, 'b2b_set_filter' ) );
65
  }
66
 
 
 
 
 
 
 
 
 
 
67
  if ( function_exists( 'dfrapi_currency_code_to_sign' ) ) {
68
  add_filter( 'woocommerce_currency_symbol', array( $this, 'dfrapi_set_currency_symbol_filter' ), 10, 2 );
69
  }
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
+ }
365
+
366
  }
367
 
368
  /*
433
 
434
  }
435
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
436
  /*
437
  * Datafeedr WooCommerce Importer plugin
438
  */
1628
 
1629
  window.setTimeout(function(){
1630
  jQuery('.aws-js-seamless').each( function() {
1631
+ try {
1632
  jQuery(this).aws_search();
1633
+ } catch (error) {
1634
+ window.setTimeout(function(){
1635
+ try {
1636
+ jQuery(this).aws_search();
1637
+ } catch (error) {}
1638
+ }, 2000);
1639
  }
1640
  });
1641
  }, 1000);
includes/modules/class-aws-barn2-protected-categories.php ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * WooCommerce Protected Categories
4
+ */
5
+
6
+
7
+ if ( ! defined( 'ABSPATH' ) ) {
8
+ exit; // Exit if accessed directly.
9
+ }
10
+
11
+
12
+ if ( ! class_exists( 'AWL_Barn2PC' ) ) :
13
+
14
+ /**
15
+ * Class
16
+ */
17
+ class AWL_Barn2PC {
18
+
19
+ /**
20
+ * Main AWL_Barn2PC Instance
21
+ *
22
+ * Ensures only one instance of AWL_Barn2PC is loaded or can be loaded.
23
+ *
24
+ * @static
25
+ * @return AWL_Barn2PC - Main instance
26
+ */
27
+ protected static $_instance = null;
28
+
29
+ private $data = array();
30
+
31
+ /**
32
+ * Main AWL_Barn2PC Instance
33
+ *
34
+ * Ensures only one instance of AWL_Barn2PC is loaded or can be loaded.
35
+ *
36
+ * @static
37
+ * @return AWL_Barn2PC - Main instance
38
+ */
39
+ public static function instance() {
40
+ if ( is_null( self::$_instance ) ) {
41
+ self::$_instance = new self();
42
+ }
43
+ return self::$_instance;
44
+ }
45
+
46
+ /**
47
+ * Constructor
48
+ */
49
+ public function __construct() {
50
+
51
+ // Show/hide products
52
+ add_filter( 'aws_search_query_array', array( $this, 'search_query_array' ), 1 );
53
+
54
+ // Show/hide categories
55
+ add_filter( 'aws_terms_search_query', array( $this, 'terms_search_query' ), 1, 2 );
56
+
57
+ }
58
+
59
+
60
+ /*
61
+ * Filter products search results
62
+ */
63
+ public function search_query_array( $query ) {
64
+
65
+ $filter = $this->get_filtered_terms();
66
+
67
+ if ( isset( $filter['terms'] ) && ! empty( $filter['terms'] ) ) {
68
+
69
+ $query['search'] .= sprintf( ' AND ( term_id NOT IN ( %s ) )', implode( ',', $filter['terms'] ) );
70
+
71
+ }
72
+
73
+ return $query;
74
+
75
+ }
76
+
77
+ /*
78
+ * Filter categories search results
79
+ */
80
+ public function terms_search_query( $sql, $taxonomy ) {
81
+
82
+ global $wpdb;
83
+
84
+ $filter = $this->get_filtered_terms();
85
+
86
+ if ( isset( $filter['terms'] ) && ! empty( $filter['terms'] ) ) {
87
+ $sql_terms = "AND $wpdb->term_taxonomy.term_id NOT IN ( " . implode( ',', $filter['terms'] ) . " )";
88
+ $sql = str_replace( 'WHERE 1 = 1', 'WHERE 1 = 1 ' . $sql_terms, $sql );
89
+ }
90
+
91
+ return $sql;
92
+
93
+ }
94
+
95
+ /*
96
+ * Get filtered products/terms
97
+ */
98
+ private function get_filtered_terms() {
99
+
100
+ if ( isset( $this->data['filtered'] ) && is_array( $this->data['filtered'] ) ) {
101
+ return $this->data['filtered'];
102
+ }
103
+
104
+ $filtered = array();
105
+ $hidden_categories = array();
106
+
107
+ if ( class_exists( '\Barn2\Plugin\WC_Protected_Categories\Util' ) ) {
108
+ $show_protected = \Barn2\Plugin\WC_Protected_Categories\Util::showing_protected_categories();
109
+ foreach ( \Barn2\Plugin\WC_Protected_Categories\Util::to_category_visibilities( \Barn2\Plugin\WC_Protected_Categories\Util::get_product_categories() ) as $category ) {
110
+ if ( $category->is_private() || ( ! $show_protected && $category->is_protected() ) ) {
111
+ $hidden_categories[] = $category->get_term_id();
112
+ }
113
+ }
114
+ } elseif ( class_exists('WC_PPC_Util') ) {
115
+ $show_protected = WC_PPC_Util::showing_protected_categories();
116
+ foreach (WC_PPC_Util::to_category_visibilities(WC_PPC_Util::get_product_categories()) as $category) {
117
+ if ($category->is_private() || (!$show_protected && $category->is_protected())) {
118
+ $hidden_categories[] = $category->term_id;
119
+ }
120
+ }
121
+ }
122
+
123
+ $filtered['terms'] = $hidden_categories;
124
+
125
+ $this->data['filtered'] = $filtered;
126
+
127
+ return $filtered;
128
+
129
+ }
130
+
131
+ }
132
+
133
+ endif;
134
+
135
+ AWL_Barn2PC::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.40
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -167,6 +167,10 @@ Yep. This plugin is always compatible with the latest version of Woocommerce?
167
 
168
  == Changelog ==
169
 
 
 
 
 
170
  = 2.40 ( 2021-11-10 ) =
171
  * Fix - Bug with condition function
172
 
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
 
168
  == Changelog ==
169
 
170
+ = 2.41 ( 2021-11-22 ) =
171
+ * Add - Support for WooCommerce Protected Categories plugin
172
+ * Fix - JS seamless integration issue
173
+
174
  = 2.40 ( 2021-11-10 ) =
175
  * Fix - Bug with condition function
176