Discount Rules for WooCommerce - Version 1.4.22

Version Description

  • 25/10/17 =
  • Fix Based on category in cart rules: Calculating subtotal while having multiple categories for same product
Download this release

Release Info

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

Code changes from version 1.4.21 to 1.4.22

includes/cart-rules-3.php CHANGED
@@ -710,7 +710,6 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
710
  {
711
  $skipRuleType = array('categories_in');
712
  $availableRuleToSkip = array_intersect($skipRuleType, array_keys($rules));
713
-
714
  switch ($index) {
715
 
716
  // Cart Subtotal.
@@ -933,15 +932,21 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
933
  $categoryFound = 0;
934
  $product_id = $cat_id = '';
935
  $sub_total = $quantity = $item_count = 0;
 
936
  foreach ($rule as $catid){
937
  if(in_array($catid, $category_ids)){
938
  if(isset($product_cat_id[$catid])){
939
  $categoryFound = 1;
940
- $cat_id = trim($cat_id.','.$product_cat_id[$catid]->cat_id, ',');
941
- $product_id = trim($product_id.','.$product_cat_id[$catid]->product_id, ',');
942
- $sub_total = $sub_total+$product_cat_id[$catid]->sub_total;
943
- $quantity = $quantity+$product_cat_id[$catid]->quantity;
944
- $item_count = $item_count+$product_cat_id[$catid]->item_count;
 
 
 
 
 
945
  }
946
  }
947
  }
@@ -955,6 +960,7 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
955
  $ruleSuccess = 0;
956
  }
957
  } elseif ($rule_type == 'subtotal_less'){
 
958
  if ($sub_total >= $rule_values) {
959
  $ruleSuccess = 0;
960
  }
710
  {
711
  $skipRuleType = array('categories_in');
712
  $availableRuleToSkip = array_intersect($skipRuleType, array_keys($rules));
 
713
  switch ($index) {
714
 
715
  // Cart Subtotal.
932
  $categoryFound = 0;
933
  $product_id = $cat_id = '';
934
  $sub_total = $quantity = $item_count = 0;
935
+ $existingProductId = array();
936
  foreach ($rule as $catid){
937
  if(in_array($catid, $category_ids)){
938
  if(isset($product_cat_id[$catid])){
939
  $categoryFound = 1;
940
+ if(isset($existingProductId[$product_cat_id[$catid]->product_id])){
941
+ $existingProductId[$product_cat_id[$catid]->product_id]['cat_ids'][] = $product_cat_id[$catid]->cat_id;
942
+ } else {
943
+ $existingProductId[$product_cat_id[$catid]->product_id]['cat_ids'][] = $product_cat_id[$catid]->cat_id;
944
+ $cat_id = trim($cat_id.','.$product_cat_id[$catid]->cat_id, ',');
945
+ $product_id = trim($product_id.','.$product_cat_id[$catid]->product_id, ',');
946
+ $sub_total = $sub_total+$product_cat_id[$catid]->sub_total;
947
+ $quantity = $quantity+$product_cat_id[$catid]->quantity;
948
+ $item_count = $item_count+$product_cat_id[$catid]->item_count;
949
+ }
950
  }
951
  }
952
  }
960
  $ruleSuccess = 0;
961
  }
962
  } elseif ($rule_type == 'subtotal_less'){
963
+
964
  if ($sub_total >= $rule_values) {
965
  $ruleSuccess = 0;
966
  }
includes/cart-rules.php CHANGED
@@ -934,15 +934,21 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
934
  $categoryFound = 0;
935
  $product_id = $cat_id = '';
936
  $sub_total = $quantity = $item_count = 0;
 
937
  foreach ($rule as $catid){
938
  if(in_array($catid, $category_ids)){
939
  if(isset($product_cat_id[$catid])){
940
  $categoryFound = 1;
941
- $cat_id = trim($cat_id.','.$product_cat_id[$catid]->cat_id, ',');
942
- $product_id = trim($product_id.','.$product_cat_id[$catid]->product_id, ',');
943
- $sub_total = $sub_total+$product_cat_id[$catid]->sub_total;
944
- $quantity = $quantity+$product_cat_id[$catid]->quantity;
945
- $item_count = $item_count+$product_cat_id[$catid]->item_count;
 
 
 
 
 
946
  }
947
  }
948
  }
934
  $categoryFound = 0;
935
  $product_id = $cat_id = '';
936
  $sub_total = $quantity = $item_count = 0;
937
+ $existingProductId = array();
938
  foreach ($rule as $catid){
939
  if(in_array($catid, $category_ids)){
940
  if(isset($product_cat_id[$catid])){
941
  $categoryFound = 1;
942
+ if(isset($existingProductId[$product_cat_id[$catid]->product_id])){
943
+ $existingProductId[$product_cat_id[$catid]->product_id]['cat_ids'][] = $product_cat_id[$catid]->cat_id;
944
+ } else {
945
+ $existingProductId[$product_cat_id[$catid]->product_id]['cat_ids'][] = $product_cat_id[$catid]->cat_id;
946
+ $cat_id = trim($cat_id.','.$product_cat_id[$catid]->cat_id, ',');
947
+ $product_id = trim($product_id.','.$product_cat_id[$catid]->product_id, ',');
948
+ $sub_total = $sub_total+$product_cat_id[$catid]->sub_total;
949
+ $quantity = $quantity+$product_cat_id[$catid]->quantity;
950
+ $item_count = $item_count+$product_cat_id[$catid]->item_count;
951
+ }
952
  }
953
  }
954
  }
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://flycart.org/
4
  Tags: woocommerce, ecommerce, discounts, coupons, promotion, campaigns, sales, price rules, advanced coupons, advanced discounts
5
  Requires at least: 4.4.1
6
  Tested up to: 4.8.1
7
- Stable tag: 1.4.21
8
  License: GPLv3 or later
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -109,6 +109,9 @@ More information could be found in the documentation
109
 
110
  == Changelog ==
111
 
 
 
 
112
  = 1.4.21 - 16/10/17 =
113
  * Fix – Based on category in cart rules: Apply discount only for the subtotal of selected category products
114
 
4
  Tags: woocommerce, ecommerce, discounts, coupons, promotion, campaigns, sales, price rules, advanced coupons, advanced discounts
5
  Requires at least: 4.4.1
6
  Tested up to: 4.8.1
7
+ Stable tag: 1.4.22
8
  License: GPLv3 or later
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
109
 
110
  == Changelog ==
111
 
112
+ = 1.4.22 - 25/10/17 =
113
+ * Fix – Based on category in cart rules: Calculating subtotal while having multiple categories for same product
114
+
115
  = 1.4.21 - 16/10/17 =
116
  * Fix – Based on category in cart rules: Apply discount only for the subtotal of selected category products
117
 
woo-discount-rules.php CHANGED
@@ -5,7 +5,7 @@
5
  * Description: Simple Discount Rules for WooCommerce.
6
  * Author: Flycart Technologies LLP
7
  * Author URI: https://www.flycart.org
8
- * Version: 1.4.21
9
  * Slug: woo-discount-rules
10
  * Text Domain: woo-discount-rules
11
  * Requires at least: 4.6.1
5
  * Description: Simple Discount Rules for WooCommerce.
6
  * Author: Flycart Technologies LLP
7
  * Author URI: https://www.flycart.org
8
+ * Version: 1.4.22
9
  * Slug: woo-discount-rules
10
  * Text Domain: woo-discount-rules
11
  * Requires at least: 4.6.1