Advanced Woo Search - Version 1.22

Version Description

  • Fix reindex bug
  • Hide empty taxonomies from search results
  • Add support for old WooCommerce versions
Download this release

Release Info

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

Code changes from version 1.21 to 1.22

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.21
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.21' );
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.22
7
  Author: ILLID
8
  Author URI: https://advanced-woo-search.com/
9
  Text Domain: aws
14
  exit;
15
  }
16
 
17
+ define( 'AWS_VERSION', '1.22' );
18
 
19
 
20
  define( 'AWS_DIR', dirname( __FILE__ ) );
assets/js/admin.js CHANGED
@@ -4,6 +4,7 @@ jQuery(document).ready(function ($) {
4
  var $reindexBlock = $('#aws-reindex');
5
  var $reindexBtn = $('#aws-reindex .button');
6
  var $reindexProgress = $('#aws-reindex .reindex-progress');
 
7
  var syncStatus = 'sync';
8
  var processed = 0;
9
  var toProcess = 0;
@@ -43,7 +44,7 @@ jQuery(document).ready(function ($) {
43
 
44
  processed = Math.floor( processed / toProcess * 100 );
45
 
46
- if ( 0 === response.data.found_posts && ! response.data.start ) {
47
 
48
  // Sync finished
49
  syncStatus = 'finished';
@@ -52,6 +53,8 @@ jQuery(document).ready(function ($) {
52
 
53
  $reindexBlock.removeClass('loading');
54
 
 
 
55
  } else {
56
 
57
  console.log( response.data );
4
  var $reindexBlock = $('#aws-reindex');
5
  var $reindexBtn = $('#aws-reindex .button');
6
  var $reindexProgress = $('#aws-reindex .reindex-progress');
7
+ var $reindexCount = $('#aws-reindex-count strong');
8
  var syncStatus = 'sync';
9
  var processed = 0;
10
  var toProcess = 0;
44
 
45
  processed = Math.floor( processed / toProcess * 100 );
46
 
47
+ if ( 0 === response.data.offset && ! response.data.start ) {
48
 
49
  // Sync finished
50
  syncStatus = 'finished';
53
 
54
  $reindexBlock.removeClass('loading');
55
 
56
+ $reindexCount.text( response.data.found_posts );
57
+
58
  } else {
59
 
60
  console.log( response.data );
includes/class-aws-admin.php CHANGED
@@ -357,7 +357,7 @@ class AWS_Admin {
357
  echo '<div id="aws-reindex"><input class="button" type="button" value="' . __( 'Reindex table', 'aws' ) . '"><span class="loader"></span><span class="reindex-progress">0%</span></div><br><br>';
358
  echo '<span class="description">' .
359
  __( 'Update all data in plugins index table. Index table - table with products data where plugin is searching all typed terms.<br>Use this button if you think that plugin not shows last actual data in its search results.<br><strong>CAUTION:</strong> this can take large amount of time.', 'aws' ) . '<br><br>' .
360
- __( 'Products in index:', 'aws' ) . '<strong> ' . AWS_Helpers::get_indexed_products_count() . '</strong>';
361
  echo '</span>';
362
  echo '</td>';
363
 
357
  echo '<div id="aws-reindex"><input class="button" type="button" value="' . __( 'Reindex table', 'aws' ) . '"><span class="loader"></span><span class="reindex-progress">0%</span></div><br><br>';
358
  echo '<span class="description">' .
359
  __( 'Update all data in plugins index table. Index table - table with products data where plugin is searching all typed terms.<br>Use this button if you think that plugin not shows last actual data in its search results.<br><strong>CAUTION:</strong> this can take large amount of time.', 'aws' ) . '<br><br>' .
360
+ __( 'Products in index:', 'aws' ) . '<span id="aws-reindex-count"> <strong>' . AWS_Helpers::get_indexed_products_count() . '</strong></span>';
361
  echo '</span>';
362
  echo '</td>';
363
 
includes/class-aws-search.php CHANGED
@@ -347,6 +347,10 @@ if ( ! class_exists( 'AWS_Search' ) ) :
347
 
348
  $product = wc_get_product( $post_id );
349
 
 
 
 
 
350
  $post_data = get_post( $post_id );
351
 
352
  $title = $product->get_title();
@@ -557,6 +561,10 @@ if ( ! class_exists( 'AWS_Search' ) ) :
557
 
558
  foreach ( $search_results as $result ) {
559
 
 
 
 
 
560
  if ( function_exists( 'wpml_object_id_filter' ) ) {
561
  $term = wpml_object_id_filter( $result->term_id, $result->taxonomy );
562
  if ( $term != $result->term_id ) {
347
 
348
  $product = wc_get_product( $post_id );
349
 
350
+ if( ! is_a( $product, 'WC_Product' ) ) {
351
+ continue;
352
+ }
353
+
354
  $post_data = get_post( $post_id );
355
 
356
  $title = $product->get_title();
561
 
562
  foreach ( $search_results as $result ) {
563
 
564
+ if ( ! $result->count > 0 ) {
565
+ continue;
566
+ }
567
+
568
  if ( function_exists( 'wpml_object_id_filter' ) ) {
569
  $term = wpml_object_id_filter( $result->term_id, $result->taxonomy );
570
  if ( $term != $result->term_id ) {
includes/class-aws-table.php CHANGED
@@ -66,6 +66,8 @@ if ( ! class_exists( 'AWS_Table' ) ) :
66
 
67
  $this->create_table();
68
 
 
 
69
  } else if ( ! empty( $index_meta['site_stack'] ) && $index_meta['offset'] >= $index_meta['found_posts'] ) {
70
  $status = 'start';
71
 
@@ -77,7 +79,7 @@ if ( ! class_exists( 'AWS_Table' ) ) :
77
  }
78
 
79
  $index_meta = apply_filters( 'aws_index_meta', $index_meta );
80
- $posts_per_page = apply_filters( 'aws_index_posts_per_page', 100 );
81
 
82
 
83
  $args = array(
@@ -96,11 +98,10 @@ if ( ! class_exists( 'AWS_Table' ) ) :
96
 
97
  $posts = get_posts( $args );
98
 
99
- $index_meta['found_posts'] = count( $posts );
100
-
101
  if ( $status !== 'start' ) {
102
 
103
  if ( $posts && count( $posts ) > 0 ) {
 
104
  $queued_posts = array();
105
 
106
  foreach( $posts as $post_id ) {
@@ -140,6 +141,36 @@ if ( ! class_exists( 'AWS_Table' ) ) :
140
 
141
  }
142
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
  /*
144
  * Check if index table exist
145
  */
@@ -189,10 +220,15 @@ if ( ! class_exists( 'AWS_Table' ) ) :
189
  $data['id'] = $found_post_id;
190
 
191
  $product = wc_get_product( $data['id'] );
 
 
 
 
 
192
  $lang = has_filter( 'wpml_post_language_details' ) ? apply_filters( 'wpml_post_language_details', NULL, $data['id'] ) : '';
193
 
194
- $data['in_stock'] = ( $product->get_stock_status() === 'outofstock' ) ? 0 : 1;
195
- $data['visibility'] = $product->get_catalog_visibility() ? $product->get_catalog_visibility() : ( $product->get_visibility() ? $product->get_visibility() : 'visible' );
196
  $data['lang'] = $lang ? $lang['language_code'] : '';
197
 
198
  $sku = $product->get_sku();
66
 
67
  $this->create_table();
68
 
69
+ $index_meta['found_posts'] = $this->get_number_of_products();
70
+
71
  } else if ( ! empty( $index_meta['site_stack'] ) && $index_meta['offset'] >= $index_meta['found_posts'] ) {
72
  $status = 'start';
73
 
79
  }
80
 
81
  $index_meta = apply_filters( 'aws_index_meta', $index_meta );
82
+ $posts_per_page = apply_filters( 'aws_index_posts_per_page', 50 );
83
 
84
 
85
  $args = array(
98
 
99
  $posts = get_posts( $args );
100
 
 
 
101
  if ( $status !== 'start' ) {
102
 
103
  if ( $posts && count( $posts ) > 0 ) {
104
+
105
  $queued_posts = array();
106
 
107
  foreach( $posts as $post_id ) {
141
 
142
  }
143
 
144
+ /*
145
+ * Get total number of products
146
+ */
147
+ private function get_number_of_products() {
148
+
149
+ $args = array(
150
+ 'posts_per_page' => -1,
151
+ 'fields' => 'ids',
152
+ 'post_type' => 'product',
153
+ 'post_status' => 'publish',
154
+ 'ignore_sticky_posts' => true,
155
+ 'suppress_filters' => true,
156
+ 'no_found_rows' => 1,
157
+ 'orderby' => 'ID',
158
+ 'order' => 'DESC',
159
+ );
160
+
161
+
162
+ $posts = get_posts( $args );
163
+
164
+ if ( $posts && count( $posts ) > 0 ) {
165
+ $count = count( $posts );
166
+ } else {
167
+ $count = 0;
168
+ }
169
+
170
+ return $count;
171
+
172
+ }
173
+
174
  /*
175
  * Check if index table exist
176
  */
220
  $data['id'] = $found_post_id;
221
 
222
  $product = wc_get_product( $data['id'] );
223
+
224
+ if( ! is_a( $product, 'WC_Product' ) ) {
225
+ continue;
226
+ }
227
+
228
  $lang = has_filter( 'wpml_post_language_details' ) ? apply_filters( 'wpml_post_language_details', NULL, $data['id'] ) : '';
229
 
230
+ $data['in_stock'] = method_exists( $product, 'get_stock_status' ) ? ( ( $product->get_stock_status() === 'outofstock' ) ? 0 : 1 ) : ( method_exists( $product, 'is_in_stock' ) ? $product->is_in_stock() : 1 );
231
+ $data['visibility'] = method_exists( $product, 'get_catalog_visibility' ) ? $product->get_catalog_visibility() : ( method_exists( $product, 'get_visibility' ) ? $product->get_visibility() : 'visible' );
232
  $data['lang'] = $lang ? $lang['language_code'] : '';
233
 
234
  $sku = $product->get_sku();
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
7
- Stable tag: 1.21
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -74,6 +74,11 @@ Yep. This plugin is always compatible with the latest version of Woocommerce?
74
 
75
  == Changelog ==
76
 
 
 
 
 
 
77
  = 1.21 =
78
  * Fix search page switching to degault language
79
 
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.1
7
+ Stable tag: 1.22
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
74
 
75
  == Changelog ==
76
 
77
+ = 1.22 =
78
+ * Fix reindex bug
79
+ * Hide empty taxonomies from search results
80
+ * Add support for old WooCommerce versions
81
+
82
  = 1.21 =
83
  * Fix search page switching to degault language
84