Discount Rules for WooCommerce - Version 1.7.6

Version Description

  • 11/01/19 =
  • Fix - Error because of action woocommerce_before_calculate_totals
  • Fix - Discount calculation for Free variant product on cart rules
Download this release

Release Info

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

Code changes from version 1.7.5 to 1.7.6

helper/woo-function.php CHANGED
@@ -464,6 +464,16 @@ if(!class_exists('FlycartWoocommerceCartProduct')){
464
  return array();
465
  }
466
 
 
 
 
 
 
 
 
 
 
 
467
  /**
468
  * Remove cart item
469
  *
464
  return array();
465
  }
466
 
467
+ /**
468
+ * Get cart object
469
+ *
470
+ * @return object
471
+ */
472
+ public static function get_cart_object()
473
+ {
474
+ return WC()->cart;
475
+ }
476
+
477
  /**
478
  * Remove cart item
479
  *
includes/cart-rules.php CHANGED
@@ -707,11 +707,11 @@ if (!class_exists('FlycartWooDiscountRulesCartRules')) {
707
  } else {
708
  //we will have to re-calculate the sub-total if it has category selected
709
  if($this->is_category_specific($rule)) {
710
- /*if(!empty($this->cart_items)){
711
  if(!did_action('woocommerce_before_calculate_totals')){
712
- do_action('woocommerce_before_calculate_totals');
713
  }
714
- }*/
715
  $this->has_category_in_rule = 1;
716
  //re-calculate the sub-total
717
  $subtotal = $this->calculate_conditional_subtotal($this->get_discounted_categories_from_json($rule));
@@ -1501,11 +1501,11 @@ if (!class_exists('FlycartWooDiscountRulesCartRules')) {
1501
  */
1502
  public function calculateCartSubtotal()
1503
  {
1504
- /*if(!empty($this->cart_items)){
1505
  if(!did_action('woocommerce_before_calculate_totals')){
1506
- do_action('woocommerce_before_calculate_totals');
1507
  }
1508
- }*/
1509
 
1510
  $cart_subtotal = 0;
1511
  // Iterate over all cart items and
@@ -1606,7 +1606,7 @@ if (!class_exists('FlycartWooDiscountRulesCartRules')) {
1606
  if (empty($cart_item['data'])) {
1607
  continue;
1608
  }
1609
- $product_id = (isset($cart_item['variation_id']) && $cart_item['variation_id'] > 0) ? $cart_item['variation_id'] : $cart_item['product_id'];
1610
  $added_products[$product_id] = array('item_name'=> FlycartWoocommerceProduct::get_name($cart_item['data']), 'item_quantity' => $cart_item['quantity'], 'item' => $cart_item_key, 'item_price' => FlycartWoocommerceProduct::get_price($cart_item['data']));
1611
  }
1612
  foreach ($product_ids as $discounted_product_id) {
@@ -1672,9 +1672,10 @@ if (!class_exists('FlycartWooDiscountRulesCartRules')) {
1672
  $free_quantity = 0;
1673
  $free_item_price = 0;
1674
  foreach ($this->cart_items as $cart_items){
1675
- $cart[$cart_items['product_id']]['quantity'] = $cart_items['quantity'];
1676
- $cart[$cart_items['product_id']]['price'] = FlycartWoocommerceProduct::get_price($cart_items['data']);
1677
- $cart[$cart_items['product_id']]['subtotal'] = $cart[$cart_items['product_id']]['price'] * $cart[$cart_items['product_id']]['quantity'];
 
1678
  }
1679
  $discounted_products = (isset($rule_set->cart_discounted_products)) ? $rule_set->cart_discounted_products : '[]';
1680
  $products = json_decode($discounted_products);
707
  } else {
708
  //we will have to re-calculate the sub-total if it has category selected
709
  if($this->is_category_specific($rule)) {
710
+ if(!empty($this->cart_items)){
711
  if(!did_action('woocommerce_before_calculate_totals')){
712
+ do_action('woocommerce_before_calculate_totals', FlycartWoocommerceCart::get_cart_object());
713
  }
714
+ }
715
  $this->has_category_in_rule = 1;
716
  //re-calculate the sub-total
717
  $subtotal = $this->calculate_conditional_subtotal($this->get_discounted_categories_from_json($rule));
1501
  */
1502
  public function calculateCartSubtotal()
1503
  {
1504
+ if(!empty($this->cart_items)){
1505
  if(!did_action('woocommerce_before_calculate_totals')){
1506
+ do_action('woocommerce_before_calculate_totals', FlycartWoocommerceCart::get_cart_object());
1507
  }
1508
+ }
1509
 
1510
  $cart_subtotal = 0;
1511
  // Iterate over all cart items and
1606
  if (empty($cart_item['data'])) {
1607
  continue;
1608
  }
1609
+ $product_id = FlycartWoocommerceProduct::get_id($cart_item['data']);
1610
  $added_products[$product_id] = array('item_name'=> FlycartWoocommerceProduct::get_name($cart_item['data']), 'item_quantity' => $cart_item['quantity'], 'item' => $cart_item_key, 'item_price' => FlycartWoocommerceProduct::get_price($cart_item['data']));
1611
  }
1612
  foreach ($product_ids as $discounted_product_id) {
1672
  $free_quantity = 0;
1673
  $free_item_price = 0;
1674
  foreach ($this->cart_items as $cart_items){
1675
+ $product_id = FlycartWoocommerceProduct::get_id($cart_items['data']);
1676
+ $cart[$product_id]['quantity'] = $cart_items['quantity'];
1677
+ $cart[$product_id]['price'] = FlycartWoocommerceProduct::get_price($cart_items['data']);
1678
+ $cart[$product_id]['subtotal'] = $cart[$product_id]['price'] * $cart[$product_id]['quantity'];
1679
  }
1680
  $discounted_products = (isset($rule_set->cart_discounted_products)) ? $rule_set->cart_discounted_products : '[]';
1681
  $products = json_decode($discounted_products);
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: 5.0
7
- Stable tag: 1.7.5
8
  License: GPLv3 or later
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -306,8 +306,16 @@ Discount - Enter minimum & Maximum quantity -> Adjustment Type -> Product Discou
306
  4. Example Promotion Offers created using Woo Discount rules
307
  5. Discounted price is applied in the Cart
308
 
 
 
 
 
309
  == Changelog ==
310
 
 
 
 
 
311
  = 1.7.5 - 10/01/19 =
312
  * Fix - Error because of repeated call woocommerce_before_calculate_totals
313
 
@@ -662,8 +670,4 @@ Discount - Enter minimum & Maximum quantity -> Adjustment Type -> Product Discou
662
  = 1.4.0 - 26/10/16 =
663
  * PHP 5.3 compatibility added
664
 
665
- == Credits ==
666
-
667
- * Dutch Translation - [@mvdburg1971](https://profiles.wordpress.org/mvdburg1971) - Michael van der Burg
668
-
669
  == Upgrade notice ==
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: 5.0
7
+ Stable tag: 1.7.6
8
  License: GPLv3 or later
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
306
  4. Example Promotion Offers created using Woo Discount rules
307
  5. Discounted price is applied in the Cart
308
 
309
+ == Credits ==
310
+
311
+ * Dutch Translation - [@mvdburg1971](https://profiles.wordpress.org/mvdburg1971) - Michael van der Burg
312
+
313
  == Changelog ==
314
 
315
+ = 1.7.6 - 11/01/19 =
316
+ * Fix - Error because of action woocommerce_before_calculate_totals
317
+ * Fix - Discount calculation for Free variant product on cart rules
318
+
319
  = 1.7.5 - 10/01/19 =
320
  * Fix - Error because of repeated call woocommerce_before_calculate_totals
321
 
670
  = 1.4.0 - 26/10/16 =
671
  * PHP 5.3 compatibility added
672
 
 
 
 
 
673
  == Upgrade notice ==
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.7.5
9
  * Slug: woo-discount-rules
10
  * Text Domain: woo-discount-rules
11
  * Domain Path: /i18n/languages/
5
  * Description: Simple Discount Rules for WooCommerce.
6
  * Author: Flycart Technologies LLP
7
  * Author URI: https://www.flycart.org
8
+ * Version: 1.7.6
9
  * Slug: woo-discount-rules
10
  * Text Domain: woo-discount-rules
11
  * Domain Path: /i18n/languages/