Advanced Woo Search - Version 1.89

Version Description

  • Add - Highlight option
  • Fix - Index method bug
Download this release

Release Info

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

Code changes from version 1.88 to 1.89

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.88
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', '1.88' );
20
 
21
 
22
  define( 'AWS_DIR', dirname( __FILE__ ) );
3
  /*
4
  Plugin Name: Advanced Woo Search
5
  Description: Advance ajax WooCommerce product search.
6
+ Version: 1.89
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', '1.89' );
20
 
21
 
22
  define( 'AWS_DIR', dirname( __FILE__ ) );
includes/admin/class-aws-admin-options.php CHANGED
@@ -358,6 +358,18 @@ if ( ! class_exists( 'AWS_Admin_Options' ) ) :
358
  )
359
  );
360
 
 
 
 
 
 
 
 
 
 
 
 
 
361
  $options['results'][] = array(
362
  "name" => __( "Description length", "advanced-woo-search" ),
363
  "desc" => __( "Maximal allowed number of words for product description.", "advanced-woo-search" ),
@@ -380,9 +392,9 @@ if ( ! class_exists( 'AWS_Admin_Options' ) ) :
380
  );
381
 
382
  $options['results'][] = array(
383
- "name" => __( "Show image", "advanced-woo-search" ),
384
- "desc" => __( "Show product image for each search result.", "advanced-woo-search" ),
385
- "id" => "show_image",
386
  "value" => 'true',
387
  "type" => "radio",
388
  'choices' => array(
@@ -392,9 +404,9 @@ if ( ! class_exists( 'AWS_Admin_Options' ) ) :
392
  );
393
 
394
  $options['results'][] = array(
395
- "name" => __( "Show description", "advanced-woo-search" ),
396
- "desc" => __( "Show product description for each search result.", "advanced-woo-search" ),
397
- "id" => "show_excerpt",
398
  "value" => 'true',
399
  "type" => "radio",
400
  'choices' => array(
@@ -404,14 +416,14 @@ if ( ! class_exists( 'AWS_Admin_Options' ) ) :
404
  );
405
 
406
  $options['results'][] = array(
407
- "name" => __( "Description content", "advanced-woo-search" ),
408
- "desc" => __( "What to show in product description?", "advanced-woo-search" ),
409
- "id" => "mark_words",
410
  "value" => 'true',
411
  "type" => "radio",
412
  'choices' => array(
413
- 'true' => __( "Smart scrapping sentences with searching terms from product description.", "advanced-woo-search" ),
414
- 'false' => __( "First N words of product description ( number of words that you choose below. )", "advanced-woo-search" ),
415
  )
416
  );
417
 
358
  )
359
  );
360
 
361
+ $options['results'][] = array(
362
+ "name" => __( "Description content", "advanced-woo-search" ),
363
+ "desc" => __( "What to show in product description?", "advanced-woo-search" ),
364
+ "id" => "mark_words",
365
+ "value" => 'true',
366
+ "type" => "radio",
367
+ 'choices' => array(
368
+ 'true' => __( "Smart scrapping sentences with searching terms from product description.", "advanced-woo-search" ),
369
+ 'false' => __( "First N words of product description ( number of words that you choose below. )", "advanced-woo-search" ),
370
+ )
371
+ );
372
+
373
  $options['results'][] = array(
374
  "name" => __( "Description length", "advanced-woo-search" ),
375
  "desc" => __( "Maximal allowed number of words for product description.", "advanced-woo-search" ),
392
  );
393
 
394
  $options['results'][] = array(
395
+ "name" => __( "Highlight words", "advanced-woo-search" ),
396
+ "desc" => __( "Highlight search words inside products content.", "advanced-woo-search" ),
397
+ "id" => "highlight",
398
  "value" => 'true',
399
  "type" => "radio",
400
  'choices' => array(
404
  );
405
 
406
  $options['results'][] = array(
407
+ "name" => __( "Show image", "advanced-woo-search" ),
408
+ "desc" => __( "Show product image for each search result.", "advanced-woo-search" ),
409
+ "id" => "show_image",
410
  "value" => 'true',
411
  "type" => "radio",
412
  'choices' => array(
416
  );
417
 
418
  $options['results'][] = array(
419
+ "name" => __( "Show description", "advanced-woo-search" ),
420
+ "desc" => __( "Show product description for each search result.", "advanced-woo-search" ),
421
+ "id" => "show_excerpt",
422
  "value" => 'true',
423
  "type" => "radio",
424
  'choices' => array(
425
+ 'true' => __( 'On', 'advanced-woo-search' ),
426
+ 'false' => __( 'Off', 'advanced-woo-search' ),
427
  )
428
  );
429
 
includes/class-aws-search.php CHANGED
@@ -483,7 +483,8 @@ if ( ! class_exists( 'AWS_Search' ) ) :
483
  $show_excerpt = AWS()->get_settings( 'show_excerpt' );
484
  $excerpt_source = AWS()->get_settings( 'desc_source' );
485
  $excerpt_length = AWS()->get_settings( 'excerpt_length' );
486
- $mark_search_words = AWS()->get_settings( 'mark_words' );
 
487
  $show_price = AWS()->get_settings( 'show_price' );
488
  $show_outofstockprice = AWS()->get_settings( 'show_outofstock_price' );
489
  $show_sale = AWS()->get_settings( 'show_sale' );
@@ -498,7 +499,9 @@ if ( ! class_exists( 'AWS_Search' ) ) :
498
  $posts_items = wc_get_products( array(
499
  'numberposts' => -1,
500
  'posts_per_page' => -1,
 
501
  'status' => 'publish',
 
502
  'include' => $posts_ids,
503
  'ignore_sticky_posts' => true,
504
  'suppress_filters' => true,
@@ -551,29 +554,30 @@ if ( ! class_exists( 'AWS_Search' ) ) :
551
 
552
 
553
  if ( $show_excerpt === 'true' ) {
 
554
  $excerpt = ( $excerpt_source === 'excerpt' && $post_data->post_excerpt ) ? $post_data->post_excerpt : $post_data->post_content;
555
  $excerpt = AWS_Helpers::html2txt( $excerpt );
556
  $excerpt = str_replace('"', "'", $excerpt);
557
  $excerpt = strip_shortcodes( $excerpt );
558
  $excerpt = AWS_Helpers::strip_shortcodes( $excerpt );
559
- }
560
 
561
- if ( $mark_search_words === 'true' ) {
562
 
563
- $marked_content = $this->mark_search_words( $title, $excerpt );
564
 
565
- $title = $marked_content['title'];
 
 
 
 
566
 
567
- if ( $marked_content['content'] ) {
568
- $excerpt = $marked_content['content'];
569
  } else {
570
  $excerpt = wp_trim_words( $excerpt, $excerpt_length, '...' );
571
  }
572
 
573
- } else {
574
- $excerpt = wp_trim_words( $excerpt, $excerpt_length, '...' );
575
  }
576
 
 
577
  if ( $show_price === 'true' && ( $product->is_in_stock() || ( ! $product->is_in_stock() && $show_outofstockprice === 'true' ) ) ) {
578
  $price = $product->get_price_html();
579
  }
@@ -625,6 +629,12 @@ if ( ! class_exists( 'AWS_Search' ) ) :
625
  // $categories = $product->get_categories( ',' );
626
  // $tags = $product->get_tags( ',' );
627
 
 
 
 
 
 
 
628
  $title = apply_filters( 'aws_title_search_result', $title, $post_id, $product );
629
  $excerpt = apply_filters( 'aws_excerpt_search_result', $excerpt, $post_id, $product );
630
 
@@ -663,25 +673,20 @@ if ( ! class_exists( 'AWS_Search' ) ) :
663
  }
664
 
665
  /*
666
- * Mark search words
667
  */
668
- private function mark_search_words( $title, $content ) {
669
 
670
- $pattern = array();
671
- $exact_pattern = array();
672
  $exact_words = array();
673
  $words = array();
674
 
675
  foreach( $this->data['search_terms'] as $search_in ) {
676
 
677
  $exact_words[] = '\b' . $search_in . '\b';
678
- $exact_pattern[] = '(\b' . $search_in . '\b)+';
679
 
680
  if ( strlen( $search_in ) > 1 ) {
681
- $pattern[] = '(' . $search_in . ')+';
682
  $words[] = $search_in;
683
  } else {
684
- $pattern[] = '\b[' . $search_in . ']{1}\b';
685
  $words[] = '\b' . $search_in . '\b';
686
  }
687
 
@@ -693,15 +698,6 @@ if ( ! class_exists( 'AWS_Search' ) ) :
693
  usort( $words, array( $this, 'sort_by_length' ) );
694
  $words = implode( '|', $words );
695
 
696
- usort( $exact_pattern, array( $this, 'sort_by_length' ) );
697
- $exact_pattern = implode( '|', $exact_pattern );
698
- $exact_pattern = sprintf( '/%s/i', $exact_pattern );
699
-
700
- usort( $pattern, array( $this, 'sort_by_length' ) );
701
- $pattern = implode( '|', $pattern );
702
- $pattern = sprintf( '/%s/i', $pattern );
703
-
704
-
705
  preg_match( '/([^.?!]*?)(' . $exact_words . '){1}(.*?[.!?])/i', $content, $matches );
706
 
707
  if ( ! isset( $matches[0] ) ) {
@@ -733,6 +729,35 @@ if ( ! class_exists( 'AWS_Search' ) ) :
733
 
734
  }
735
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
736
  /**
737
  * Tag to use for highlighting search words inside content
738
  * @since 1.88
@@ -742,13 +767,9 @@ if ( ! class_exists( 'AWS_Search' ) ) :
742
 
743
  $highlight_tag_pattern = '<' . $highlight_tag . '>${0}</' . $highlight_tag . '>';
744
 
745
- $title = preg_replace($pattern, $highlight_tag_pattern, $title );
746
- $content = preg_replace( $pattern, $highlight_tag_pattern, $content );
747
 
748
- return array(
749
- 'title' => $title,
750
- 'content' => $content
751
- );
752
 
753
  }
754
 
483
  $show_excerpt = AWS()->get_settings( 'show_excerpt' );
484
  $excerpt_source = AWS()->get_settings( 'desc_source' );
485
  $excerpt_length = AWS()->get_settings( 'excerpt_length' );
486
+ $desc_scrap_words = AWS()->get_settings( 'mark_words' );
487
+ $highlight_words = AWS()->get_settings( 'highlight' );
488
  $show_price = AWS()->get_settings( 'show_price' );
489
  $show_outofstockprice = AWS()->get_settings( 'show_outofstock_price' );
490
  $show_sale = AWS()->get_settings( 'show_sale' );
499
  $posts_items = wc_get_products( array(
500
  'numberposts' => -1,
501
  'posts_per_page' => -1,
502
+ 'limit' => -1,
503
  'status' => 'publish',
504
+ 'post_status' => 'publish',
505
  'include' => $posts_ids,
506
  'ignore_sticky_posts' => true,
507
  'suppress_filters' => true,
554
 
555
 
556
  if ( $show_excerpt === 'true' ) {
557
+
558
  $excerpt = ( $excerpt_source === 'excerpt' && $post_data->post_excerpt ) ? $post_data->post_excerpt : $post_data->post_content;
559
  $excerpt = AWS_Helpers::html2txt( $excerpt );
560
  $excerpt = str_replace('"', "'", $excerpt);
561
  $excerpt = strip_shortcodes( $excerpt );
562
  $excerpt = AWS_Helpers::strip_shortcodes( $excerpt );
 
563
 
564
+ if ( $desc_scrap_words === 'true' ) {
565
 
566
+ $marked_content = $this->scrap_content( $excerpt );
567
 
568
+ if ( $marked_content ) {
569
+ $excerpt = $marked_content;
570
+ } else {
571
+ $excerpt = wp_trim_words( $excerpt, $excerpt_length, '...' );
572
+ }
573
 
 
 
574
  } else {
575
  $excerpt = wp_trim_words( $excerpt, $excerpt_length, '...' );
576
  }
577
 
 
 
578
  }
579
 
580
+
581
  if ( $show_price === 'true' && ( $product->is_in_stock() || ( ! $product->is_in_stock() && $show_outofstockprice === 'true' ) ) ) {
582
  $price = $product->get_price_html();
583
  }
629
  // $categories = $product->get_categories( ',' );
630
  // $tags = $product->get_tags( ',' );
631
 
632
+ if ( $highlight_words === 'true' ) {
633
+ $title = $this->highlight_words( $title );
634
+ $excerpt = $this->highlight_words( $excerpt );
635
+ $sku = $this->highlight_words( $sku );
636
+ }
637
+
638
  $title = apply_filters( 'aws_title_search_result', $title, $post_id, $product );
639
  $excerpt = apply_filters( 'aws_excerpt_search_result', $excerpt, $post_id, $product );
640
 
673
  }
674
 
675
  /*
676
+ * Scrap content excerpt
677
  */
678
+ private function scrap_content( $content ) {
679
 
 
 
680
  $exact_words = array();
681
  $words = array();
682
 
683
  foreach( $this->data['search_terms'] as $search_in ) {
684
 
685
  $exact_words[] = '\b' . $search_in . '\b';
 
686
 
687
  if ( strlen( $search_in ) > 1 ) {
 
688
  $words[] = $search_in;
689
  } else {
 
690
  $words[] = '\b' . $search_in . '\b';
691
  }
692
 
698
  usort( $words, array( $this, 'sort_by_length' ) );
699
  $words = implode( '|', $words );
700
 
 
 
 
 
 
 
 
 
 
701
  preg_match( '/([^.?!]*?)(' . $exact_words . '){1}(.*?[.!?])/i', $content, $matches );
702
 
703
  if ( ! isset( $matches[0] ) ) {
729
 
730
  }
731
 
732
+ return $content;
733
+
734
+ }
735
+
736
+ /*
737
+ * Highlight search words
738
+ */
739
+ private function highlight_words( $text ) {
740
+
741
+ if ( ! $text ) {
742
+ return $text;
743
+ }
744
+
745
+ $pattern = array();
746
+
747
+ foreach( $this->data['search_terms'] as $search_in ) {
748
+
749
+ if ( strlen( $search_in ) > 1 ) {
750
+ $pattern[] = '(' . $search_in . ')+';
751
+ } else {
752
+ $pattern[] = '\b[' . $search_in . ']{1}\b';
753
+ }
754
+
755
+ }
756
+
757
+ usort( $pattern, array( $this, 'sort_by_length' ) );
758
+ $pattern = implode( '|', $pattern );
759
+ $pattern = sprintf( '/%s/i', $pattern );
760
+
761
  /**
762
  * Tag to use for highlighting search words inside content
763
  * @since 1.88
767
 
768
  $highlight_tag_pattern = '<' . $highlight_tag . '>${0}</' . $highlight_tag . '>';
769
 
770
+ $text = preg_replace($pattern, $highlight_tag_pattern, $text );
 
771
 
772
+ return $text;
 
 
 
773
 
774
  }
775
 
includes/class-aws-table.php CHANGED
@@ -112,43 +112,24 @@ if ( ! class_exists( 'AWS_Table' ) ) :
112
 
113
  $posts = array();
114
 
115
- if ( function_exists( 'wc_get_products' ) ) {
116
-
117
- $posts = wc_get_products( array(
118
- 'numberposts' => $posts_per_page,
119
- 'posts_per_page' => $posts_per_page,
120
- 'status' => 'publish',
121
- 'offset' => $index_meta['offset'],
122
- 'ignore_sticky_posts' => true,
123
- 'suppress_filters' => true,
124
- 'no_found_rows' => 1,
125
- 'orderby' => 'ID',
126
- 'order' => 'DESC',
127
- 'lang' => ''
128
- ));
129
-
130
- } else {
131
-
132
- $queued_posts = get_posts( array(
133
- 'posts_per_page' => $posts_per_page,
134
- 'fields' => 'ids',
135
- 'post_type' => 'product',
136
- 'post_status' => 'publish',
137
- 'offset' => $index_meta['offset'],
138
- 'ignore_sticky_posts' => true,
139
- 'suppress_filters' => true,
140
- 'no_found_rows' => 1,
141
- 'orderby' => 'ID',
142
- 'order' => 'DESC',
143
- 'lang' => ''
144
- ) );
145
-
146
- if ( $queued_posts && count( $queued_posts ) ) {
147
- foreach( $queued_posts as $post_id ) {
148
- $posts[] = absint( $post_id );
149
- }
150
  }
151
-
152
  }
153
 
154
  if ( $posts && count( $posts ) > 0 ) {
112
 
113
  $posts = array();
114
 
115
+ $queued_posts = get_posts( array(
116
+ 'posts_per_page' => $posts_per_page,
117
+ 'fields' => 'ids',
118
+ 'post_type' => 'product',
119
+ 'post_status' => 'publish',
120
+ 'offset' => $index_meta['offset'],
121
+ 'ignore_sticky_posts' => true,
122
+ 'suppress_filters' => true,
123
+ 'no_found_rows' => 1,
124
+ 'orderby' => 'ID',
125
+ 'order' => 'DESC',
126
+ 'lang' => ''
127
+ ) );
128
+
129
+ if ( $queued_posts && count( $queued_posts ) ) {
130
+ foreach( $queued_posts as $post_id ) {
131
+ $posts[] = absint( $post_id );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
  }
 
133
  }
134
 
135
  if ( $posts && count( $posts ) > 0 ) {
includes/class-aws-versions.php CHANGED
@@ -283,6 +283,20 @@ if ( ! class_exists( 'AWS_Versions' ) ) :
283
 
284
  }
285
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
286
  }
287
 
288
  update_option( 'aws_plugin_ver', AWS_VERSION );
283
 
284
  }
285
 
286
+ if ( version_compare( $current_version, '1.89', '<' ) ) {
287
+
288
+ $settings = get_option( 'aws_settings' );
289
+
290
+ if ( $settings ) {
291
+ if ( ! isset( $settings['highlight'] ) && isset( $settings['mark_words'] ) ) {
292
+ $mark_words = $settings['mark_words'];
293
+ $settings['highlight'] = $mark_words;
294
+ update_option( 'aws_settings', $settings );
295
+ }
296
+ }
297
+
298
+ }
299
+
300
  }
301
 
302
  update_option( 'aws_plugin_ver', AWS_VERSION );
languages/advanced-woo-search.pot CHANGED
@@ -265,6 +265,12 @@ msgstr ""
265
  msgid "Filter button will be visible only if you have more than one active filter for current search form instance."
266
  msgstr ""
267
 
 
 
 
 
 
 
268
  #: includes/options.php:49
269
  msgid "Show image"
270
  msgstr ""
265
  msgid "Filter button will be visible only if you have more than one active filter for current search form instance."
266
  msgstr ""
267
 
268
+ msgid "Highlight words"
269
+ msgstr ""
270
+
271
+ msgid "Highlight search words inside products content."
272
+ msgstr ""
273
+
274
  #: includes/options.php:49
275
  msgid "Show image"
276
  msgstr ""
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.3
7
- Stable tag: 1.88
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -104,6 +104,10 @@ Yep. This plugin is always compatible with the latest version of Woocommerce?
104
 
105
  == Changelog ==
106
 
 
 
 
 
107
  = 1.88 =
108
  * Add - WooCommerce Product Table plugin support
109
  * Add - aws_highlight_tag filter
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.3
7
+ Stable tag: 1.89
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
104
 
105
  == Changelog ==
106
 
107
+ = 1.89 =
108
+ * Add - Highlight option
109
+ * Fix - Index method bug
110
+
111
  = 1.88 =
112
  * Add - WooCommerce Product Table plugin support
113
  * Add - aws_highlight_tag filter