Advanced Woo Search - Version 2.00

Version Description

  • Update - Search page ordering. Add order by quantity
  • Update - Remove sql query from output
  • Dev - Add aws_products_order filter
Download this release

Release Info

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

Code changes from version 1.99 to 2.00

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.99
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.99' );
20
 
21
 
22
  define( 'AWS_DIR', dirname( __FILE__ ) );
3
  /*
4
  Plugin Name: Advanced Woo Search
5
  Description: Advance ajax WooCommerce product search.
6
+ Version: 2.00
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', '2.00' );
20
 
21
 
22
  define( 'AWS_DIR', dirname( __FILE__ ) );
includes/class-aws-helpers.php CHANGED
@@ -745,6 +745,28 @@ if ( ! class_exists( 'AWS_Helpers' ) ) :
745
 
746
  }
747
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
748
  }
749
 
750
  endif;
745
 
746
  }
747
 
748
+ /**
749
+ * Get product quantity
750
+ * @param object $product Product
751
+ * @return integer
752
+ */
753
+ static public function get_quantity( $product ) {
754
+
755
+ $stock_levels = array();
756
+
757
+ if ( $product->is_type( 'variable' ) ) {
758
+ foreach ( $product->get_children() as $variation ) {
759
+ $var = wc_get_product( $variation );
760
+ $stock_levels[] = $var->get_stock_quantity();
761
+ }
762
+ } else {
763
+ $stock_levels[] = $product->get_stock_quantity();
764
+ }
765
+
766
+ return max( $stock_levels );
767
+
768
+ }
769
+
770
  }
771
 
772
  endif;
includes/class-aws-order.php CHANGED
@@ -330,8 +330,32 @@ if ( ! class_exists( 'AWS_Order' ) ) :
330
 
331
  break;
332
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
333
  }
334
 
 
 
 
 
 
 
 
 
335
  }
336
 
337
  /*
@@ -432,6 +456,60 @@ if ( ! class_exists( 'AWS_Order' ) ) :
432
  return $res;
433
  }
434
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
435
  /*
436
  * Return array of sorted products
437
  */
330
 
331
  break;
332
 
333
+ case 'stock_quantity-asc':
334
+
335
+ if ( isset( $this->products[0]['id'] ) ) {
336
+ usort( $this->products, array( $this, 'compare_f_quantity_asc' ) );
337
+ }
338
+
339
+ break;
340
+
341
+ case 'stock_quantity-desc':
342
+
343
+ if ( isset( $this->products[0]['id'] ) ) {
344
+ usort( $this->products, array( $this, 'compare_f_quantity_desc' ) );
345
+ }
346
+
347
+ break;
348
+
349
  }
350
 
351
+ /**
352
+ * Filter search results after ordering
353
+ * @since 2.00
354
+ * @param array $this->products Products
355
+ * @param string $order_by Order by value
356
+ */
357
+ $this->products = apply_filters( 'aws_products_order', $this->products, $order_by );
358
+
359
  }
360
 
361
  /*
456
  return $res;
457
  }
458
 
459
+ /*
460
+ * Compare quantity values asc
461
+ */
462
+ private function compare_f_quantity_asc( $a, $b ) {
463
+
464
+ $product_a = wc_get_product( $a['id'] );
465
+ $product_b = wc_get_product( $b['id'] );
466
+
467
+ if ( ! is_a( $product_a, 'WC_Product' ) || ! is_a( $product_b, 'WC_Product' ) ) {
468
+ return 0;
469
+ }
470
+
471
+ $a_val = AWS_Helpers::get_quantity( $product_a );
472
+ $b_val = AWS_Helpers::get_quantity( $product_b );
473
+
474
+ if ( ! is_numeric( $a_val['f_price'] ) || ! is_numeric( $b_val['f_price'] ) ) {
475
+ return 0;
476
+ }
477
+
478
+ if ($a_val == $b_val) {
479
+ return 0;
480
+ }
481
+
482
+ return ($a_val < $b_val) ? -1 : 1;
483
+
484
+ }
485
+
486
+ /*
487
+ * Compare quantity values desc
488
+ */
489
+ private function compare_f_quantity_desc( $a, $b ) {
490
+
491
+ $product_a = wc_get_product( $a['id'] );
492
+ $product_b = wc_get_product( $b['id'] );
493
+
494
+ if ( ! is_a( $product_a, 'WC_Product' ) || ! is_a( $product_b, 'WC_Product' ) ) {
495
+ return 0;
496
+ }
497
+
498
+ $a_val = AWS_Helpers::get_quantity( $product_a );
499
+ $b_val = AWS_Helpers::get_quantity( $product_b );
500
+
501
+ if ( ! is_numeric( $a_val['f_price'] ) || ! is_numeric( $b_val['f_price'] ) ) {
502
+ return 0;
503
+ }
504
+
505
+ if ($a_val == $b_val) {
506
+ return 0;
507
+ }
508
+
509
+ return ($a_val > $b_val) ? -1 : 1;
510
+
511
+ }
512
+
513
  /*
514
  * Return array of sorted products
515
  */
includes/class-aws-search.php CHANGED
@@ -219,7 +219,6 @@ if ( ! class_exists( 'AWS_Search' ) ) :
219
  $result_array = array(
220
  'tax' => $custom_tax_array,
221
  'products' => $products_array,
222
- 'sql' => isset( $this->data['sql'] ) ? $this->data['sql'] : ''
223
  );
224
 
225
 
219
  $result_array = array(
220
  'tax' => $custom_tax_array,
221
  'products' => $products_array,
 
222
  );
223
 
224
 
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.4
7
- Stable tag: 1.99
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -104,6 +104,11 @@ Yep. This plugin is always compatible with the latest version of Woocommerce?
104
 
105
  == Changelog ==
106
 
 
 
 
 
 
107
  = 1.99 =
108
  * Update - OceanWp theme integration
109
  * Fix - Bug with product short description search
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.4
7
+ Stable tag: 2.00
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
104
 
105
  == Changelog ==
106
 
107
+ = 2.00 =
108
+ * Update - Search page ordering. Add order by quantity
109
+ * Update - Remove sql query from output
110
+ * Dev - Add aws_products_order filter
111
+
112
  = 1.99 =
113
  * Update - OceanWp theme integration
114
  * Fix - Bug with product short description search