Discount Rules for WooCommerce - Version 1.6.19

Version Description

  • 29/10/18 =
  • Fix: coupon doesn't works for few language
  • Fix: displaying promotion text even if the rule doesn't matches
  • Fix: Buy x and get y and z each 1 quantity
  • Improvement: Exclude the bundled products items from applying discount
Download this release

Release Info

Developer flycart
Plugin Icon 128x128 Discount Rules for WooCommerce
Version 1.6.19
Comparing to
See all releases

Code changes from version 1.6.18 to 1.6.19

includes/cart-rules.php CHANGED
@@ -301,8 +301,8 @@ if (!class_exists('FlycartWooDiscountRulesCartRules')) {
301
  $is_removed = WC()->session->get('woo_coupon_removed');
302
  // If Both are same, then it won't added.
303
  if ($coupon_code == $is_removed) return false;
 
304
 
305
- if ($old_coupon_code == $coupon_code) {
306
  if ($this->postData->get('remove_coupon', false) == $coupon_code) return false;
307
  $this->makeLog();
308
  $discount_type = 'fixed_cart';
301
  $is_removed = WC()->session->get('woo_coupon_removed');
302
  // If Both are same, then it won't added.
303
  if ($coupon_code == $is_removed) return false;
304
+ if ($old_coupon_code == $coupon_code || wc_strtolower($old_coupon_code) == wc_strtolower($coupon_code)) {
305
 
 
306
  if ($this->postData->get('remove_coupon', false) == $coupon_code) return false;
307
  $this->makeLog();
308
  $discount_type = 'fixed_cart';
includes/pricing-rules.php CHANGED
@@ -555,8 +555,10 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
555
  $carts = FlycartWoocommerceCart::get_cart();
556
  if(!empty($carts)){
557
  foreach ($carts as $cart_key => $cart){
558
- if($cart_key == $cart_item_key){
559
- $cart_item_data['quantity'] = $cart['quantity'];
 
 
560
  }
561
  }
562
  }
@@ -566,13 +568,16 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
566
  if(count($this->bogo_matches) > 0){
567
  foreach ($this->bogo_matches as $free_product_id => $bogo_match){
568
  $found = false;
569
- foreach ($carts as $cart_item) {
 
 
 
570
  $cart_product_id = $cart_item['product_id'];
571
  if($cart_item['variation_id']) $cart_product_id = $cart_item['variation_id'];
572
  if ($free_product_id == $cart_product_id) {
573
  $found = true;
574
  $quantity = $cart_item['quantity'];
575
- $cart_item_key = $cart_item['key'];
576
  break;
577
  }
578
  }
@@ -602,6 +607,9 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
602
  public function handleBOGODiscountAfterApplyCoupon($coupon_code){
603
  $carts = FlycartWoocommerceCart::get_cart();
604
  foreach ($carts as $cart_item_key => $cart_item){
 
 
 
605
  $quantity = $old_quantity = $cart_item['quantity'];
606
  do_action( 'woocommerce_after_cart_item_quantity_update', $cart_item_key, $quantity, $old_quantity, $carts );
607
  }
@@ -658,13 +666,16 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
658
  if(count($this->bogo_matches) > 0){
659
  foreach ($this->bogo_matches as $free_product_id => $bogo_match){
660
  $found = false;
661
- foreach ($carts as $cart_item) {
 
 
 
662
  $cart_product_id = $cart_item['product_id'];
663
  if($cart_item['variation_id']) $cart_product_id = $cart_item['variation_id'];
664
  if ($free_product_id == $cart_product_id) {
665
  $found = true;
666
  $quantity = $cart_item['quantity'];
667
- $cart_item_key = $cart_item['key'];
668
  break;
669
  }
670
  }
@@ -1230,6 +1241,9 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1230
  foreach ($applyToProducts as $key => $productId) {
1231
  $cart = FlycartWoocommerceCart::get_cart();
1232
  foreach ($cart as $cart_item_key => $values) {
 
 
 
1233
  $_product = $values['data'];
1234
  if (FlycartWoocommerceProduct::get_id($_product) == $productId){
1235
  $additionalKeys = array('apply_from' => $item['product_id']);
@@ -1257,6 +1271,9 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1257
  } else {
1258
  $cart = FlycartWoocommerceCart::get_cart();
1259
  foreach ($cart as $cart_item_key => $values) {
 
 
 
1260
  $_product = $values['data'];
1261
  if (FlycartWoocommerceProduct::get_id($_product) == $productId){
1262
  $additionalKeys = array('apply_from' => $item['product_id']);
@@ -1323,6 +1340,9 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1323
  $product_to_apply = array();
1324
  if ( sizeof( $cart ) > 0 ) {
1325
  foreach ($cart as $cart_item_key => $values) {
 
 
 
1326
  $resultInCat = $this->isItemInCategoryList($category_to_apply, $values);
1327
  if($resultInCat){
1328
  if(isset($values['variation_id']) && $values['variation_id'])
@@ -1337,6 +1357,9 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1337
  if ( sizeof( $cart ) > 0 ) {
1338
  foreach ($product_to_buy as $key => $productId) {
1339
  foreach ($cart as $cart_item_key => $values) {
 
 
 
1340
  $_product = $values['data'];
1341
  if (FlycartWoocommerceProduct::get_id($_product) == $productId){
1342
  $_quantity[$productId] = $values['quantity'];
@@ -1373,6 +1396,9 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1373
  if(!empty($product_to_exclude) && is_array($product_to_exclude) && count($product_to_exclude)) $hasExcludeProduct = 1;
1374
  if(count($woocommerce->cart->cart_contents)){
1375
  foreach ($woocommerce->cart->cart_contents as $cartItem) {
 
 
 
1376
  //Exclude the bundled products items
1377
  if(isset($cartItem['bundled_item_id']) && !empty($cartItem['bundled_item_id'])){
1378
  continue;
@@ -1430,6 +1456,9 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1430
  if(!empty($product_to_exclude) && is_array($product_to_exclude) && count($product_to_exclude)) $hasExcludeProduct = 1;
1431
  if(count($woocommerce->cart->cart_contents)){
1432
  foreach ($woocommerce->cart->cart_contents as $cartItem) {
 
 
 
1433
  $is_exclude_sale_items = $this->isItemInSaleItems($exclude_sale_items, $cartItem['data']);
1434
  if($is_exclude_sale_items){
1435
  continue;
@@ -1468,6 +1497,9 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1468
  if($product_page) $quantity++;
1469
  if(count($woocommerce->cart->cart_contents)){
1470
  foreach ($woocommerce->cart->cart_contents as $cartItem) {
 
 
 
1471
  $product_id = $cartItem['product_id'];
1472
  if(isset($cartItem['variation_id']) && $cartItem['variation_id']){
1473
  $product_id = $cartItem['variation_id'];
@@ -1493,6 +1525,9 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1493
  if(!empty($product_to_exclude) && is_array($product_to_exclude) && count($product_to_exclude)) $hasExcludeProduct = 1;
1494
  if(count($woocommerce->cart->cart_contents)){
1495
  foreach ($woocommerce->cart->cart_contents as $cartItem) {
 
 
 
1496
  $is_exclude_sale_items = $this->isItemInSaleItems($exclude_sale_items, $cartItem['data']);
1497
  if($is_exclude_sale_items){
1498
  continue;
@@ -1599,6 +1634,7 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1599
  $this->bogo_matches = $free_product;
1600
  $adjustment[$type] = $productIds;
1601
  } else {
 
1602
  $productCheapest = $this->getMoreThanOneCheapestProductFromCart($productIds, $bogo_count, count($productIds), $range, $product_to_exclude);
1603
  if (!empty($productCheapest)) {
1604
  $adjustment = $productCheapest;
@@ -1736,6 +1772,9 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1736
  }
1737
  $cart = FlycartWoocommerceCart::get_cart();
1738
  foreach ($cart as $cart_item_key => $values) {
 
 
 
1739
  $_product = $values['data'];
1740
  $productId = FlycartWoocommerceProduct::get_id($_product);
1741
  if(!empty($product_to_exclude) && is_array($product_to_exclude)){
@@ -2007,6 +2046,9 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
2007
  */
2008
  public function sortCartByPrice_asc($first, $second)
2009
  {
 
 
 
2010
  if (isset($first['data'])) {
2011
  if (FlycartWoocommerceProduct::get_price($first['data']) == FlycartWoocommerceProduct::get_price($second['data'])) {
2012
  return 0;
@@ -2527,7 +2569,7 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
2527
  $condition .= esc_html__('Category(ies) ').' '.trim($htmlCategories, ', ');
2528
  }
2529
  }
2530
-
2531
  return $condition;
2532
  }
2533
 
@@ -2901,6 +2943,12 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
2901
  if (!isset($woocommerce->cart->cart_contents[$item])) {
2902
  return;
2903
  }
 
 
 
 
 
 
2904
  $product = $woocommerce->cart->cart_contents[$item]['data'];
2905
 
2906
  $product_id = FlycartWoocommerceProduct::get_id($product);
@@ -2938,17 +2986,19 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
2938
  // $woocommerce->cart->cart_contents[$item]['data']->price = $amount;
2939
  FlycartWoocommerceProduct::set_price($product, $amount);
2940
  $product->woo_discount_rules_applied = 1;
2941
-
2942
  // To get the applied discount in cart
2943
- if(isset($this->matched_sets[$item])){
2944
- self::$matched_discounts[$item] = $this->matched_sets[$item];
2945
- foreach (self::$matched_discounts[$item] as $matched_discounts){
2946
- $rule_order_id = $matched_discounts['rule_order'];
2947
- if(isset($this->rule_sets[$rule_order_id])){
2948
- self::$applied_discount_rules[$rule_order_id] = $this->rule_sets[$rule_order_id];
 
 
 
2949
  }
2950
- }
2951
 
 
2952
  }
2953
  }
2954
 
555
  $carts = FlycartWoocommerceCart::get_cart();
556
  if(!empty($carts)){
557
  foreach ($carts as $cart_key => $cart){
558
+ if(!empty($cart['data'])){
559
+ if($cart_key == $cart_item_key){
560
+ $cart_item_data['quantity'] = $cart['quantity'];
561
+ }
562
  }
563
  }
564
  }
568
  if(count($this->bogo_matches) > 0){
569
  foreach ($this->bogo_matches as $free_product_id => $bogo_match){
570
  $found = false;
571
+ foreach ($carts as $cart_item_key => $cart_item) {
572
+ if(empty($cart_item['data'])){
573
+ continue;
574
+ }
575
  $cart_product_id = $cart_item['product_id'];
576
  if($cart_item['variation_id']) $cart_product_id = $cart_item['variation_id'];
577
  if ($free_product_id == $cart_product_id) {
578
  $found = true;
579
  $quantity = $cart_item['quantity'];
580
+ $cart_item_key = $cart_item_key;
581
  break;
582
  }
583
  }
607
  public function handleBOGODiscountAfterApplyCoupon($coupon_code){
608
  $carts = FlycartWoocommerceCart::get_cart();
609
  foreach ($carts as $cart_item_key => $cart_item){
610
+ if(empty($cart_item['data'])){
611
+ continue;
612
+ }
613
  $quantity = $old_quantity = $cart_item['quantity'];
614
  do_action( 'woocommerce_after_cart_item_quantity_update', $cart_item_key, $quantity, $old_quantity, $carts );
615
  }
666
  if(count($this->bogo_matches) > 0){
667
  foreach ($this->bogo_matches as $free_product_id => $bogo_match){
668
  $found = false;
669
+ foreach ($carts as $key => $cart_item) {
670
+ if(empty($cart_item['data'])){
671
+ continue;
672
+ }
673
  $cart_product_id = $cart_item['product_id'];
674
  if($cart_item['variation_id']) $cart_product_id = $cart_item['variation_id'];
675
  if ($free_product_id == $cart_product_id) {
676
  $found = true;
677
  $quantity = $cart_item['quantity'];
678
+ $cart_item_key = $key;
679
  break;
680
  }
681
  }
1241
  foreach ($applyToProducts as $key => $productId) {
1242
  $cart = FlycartWoocommerceCart::get_cart();
1243
  foreach ($cart as $cart_item_key => $values) {
1244
+ if(empty($values['data'])){
1245
+ continue;
1246
+ }
1247
  $_product = $values['data'];
1248
  if (FlycartWoocommerceProduct::get_id($_product) == $productId){
1249
  $additionalKeys = array('apply_from' => $item['product_id']);
1271
  } else {
1272
  $cart = FlycartWoocommerceCart::get_cart();
1273
  foreach ($cart as $cart_item_key => $values) {
1274
+ if(empty($values['data'])){
1275
+ continue;
1276
+ }
1277
  $_product = $values['data'];
1278
  if (FlycartWoocommerceProduct::get_id($_product) == $productId){
1279
  $additionalKeys = array('apply_from' => $item['product_id']);
1340
  $product_to_apply = array();
1341
  if ( sizeof( $cart ) > 0 ) {
1342
  foreach ($cart as $cart_item_key => $values) {
1343
+ if(empty($values['data'])){
1344
+ continue;
1345
+ }
1346
  $resultInCat = $this->isItemInCategoryList($category_to_apply, $values);
1347
  if($resultInCat){
1348
  if(isset($values['variation_id']) && $values['variation_id'])
1357
  if ( sizeof( $cart ) > 0 ) {
1358
  foreach ($product_to_buy as $key => $productId) {
1359
  foreach ($cart as $cart_item_key => $values) {
1360
+ if(empty($values['data'])){
1361
+ continue;
1362
+ }
1363
  $_product = $values['data'];
1364
  if (FlycartWoocommerceProduct::get_id($_product) == $productId){
1365
  $_quantity[$productId] = $values['quantity'];
1396
  if(!empty($product_to_exclude) && is_array($product_to_exclude) && count($product_to_exclude)) $hasExcludeProduct = 1;
1397
  if(count($woocommerce->cart->cart_contents)){
1398
  foreach ($woocommerce->cart->cart_contents as $cartItem) {
1399
+ if(empty($cartItem['data'])){
1400
+ continue;
1401
+ }
1402
  //Exclude the bundled products items
1403
  if(isset($cartItem['bundled_item_id']) && !empty($cartItem['bundled_item_id'])){
1404
  continue;
1456
  if(!empty($product_to_exclude) && is_array($product_to_exclude) && count($product_to_exclude)) $hasExcludeProduct = 1;
1457
  if(count($woocommerce->cart->cart_contents)){
1458
  foreach ($woocommerce->cart->cart_contents as $cartItem) {
1459
+ if(empty($cartItem['data'])){
1460
+ continue;
1461
+ }
1462
  $is_exclude_sale_items = $this->isItemInSaleItems($exclude_sale_items, $cartItem['data']);
1463
  if($is_exclude_sale_items){
1464
  continue;
1497
  if($product_page) $quantity++;
1498
  if(count($woocommerce->cart->cart_contents)){
1499
  foreach ($woocommerce->cart->cart_contents as $cartItem) {
1500
+ if(empty($cartItem['data'])){
1501
+ continue;
1502
+ }
1503
  $product_id = $cartItem['product_id'];
1504
  if(isset($cartItem['variation_id']) && $cartItem['variation_id']){
1505
  $product_id = $cartItem['variation_id'];
1525
  if(!empty($product_to_exclude) && is_array($product_to_exclude) && count($product_to_exclude)) $hasExcludeProduct = 1;
1526
  if(count($woocommerce->cart->cart_contents)){
1527
  foreach ($woocommerce->cart->cart_contents as $cartItem) {
1528
+ if(empty($cartItem['data'])){
1529
+ continue;
1530
+ }
1531
  $is_exclude_sale_items = $this->isItemInSaleItems($exclude_sale_items, $cartItem['data']);
1532
  if($is_exclude_sale_items){
1533
  continue;
1634
  $this->bogo_matches = $free_product;
1635
  $adjustment[$type] = $productIds;
1636
  } else {
1637
+ $range->discount_product_item_type = 'static';
1638
  $productCheapest = $this->getMoreThanOneCheapestProductFromCart($productIds, $bogo_count, count($productIds), $range, $product_to_exclude);
1639
  if (!empty($productCheapest)) {
1640
  $adjustment = $productCheapest;
1772
  }
1773
  $cart = FlycartWoocommerceCart::get_cart();
1774
  foreach ($cart as $cart_item_key => $values) {
1775
+ if(empty($values['data'])){
1776
+ continue;
1777
+ }
1778
  $_product = $values['data'];
1779
  $productId = FlycartWoocommerceProduct::get_id($_product);
1780
  if(!empty($product_to_exclude) && is_array($product_to_exclude)){
2046
  */
2047
  public function sortCartByPrice_asc($first, $second)
2048
  {
2049
+ if(!isset($first['data']) || !isset($second['data'])){
2050
+ return 0;
2051
+ }
2052
  if (isset($first['data'])) {
2053
  if (FlycartWoocommerceProduct::get_price($first['data']) == FlycartWoocommerceProduct::get_price($second['data'])) {
2054
  return 0;
2569
  $condition .= esc_html__('Category(ies) ').' '.trim($htmlCategories, ', ');
2570
  }
2571
  }
2572
+
2573
  return $condition;
2574
  }
2575
 
2943
  if (!isset($woocommerce->cart->cart_contents[$item])) {
2944
  return;
2945
  }
2946
+
2947
+ //Exclude the bundled products items
2948
+ if(isset($woocommerce->cart->cart_contents[$item]['bundled_item_id']) && !empty($woocommerce->cart->cart_contents[$item]['bundled_item_id'])){
2949
+ return;
2950
+ }
2951
+
2952
  $product = $woocommerce->cart->cart_contents[$item]['data'];
2953
 
2954
  $product_id = FlycartWoocommerceProduct::get_id($product);
2986
  // $woocommerce->cart->cart_contents[$item]['data']->price = $amount;
2987
  FlycartWoocommerceProduct::set_price($product, $amount);
2988
  $product->woo_discount_rules_applied = 1;
 
2989
  // To get the applied discount in cart
2990
+ $original_price = $woocommerce->cart->cart_contents[$item]['woo_discount']['original_price'];
2991
+ if($amount < $original_price){
2992
+ if(isset($this->matched_sets[$item])){
2993
+ self::$matched_discounts[$item] = $this->matched_sets[$item];
2994
+ foreach (self::$matched_discounts[$item] as $matched_discounts){
2995
+ $rule_order_id = $matched_discounts['rule_order'];
2996
+ if(isset($this->rule_sets[$rule_order_id])){
2997
+ self::$applied_discount_rules[$rule_order_id] = $this->rule_sets[$rule_order_id];
2998
+ }
2999
  }
 
3000
 
3001
+ }
3002
  }
3003
  }
3004
 
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://flycart.org/
4
  Tags: woocommerce, discounts, dynamic pricing, Buy One Get One Free, pricing deals, price rules, bulk discounts, advanced discounts, pricing deals
5
  Requires at least: 4.4.1
6
  Tested up to: 4.9
7
- Stable tag: 1.6.18
8
  License: GPLv3 or later
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -212,7 +212,7 @@ We are happy to help you and guide you with the set up.
212
  Just reach out to us and we will get back to you. You can either contact us via the Live Chat or via the [support request form](https://www.flycart.org/support)
213
 
214
  == Installation ==
215
- Just use the WordPress installer or upload to the /wp-content/plugins folder. Then Activate the WooCommerce Email Builder and Customizer plugin.
216
  More information could be found in the documentation
217
 
218
  = Minimum Requirements =
@@ -308,6 +308,12 @@ Discount - Enter minimum & Maximum quantity -> Adjustment Type -> Product Discou
308
 
309
  == Changelog ==
310
 
 
 
 
 
 
 
311
  = 1.6.18 - 23/10/18 =
312
  * Fix - Adding additional quantity when BOGO rule applied
313
  * Fix - Other rules doesn't works when BOGO rule applied
4
  Tags: woocommerce, discounts, dynamic pricing, Buy One Get One Free, pricing deals, price rules, bulk discounts, advanced discounts, pricing deals
5
  Requires at least: 4.4.1
6
  Tested up to: 4.9
7
+ Stable tag: 1.6.19
8
  License: GPLv3 or later
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
212
  Just reach out to us and we will get back to you. You can either contact us via the Live Chat or via the [support request form](https://www.flycart.org/support)
213
 
214
  == Installation ==
215
+ Just use the WordPress installer or upload to the /wp-content/plugins folder. Then Activate the Woo Discount Rules plugin.
216
  More information could be found in the documentation
217
 
218
  = Minimum Requirements =
308
 
309
  == Changelog ==
310
 
311
+ = 1.6.19 - 29/10/18 =
312
+ * Fix: coupon doesn't works for few language
313
+ * Fix: displaying promotion text even if the rule doesn't matches
314
+ * Fix: Buy x and get y and z each 1 quantity
315
+ * Improvement: Exclude the bundled products items from applying discount
316
+
317
  = 1.6.18 - 23/10/18 =
318
  * Fix - Adding additional quantity when BOGO rule applied
319
  * Fix - Other rules doesn't works when BOGO rule applied
woo-discount-rules.php CHANGED
@@ -5,13 +5,13 @@
5
  * Description: Simple Discount Rules for WooCommerce.
6
  * Author: Flycart Technologies LLP
7
  * Author URI: https://www.flycart.org
8
- * Version: 1.6.18
9
  * Slug: woo-discount-rules
10
  * Text Domain: woo-discount-rules
11
  * Domain Path: /i18n/languages/
12
  * Requires at least: 4.6.1
13
  * WC requires at least: 2.4
14
- * WC tested up to: 3.4
15
  */
16
 
17
  if (!defined('ABSPATH')) exit; // Exit if accessed directly
5
  * Description: Simple Discount Rules for WooCommerce.
6
  * Author: Flycart Technologies LLP
7
  * Author URI: https://www.flycart.org
8
+ * Version: 1.6.19
9
  * Slug: woo-discount-rules
10
  * Text Domain: woo-discount-rules
11
  * Domain Path: /i18n/languages/
12
  * Requires at least: 4.6.1
13
  * WC requires at least: 2.4
14
+ * WC tested up to: 3.5
15
  */
16
 
17
  if (!defined('ABSPATH')) exit; // Exit if accessed directly