Discount Rules for WooCommerce - Version 2.3.3

Version Description

  • 16/12/20 =
  • Fix - Attribute doesn't loads for few language.
  • Fix - Show Discount bar for 0 price product.
  • Fix - Duplicate rule is not generated when title has '.
  • Fix - Exclusive option for free shipping is not working.
  • Fix - Set discount not applies for few cases.
  • Fix - Warning message for empty variants.
  • Fix - Customer chosen product is not updating for variant together option.
  • Improvement - Product addon compatible improvement.
  • Improvement - Product addon by themehigh compatible improvement.
  • Improvement - Display parent name of category while select child.
  • Improvement - Translation for discount label, rule title, Free shipping.
  • Improvement - Event: advanced_woo_discount_rules_recalculate_discount_before_apply_coupon.
  • Improvement - Calculating tax with fee.
  • Improvement - Removing jquery-ui-datepicker script on our pages as it making conflict in few sites.
  • Improvement - Improved query for purchase history rules.
  • Improvement - Shipping state and country condition.
  • Improvement - Event: advanced_woo_discount_rules_set_cheapest_item_key_as_product_id_for_product_page.
Download this release

Release Info

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

Code changes from version 2.3.2 to 2.3.3

readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://flycart.org/
4
  Tags: woocommerce, coupons, discounts, dynamic pricing, Buy One Get One Free, pricing deals, bulk discount, discount
5
  Requires at least: 4.4.1
6
  Tested up to: 5.5
7
- Stable tag: 2.3.2
8
  License: GPLv3 or later
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -337,6 +337,25 @@ Note : Enable recursive checkbox if the discounts should be applied in sequentia
337
 
338
  == Changelog ==
339
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
340
  = 2.3.2 - 05/11/20 =
341
  * Fix - Displaying discount table if user role based condition is false.
342
  * Fix - Discount fee doesn't works when Combine all discounts option enabled.
4
  Tags: woocommerce, coupons, discounts, dynamic pricing, Buy One Get One Free, pricing deals, bulk discount, discount
5
  Requires at least: 4.4.1
6
  Tested up to: 5.5
7
+ Stable tag: 2.3.3
8
  License: GPLv3 or later
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
337
 
338
  == Changelog ==
339
 
340
+ = 2.3.3 - 16/12/20 =
341
+ * Fix - Attribute doesn't loads for few language.
342
+ * Fix - Show Discount bar for 0 price product.
343
+ * Fix - Duplicate rule is not generated when title has '.
344
+ * Fix - Exclusive option for free shipping is not working.
345
+ * Fix - Set discount not applies for few cases.
346
+ * Fix - Warning message for empty variants.
347
+ * Fix - Customer chosen product is not updating for variant together option.
348
+ * Improvement - Product addon compatible improvement.
349
+ * Improvement - Product addon by themehigh compatible improvement.
350
+ * Improvement - Display parent name of category while select child.
351
+ * Improvement - Translation for discount label, rule title, Free shipping.
352
+ * Improvement - Event: advanced_woo_discount_rules_recalculate_discount_before_apply_coupon.
353
+ * Improvement - Calculating tax with fee.
354
+ * Improvement - Removing jquery-ui-datepicker script on our pages as it making conflict in few sites.
355
+ * Improvement - Improved query for purchase history rules.
356
+ * Improvement - Shipping state and country condition.
357
+ * Improvement - Event: advanced_woo_discount_rules_set_cheapest_item_key_as_product_id_for_product_page.
358
+
359
  = 2.3.2 - 05/11/20 =
360
  * Fix - Displaying discount table if user role based condition is false.
361
  * Fix - Discount fee doesn't works when Combine all discounts option enabled.
v2/App/Compatibility/ExtraProductOptionsProByThemeHigh.php CHANGED
@@ -27,7 +27,7 @@ class ExtraProductOptionsProByThemeHigh extends Base
27
  $price = str_replace($replace_strings, '', $prices[0]);
28
  $price = (float)$price;
29
  if($original_price != $price){
30
- $result = apply_filters('advanced_woo_discount_rules_get_product_discount_price_from_custom_price', $price, $product, 1, $price);
31
  if($result !== false){
32
  $price_html = "<del>".$price_html."</del><ins>".wc_price($result)."</ins>";
33
  }
27
  $price = str_replace($replace_strings, '', $prices[0]);
28
  $price = (float)$price;
29
  if($original_price != $price){
30
+ $result = apply_filters('advanced_woo_discount_rules_get_product_discount_price_from_custom_price', $price, $product, 1, $price, 'discounted_price', true, true);
31
  if($result !== false){
32
  $price_html = "<del>".$price_html."</del><ins>".wc_price($result)."</ins>";
33
  }
v2/App/Compatibility/ProductAddOnsByWooCommerce.php CHANGED
@@ -36,12 +36,14 @@ class ProductAddOnsByWooCommerce extends Base
36
  }
37
  if($lock == false){
38
  var price = newText = $(this).text().replace(currency_string, '');
39
- var option = {
40
- custom_price: price,
41
- original_price: price
42
- };
43
- $targets.attr('data-lock', true);
44
- $.AdvanceWooDiscountRules.getDynamicDiscountPriceFromCartForm($form, $targets, option);
 
 
45
  }
46
  });
47
 
@@ -72,12 +74,14 @@ class ProductAddOnsByWooCommerce extends Base
72
  }
73
  if($lock == false){
74
  var price = newText = $(this).text().replace(currency_string, '');
75
- var option = {
76
- custom_price: price,
77
- original_price: price
78
- };
79
- $targets.attr('data-lock', true);
80
- $.AdvanceWooDiscountRules.getDynamicDiscountPriceFromCartForm($form, $targets, option);
 
 
81
  }
82
  });
83
  }, 0);
36
  }
37
  if($lock == false){
38
  var price = newText = $(this).text().replace(currency_string, '');
39
+ if(price != '' && price != "-"){
40
+ var option = {
41
+ custom_price: price,
42
+ original_price: price
43
+ };
44
+ $targets.attr('data-lock', true);
45
+ $.AdvanceWooDiscountRules.getDynamicDiscountPriceFromCartForm($form, $targets, option);
46
+ }
47
  }
48
  });
49
 
74
  }
75
  if($lock == false){
76
  var price = newText = $(this).text().replace(currency_string, '');
77
+ if(price != '' && price != "-"){
78
+ var option = {
79
+ custom_price: price,
80
+ original_price: price
81
+ };
82
+ $targets.attr('data-lock', true);
83
+ $.AdvanceWooDiscountRules.getDynamicDiscountPriceFromCartForm($form, $targets, option);
84
+ }
85
  }
86
  });
87
  }, 0);
v2/App/Controllers/Admin/Settings.php CHANGED
@@ -236,6 +236,12 @@ class Settings extends Base
236
  'rule_id' => $this->input->get('task', 'create'),
237
  );
238
  wp_localize_script(WDR_SLUG . '-admin', 'wdr_data', $wdr_data);
 
 
 
 
 
 
239
  }
240
 
241
  /**
236
  'rule_id' => $this->input->get('task', 'create'),
237
  );
238
  wp_localize_script(WDR_SLUG . '-admin', 'wdr_data', $wdr_data);
239
+
240
+ //Remove UI Date picker which making conflict in some websites
241
+ wp_dequeue_script( 'jquery-ui-datepicker' );
242
+ wp_deregister_script( 'jquery-ui-datepicker' );
243
+ wp_dequeue_script( 'jquery-datetimepicker' );
244
+ wp_deregister_script( 'jquery-datetimepicker' );
245
  }
246
 
247
  /**
v2/App/Controllers/Admin/WDRAjax.php CHANGED
@@ -154,6 +154,17 @@ class WDRAjax extends Base
154
  if (function_exists('get_the_category_by_ID')) {
155
  $parant_names = get_the_category_by_ID((int)$term->parent);
156
  $parant_name = $parant_names . ' -> ';
 
 
 
 
 
 
 
 
 
 
 
157
  }
158
  }
159
  return array(
@@ -430,6 +441,7 @@ class WDRAjax extends Base
430
  $priority = intval($rule_priority->priority) + 1;
431
  }
432
  $rule_title = !empty($rule_title) && isset($rule_title->title) ? $rule_title->title : '';
 
433
  $sql = "INSERT INTO " . $wpdb->prefix . self::$wdr_rules_table . " (enabled, exclusive, title, priority, filters, conditions, product_adjustments, cart_adjustments, buy_x_get_x_adjustments, buy_x_get_y_adjustments, bulk_adjustments, set_adjustments, other_discounts, date_from, date_to, usage_limits, rule_language, additional, max_discount_sum, advanced_discount_message, discount_type, used_coupons )
434
  SELECT 0, exclusive, '" . $rule_title . " - copy'," . $priority . ", filters, conditions, product_adjustments, cart_adjustments, buy_x_get_x_adjustments, buy_x_get_y_adjustments, bulk_adjustments, set_adjustments, other_discounts, date_from, date_to, usage_limits, rule_language, additional, max_discount_sum, advanced_discount_message, discount_type, used_coupons
435
  FROM " . $wpdb->prefix . self::$wdr_rules_table . "
154
  if (function_exists('get_the_category_by_ID')) {
155
  $parant_names = get_the_category_by_ID((int)$term->parent);
156
  $parant_name = $parant_names . ' -> ';
157
+ $parant_category = get_term( (int)$term->parent );
158
+ if(is_object($parant_category) && !empty($parant_category->parent)){
159
+ $grant_parant_names = get_the_category_by_ID((int)$parant_category->parent);
160
+ $parant_name = $grant_parant_names . ' -> '.$parant_names . ' -> ';
161
+ $grant_parant_category = get_term( (int)$parant_category->parent );
162
+ if(is_object($grant_parant_category) && !empty($grant_parant_category->parent)){
163
+ $grant_grant_parant_names = get_the_category_by_ID((int)$grant_parant_category->parent);
164
+ $parant_name = $grant_grant_parant_names. ' -> '.$grant_parant_names . ' -> '.$parant_names . ' -> ';
165
+ }
166
+ }
167
+
168
  }
169
  }
170
  return array(
441
  $priority = intval($rule_priority->priority) + 1;
442
  }
443
  $rule_title = !empty($rule_title) && isset($rule_title->title) ? $rule_title->title : '';
444
+ $rule_title = addslashes($rule_title);
445
  $sql = "INSERT INTO " . $wpdb->prefix . self::$wdr_rules_table . " (enabled, exclusive, title, priority, filters, conditions, product_adjustments, cart_adjustments, buy_x_get_x_adjustments, buy_x_get_y_adjustments, bulk_adjustments, set_adjustments, other_discounts, date_from, date_to, usage_limits, rule_language, additional, max_discount_sum, advanced_discount_message, discount_type, used_coupons )
446
  SELECT 0, exclusive, '" . $rule_title . " - copy'," . $priority . ", filters, conditions, product_adjustments, cart_adjustments, buy_x_get_x_adjustments, buy_x_get_y_adjustments, bulk_adjustments, set_adjustments, other_discounts, date_from, date_to, usage_limits, rule_language, additional, max_discount_sum, advanced_discount_message, discount_type, used_coupons
447
  FROM " . $wpdb->prefix . self::$wdr_rules_table . "
v2/App/Controllers/DiscountCalculator.php CHANGED
@@ -112,7 +112,7 @@ class DiscountCalculator extends Base
112
  }
113
 
114
  if($calculate_discount_from != 'sale_price' && Woocommerce::productTypeIs($product, array('variable'))) {
115
- /*Process lowest regular price of variant*/
116
  if($discount_type == 'fixed_price'){
117
  $discounted_price = $this->mayHaveTax($product, $discounted_price);
118
  }
@@ -186,7 +186,7 @@ class DiscountCalculator extends Base
186
  'discount_value' => $discount_value,
187
  'discount_price' => $discount_price,
188
  'discounted_price' => $discounted_price,
189
- 'rule_title' => $rule_title
190
  );
191
  }
192
 
@@ -209,7 +209,7 @@ class DiscountCalculator extends Base
209
  $product_price = self::$woocommerce_helper->getProductPrice($product);
210
  }
211
  if(empty($product_price)){
212
- return array();
213
  }
214
  $language_helper_object = self::$language_helper;
215
  $discount_calculator = $this;
@@ -235,60 +235,60 @@ class DiscountCalculator extends Base
235
  }
236
  $html_content = $rule->getAdvancedDiscountMessage('badge_text');
237
  //if ($has_product_discount || $has_bulk_discount || $has_set_discount || $has_cart_discount) {
238
- if ($rule->isFilterPassed($product, true) && !empty($html_content)) {
239
- if ($has_product_discount) {
240
- $product_adjustments = $rule->getProductAdjustments();
241
- if (is_object($product_adjustments) && !empty($product_adjustments) && !empty($product_adjustments->value)) {
242
- $discount_method = "product_discount";
243
- $discount_price = $rule->calculator($product_adjustments->type, $product_price, $product_adjustments->value);
244
- $value = (isset($product_adjustments->value) && !empty($product_adjustments->value)) ? $product_adjustments->value : 0;
 
 
 
 
 
 
 
 
 
 
 
 
245
  $badge_bg_color = $rule->getAdvancedDiscountMessage('badge_color_picker', '#ffffff');
246
  $badge_text_color = $rule->getAdvancedDiscountMessage('badge_text_color_picker', '#000000');
247
- $this->advancedLayoutTextFormation($advanced_layout, $rule, $product_adjustments->type, $discount_method, $product_price, $value, $discount_price, $discounted_title_text, $html_content, $badge_bg_color, $badge_text_color);
248
  }
249
  }
250
- if ($has_cart_discount) {
251
- $cart_discount = $rule->getCartAdjustments();
252
- if (!empty($cart_discount)) {
253
- if (is_object($cart_discount) && !empty($cart_discount) && !empty($cart_discount->value)) {
254
- $discount_method = "cart_discount";
255
- $discount_price = $rule->calculator($cart_discount->type, $product_price, $cart_discount->value);
256
- $value = (isset($cart_discount->value) && !empty($cart_discount->value)) ? $cart_discount->value : 0;
257
- $badge_bg_color = $rule->getAdvancedDiscountMessage('badge_color_picker', '#ffffff');
258
- $badge_text_color = $rule->getAdvancedDiscountMessage('badge_text_color_picker', '#000000');
259
- $this->advancedLayoutTextFormation($advanced_layout, $rule, $cart_discount->type, $discount_method, $product_price, $value, $discount_price, $discounted_title_text, $html_content, $badge_bg_color, $badge_text_color);
260
- }
261
- }
262
- }
263
- if ($has_bulk_discount) {
264
- $bulk_adjustments = $rule->getBulkAdjustments();
265
- if (isset($bulk_adjustments) && is_object($bulk_adjustments) && !empty($bulk_adjustments) && isset($bulk_adjustments->ranges) && !empty($bulk_adjustments->ranges)) {
266
- foreach ($bulk_adjustments->ranges as $range) {
267
- if (isset($range->value) && !empty($range->value)) {
268
- $min = intval(isset($range->from) ? $range->from : 0);
269
- $max = intval(isset($range->to) ? $range->to : 0);
270
- if (empty($min) && empty($max)) {
271
- continue;
272
- } else {
273
- $discount_method = "bulk_discount";
274
- $discount_type = isset($range->type)? $range->type: 'percentage';
275
- $discount_price = $rule->calculator($discount_type, $product_price, $range->value);
276
- $value = (isset($range->value) && !empty($range->value)) ? $range->value : 0;
277
- $badge_bg_color = $rule->getAdvancedDiscountMessage('badge_color_picker', '#ffffff');
278
- $badge_text_color = $rule->getAdvancedDiscountMessage('badge_text_color_picker', '#000000');
279
- $this->advancedLayoutTextFormation($advanced_layout, $rule, $discount_type, $discount_method, $product_price, $value, $discount_price, $discounted_title_text, $html_content, $badge_bg_color, $badge_text_color, $min, $max);
280
- }
281
  }
282
  }
283
  }
284
  }
285
- if($discount_type == 'wdr_free_shipping' || $discount_type == 'wdr_buy_x_get_x_discount'){
286
- $discount_method = "free_shipping";
287
- $badge_bg_color = $rule->getAdvancedDiscountMessage('badge_color_picker', '#ffffff');
288
- $badge_text_color = $rule->getAdvancedDiscountMessage('badge_text_color_picker', '#000000');
289
- $this->advancedLayoutTextFormation($advanced_layout, $rule, 'free_shipping', $discount_method, $product_price, '0', '0', $discounted_title_text, $html_content, $badge_bg_color, $badge_text_color, 0, 0);
290
- }
291
  }
 
 
 
 
 
 
 
292
  //}
293
  $advanced_layout = apply_filters('advanced_woo_discount_rules_advance_table_based_on_rule', $advanced_layout, $rule, $discount_calculator, $product, $product_price, $html_content);
294
  }
@@ -321,7 +321,7 @@ class DiscountCalculator extends Base
321
  $discounted_price_text = '';
322
  switch ($type) {
323
  case 'fixed_price':
324
- if (!empty($value)) {
325
  $value = Woocommerce::getConvertedFixedPrice($value, 'fixed_price');
326
  if($value < 0){
327
  $value = 0;
@@ -332,7 +332,7 @@ class DiscountCalculator extends Base
332
  }
333
  break;
334
  case 'fixed_set_price':
335
- if (!empty($value) && !empty($min)) {
336
  $value = Woocommerce::getConvertedFixedPrice($value, 'fixed_set_price');
337
  $discounted_price = $value / $min;
338
  if($discounted_price < 0){
@@ -344,7 +344,7 @@ class DiscountCalculator extends Base
344
  }
345
  break;
346
  case 'percentage':
347
- if (!empty($value) && !empty($discount_price)) {
348
  $discount = $product_price - $discount_price;
349
  if($discount < 0){
350
  $discount = 0;
@@ -358,7 +358,7 @@ class DiscountCalculator extends Base
358
  break;
359
  default:
360
  case 'flat':
361
- if (!empty($value)) {
362
  $value = Woocommerce::getConvertedFixedPrice($value, 'flat');
363
  $discount = $product_price - $value;
364
  if($discount < 0){
@@ -370,50 +370,50 @@ class DiscountCalculator extends Base
370
  break;
371
  }
372
  //if (!empty($discount_text) && !empty($discounted_price_text)) {
373
- $dont_allow_duplicate = true;
374
- if ($discount_method == "bulk_discount") {
375
- $searchForReplace = array('{{title}}', '{{min_quantity}}', '{{max_quantity}}', '{{discount}}', '{{discounted_price}}');//, '{{min_quantity}}', '{{max_quantity}}', '{{discount}}', '{{discounted_price}}'
376
- $string_to_replace = array($discounted_title_text, $min, $max, $discount_text, $discounted_price_text); //, $min, $max, $discount_text, $discounted_price_text
377
- $html_content = str_replace($searchForReplace, $string_to_replace, $html_content);
378
- } elseif ($discount_method == "set_discount") {
379
- $searchForReplace = array('{{title}}', '{{min_quantity}}', '{{discount}}', '{{discounted_price}}'); //, '{{min_quantity}}', '{{discount}}', '{{discounted_price}}'
380
- $string_to_replace = array($discounted_title_text, $min, $discount_text, $discounted_price_text);//, $min, $discount_text, $discounted_price_text
381
- $html_content = str_replace($searchForReplace, $string_to_replace, $html_content);
382
- $searchForRemove = array('/{{max_quantity}}/');
383
- $replacements = array('');
384
- $html_content = preg_replace($searchForRemove, $replacements, $html_content);
385
- } else if($discount_method == 'free_shipping'){
386
- $searchForReplace = array('{{title}}');
387
- $string_to_replace = array($discounted_title_text);
388
- $html_content = str_replace($searchForReplace, $string_to_replace, $html_content);
389
- $searchForRemove = array('/{{min_quantity}}/', '/{{max_quantity}}/', '/{{discount}}/', '/{{discounted_price}}/');
390
- $replacements = array('', '');
391
- $html_content = preg_replace($searchForRemove, $replacements, $html_content);
392
- }else {
393
- $searchForReplace = array('{{title}}', '{{discount}}', '{{discounted_price}}');//, '{{discount}}', '{{discounted_price}}'
394
- $string_to_replace = array($discounted_title_text, $discount_text, $discounted_price_text);//, $discount_text, $discounted_price_text
395
- $html_content = str_replace($searchForReplace, $string_to_replace, $html_content);
396
- $searchForRemove = array('/{{min_quantity}}/', '/{{max_quantity}}/');
397
- $replacements = array('', '');
398
- $html_content = preg_replace($searchForRemove, $replacements, $html_content);
399
- }
400
- if (!empty($advanced_layout)) {
401
- foreach ($advanced_layout as $layout_options) {
402
- $check_exists = array($layout_options['badge_text']);
403
- if (in_array($html_content, $check_exists)) {
404
- $dont_allow_duplicate = false;
405
- break;
406
- }
407
  }
408
  }
409
- if ($dont_allow_duplicate) {
410
- $advanced_layout[] = array(
411
- 'badge_bg_color' => $badge_bg_color,
412
- 'badge_text_color' => $badge_text_color,
413
- 'badge_text' => $html_content,
414
- 'rule_id' => $rule->rule->id,
415
- );
416
- }
 
417
  //}
418
  }
419
 
@@ -463,7 +463,7 @@ class DiscountCalculator extends Base
463
  $product_price = $custom_price;
464
  }
465
 
466
- if ($rule->isFilterPassed($product)) {
467
  if ($rule->hasConditions()) {
468
  if ($rule->isCartConditionsPassed($cart)) {
469
  $rule_passed = true;
@@ -472,21 +472,24 @@ class DiscountCalculator extends Base
472
  $rule_passed = true;
473
  }
474
  if($rule_passed){
475
-
476
- if(!in_array($rule->rule->discount_type, array('wdr_buy_x_get_x_discount', 'wdr_set_discount'))){
477
- if ($discounted_price = $rule->calculateDiscount($product_price, $quantity, $product, $ajax_price, $cart_item, $price_display_condition, $is_cart, $manual_request)) {
478
- $has_exclusive_rule = true;
 
 
 
 
 
 
 
 
479
  } else {
480
  $rule_passed = apply_filters('advanced_woo_discount_rules_is_rule_passed_with_out_discount_for_exclusive_rule', false, $product, $rule, $cart_item);
481
  if($rule_passed){
482
  $has_exclusive_rule = true;
483
  }
484
  }
485
- } else {
486
- $rule_passed = apply_filters('advanced_woo_discount_rules_is_rule_passed_with_out_discount_for_exclusive_rule', false, $product, $rule, $cart_item);
487
- if($rule_passed){
488
- $has_exclusive_rule = true;
489
- }
490
  }
491
  }
492
  } else {
@@ -538,7 +541,7 @@ class DiscountCalculator extends Base
538
  }
539
 
540
  $original_product_price = apply_filters('advanced_woo_discount_rules_product_original_price_on_before_calculate_discount', $product_price, $product, $quantity, $cart_item, $calculate_discount_from);
541
- $product_price = apply_filters('advanced_woo_discount_rules_product_price_on_before_calculate_discount', $product_price, $product, $quantity, $cart_item, $calculate_discount_from);
542
 
543
  $exclusive_rules = $discounts = $exclude_products = array();
544
  $cart = self::$woocommerce_helper->getCart();
@@ -608,80 +611,80 @@ class DiscountCalculator extends Base
608
  }
609
  }
610
  //if(!empty($cart_item)) {
611
- $this_apply_as_cart_rule = false;
612
- switch ($discount_type) {
613
- case 'wdr_simple_discount':
614
- if ($simple_discount = $rule->getProductAdjustments()) {
615
- if (isset($simple_discount->apply_as_cart_rule) && !empty($simple_discount->apply_as_cart_rule)) {
616
- $this_apply_as_cart_rule = true;
617
- if(!empty($cart_item)) {
618
- $price_as_cart_discount[$rule_id][$product_id] = array(
619
- 'discount_type' => 'wdr_simple_discount',
620
- 'discount_label' => $simple_discount->cart_label,
621
- 'discount_value' => $simple_discount->value,
622
- 'discounted_price' => $cart_discounted_price,
623
- 'rule_name' => $rule->getTitle(),
624
- 'cart_item_key' => isset($cart_item['key']) ? $cart_item['key'] : '',
625
- 'product_id' => self::$woocommerce_helper->getProductId($cart_item['data']),
626
- 'rule_id' => $rule_id,
627
- );
628
- $discounts[$rule_id] = $discounted_price;
629
- }
630
- }
631
- }
632
- break;
633
- case 'wdr_cart_discount':
634
- if ($cart_discount = $rule->getCartAdjustments()) {
635
  $this_apply_as_cart_rule = true;
636
  if(!empty($cart_item)) {
637
  $price_as_cart_discount[$rule_id][$product_id] = array(
638
- 'discount_type' => 'wdr_cart_discount',
639
- 'apply_type' => $cart_discount->type,
640
- 'discount_label' => $discount_label,
641
- 'discount_value' => $cart_discount->value,
642
- 'discounted_price' => $discounted_price,
643
  'rule_name' => $rule->getTitle(),
644
  'cart_item_key' => isset($cart_item['key']) ? $cart_item['key'] : '',
645
  'product_id' => self::$woocommerce_helper->getProductId($cart_item['data']),
646
  'rule_id' => $rule_id,
647
  );
648
- $discounts[$rule_id] = (isset($discounted_price_array[0]['discount_fee']) && !empty($discounted_price_array[0]['discount_fee'])) ? $discounted_price_array[0]['discount_fee'] : 0;
649
  }
650
  }
651
- break;
652
- case 'wdr_bulk_discount':
653
- if ($bulk_discount = $rule->getBulkAdjustments()) {
654
- if (isset($bulk_discount->apply_as_cart_rule) && !empty($bulk_discount->apply_as_cart_rule)) {
655
- $this_apply_as_cart_rule = true;
656
- if(!empty($cart_item)) {
657
- $price_as_cart_discount[$rule_id][$product_id] = array(
658
- 'discount_type' => 'wdr_bulk_discount',
659
- 'discount_label' => $bulk_discount->cart_label,
660
- 'discount_value' => 0,
661
- 'discounted_price' => $cart_discounted_price,
662
- 'rule_name' => $rule->getTitle(),
663
- 'cart_item_key' => isset($cart_item['key']) ? $cart_item['key'] : '',
664
- 'product_id' => self::$woocommerce_helper->getProductId($cart_item['data']),
665
- 'rule_id' => $rule_id,
666
- );
667
- $discounts[$rule_id] = $discounted_price;
668
- }
669
- }
670
  }
671
- break;
672
- default:
673
- $apply_discount_in_cart = apply_filters('advanced_woo_discount_rules_apply_the_discount_as_fee_in_cart', false, $rule);
674
- if($apply_discount_in_cart === true){
 
675
  $this_apply_as_cart_rule = true;
676
- $price_as_cart_discount = apply_filters('advanced_woo_discount_rules_fee_values', $price_as_cart_discount, $rule, $cart_discounted_price, $product_id, $cart_item);
677
- $discounts[$rule_id] = $discounted_price;
 
 
 
 
 
 
 
 
 
 
 
678
  }
679
- break;
680
- }
681
- $show_stike_out_depends_cart_rule[] = ($this_apply_as_cart_rule === true) ? 'yes' : 'no';
682
- if( $this_apply_as_cart_rule === true){
683
- continue;
684
- }
 
 
 
 
 
 
 
 
 
685
  //}
686
  if($discount_type === 'wdr_cart_discount'){
687
  continue;
@@ -759,11 +762,12 @@ class DiscountCalculator extends Base
759
  if (isset(self::$rules[$rule_id]) && isset($discounts[$rule_id])) {
760
  if(!empty($discounts[$rule_id])){
761
  //$discount_price += $discounts[$rule_id];
762
- $matched_price_discounts = $this->getDiscountForMatchedItemAndRule(self::$total_discounts[$matched_item_key][$rule_id]);
763
- if(!empty($matched_price_discounts)){
764
- $price_discounts = array_merge($price_discounts, $matched_price_discounts);
 
 
765
  }
766
-
767
  }
768
  self::$applied_rules[$rule_id] = self::$rules[$rule_id];
769
  }
@@ -775,7 +779,12 @@ class DiscountCalculator extends Base
775
  self::$total_discounts[$matched_item_key] = $valid_discounts[$matched_item_key];
776
  }
777
  $product_price = floatval($product_price);
778
- $discount_values = $this->calculateDiscountFromMatchedRule($product_price, $matched_item_key, $quantity, $price_discounts);
 
 
 
 
 
779
  $discounted_price = $product_price - $discount_values['discount_price'];
780
  if ($discounted_price < 0 ) {
781
  $discounted_price = 0;
@@ -822,7 +831,7 @@ class DiscountCalculator extends Base
822
  * @param $price_discounts int/float
823
  * @return array
824
  * */
825
- protected function calculateDiscountFromMatchedRule($product_price, $matched_item_key, $quantity, $price_discounts){
826
  if(isset(self::$original_price_of_product[$matched_item_key])){
827
  $product_price = self::$original_price_of_product[$matched_item_key];
828
  } else {
@@ -837,7 +846,7 @@ class DiscountCalculator extends Base
837
  }
838
  $discount_price = 0;
839
  $discount_lines = array();
840
- $discount_lines['non_applied'] = array('quantity' => $quantity, 'discount' => 0, 'price' => $product_price);
841
  $price_discounts = $this->mergeAdditionalDiscounts($price_discounts);
842
  foreach ($price_discounts as $price_discount){
843
  // $discount_price = $discount_price+($price_discount['discount_price']);
@@ -845,7 +854,7 @@ class DiscountCalculator extends Base
845
  $available_qty = $discount_lines['non_applied']['quantity'];
846
  $applied_qty = 0;
847
  if($available_qty > 0 && $discount_qty <= $available_qty){
848
- $current_product_price = $discount_lines['non_applied']['price'];
849
  $available_qty = $discount_lines['non_applied']['quantity'];
850
  $discount_lines['non_applied']['quantity'] = $available_qty - $discount_qty;
851
  $current_discount_amount = $rule->calculator($price_discount['discount_type'], $current_product_price, $price_discount['discount_value']);
@@ -858,9 +867,9 @@ class DiscountCalculator extends Base
858
  foreach ($discount_lines as $key_f => $discount_line){
859
  if($key_f !== 'non_applied'){
860
  if($apply_subsequently === true){
861
- $current_product_price = $discount_lines['non_applied']['price'] - $discount_lines[$key_f]['discount'];
862
  } else {
863
- $current_product_price = $discount_lines['non_applied']['price'];
864
  }
865
  $available_qty = $discount_lines[$key_f]['quantity'];
866
  if($available_qty > $discount_qty){
@@ -881,7 +890,7 @@ class DiscountCalculator extends Base
881
  if($remaining_qty > 0){
882
  $available_qty = $quantity-$applied_qty;
883
  if($remaining_qty <= $available_qty){
884
- $current_product_price = $discount_lines['non_applied']['price'];
885
  $discount_lines['non_applied']['quantity'] = $available_qty - $remaining_qty;
886
  $current_discount_amount = $rule->calculator($price_discount['discount_type'], $current_product_price, $price_discount['discount_value']);
887
  if($apply_subsequently === true) $current_product_price = $current_product_price - $current_discount_amount;
@@ -979,29 +988,29 @@ class DiscountCalculator extends Base
979
  $cart_discount_against_product = array();
980
  $apply_as_cart_fee_details = self::$price_discount_apply_as_cart_discount;
981
  if (!empty($apply_as_cart_fee_details) && !empty($cart)) {
982
- foreach ($apply_as_cart_fee_details as $rule_id => $product_id){
983
- $discount_value = 0;
984
- $rule_applied_product_id = array();
985
- foreach ($product_id as $detail) {
986
- $discount_value += isset($detail['discounted_price']) ? $detail['discounted_price'] : 0 ;
987
- $label = (isset($detail['discount_label']) && !empty($detail['discount_label'])) ? $detail['discount_label'] : $detail['rule_name'];
988
- $value = (isset($detail['discount_value']) && !empty($detail['discount_value'])) ? $detail['discount_value'] : 0;
989
- $product_id = isset($detail['product_id']) ? $detail['product_id'] : 0;
990
- $rule_applied_product_id = array_merge($rule_applied_product_id, array($product_id));
991
- $current_discounted_price = isset($detail['discounted_price']) ? $detail['discounted_price'] : 0 ;
992
- $cart_discount_against_product[$product_id][$rule_id] = $current_discounted_price;
993
- }
994
- if(!empty($rule_applied_product_id)){
995
- $rule_applied_product_id = array_unique($rule_applied_product_id);
996
- }
997
- self::$cart_adjustments[$rule_id]['cart_discount'] = isset($value) ? $value : '';
998
- self::$cart_adjustments[$rule_id]['cart_shipping'] = 'no';
999
- self::$cart_adjustments[$rule_id]['cart_discount_label'] = isset($label) ? $label : '';
1000
- self::$cart_adjustments[$rule_id]['cart_discount_price'] = $discount_value;
1001
- self::$cart_adjustments[$rule_id]['cart_discount_product_price'] = $cart_discount_against_product;
1002
- self::$cart_adjustments[$rule_id]['applied_product_ids'] = $rule_applied_product_id;
1003
  }
1004
- array_push($cart_discount_arr, $apply_as_cart_fee_details);
 
 
 
 
 
 
 
 
 
 
1005
  if ($discount_calculation_call) {
1006
  return self::$cart_adjustments;
1007
  }
@@ -1115,7 +1124,7 @@ class DiscountCalculator extends Base
1115
  static public function getUsedCoupons(){
1116
  $all_used_coupons = array();
1117
  foreach (self::$rules as $rule) {
1118
- $used_coupons_per_rule = $rule->hasUsedCoupons();
1119
  if($used_coupons_per_rule && !empty($used_coupons_per_rule)){
1120
  $all_used_coupons = array_merge($all_used_coupons,$used_coupons_per_rule);
1121
  }
112
  }
113
 
114
  if($calculate_discount_from != 'sale_price' && Woocommerce::productTypeIs($product, array('variable'))) {
115
+ /*Process lowest regular price of variant*/
116
  if($discount_type == 'fixed_price'){
117
  $discounted_price = $this->mayHaveTax($product, $discounted_price);
118
  }
186
  'discount_value' => $discount_value,
187
  'discount_price' => $discount_price,
188
  'discounted_price' => $discounted_price,
189
+ 'rule_title' => __($rule_title, WDR_TEXT_DOMAIN)
190
  );
191
  }
192
 
209
  $product_price = self::$woocommerce_helper->getProductPrice($product);
210
  }
211
  if(empty($product_price)){
212
+ $product_price = 0;
213
  }
214
  $language_helper_object = self::$language_helper;
215
  $discount_calculator = $this;
235
  }
236
  $html_content = $rule->getAdvancedDiscountMessage('badge_text');
237
  //if ($has_product_discount || $has_bulk_discount || $has_set_discount || $has_cart_discount) {
238
+ if ($rule->isFilterPassed($product, true) && !empty($html_content)) {
239
+ if ($has_product_discount) {
240
+ $product_adjustments = $rule->getProductAdjustments();
241
+ if (is_object($product_adjustments) && !empty($product_adjustments) && !empty($product_adjustments->value)) {
242
+ $discount_method = "product_discount";
243
+ $discount_price = $rule->calculator($product_adjustments->type, $product_price, $product_adjustments->value);
244
+ $value = (isset($product_adjustments->value) && !empty($product_adjustments->value)) ? $product_adjustments->value : 0;
245
+ $badge_bg_color = $rule->getAdvancedDiscountMessage('badge_color_picker', '#ffffff');
246
+ $badge_text_color = $rule->getAdvancedDiscountMessage('badge_text_color_picker', '#000000');
247
+ $this->advancedLayoutTextFormation($advanced_layout, $rule, $product_adjustments->type, $discount_method, $product_price, $value, $discount_price, $discounted_title_text, $html_content, $badge_bg_color, $badge_text_color);
248
+ }
249
+ }
250
+ if ($has_cart_discount) {
251
+ $cart_discount = $rule->getCartAdjustments();
252
+ if (!empty($cart_discount)) {
253
+ if (is_object($cart_discount) && !empty($cart_discount) && !empty($cart_discount->value)) {
254
+ $discount_method = "cart_discount";
255
+ $discount_price = $rule->calculator($cart_discount->type, $product_price, $cart_discount->value);
256
+ $value = (isset($cart_discount->value) && !empty($cart_discount->value)) ? $cart_discount->value : 0;
257
  $badge_bg_color = $rule->getAdvancedDiscountMessage('badge_color_picker', '#ffffff');
258
  $badge_text_color = $rule->getAdvancedDiscountMessage('badge_text_color_picker', '#000000');
259
+ $this->advancedLayoutTextFormation($advanced_layout, $rule, $cart_discount->type, $discount_method, $product_price, $value, $discount_price, $discounted_title_text, $html_content, $badge_bg_color, $badge_text_color);
260
  }
261
  }
262
+ }
263
+ if ($has_bulk_discount) {
264
+ $bulk_adjustments = $rule->getBulkAdjustments();
265
+ if (isset($bulk_adjustments) && is_object($bulk_adjustments) && !empty($bulk_adjustments) && isset($bulk_adjustments->ranges) && !empty($bulk_adjustments->ranges)) {
266
+ foreach ($bulk_adjustments->ranges as $range) {
267
+ if (isset($range->value) && !empty($range->value)) {
268
+ $min = intval(isset($range->from) ? $range->from : 0);
269
+ $max = intval(isset($range->to) ? $range->to : 0);
270
+ if (empty($min) && empty($max)) {
271
+ continue;
272
+ } else {
273
+ $discount_method = "bulk_discount";
274
+ $discount_type = isset($range->type)? $range->type: 'percentage';
275
+ $discount_price = $rule->calculator($discount_type, $product_price, $range->value);
276
+ $value = (isset($range->value) && !empty($range->value)) ? $range->value : 0;
277
+ $badge_bg_color = $rule->getAdvancedDiscountMessage('badge_color_picker', '#ffffff');
278
+ $badge_text_color = $rule->getAdvancedDiscountMessage('badge_text_color_picker', '#000000');
279
+ $this->advancedLayoutTextFormation($advanced_layout, $rule, $discount_type, $discount_method, $product_price, $value, $discount_price, $discounted_title_text, $html_content, $badge_bg_color, $badge_text_color, $min, $max);
 
 
 
 
 
 
 
 
 
 
 
 
 
280
  }
281
  }
282
  }
283
  }
 
 
 
 
 
 
284
  }
285
+ if($discount_type == 'wdr_free_shipping' || $discount_type == 'wdr_buy_x_get_x_discount'){
286
+ $discount_method = "free_shipping";
287
+ $badge_bg_color = $rule->getAdvancedDiscountMessage('badge_color_picker', '#ffffff');
288
+ $badge_text_color = $rule->getAdvancedDiscountMessage('badge_text_color_picker', '#000000');
289
+ $this->advancedLayoutTextFormation($advanced_layout, $rule, 'free_shipping', $discount_method, $product_price, '0', '0', $discounted_title_text, $html_content, $badge_bg_color, $badge_text_color, 0, 0);
290
+ }
291
+ }
292
  //}
293
  $advanced_layout = apply_filters('advanced_woo_discount_rules_advance_table_based_on_rule', $advanced_layout, $rule, $discount_calculator, $product, $product_price, $html_content);
294
  }
321
  $discounted_price_text = '';
322
  switch ($type) {
323
  case 'fixed_price':
324
+ if (!empty($value) && !empty($product_price)) {
325
  $value = Woocommerce::getConvertedFixedPrice($value, 'fixed_price');
326
  if($value < 0){
327
  $value = 0;
332
  }
333
  break;
334
  case 'fixed_set_price':
335
+ if (!empty($value) && !empty($min) && !empty($product_price)) {
336
  $value = Woocommerce::getConvertedFixedPrice($value, 'fixed_set_price');
337
  $discounted_price = $value / $min;
338
  if($discounted_price < 0){
344
  }
345
  break;
346
  case 'percentage':
347
+ if (!empty($value) && !empty($discount_price) && !empty($product_price)) {
348
  $discount = $product_price - $discount_price;
349
  if($discount < 0){
350
  $discount = 0;
358
  break;
359
  default:
360
  case 'flat':
361
+ if (!empty($value) && !empty($product_price)) {
362
  $value = Woocommerce::getConvertedFixedPrice($value, 'flat');
363
  $discount = $product_price - $value;
364
  if($discount < 0){
370
  break;
371
  }
372
  //if (!empty($discount_text) && !empty($discounted_price_text)) {
373
+ $dont_allow_duplicate = true;
374
+ if ($discount_method == "bulk_discount") {
375
+ $searchForReplace = array('{{title}}', '{{min_quantity}}', '{{max_quantity}}', '{{discount}}', '{{discounted_price}}');//, '{{min_quantity}}', '{{max_quantity}}', '{{discount}}', '{{discounted_price}}'
376
+ $string_to_replace = array($discounted_title_text, $min, $max, $discount_text, $discounted_price_text); //, $min, $max, $discount_text, $discounted_price_text
377
+ $html_content = str_replace($searchForReplace, $string_to_replace, $html_content);
378
+ } elseif ($discount_method == "set_discount") {
379
+ $searchForReplace = array('{{title}}', '{{min_quantity}}', '{{discount}}', '{{discounted_price}}'); //, '{{min_quantity}}', '{{discount}}', '{{discounted_price}}'
380
+ $string_to_replace = array($discounted_title_text, $min, $discount_text, $discounted_price_text);//, $min, $discount_text, $discounted_price_text
381
+ $html_content = str_replace($searchForReplace, $string_to_replace, $html_content);
382
+ $searchForRemove = array('/{{max_quantity}}/');
383
+ $replacements = array('');
384
+ $html_content = preg_replace($searchForRemove, $replacements, $html_content);
385
+ } else if($discount_method == 'free_shipping'){
386
+ $searchForReplace = array('{{title}}');
387
+ $string_to_replace = array($discounted_title_text);
388
+ $html_content = str_replace($searchForReplace, $string_to_replace, $html_content);
389
+ $searchForRemove = array('/{{min_quantity}}/', '/{{max_quantity}}/', '/{{discount}}/', '/{{discounted_price}}/');
390
+ $replacements = array('', '');
391
+ $html_content = preg_replace($searchForRemove, $replacements, $html_content);
392
+ }else {
393
+ $searchForReplace = array('{{title}}', '{{discount}}', '{{discounted_price}}');//, '{{discount}}', '{{discounted_price}}'
394
+ $string_to_replace = array($discounted_title_text, $discount_text, $discounted_price_text);//, $discount_text, $discounted_price_text
395
+ $html_content = str_replace($searchForReplace, $string_to_replace, $html_content);
396
+ $searchForRemove = array('/{{min_quantity}}/', '/{{max_quantity}}/');
397
+ $replacements = array('', '');
398
+ $html_content = preg_replace($searchForRemove, $replacements, $html_content);
399
+ }
400
+ if (!empty($advanced_layout)) {
401
+ foreach ($advanced_layout as $layout_options) {
402
+ $check_exists = array($layout_options['badge_text']);
403
+ if (in_array($html_content, $check_exists)) {
404
+ $dont_allow_duplicate = false;
405
+ break;
 
406
  }
407
  }
408
+ }
409
+ if ($dont_allow_duplicate) {
410
+ $advanced_layout[] = array(
411
+ 'badge_bg_color' => $badge_bg_color,
412
+ 'badge_text_color' => $badge_text_color,
413
+ 'badge_text' => $html_content,
414
+ 'rule_id' => $rule->rule->id,
415
+ );
416
+ }
417
  //}
418
  }
419
 
463
  $product_price = $custom_price;
464
  }
465
 
466
+ if ($rule->isFilterPassed($product) || $rule->rule->discount_type == 'wdr_free_shipping') {
467
  if ($rule->hasConditions()) {
468
  if ($rule->isCartConditionsPassed($cart)) {
469
  $rule_passed = true;
472
  $rule_passed = true;
473
  }
474
  if($rule_passed){
475
+ if($rule->rule->discount_type == 'wdr_free_shipping'){
476
+ $has_exclusive_rule = true;
477
+ } else {
478
+ if(!in_array($rule->rule->discount_type, array('wdr_buy_x_get_x_discount', 'wdr_set_discount'))){
479
+ if ($discounted_price = $rule->calculateDiscount($product_price, $quantity, $product, $ajax_price, $cart_item, $price_display_condition, $is_cart, $manual_request)) {
480
+ $has_exclusive_rule = true;
481
+ } else {
482
+ $rule_passed = apply_filters('advanced_woo_discount_rules_is_rule_passed_with_out_discount_for_exclusive_rule', false, $product, $rule, $cart_item);
483
+ if($rule_passed){
484
+ $has_exclusive_rule = true;
485
+ }
486
+ }
487
  } else {
488
  $rule_passed = apply_filters('advanced_woo_discount_rules_is_rule_passed_with_out_discount_for_exclusive_rule', false, $product, $rule, $cart_item);
489
  if($rule_passed){
490
  $has_exclusive_rule = true;
491
  }
492
  }
 
 
 
 
 
493
  }
494
  }
495
  } else {
541
  }
542
 
543
  $original_product_price = apply_filters('advanced_woo_discount_rules_product_original_price_on_before_calculate_discount', $product_price, $product, $quantity, $cart_item, $calculate_discount_from);
544
+ $calculate_from_price = $product_price = apply_filters('advanced_woo_discount_rules_product_price_on_before_calculate_discount', $product_price, $product, $quantity, $cart_item, $calculate_discount_from);
545
 
546
  $exclusive_rules = $discounts = $exclude_products = array();
547
  $cart = self::$woocommerce_helper->getCart();
611
  }
612
  }
613
  //if(!empty($cart_item)) {
614
+ $this_apply_as_cart_rule = false;
615
+ switch ($discount_type) {
616
+ case 'wdr_simple_discount':
617
+ if ($simple_discount = $rule->getProductAdjustments()) {
618
+ if (isset($simple_discount->apply_as_cart_rule) && !empty($simple_discount->apply_as_cart_rule)) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
619
  $this_apply_as_cart_rule = true;
620
  if(!empty($cart_item)) {
621
  $price_as_cart_discount[$rule_id][$product_id] = array(
622
+ 'discount_type' => 'wdr_simple_discount',
623
+ 'discount_label' => $simple_discount->cart_label,
624
+ 'discount_value' => $simple_discount->value,
625
+ 'discounted_price' => $cart_discounted_price,
 
626
  'rule_name' => $rule->getTitle(),
627
  'cart_item_key' => isset($cart_item['key']) ? $cart_item['key'] : '',
628
  'product_id' => self::$woocommerce_helper->getProductId($cart_item['data']),
629
  'rule_id' => $rule_id,
630
  );
631
+ $discounts[$rule_id] = $discounted_price;
632
  }
633
  }
634
+ }
635
+ break;
636
+ case 'wdr_cart_discount':
637
+ if ($cart_discount = $rule->getCartAdjustments()) {
638
+ $this_apply_as_cart_rule = true;
639
+ if(!empty($cart_item)) {
640
+ $price_as_cart_discount[$rule_id][$product_id] = array(
641
+ 'discount_type' => 'wdr_cart_discount',
642
+ 'apply_type' => $cart_discount->type,
643
+ 'discount_label' => $discount_label,
644
+ 'discount_value' => $cart_discount->value,
645
+ 'discounted_price' => $discounted_price,
646
+ 'rule_name' => $rule->getTitle(),
647
+ 'cart_item_key' => isset($cart_item['key']) ? $cart_item['key'] : '',
648
+ 'product_id' => self::$woocommerce_helper->getProductId($cart_item['data']),
649
+ 'rule_id' => $rule_id,
650
+ );
651
+ $discounts[$rule_id] = (isset($discounted_price_array[0]['discount_fee']) && !empty($discounted_price_array[0]['discount_fee'])) ? $discounted_price_array[0]['discount_fee'] : 0;
 
652
  }
653
+ }
654
+ break;
655
+ case 'wdr_bulk_discount':
656
+ if ($bulk_discount = $rule->getBulkAdjustments()) {
657
+ if (isset($bulk_discount->apply_as_cart_rule) && !empty($bulk_discount->apply_as_cart_rule)) {
658
  $this_apply_as_cart_rule = true;
659
+ if(!empty($cart_item)) {
660
+ $price_as_cart_discount[$rule_id][$product_id] = array(
661
+ 'discount_type' => 'wdr_bulk_discount',
662
+ 'discount_label' => $bulk_discount->cart_label,
663
+ 'discount_value' => 0,
664
+ 'discounted_price' => $cart_discounted_price,
665
+ 'rule_name' => $rule->getTitle(),
666
+ 'cart_item_key' => isset($cart_item['key']) ? $cart_item['key'] : '',
667
+ 'product_id' => self::$woocommerce_helper->getProductId($cart_item['data']),
668
+ 'rule_id' => $rule_id,
669
+ );
670
+ $discounts[$rule_id] = $discounted_price;
671
+ }
672
  }
673
+ }
674
+ break;
675
+ default:
676
+ $apply_discount_in_cart = apply_filters('advanced_woo_discount_rules_apply_the_discount_as_fee_in_cart', false, $rule);
677
+ if($apply_discount_in_cart === true){
678
+ $this_apply_as_cart_rule = true;
679
+ $price_as_cart_discount = apply_filters('advanced_woo_discount_rules_fee_values', $price_as_cart_discount, $rule, $cart_discounted_price, $product_id, $cart_item);
680
+ $discounts[$rule_id] = $discounted_price;
681
+ }
682
+ break;
683
+ }
684
+ $show_stike_out_depends_cart_rule[] = ($this_apply_as_cart_rule === true) ? 'yes' : 'no';
685
+ if( $this_apply_as_cart_rule === true){
686
+ continue;
687
+ }
688
  //}
689
  if($discount_type === 'wdr_cart_discount'){
690
  continue;
762
  if (isset(self::$rules[$rule_id]) && isset($discounts[$rule_id])) {
763
  if(!empty($discounts[$rule_id])){
764
  //$discount_price += $discounts[$rule_id];
765
+ if(isset(self::$total_discounts[$matched_item_key]) && isset(self::$total_discounts[$matched_item_key][$rule_id])){
766
+ $matched_price_discounts = $this->getDiscountForMatchedItemAndRule(self::$total_discounts[$matched_item_key][$rule_id]);
767
+ if(!empty($matched_price_discounts)){
768
+ $price_discounts = array_merge($price_discounts, $matched_price_discounts);
769
+ }
770
  }
 
771
  }
772
  self::$applied_rules[$rule_id] = self::$rules[$rule_id];
773
  }
779
  self::$total_discounts[$matched_item_key] = $valid_discounts[$matched_item_key];
780
  }
781
  $product_price = floatval($product_price);
782
+ if($product_price == floatval($calculate_from_price)){
783
+ $discount_values = $this->calculateDiscountFromMatchedRule($product_price, $matched_item_key, $quantity, $price_discounts, $product_price);
784
+ } else {
785
+ $discount_values = $this->calculateDiscountFromMatchedRule($product_price, $matched_item_key, $quantity, $price_discounts, floatval($calculate_from_price));
786
+ }
787
+
788
  $discounted_price = $product_price - $discount_values['discount_price'];
789
  if ($discounted_price < 0 ) {
790
  $discounted_price = 0;
831
  * @param $price_discounts int/float
832
  * @return array
833
  * */
834
+ protected function calculateDiscountFromMatchedRule($product_price, $matched_item_key, $quantity, $price_discounts, $calculate_discount_from){
835
  if(isset(self::$original_price_of_product[$matched_item_key])){
836
  $product_price = self::$original_price_of_product[$matched_item_key];
837
  } else {
846
  }
847
  $discount_price = 0;
848
  $discount_lines = array();
849
+ $discount_lines['non_applied'] = array('quantity' => $quantity, 'discount' => 0, 'price' => $product_price, 'calculate_discount_from' => $calculate_discount_from);
850
  $price_discounts = $this->mergeAdditionalDiscounts($price_discounts);
851
  foreach ($price_discounts as $price_discount){
852
  // $discount_price = $discount_price+($price_discount['discount_price']);
854
  $available_qty = $discount_lines['non_applied']['quantity'];
855
  $applied_qty = 0;
856
  if($available_qty > 0 && $discount_qty <= $available_qty){
857
+ $current_product_price = $discount_lines['non_applied']['calculate_discount_from'];
858
  $available_qty = $discount_lines['non_applied']['quantity'];
859
  $discount_lines['non_applied']['quantity'] = $available_qty - $discount_qty;
860
  $current_discount_amount = $rule->calculator($price_discount['discount_type'], $current_product_price, $price_discount['discount_value']);
867
  foreach ($discount_lines as $key_f => $discount_line){
868
  if($key_f !== 'non_applied'){
869
  if($apply_subsequently === true){
870
+ $current_product_price = $discount_lines['non_applied']['calculate_discount_from'] - $discount_lines[$key_f]['discount'];
871
  } else {
872
+ $current_product_price = $discount_lines['non_applied']['calculate_discount_from'];
873
  }
874
  $available_qty = $discount_lines[$key_f]['quantity'];
875
  if($available_qty > $discount_qty){
890
  if($remaining_qty > 0){
891
  $available_qty = $quantity-$applied_qty;
892
  if($remaining_qty <= $available_qty){
893
+ $current_product_price = $discount_lines['non_applied']['calculate_discount_from'];
894
  $discount_lines['non_applied']['quantity'] = $available_qty - $remaining_qty;
895
  $current_discount_amount = $rule->calculator($price_discount['discount_type'], $current_product_price, $price_discount['discount_value']);
896
  if($apply_subsequently === true) $current_product_price = $current_product_price - $current_discount_amount;
988
  $cart_discount_against_product = array();
989
  $apply_as_cart_fee_details = self::$price_discount_apply_as_cart_discount;
990
  if (!empty($apply_as_cart_fee_details) && !empty($cart)) {
991
+ foreach ($apply_as_cart_fee_details as $rule_id => $product_id){
992
+ $discount_value = 0;
993
+ $rule_applied_product_id = array();
994
+ foreach ($product_id as $detail) {
995
+ $discount_value += isset($detail['discounted_price']) ? $detail['discounted_price'] : 0 ;
996
+ $label = (isset($detail['discount_label']) && !empty($detail['discount_label'])) ? $detail['discount_label'] : $detail['rule_name'];
997
+ $value = (isset($detail['discount_value']) && !empty($detail['discount_value'])) ? $detail['discount_value'] : 0;
998
+ $product_id = isset($detail['product_id']) ? $detail['product_id'] : 0;
999
+ $rule_applied_product_id = array_merge($rule_applied_product_id, array($product_id));
1000
+ $current_discounted_price = isset($detail['discounted_price']) ? $detail['discounted_price'] : 0 ;
1001
+ $cart_discount_against_product[$product_id][$rule_id] = $current_discounted_price;
 
 
 
 
 
 
 
 
 
 
1002
  }
1003
+ if(!empty($rule_applied_product_id)){
1004
+ $rule_applied_product_id = array_unique($rule_applied_product_id);
1005
+ }
1006
+ self::$cart_adjustments[$rule_id]['cart_discount'] = isset($value) ? $value : '';
1007
+ self::$cart_adjustments[$rule_id]['cart_shipping'] = 'no';
1008
+ self::$cart_adjustments[$rule_id]['cart_discount_label'] = isset($label) ? $label : '';
1009
+ self::$cart_adjustments[$rule_id]['cart_discount_price'] = $discount_value;
1010
+ self::$cart_adjustments[$rule_id]['cart_discount_product_price'] = $cart_discount_against_product;
1011
+ self::$cart_adjustments[$rule_id]['applied_product_ids'] = $rule_applied_product_id;
1012
+ }
1013
+ array_push($cart_discount_arr, $apply_as_cart_fee_details);
1014
  if ($discount_calculation_call) {
1015
  return self::$cart_adjustments;
1016
  }
1124
  static public function getUsedCoupons(){
1125
  $all_used_coupons = array();
1126
  foreach (self::$rules as $rule) {
1127
+ $used_coupons_per_rule = $rule->hasUsedCoupons();
1128
  if($used_coupons_per_rule && !empty($used_coupons_per_rule)){
1129
  $all_used_coupons = array_merge($all_used_coupons,$used_coupons_per_rule);
1130
  }
v2/App/Controllers/ManageDiscount.php CHANGED
@@ -466,14 +466,14 @@ class ManageDiscount extends Base
466
  if ($min_original_price == $max_original_price) {
467
  $price_html = self::$woocommerce_helper->formatPrice($min_original_price) . $price_range_suffix;
468
  } elseif ($min_original_price < $max_original_price) {
469
- $price_html = self::$woocommerce_helper->formatPriceRange($min_original_price, $max_original_price) . $price_range_suffix;
470
  }
471
 
472
  if ($min_price == $max_price) {
473
  $price_html_discounted = self::$woocommerce_helper->formatPrice($min_price) . $price_range_suffix;
474
  return $this->getStrikeoutPrice($price_html, $price_html_discounted, false, true);
475
  } elseif ($min_price < $max_price) {
476
- $price_html_discounted = self::$woocommerce_helper->formatPriceRange($min_price, $max_price) . $price_range_suffix;
477
  return $this->getStrikeoutPrice($price_html, $price_html_discounted, false, true);
478
  }
479
  }
@@ -510,7 +510,7 @@ class ManageDiscount extends Base
510
  $html = '<del>' . $original_price . '</del>' . $separator . '<ins>' . $discounted_price . '</ins>';
511
  }
512
  }
513
- return apply_filters('advanced_woo_discount_rules_strikeout_price_html', $html, $original_price, $discounted_price);
514
  }
515
 
516
  /**
@@ -845,7 +845,9 @@ class ManageDiscount extends Base
845
  $total_combined_discounts = 0;
846
  $combined_discounts_cart_items = array();
847
  if(function_exists('WC')){
848
- $this->applyCartProductDiscount(WC()->cart);
 
 
849
  }
850
  $apply_as_cart_fee_details = DiscountCalculator::$price_discount_apply_as_cart_discount;
851
  DiscountCalculator::$price_discount_apply_as_cart_discount = array();
@@ -871,6 +873,7 @@ class ManageDiscount extends Base
871
  if ($discount_value > 0) {
872
  if (empty($combine_all_discounts)) {
873
  $discount_value = $discount_value;
 
874
  self::setCartCouponValues($label, $discount_value, $cart_item_keys);
875
  $this->applyFakeCouponsForCartRules($label);
876
  }else{
@@ -886,6 +889,7 @@ class ManageDiscount extends Base
886
  if(empty($combine_all_discounts)){
887
  $discount_value = $discount['value'];
888
  $label = $discount['label'];
 
889
  self::setCartCouponValues($label, $discount_value, $discount['cart_item_keys']);
890
  $this->applyFakeCouponsForCartRules($label);
891
  }else{
@@ -902,6 +906,7 @@ class ManageDiscount extends Base
902
  if(empty($label)){
903
  $label = __('Cart discount', WDR_TEXT_DOMAIN);
904
  }
 
905
  self::setCartCouponValues($label, $total_combined_discounts, $combined_discounts_cart_items);
906
  $this->applyFakeCouponsForCartRules($label);
907
  }
@@ -1199,12 +1204,12 @@ class ManageDiscount extends Base
1199
  if (array_key_exists($key, self::$calculated_cart_item_discount)) {
1200
  $processed_rule = true;
1201
  $product_id = isset($cart_item['product_id']) ? $cart_item['product_id'] : 0;
1202
- if (empty($product_id)) {
1203
- return false;
1204
- }
1205
  if (isset($cart_item['variation_id']) && !empty($cart_item['variation_id'])) {
1206
  $product_id = $cart_item['variation_id'];
1207
  }
 
 
 
1208
  $product_obj = isset($cart_item['data']) ? $cart_item['data'] : $cart_item;
1209
  $item_quantity = isset($cart_item['quantity']) ? $cart_item['quantity'] : 0;
1210
  //product price
@@ -2453,12 +2458,14 @@ class ManageDiscount extends Base
2453
  * Include tax in fee
2454
  * */
2455
  public function applyTaxInFee($fee, $cart){
2456
- if(Woocommerce::isEnteredPriceIncludeTax()){
2457
- if(class_exists('\WC_Tax')){
2458
- $fee_taxs = \WC_Tax::calc_tax( $fee, \WC_Tax::get_rates( '', \WC()->cart->get_customer() ), true );
2459
- if(!empty($fee_taxs)){
2460
- foreach ($fee_taxs as $key => $val){
2461
- $fee = $fee - $val;
 
 
2462
  }
2463
  }
2464
  }
466
  if ($min_original_price == $max_original_price) {
467
  $price_html = self::$woocommerce_helper->formatPrice($min_original_price) . $price_range_suffix;
468
  } elseif ($min_original_price < $max_original_price) {
469
+ $price_html = self::$woocommerce_helper->formatPriceRange($min_original_price, $max_original_price, true) . $price_range_suffix;
470
  }
471
 
472
  if ($min_price == $max_price) {
473
  $price_html_discounted = self::$woocommerce_helper->formatPrice($min_price) . $price_range_suffix;
474
  return $this->getStrikeoutPrice($price_html, $price_html_discounted, false, true);
475
  } elseif ($min_price < $max_price) {
476
+ $price_html_discounted = self::$woocommerce_helper->formatPriceRange($min_price, $max_price, false) . $price_range_suffix;
477
  return $this->getStrikeoutPrice($price_html, $price_html_discounted, false, true);
478
  }
479
  }
510
  $html = '<del>' . $original_price . '</del>' . $separator . '<ins>' . $discounted_price . '</ins>';
511
  }
512
  }
513
+ return apply_filters('advanced_woo_discount_rules_strikeout_price_html', $html, $original_price, $discounted_price, $is_variable_product);
514
  }
515
 
516
  /**
845
  $total_combined_discounts = 0;
846
  $combined_discounts_cart_items = array();
847
  if(function_exists('WC')){
848
+ if(apply_filters('advanced_woo_discount_rules_recalculate_discount_before_apply_coupon', true)){
849
+ $this->applyCartProductDiscount(WC()->cart);
850
+ }
851
  }
852
  $apply_as_cart_fee_details = DiscountCalculator::$price_discount_apply_as_cart_discount;
853
  DiscountCalculator::$price_discount_apply_as_cart_discount = array();
873
  if ($discount_value > 0) {
874
  if (empty($combine_all_discounts)) {
875
  $discount_value = $discount_value;
876
+ $label = __($label, WDR_TEXT_DOMAIN);
877
  self::setCartCouponValues($label, $discount_value, $cart_item_keys);
878
  $this->applyFakeCouponsForCartRules($label);
879
  }else{
889
  if(empty($combine_all_discounts)){
890
  $discount_value = $discount['value'];
891
  $label = $discount['label'];
892
+ $label = __($label, WDR_TEXT_DOMAIN);
893
  self::setCartCouponValues($label, $discount_value, $discount['cart_item_keys']);
894
  $this->applyFakeCouponsForCartRules($label);
895
  }else{
906
  if(empty($label)){
907
  $label = __('Cart discount', WDR_TEXT_DOMAIN);
908
  }
909
+ $label = __($label, WDR_TEXT_DOMAIN);
910
  self::setCartCouponValues($label, $total_combined_discounts, $combined_discounts_cart_items);
911
  $this->applyFakeCouponsForCartRules($label);
912
  }
1204
  if (array_key_exists($key, self::$calculated_cart_item_discount)) {
1205
  $processed_rule = true;
1206
  $product_id = isset($cart_item['product_id']) ? $cart_item['product_id'] : 0;
 
 
 
1207
  if (isset($cart_item['variation_id']) && !empty($cart_item['variation_id'])) {
1208
  $product_id = $cart_item['variation_id'];
1209
  }
1210
+ if (empty($product_id)) {
1211
+ return false;
1212
+ }
1213
  $product_obj = isset($cart_item['data']) ? $cart_item['data'] : $cart_item;
1214
  $item_quantity = isset($cart_item['quantity']) ? $cart_item['quantity'] : 0;
1215
  //product price
2458
  * Include tax in fee
2459
  * */
2460
  public function applyTaxInFee($fee, $cart){
2461
+ if(Woocommerce::isTaxEnabled()){
2462
+ if(Woocommerce::isEnteredPriceIncludeTax()){
2463
+ if(class_exists('\WC_Tax')){
2464
+ $fee_taxs = \WC_Tax::calc_tax( $fee, \WC_Tax::get_rates( '', \WC()->cart->get_customer() ), true );
2465
+ if(!empty($fee_taxs)){
2466
+ foreach ($fee_taxs as $key => $val){
2467
+ $fee = $fee - $val;
2468
+ }
2469
  }
2470
  }
2471
  }
v2/App/Helpers/Filter.php CHANGED
@@ -197,6 +197,7 @@ class Filter
197
  $product_variation = Woocommerce::getProduct(Woocommerce::getProductParentId($product));
198
  foreach ($attrs as $taxonomy => $value) {
199
  if ($value) {
 
200
  $term_obj = get_term_by('slug', $value, $taxonomy);
201
  if (!is_wp_error($term_obj) && $term_obj && $term_obj->name) {
202
  $attr_ids = array_merge($attr_ids, (array)($term_obj->term_id));
197
  $product_variation = Woocommerce::getProduct(Woocommerce::getProductParentId($product));
198
  foreach ($attrs as $taxonomy => $value) {
199
  if ($value) {
200
+ $taxonomy = apply_filters('advanced_woo_discount_rules_attribute_slug', urldecode($taxonomy), $taxonomy, $value);
201
  $term_obj = get_term_by('slug', $value, $taxonomy);
202
  if (!is_wp_error($term_obj) && $term_obj && $term_obj->name) {
203
  $attr_ids = array_merge($attr_ids, (array)($term_obj->term_id));
v2/App/Helpers/Helper.php CHANGED
@@ -329,9 +329,9 @@ class Helper
329
 
330
  public static function displayCompatibleCheckMessages()
331
  {
332
- if (version_compare(WDR_VERSION, '2.3.2', '>=')) {
333
  if (defined('WDR_PRO_VERSION')) {
334
- if (version_compare(WDR_PRO_VERSION, '2.3.2', '<')) {
335
  $url = admin_url() . "plugins.php";
336
  $plugin_page = '<a target="_blank" href="' . $url . '">' . __('Update now', WDR_TEXT_DOMAIN) . '</a>';
337
  ?>
329
 
330
  public static function displayCompatibleCheckMessages()
331
  {
332
+ if (version_compare(WDR_VERSION, '2.3.3', '>=')) {
333
  if (defined('WDR_PRO_VERSION')) {
334
+ if (version_compare(WDR_PRO_VERSION, '2.3.3', '<')) {
335
  $url = admin_url() . "plugins.php";
336
  $plugin_page = '<a target="_blank" href="' . $url . '">' . __('Update now', WDR_TEXT_DOMAIN) . '</a>';
337
  ?>
v2/App/Helpers/Rule.php CHANGED
@@ -389,7 +389,7 @@ class Rule
389
  $filter_helper = new Filter();
390
  $filter_passed = $filter_helper->matchFilters($product, $filters, $sale_badge, $product_table);
391
  $conditions = $this->getConditions();
392
- $filter_passed_user_logged_in = $user_logged_in_passed = $filter_passed_user_role = $filter_passed_user_list = $user_role_passed = $user_list_passed = $has_other_conditions = false;
393
  $condition_relationship = $this->getRelationship('condition', 'and');
394
  if($filter_passed){
395
  if(!empty($conditions)){
@@ -400,28 +400,34 @@ class Rule
400
  if( !empty($condition_type) ){
401
  if (!empty($options) && isset($this->available_conditions[$condition_type]['object']) && is_object($this->available_conditions[$condition_type]['object']) && method_exists($this->available_conditions[$condition_type]['object'], 'check')) {
402
  $this->available_conditions[$condition_type]['object']->rule = $this;
403
- if( $condition_type == 'user_role'){
404
- $user_role_passed = true;
405
- $filter_passed_user_role = $this->available_conditions[$condition_type]['object']->check($cart, $options);
406
- }
407
- if( $condition_type == 'user_list'){
408
- $user_list_passed = true;
409
- $filter_passed_user_list = $this->available_conditions[$condition_type]['object']->check($cart, $options);
410
- }
411
- if( $condition_type == 'user_logged_in'){
412
- $user_logged_in_passed = true;
413
- $filter_passed_user_logged_in = $this->available_conditions[$condition_type]['object']->check($cart, $options);
 
 
 
 
 
 
414
  }
415
  }
416
  }
417
 
418
- if( !empty($condition_type) && !in_array($condition_type, array('user_role', 'user_list', 'user_logged_in'))){
419
  $has_other_conditions = true;
420
  }
421
  }
422
  }
423
- if($user_role_passed || $user_list_passed || $user_logged_in_passed){
424
- if($filter_passed_user_role || $filter_passed_user_list || $filter_passed_user_logged_in){
425
  if($condition_relationship == 'and'){
426
  if($user_role_passed && $user_logged_in_passed){
427
  if($filter_passed_user_role && $filter_passed_user_logged_in){
@@ -435,6 +441,12 @@ class Rule
435
  $filter_passed = false;
436
  }
437
  }
 
 
 
 
 
 
438
  //$this -> rule
439
  $filter_passed = apply_filters('advanced_woo_discount_rules_customer_condition_filter_passed', $filter_passed, $this, $product, $sale_badge, $product_table, $conditions);
440
  }
@@ -723,6 +735,7 @@ class Rule
723
  }else if($price_display_condition == "show_after_matched" || $is_cart){
724
  if(!empty($cart_items)){
725
  foreach ($cart_items as $cart_item){
 
726
  $current_product_parent_id = self::$woocommerce_helper->getProductParentId($product);
727
  $cart_product_id = isset($cart_item['product_id']) ? $cart_item['product_id'] : 0;
728
  $cart_variation_id = isset($cart_item['variation_id']) ? $cart_item['variation_id'] : 0;
@@ -734,6 +747,8 @@ class Rule
734
  if(!empty($cart_variation_id)){
735
  if(!empty($cart_product_id) && $cart_product_id == $current_product_parent_id){
736
  $cart_quantity = isset($cart_item['quantity']) ? $cart_item['quantity'] : 0;
 
 
737
  }
738
  }
739
  }
@@ -1017,7 +1032,7 @@ class Rule
1017
  function calculator($type, $original_value, $value)
1018
  {
1019
  $discount = 0;
1020
- if (empty($value)) {
1021
  return $discount;
1022
  }
1023
  $original_value = floatval($original_value);
389
  $filter_helper = new Filter();
390
  $filter_passed = $filter_helper->matchFilters($product, $filters, $sale_badge, $product_table);
391
  $conditions = $this->getConditions();
392
+ $purchase_first_order_passed = $filter_passed_purchase_first_order = $filter_passed_user_logged_in = $user_logged_in_passed = $filter_passed_user_role = $filter_passed_user_list = $user_role_passed = $user_list_passed = $has_other_conditions = false;
393
  $condition_relationship = $this->getRelationship('condition', 'and');
394
  if($filter_passed){
395
  if(!empty($conditions)){
400
  if( !empty($condition_type) ){
401
  if (!empty($options) && isset($this->available_conditions[$condition_type]['object']) && is_object($this->available_conditions[$condition_type]['object']) && method_exists($this->available_conditions[$condition_type]['object'], 'check')) {
402
  $this->available_conditions[$condition_type]['object']->rule = $this;
403
+ switch ($condition_type){
404
+ case 'user_role':
405
+ $user_role_passed = true;
406
+ $filter_passed_user_role = $this->available_conditions[$condition_type]['object']->check($cart, $options);
407
+ break;
408
+ case 'user_list':
409
+ $user_list_passed = true;
410
+ $filter_passed_user_list = $this->available_conditions[$condition_type]['object']->check($cart, $options);
411
+ break;
412
+ case 'user_logged_in':
413
+ $user_logged_in_passed = true;
414
+ $filter_passed_user_logged_in = $this->available_conditions[$condition_type]['object']->check($cart, $options);
415
+ break;
416
+ case 'purchase_first_order':
417
+ $purchase_first_order_passed = true;
418
+ $filter_passed_purchase_first_order = $this->available_conditions[$condition_type]['object']->check($cart, $options);
419
+ break;
420
  }
421
  }
422
  }
423
 
424
+ if( !empty($condition_type) && !in_array($condition_type, array('user_role', 'user_list', 'user_logged_in', 'purchase_first_order'))){
425
  $has_other_conditions = true;
426
  }
427
  }
428
  }
429
+ if($user_role_passed || $user_list_passed || $user_logged_in_passed || $purchase_first_order_passed){
430
+ if($filter_passed_user_role || $filter_passed_user_list || $filter_passed_user_logged_in || $filter_passed_purchase_first_order){
431
  if($condition_relationship == 'and'){
432
  if($user_role_passed && $user_logged_in_passed){
433
  if($filter_passed_user_role && $filter_passed_user_logged_in){
441
  $filter_passed = false;
442
  }
443
  }
444
+ if($purchase_first_order_passed && $user_logged_in_passed){
445
+ if($filter_passed_purchase_first_order && $filter_passed_user_logged_in){
446
+ }else{
447
+ $filter_passed = false;
448
+ }
449
+ }
450
  //$this -> rule
451
  $filter_passed = apply_filters('advanced_woo_discount_rules_customer_condition_filter_passed', $filter_passed, $this, $product, $sale_badge, $product_table, $conditions);
452
  }
735
  }else if($price_display_condition == "show_after_matched" || $is_cart){
736
  if(!empty($cart_items)){
737
  foreach ($cart_items as $cart_item){
738
+ $cart_product_parent_id = isset($cart_item['data']) ? self::$woocommerce_helper->getProductParentId($cart_item['data']) : '';
739
  $current_product_parent_id = self::$woocommerce_helper->getProductParentId($product);
740
  $cart_product_id = isset($cart_item['product_id']) ? $cart_item['product_id'] : 0;
741
  $cart_variation_id = isset($cart_item['variation_id']) ? $cart_item['variation_id'] : 0;
747
  if(!empty($cart_variation_id)){
748
  if(!empty($cart_product_id) && $cart_product_id == $current_product_parent_id){
749
  $cart_quantity = isset($cart_item['quantity']) ? $cart_item['quantity'] : 0;
750
+ }elseif (empty($cart_product_id) && $cart_product_parent_id == $current_product_parent_id){
751
+ $cart_quantity = isset($cart_item['quantity']) ? $cart_item['quantity'] : 0;
752
  }
753
  }
754
  }
1032
  function calculator($type, $original_value, $value)
1033
  {
1034
  $discount = 0;
1035
+ if (empty($value) || empty($original_value)) {
1036
  return $discount;
1037
  }
1038
  $original_value = floatval($original_value);
v2/App/Helpers/Woocommerce.php CHANGED
@@ -389,9 +389,10 @@ class Woocommerce
389
  * format the price //range
390
  * @param $min_price
391
  * @param $max_price
 
392
  * @return string
393
  */
394
- static function formatPriceRange($min_price, $max_price)
395
  {
396
  if (function_exists('wc_format_price_range')) {
397
  $html = wc_format_price_range($min_price, $max_price);
@@ -399,7 +400,7 @@ class Woocommerce
399
  $html = self::formatPrice($min_price) . ' - ' . self::formatPrice($max_price);
400
  }
401
 
402
- return apply_filters('advanced_woo_discount_rules_format_sale_price_range', $html, $min_price, $max_price);
403
  }
404
 
405
  /**
@@ -730,12 +731,21 @@ class Woocommerce
730
  }, 10, 3);
731
  }
732
  $fee = apply_filters('advanced_discount_rules_discount_fee_amount', $fee, $name, $cart);
 
733
  return $cart->add_fee($name, $fee);
734
  }
735
  }
736
  return array();
737
  }
738
 
 
 
 
 
 
 
 
 
739
  static function isEnteredPriceIncludeTax(){
740
  if(get_option('woocommerce_prices_include_tax', 'no') == 'no'){
741
  return false;
389
  * format the price //range
390
  * @param $min_price
391
  * @param $max_price
392
+ * @param $original_html
393
  * @return string
394
  */
395
+ static function formatPriceRange($min_price, $max_price, $original_html = false)
396
  {
397
  if (function_exists('wc_format_price_range')) {
398
  $html = wc_format_price_range($min_price, $max_price);
400
  $html = self::formatPrice($min_price) . ' - ' . self::formatPrice($max_price);
401
  }
402
 
403
+ return apply_filters('advanced_woo_discount_rules_format_sale_price_range', $html, $min_price, $max_price, $original_html);
404
  }
405
 
406
  /**
731
  }, 10, 3);
732
  }
733
  $fee = apply_filters('advanced_discount_rules_discount_fee_amount', $fee, $name, $cart);
734
+ $name = __($name, WDR_TEXT_DOMAIN);
735
  return $cart->add_fee($name, $fee);
736
  }
737
  }
738
  return array();
739
  }
740
 
741
+ static function isTaxEnabled(){
742
+ if(get_option( 'woocommerce_calc_taxes' ) === 'yes'){
743
+ return true;
744
+ } else {
745
+ return false;
746
+ }
747
+ }
748
+
749
  static function isEnteredPriceIncludeTax(){
750
  if(get_option('woocommerce_prices_include_tax', 'no') == 'no'){
751
  return false;
woo-discount-rules.php CHANGED
@@ -5,13 +5,13 @@
5
  * Description: Simple to complex discount rules for your WooCommerce store. Core package.
6
  * Author: Flycart Technologies LLP
7
  * Author URI: https://www.flycart.org
8
- * Version: 2.3.2
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: 3.0
14
- * WC tested up to: 4.6
15
  */
16
  if (!defined('ABSPATH')) {
17
  exit;
@@ -21,7 +21,7 @@ if (!defined('ABSPATH')) {
21
  * Current version of our app
22
  */
23
  if (!defined('WDR_VERSION')) {
24
- define('WDR_VERSION', '2.3.2');
25
  }
26
 
27
  global $awdr_load_version;
5
  * Description: Simple to complex discount rules for your WooCommerce store. Core package.
6
  * Author: Flycart Technologies LLP
7
  * Author URI: https://www.flycart.org
8
+ * Version: 2.3.3
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: 3.0
14
+ * WC tested up to: 4.8
15
  */
16
  if (!defined('ABSPATH')) {
17
  exit;
21
  * Current version of our app
22
  */
23
  if (!defined('WDR_VERSION')) {
24
+ define('WDR_VERSION', '2.3.3');
25
  }
26
 
27
  global $awdr_load_version;