Advanced Woo Search - Version 1.27

Version Description

  • Add option to show stock status in search results
  • Add 'aws_special_chars' filter
Download this release

Release Info

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

Code changes from version 1.26 to 1.27

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: 1.26
7
  Author: ILLID
8
  Author URI: https://advanced-woo-search.com/
9
  Text Domain: aws
@@ -14,7 +14,7 @@ if ( ! defined( 'ABSPATH' ) ) {
14
  exit;
15
  }
16
 
17
- define( 'AWS_VERSION', '1.26' );
18
 
19
 
20
  define( 'AWS_DIR', dirname( __FILE__ ) );
3
  /*
4
  Plugin Name: Advanced Woo Search
5
  Description: Advance ajax WooCommerce product search.
6
+ Version: 1.27
7
  Author: ILLID
8
  Author URI: https://advanced-woo-search.com/
9
  Text Domain: aws
14
  exit;
15
  }
16
 
17
+ define( 'AWS_VERSION', '1.27' );
18
 
19
 
20
  define( 'AWS_DIR', dirname( __FILE__ ) );
assets/css/common.css CHANGED
@@ -90,7 +90,6 @@
90
  display: block;
91
  cursor: pointer;
92
  padding: 10px 8px;
93
- width: 100%;
94
  height: 100%;
95
  overflow: hidden;
96
  text-decoration: none;
@@ -113,6 +112,17 @@
113
  color: #21759b;
114
  }
115
 
 
 
 
 
 
 
 
 
 
 
 
116
  .aws-search-result .aws_result_sku {
117
  display: block;
118
  font-weight: normal;
90
  display: block;
91
  cursor: pointer;
92
  padding: 10px 8px;
 
93
  height: 100%;
94
  overflow: hidden;
95
  text-decoration: none;
112
  color: #21759b;
113
  }
114
 
115
+ .aws-search-result .aws_result_stock {
116
+ display: block;
117
+ font-weight: normal;
118
+ margin-top: 4px;
119
+ margin-bottom: 5px;
120
+ color: #7ad03a;
121
+ }
122
+ .aws-search-result .aws_result_stock.out {
123
+ color: #a44;
124
+ }
125
+
126
  .aws-search-result .aws_result_sku {
127
  display: block;
128
  font-weight: normal;
assets/js/common.js CHANGED
@@ -17,7 +17,7 @@
17
 
18
  $('body').append('<div id="aws-search-result-' + instance + '" class="aws-search-result" style="display: none;"></div>');
19
 
20
- setTimeout(function() { methods.resultLayout(); }, 500)
21
 
22
  },
23
 
@@ -25,7 +25,7 @@
25
 
26
  searchFor = $searchField.val();
27
  searchFor = searchFor.trim();
28
- searchFor = searchFor.replace( /[`~!@#$%^&*()\-_|+\?;:'",.<>\{\}\[\]\\\/]/gi, '' );
29
  searchFor = searchFor.replace( /\s\s+/g, ' ' );
30
 
31
  for ( var i = 0; i < requests.length; i++ ) {
@@ -142,6 +142,13 @@
142
 
143
  html += '<span class="aws_result_content">';
144
  html += '<span class="aws_result_title">' + result.title + '</span>';
 
 
 
 
 
 
 
145
 
146
  if ( result.sku ) {
147
  html += '<span class="aws_result_sku">SKU: ' + result.sku + '</span>';
17
 
18
  $('body').append('<div id="aws-search-result-' + instance + '" class="aws-search-result" style="display: none;"></div>');
19
 
20
+ setTimeout(function() { methods.resultLayout(); }, 500);
21
 
22
  },
23
 
25
 
26
  searchFor = $searchField.val();
27
  searchFor = searchFor.trim();
28
+ searchFor = searchFor.replace( /<>\{\}\[\]\\\/]/gi, '' );
29
  searchFor = searchFor.replace( /\s\s+/g, ' ' );
30
 
31
  for ( var i = 0; i < requests.length; i++ ) {
142
 
143
  html += '<span class="aws_result_content">';
144
  html += '<span class="aws_result_title">' + result.title + '</span>';
145
+
146
+ if ( result.stock_status ) {
147
+ var statusClass = result.stock_status.status ? 'in' : 'out';
148
+ html += '<span class="aws_result_stock ' + statusClass + '">';
149
+ html += result.stock_status.text;
150
+ html += '</span>';
151
+ }
152
 
153
  if ( result.sku ) {
154
  html += '<span class="aws_result_sku">SKU: ' + result.sku + '</span>';
includes/class-aws-helpers.php CHANGED
@@ -60,6 +60,49 @@ if ( ! class_exists( 'AWS_Helpers' ) ) :
60
  return $indexed_products;
61
 
62
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
 
64
  }
65
 
60
  return $indexed_products;
61
 
62
  }
63
+
64
+ /*
65
+ * Get special characters that must be striped
66
+ */
67
+ static public function get_special_chars() {
68
+
69
+ $chars = array(
70
+ '-',
71
+ '_',
72
+ '|',
73
+ '+',
74
+ '`',
75
+ '~',
76
+ '!',
77
+ '@',
78
+ '#',
79
+ '$',
80
+ '%',
81
+ '^',
82
+ '&',
83
+ '*',
84
+ '(',
85
+ ')',
86
+ '\\',
87
+ '?',
88
+ ';',
89
+ ':',
90
+ "'",
91
+ '"',
92
+ ".",
93
+ ",",
94
+ "<",
95
+ ">",
96
+ "{",
97
+ "}",
98
+ "/",
99
+ "[",
100
+ "]",
101
+ );
102
+
103
+ return apply_filters( 'aws_special_chars', $chars );
104
+
105
+ }
106
 
107
  }
108
 
includes/class-aws-search-page.php CHANGED
@@ -96,7 +96,8 @@ if ( ! class_exists( 'AWS_Search_Page' ) ) :
96
 
97
  $new_posts = array();
98
 
99
- $search_query = str_replace( array( '.', '`', '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '_', '|', '+', '\\', '?', ';', ':', '"', ',', '<', '>', '{', '}', '/' ), '', $query->query_vars['s'] );
 
100
  $posts_array = aws_search( $search_query );
101
 
102
  $query->found_posts = count( $posts_array['products'] );
96
 
97
  $new_posts = array();
98
 
99
+ $search_query = $query->query_vars['s'];
100
+
101
  $posts_array = aws_search( $search_query );
102
 
103
  $query->found_posts = count( $posts_array['products'] );
includes/class-aws-search.php CHANGED
@@ -48,7 +48,18 @@ if ( ! class_exists( 'AWS_Search' ) ) :
48
  add_action( 'wp_ajax_nopriv_aws_action', array( $this, 'action_callback' ) );
49
 
50
  }
 
 
 
 
 
 
 
51
 
 
 
 
 
52
  /**
53
  * Get caching option name
54
  */
@@ -72,10 +83,12 @@ if ( ! class_exists( 'AWS_Search' ) ) :
72
  global $wpdb;
73
 
74
  $cache = AWS()->get_settings( 'cache' );
 
75
 
76
  $s = $keyword ? esc_attr( $keyword ) : esc_attr( $_POST['keyword'] );
77
  $s = stripslashes( $s );
78
  $s = str_replace( array( "\r", "\n" ), '', $s );
 
79
 
80
  $cache_option_name = $this->get_cache_name( $s );
81
 
@@ -142,17 +155,6 @@ if ( ! class_exists( 'AWS_Search' ) ) :
142
 
143
  }
144
 
145
- /*
146
- * AJAX call action callback
147
- */
148
- public function action_callback() {
149
-
150
- echo json_encode( $this->search() );
151
-
152
- die;
153
-
154
- }
155
-
156
  /*
157
  * Query in index table
158
  */
@@ -354,6 +356,8 @@ if ( ! class_exists( 'AWS_Search' ) ) :
354
  $show_sale = AWS()->get_settings( 'show_sale' );
355
  $show_image = AWS()->get_settings( 'show_image' );
356
  $show_sku = AWS()->get_settings( 'show_sku' );
 
 
357
 
358
  foreach ( $posts_ids as $post_id ) {
359
 
@@ -368,11 +372,12 @@ if ( ! class_exists( 'AWS_Search' ) ) :
368
  $title = $product->get_title();
369
  $title = AWS_Helpers::html2txt( $title );
370
 
371
- $excerpt = '';
372
- $price = '';
373
- $on_sale = '';
374
- $image = '';
375
- $sku = '';
 
376
 
377
  if ( $show_excerpt === 'true' ) {
378
  $excerpt = ( $excerpt_source === 'excerpt' && $post_data->post_excerpt ) ? $post_data->post_excerpt : $post_data->post_content;
@@ -409,19 +414,34 @@ if ( ! class_exists( 'AWS_Search' ) ) :
409
  if ( $show_sku === 'true' ) {
410
  $sku = $product->get_sku();
411
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
412
 
413
  // $categories = $product->get_categories( ',' );
414
  // $tags = $product->get_tags( ',' );
415
 
416
  $new_result = array(
417
- 'title' => $title,
418
- 'excerpt' => $excerpt,
419
- 'link' => get_permalink( $post_id ),
420
- 'image' => $image,
421
- 'price' => $price,
422
- 'on_sale' => $on_sale,
423
- 'sku' => $sku,
424
- 'post_data' => $post_data
 
425
  );
426
 
427
  $products_array[] = $new_result;
48
  add_action( 'wp_ajax_nopriv_aws_action', array( $this, 'action_callback' ) );
49
 
50
  }
51
+
52
+ /*
53
+ * AJAX call action callback
54
+ */
55
+ public function action_callback() {
56
+
57
+ echo json_encode( $this->search() );
58
 
59
+ die;
60
+
61
+ }
62
+
63
  /**
64
  * Get caching option name
65
  */
83
  global $wpdb;
84
 
85
  $cache = AWS()->get_settings( 'cache' );
86
+ $special_chars = AWS_Helpers::get_special_chars();
87
 
88
  $s = $keyword ? esc_attr( $keyword ) : esc_attr( $_POST['keyword'] );
89
  $s = stripslashes( $s );
90
  $s = str_replace( array( "\r", "\n" ), '', $s );
91
+ $s = str_replace( $special_chars, '', $s );
92
 
93
  $cache_option_name = $this->get_cache_name( $s );
94
 
155
 
156
  }
157
 
 
 
 
 
 
 
 
 
 
 
 
158
  /*
159
  * Query in index table
160
  */
356
  $show_sale = AWS()->get_settings( 'show_sale' );
357
  $show_image = AWS()->get_settings( 'show_image' );
358
  $show_sku = AWS()->get_settings( 'show_sku' );
359
+ $show_stock_status = AWS()->get_settings( 'show_stock' );
360
+
361
 
362
  foreach ( $posts_ids as $post_id ) {
363
 
372
  $title = $product->get_title();
373
  $title = AWS_Helpers::html2txt( $title );
374
 
375
+ $excerpt = '';
376
+ $price = '';
377
+ $on_sale = '';
378
+ $image = '';
379
+ $sku = '';
380
+ $stock_status = '';
381
 
382
  if ( $show_excerpt === 'true' ) {
383
  $excerpt = ( $excerpt_source === 'excerpt' && $post_data->post_excerpt ) ? $post_data->post_excerpt : $post_data->post_content;
414
  if ( $show_sku === 'true' ) {
415
  $sku = $product->get_sku();
416
  }
417
+
418
+ if ( $show_stock_status === 'true' ) {
419
+ if ( $product->is_in_stock() ) {
420
+ $stock_status = array(
421
+ 'status' => true,
422
+ 'text' => __( 'In stock', 'aws' )
423
+ );
424
+ } else {
425
+ $stock_status = array(
426
+ 'status' => false,
427
+ 'text' => __( 'Out of stock', 'aws' )
428
+ );
429
+ }
430
+ }
431
 
432
  // $categories = $product->get_categories( ',' );
433
  // $tags = $product->get_tags( ',' );
434
 
435
  $new_result = array(
436
+ 'title' => $title,
437
+ 'excerpt' => $excerpt,
438
+ 'link' => get_permalink( $post_id ),
439
+ 'image' => $image,
440
+ 'price' => $price,
441
+ 'on_sale' => $on_sale,
442
+ 'sku' => $sku,
443
+ 'stock_status' => $stock_status,
444
+ 'post_data' => $post_data
445
  );
446
 
447
  $products_array[] = $new_result;
includes/class-aws-table.php CHANGED
@@ -523,40 +523,9 @@ if ( ! class_exists( 'AWS_Table' ) ) :
523
 
524
  // Avoid single A-Z.
525
  //$str = preg_replace( '/\b\w{1}\b/i', " ", $str );
526
-
527
- $str = str_replace( array(
528
- '-',
529
- '_',
530
- '|',
531
- '+',
532
- '`',
533
- '~',
534
- '!',
535
- '@',
536
- '#',
537
- '$',
538
- '%',
539
- '^',
540
- '&',
541
- '*',
542
- '(',
543
- ')',
544
- '\\',
545
- '?',
546
- ';',
547
- ':',
548
- "'",
549
- '"',
550
- ".",
551
- ",",
552
- "<",
553
- ">",
554
- "{",
555
- "}",
556
- "/",
557
- "[",
558
- "]",
559
- ), "", $str );
560
 
561
  $str = str_replace( array(
562
  "ˇ",
@@ -620,21 +589,6 @@ if ( ! class_exists( 'AWS_Table' ) ) :
620
 
621
  }
622
 
623
- /*
624
- * Removes scripts, styles, html tags
625
- */
626
- private function html2txt( $str ) {
627
- $search = array(
628
- '@<script[^>]*?>.*?</script>@si',
629
- '@<[\/\!]*?[^<>]*?>@si',
630
- '@<style[^>]*?>.*?</style>@siU',
631
- '@<![\s\S]*?--[ \t\n\r]*>@'
632
- );
633
- $text = preg_replace( $search, '', $str );
634
-
635
- return $text;
636
- }
637
-
638
  /*
639
  * Get string with current product terms ids
640
  *
523
 
524
  // Avoid single A-Z.
525
  //$str = preg_replace( '/\b\w{1}\b/i', " ", $str );
526
+
527
+ $special_cars = AWS_Helpers::get_special_chars();
528
+ $str = str_replace( $special_cars, "", $str );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
529
 
530
  $str = str_replace( array(
531
  "ˇ",
589
 
590
  }
591
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
592
  /*
593
  * Get string with current product terms ids
594
  *
includes/class-aws-versions.php CHANGED
@@ -104,6 +104,19 @@ if ( ! class_exists( 'AWS_Versions' ) ) :
104
  }
105
 
106
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
107
 
108
  }
109
 
104
  }
105
 
106
  }
107
+
108
+ if ( version_compare( $current_version, '1.27', '<' ) ) {
109
+
110
+ $settings = get_option( 'aws_settings' );
111
+
112
+ if ( $settings ) {
113
+ if ( ! isset( $settings['show_stock'] ) ) {
114
+ $settings['show_stock'] = 'false';
115
+ update_option( 'aws_settings', $settings );
116
+ }
117
+ }
118
+
119
+ }
120
 
121
  }
122
 
includes/options.php CHANGED
@@ -225,6 +225,19 @@ $options['results'][] = array(
225
  )
226
  );
227
 
 
 
 
 
 
 
 
 
 
 
 
 
 
228
  $options['results'][] = array(
229
  "name" => __( "Max number of results", "aws" ),
230
  "desc" => __( "Maximum number of displayed search results.", "aws" ),
225
  )
226
  );
227
 
228
+
229
+ $options['results'][] = array(
230
+ "name" => __( "Show stock status", "aws" ),
231
+ "desc" => __( "Show stock status for every product in search results.", "aws" ),
232
+ "id" => "show_stock",
233
+ "value" => 'false',
234
+ "type" => "radio",
235
+ 'choices' => array(
236
+ 'true' => __( 'On', 'aws' ),
237
+ 'false' => __( 'Off', 'aws' ),
238
+ )
239
+ );
240
+
241
  $options['results'][] = array(
242
  "name" => __( "Max number of results", "aws" ),
243
  "desc" => __( "Maximum number of displayed search results.", "aws" ),
languages/aws.pot CHANGED
@@ -271,6 +271,12 @@ msgstr ""
271
  msgid "Show product SKU in search results."
272
  msgstr ""
273
 
 
 
 
 
 
 
274
  #: includes/options.php:167
275
  msgid "Max number of results"
276
  msgstr ""
@@ -316,6 +322,12 @@ msgstr ""
316
  msgid "Will send event with category - 'AWS search', action - 'AWS Search Term' and label of value of search term."
317
  msgstr ""
318
 
 
 
 
 
 
 
319
  #. Name of the plugin
320
  msgid "Advanced Woo Search"
321
  msgstr ""
271
  msgid "Show product SKU in search results."
272
  msgstr ""
273
 
274
+ msgid "Show stock status"
275
+ msgstr ""
276
+
277
+ msgid "Show stock status for every product in search results."
278
+ msgstr ""
279
+
280
  #: includes/options.php:167
281
  msgid "Max number of results"
282
  msgstr ""
322
  msgid "Will send event with category - 'AWS search', action - 'AWS Search Term' and label of value of search term."
323
  msgstr ""
324
 
325
+ msgid "In stock"
326
+ msgstr ""
327
+
328
+ msgid "Out of stock"
329
+ msgstr ""
330
+
331
  #. Name of the plugin
332
  msgid "Advanced Woo Search"
333
  msgstr ""
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: 4.8.3
7
- Stable tag: 1.26
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -75,6 +75,10 @@ Yep. This plugin is always compatible with the latest version of Woocommerce?
75
 
76
  == Changelog ==
77
 
 
 
 
 
78
  = 1.26 =
79
  * Add Polylang plugin support
80
 
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: 4.9
7
+ Stable tag: 1.27
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
75
 
76
  == Changelog ==
77
 
78
+ = 1.27 =
79
+ * Add option to show stock status in search results
80
+ * Add 'aws_special_chars' filter
81
+
82
  = 1.26 =
83
  * Add Polylang plugin support
84