Discount Rules for WooCommerce - Version 1.7.3

Version Description

  • 12/12/18 =
  • Fix - Fatal error on discount table when config is not yet save
  • Fix - Warning while the price is in string format
  • Feature - BOGO in Cart rules(pro)
  • Feature - Option to include and variant while choose parent products
Download this release

Release Info

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

Code changes from version 1.7.2 to 1.7.3

assets/css/style.css CHANGED
@@ -189,4 +189,7 @@ span.wdr_block_span{
189
  }
190
  .wdr_invalid{
191
  border-color: red !important;
 
 
 
192
  }
189
  }
190
  .wdr_invalid{
191
  border-color: red !important;
192
+ }
193
+ .small-text{
194
+ width: unset !important;
195
  }
assets/js/app.js CHANGED
@@ -699,10 +699,19 @@ function trigger_woocommerce_tooltip(){
699
 
700
  $('#cart_rule_discount_type').on('change', function () {
701
  var option = $(this).val();
702
- if (option == 'shipping_price') {
703
- $('#cart_rule_discount_value_con').addClass('wdr_hide_important');
704
- } else {
705
- $('#cart_rule_discount_value_con').removeClass('wdr_hide_important');
 
 
 
 
 
 
 
 
 
706
  }
707
  });
708
  $('#cart_rule_discount_type').trigger('change');
699
 
700
  $('#cart_rule_discount_type').on('change', function () {
701
  var option = $(this).val();
702
+ switch (option) {
703
+ case 'shipping_price':
704
+ $('#cart_rule_discount_value_con').addClass('wdr_hide_important');
705
+ $('#cart_rule_product_discount_field').addClass('wdr_hide_important');
706
+ break;
707
+ case 'product_discount':
708
+ $('#cart_rule_discount_value_con').addClass('wdr_hide_important');
709
+ $('#cart_rule_product_discount_field').removeClass('wdr_hide_important');
710
+ break;
711
+ default:
712
+ $('#cart_rule_product_discount_field').addClass('wdr_hide_important');
713
+ $('#cart_rule_discount_value_con').removeClass('wdr_hide_important');
714
+ break;
715
  }
716
  });
717
  $('#cart_rule_discount_type').trigger('change');
helper/woo-function.php CHANGED
@@ -152,6 +152,17 @@ if(!class_exists('FlycartWoocommerceProduct')){
152
  }
153
  }
154
 
 
 
 
 
 
 
 
 
 
 
 
155
  /**
156
  * Get WooCommerce product price
157
  *
152
  }
153
  }
154
 
155
+ /**
156
+ * Get WooCommerce product name
157
+ *
158
+ * @access public
159
+ * @param array $product
160
+ * @return int/float
161
+ */
162
+ public static function get_name($product){
163
+ return FlycartWoocommerceVersion::wcVersion('3.0') ? $product->get_name() : $product->name;
164
+ }
165
+
166
  /**
167
  * Get WooCommerce product price
168
  *
i18n/languages/woo-discount-rules.pot CHANGED
@@ -103,11 +103,11 @@ msgstr ""
103
  msgid "License key seems to be Invalid. Please enter a valid license key"
104
  msgstr ""
105
 
106
- #: helper/woo-function.php:355 helper/woo-function.php:365
107
  msgid "Search for a product…"
108
  msgstr ""
109
 
110
- #: helper/woo-function.php:398 helper/woo-function.php:410
111
  msgid "Search for a user…"
112
  msgstr ""
113
 
@@ -119,13 +119,13 @@ msgstr ""
119
  msgid "Custom Shipping Method for Woocommerce Discount Rules"
120
  msgstr ""
121
 
122
- #: includes/advanced/free_shipping_method.php:68 view/settings.php:492
123
  msgid "Free Shipping"
124
  msgstr ""
125
 
126
  #: includes/advanced/free_shipping_method.php:73 includes/discount-base.php:897
127
- #: view/cart-rules.php:127 view/pricing-rules.php:157 view/settings.php:573
128
- #: view/settings.php:608
129
  msgid "Enable"
130
  msgstr ""
131
 
@@ -147,9 +147,9 @@ msgid "Active"
147
  msgstr ""
148
 
149
  #: includes/discount-base.php:180 view/cart-rules.php:143
150
- #: view/pricing-rules.php:173 view/settings.php:227 view/settings.php:362
151
- #: view/settings.php:461 view/settings.php:468 view/settings.php:570
152
- #: view/settings.php:605
153
  msgid "Disabled"
154
  msgstr ""
155
 
@@ -620,92 +620,92 @@ msgid ""
620
  "no.of quantities"
621
  msgstr ""
622
 
623
- #: includes/pricing-rules.php:2549 view/view-pricing-rules.php:561
624
  msgid "Buy"
625
  msgstr ""
626
 
627
- #: includes/pricing-rules.php:2553
628
  msgid " less than or equal to "
629
  msgstr ""
630
 
631
- #: includes/pricing-rules.php:2553 includes/pricing-rules.php:2559
632
  msgid " Quantity"
633
  msgstr ""
634
 
635
- #: includes/pricing-rules.php:2556
636
  msgid " Quantity "
637
  msgstr ""
638
 
639
- #: includes/pricing-rules.php:2563
640
  msgid " or more Quantity"
641
  msgstr ""
642
 
643
- #: includes/pricing-rules.php:2572
644
  msgid " any "
645
  msgstr ""
646
 
647
- #: includes/pricing-rules.php:2572
648
  msgid " products from "
649
  msgstr ""
650
 
651
- #: includes/pricing-rules.php:2579
652
  msgid " in each products"
653
  msgstr ""
654
 
655
- #: includes/pricing-rules.php:2591
656
  msgid " and get discount in "
657
  msgstr ""
658
 
659
- #: includes/pricing-rules.php:2594
660
  msgid " first "
661
  msgstr ""
662
 
663
- #: includes/pricing-rules.php:2596 includes/pricing-rules.php:2600
664
  msgid " quantity of product(s) - "
665
  msgstr ""
666
 
667
- #: includes/pricing-rules.php:2598
668
  msgid " after first "
669
  msgstr ""
670
 
671
- #: includes/pricing-rules.php:2616
672
  msgid "Category(ies) "
673
  msgstr ""
674
 
675
- #: includes/pricing-rules.php:2682
676
  msgid "Get "
677
  msgstr ""
678
 
679
- #: includes/pricing-rules.php:2684
680
  #, php-format
681
  msgid "% discount in "
682
  msgstr ""
683
 
684
- #: includes/pricing-rules.php:2687
685
  msgid "same product"
686
  msgstr ""
687
 
688
- #: includes/pricing-rules.php:2689
689
  msgid "any cheapest one from cart"
690
  msgstr ""
691
 
692
- #: includes/pricing-rules.php:2692
693
  msgid "any cheapest one of "
694
  msgstr ""
695
 
696
- #: includes/pricing-rules.php:2697
697
  msgid " quantity of any "
698
  msgstr ""
699
 
700
- #: includes/pricing-rules.php:2699
701
  msgid " cheapest item "
702
  msgstr ""
703
 
704
- #: includes/pricing-rules.php:2702
705
  msgid " quantity of cheapest item "
706
  msgstr ""
707
 
708
- #: includes/pricing-rules.php:2706
709
  msgid "from the category "
710
  msgstr ""
711
 
@@ -952,13 +952,13 @@ msgstr ""
952
 
953
  #: view/settings.php:88 view/settings.php:105 view/settings.php:117
954
  #: view/settings.php:130 view/settings.php:336 view/settings.php:348
955
- #: view/settings.php:535
956
  msgid "Yes"
957
  msgstr ""
958
 
959
  #: view/settings.php:89 view/settings.php:106 view/settings.php:118
960
  #: view/settings.php:131 view/settings.php:337 view/settings.php:349
961
- #: view/settings.php:536 view/view-cart-rules.php:568
962
  #: view/view-pricing-rules.php:410
963
  msgid "No"
964
  msgstr ""
@@ -991,17 +991,17 @@ msgstr ""
991
  msgid "Rule Setup for Price:"
992
  msgstr ""
993
 
994
- #: view/settings.php:156 view/settings.php:425
995
  msgid "Apply first matched rule"
996
  msgstr ""
997
 
998
- #: view/settings.php:162 view/settings.php:164 view/settings.php:431
999
- #: view/settings.php:433
1000
  msgid "Apply all matched rules"
1001
  msgstr ""
1002
 
1003
- #: view/settings.php:171 view/settings.php:173 view/settings.php:440
1004
- #: view/settings.php:442
1005
  msgid "Apply biggest discount"
1006
  msgstr ""
1007
 
@@ -1070,113 +1070,117 @@ msgstr ""
1070
  msgid "Auto add free product on coupon applied (For coupon based rules)"
1071
  msgstr ""
1072
 
1073
- #: view/settings.php:356
 
 
 
 
1074
  msgid "Display savings text"
1075
  msgstr ""
1076
 
1077
- #: view/settings.php:365
1078
  msgid "On each line item"
1079
  msgstr ""
1080
 
1081
- #: view/settings.php:368
1082
  msgid "On after total"
1083
  msgstr ""
1084
 
1085
- #: view/settings.php:371
1086
  msgid "Both in line item and after total"
1087
  msgstr ""
1088
 
1089
- #: view/settings.php:379
1090
  msgid "Savings text to show"
1091
  msgstr ""
1092
 
1093
- #: view/settings.php:387
1094
  msgid "{{total_discount_price}} -> Total discount applied"
1095
  msgstr ""
1096
 
1097
- #: view/settings.php:399
1098
  msgid "Cart rules settings"
1099
  msgstr ""
1100
 
1101
- #: view/settings.php:406
1102
  msgid "Coupon Name to be displayed :"
1103
  msgstr ""
1104
 
1105
- #: view/settings.php:412
1106
  msgid "Discount Coupon Name"
1107
  msgstr ""
1108
 
1109
- #: view/settings.php:419
1110
  msgid "Rule Setup for Cart:"
1111
  msgstr ""
1112
 
1113
- #: view/settings.php:451
1114
  msgid "Enable free shipping option"
1115
  msgstr ""
1116
 
1117
- #: view/settings.php:458 view/view-pricing-rules.php:300
1118
  #: view/view-pricing-rules.php:357 view/view-pricing-rules.php:422
1119
  #: view/view-pricing-rules.php:468 view/view-pricing-rules.php:497
1120
  msgid "Supported in PRO version"
1121
  msgstr ""
1122
 
1123
- #: view/settings.php:471
1124
  msgid "Use Woocommerce free shipping"
1125
  msgstr ""
1126
 
1127
- #: view/settings.php:474
1128
  msgid "Use Woo-Discount free shipping"
1129
  msgstr ""
1130
 
1131
- #: view/settings.php:488
1132
  msgid "Free shipping text to be displayed"
1133
  msgstr ""
1134
 
1135
- #: view/settings.php:495
1136
  msgid "Free Shipping title"
1137
  msgstr ""
1138
 
1139
- #: view/settings.php:502
1140
  msgid "Draft"
1141
  msgstr ""
1142
 
1143
- #: view/settings.php:512
1144
  msgid "Exclude Draft products in product select box."
1145
  msgstr ""
1146
 
1147
- #: view/settings.php:522
1148
  msgid "Performance settings"
1149
  msgstr ""
1150
 
1151
- #: view/settings.php:530
1152
  msgid "Enable cache for variable products table content"
1153
  msgstr ""
1154
 
1155
- #: view/settings.php:542 view/settings.php:546
1156
  msgid "Clear cache"
1157
  msgstr ""
1158
 
1159
- #: view/settings.php:556
1160
  msgid "Promotion settings"
1161
  msgstr ""
1162
 
1163
- #: view/settings.php:563
1164
  msgid "Show a message on applying price rules in cart"
1165
  msgstr ""
1166
 
1167
- #: view/settings.php:581 view/settings.php:616
1168
  msgid "Message"
1169
  msgstr ""
1170
 
1171
- #: view/settings.php:589 view/settings.php:624
1172
  msgid "{{title}} -> Rule title"
1173
  msgstr ""
1174
 
1175
- #: view/settings.php:590 view/settings.php:625
1176
  msgid "{{description}} -> Rule description"
1177
  msgstr ""
1178
 
1179
- #: view/settings.php:598
1180
  msgid "Show a message on applying cart rules in cart"
1181
  msgstr ""
1182
 
@@ -1294,7 +1298,7 @@ msgstr ""
1294
  msgid "in cart to"
1295
  msgstr ""
1296
 
1297
- #: view/view-cart-rules.php:587 view/view-cart-rules.php:648
1298
  #: view/view-pricing-rules.php:619 view/view-pricing-rules.php:817
1299
  msgid "Previous"
1300
  msgstr ""
@@ -1308,13 +1312,25 @@ msgid "Discount Type :"
1308
  msgstr ""
1309
 
1310
  #: view/view-cart-rules.php:629 view/view-cart-rules.php:631
 
 
 
 
1311
  msgid "Free shipping"
1312
  msgstr ""
1313
 
1314
- #: view/view-cart-rules.php:640
1315
  msgid "value :"
1316
  msgstr ""
1317
 
 
 
 
 
 
 
 
 
1318
  #: view/view-pricing-rules.php:43
1319
  msgid "New Price Rule"
1320
  msgstr ""
103
  msgid "License key seems to be Invalid. Please enter a valid license key"
104
  msgstr ""
105
 
106
+ #: helper/woo-function.php:366 helper/woo-function.php:376
107
  msgid "Search for a product…"
108
  msgstr ""
109
 
110
+ #: helper/woo-function.php:409 helper/woo-function.php:421
111
  msgid "Search for a user…"
112
  msgstr ""
113
 
119
  msgid "Custom Shipping Method for Woocommerce Discount Rules"
120
  msgstr ""
121
 
122
+ #: includes/advanced/free_shipping_method.php:68 view/settings.php:504
123
  msgid "Free Shipping"
124
  msgstr ""
125
 
126
  #: includes/advanced/free_shipping_method.php:73 includes/discount-base.php:897
127
+ #: view/cart-rules.php:127 view/pricing-rules.php:157 view/settings.php:585
128
+ #: view/settings.php:620
129
  msgid "Enable"
130
  msgstr ""
131
 
147
  msgstr ""
148
 
149
  #: includes/discount-base.php:180 view/cart-rules.php:143
150
+ #: view/pricing-rules.php:173 view/settings.php:227 view/settings.php:374
151
+ #: view/settings.php:473 view/settings.php:480 view/settings.php:582
152
+ #: view/settings.php:617
153
  msgid "Disabled"
154
  msgstr ""
155
 
620
  "no.of quantities"
621
  msgstr ""
622
 
623
+ #: includes/pricing-rules.php:2559 view/view-pricing-rules.php:561
624
  msgid "Buy"
625
  msgstr ""
626
 
627
+ #: includes/pricing-rules.php:2563
628
  msgid " less than or equal to "
629
  msgstr ""
630
 
631
+ #: includes/pricing-rules.php:2563 includes/pricing-rules.php:2569
632
  msgid " Quantity"
633
  msgstr ""
634
 
635
+ #: includes/pricing-rules.php:2566
636
  msgid " Quantity "
637
  msgstr ""
638
 
639
+ #: includes/pricing-rules.php:2573
640
  msgid " or more Quantity"
641
  msgstr ""
642
 
643
+ #: includes/pricing-rules.php:2582
644
  msgid " any "
645
  msgstr ""
646
 
647
+ #: includes/pricing-rules.php:2582
648
  msgid " products from "
649
  msgstr ""
650
 
651
+ #: includes/pricing-rules.php:2589
652
  msgid " in each products"
653
  msgstr ""
654
 
655
+ #: includes/pricing-rules.php:2601
656
  msgid " and get discount in "
657
  msgstr ""
658
 
659
+ #: includes/pricing-rules.php:2604
660
  msgid " first "
661
  msgstr ""
662
 
663
+ #: includes/pricing-rules.php:2606 includes/pricing-rules.php:2610
664
  msgid " quantity of product(s) - "
665
  msgstr ""
666
 
667
+ #: includes/pricing-rules.php:2608
668
  msgid " after first "
669
  msgstr ""
670
 
671
+ #: includes/pricing-rules.php:2626
672
  msgid "Category(ies) "
673
  msgstr ""
674
 
675
+ #: includes/pricing-rules.php:2692
676
  msgid "Get "
677
  msgstr ""
678
 
679
+ #: includes/pricing-rules.php:2694
680
  #, php-format
681
  msgid "% discount in "
682
  msgstr ""
683
 
684
+ #: includes/pricing-rules.php:2697
685
  msgid "same product"
686
  msgstr ""
687
 
688
+ #: includes/pricing-rules.php:2699
689
  msgid "any cheapest one from cart"
690
  msgstr ""
691
 
692
+ #: includes/pricing-rules.php:2702
693
  msgid "any cheapest one of "
694
  msgstr ""
695
 
696
+ #: includes/pricing-rules.php:2707
697
  msgid " quantity of any "
698
  msgstr ""
699
 
700
+ #: includes/pricing-rules.php:2709
701
  msgid " cheapest item "
702
  msgstr ""
703
 
704
+ #: includes/pricing-rules.php:2712
705
  msgid " quantity of cheapest item "
706
  msgstr ""
707
 
708
+ #: includes/pricing-rules.php:2716
709
  msgid "from the category "
710
  msgstr ""
711
 
952
 
953
  #: view/settings.php:88 view/settings.php:105 view/settings.php:117
954
  #: view/settings.php:130 view/settings.php:336 view/settings.php:348
955
+ #: view/settings.php:360 view/settings.php:547
956
  msgid "Yes"
957
  msgstr ""
958
 
959
  #: view/settings.php:89 view/settings.php:106 view/settings.php:118
960
  #: view/settings.php:131 view/settings.php:337 view/settings.php:349
961
+ #: view/settings.php:361 view/settings.php:548 view/view-cart-rules.php:568
962
  #: view/view-pricing-rules.php:410
963
  msgid "No"
964
  msgstr ""
991
  msgid "Rule Setup for Price:"
992
  msgstr ""
993
 
994
+ #: view/settings.php:156 view/settings.php:437
995
  msgid "Apply first matched rule"
996
  msgstr ""
997
 
998
+ #: view/settings.php:162 view/settings.php:164 view/settings.php:443
999
+ #: view/settings.php:445
1000
  msgid "Apply all matched rules"
1001
  msgstr ""
1002
 
1003
+ #: view/settings.php:171 view/settings.php:173 view/settings.php:452
1004
+ #: view/settings.php:454
1005
  msgid "Apply biggest discount"
1006
  msgstr ""
1007
 
1070
  msgid "Auto add free product on coupon applied (For coupon based rules)"
1071
  msgstr ""
1072
 
1073
+ #: view/settings.php:355
1074
+ msgid "Include variants when just parent product is chosen in the rules"
1075
+ msgstr ""
1076
+
1077
+ #: view/settings.php:368
1078
  msgid "Display savings text"
1079
  msgstr ""
1080
 
1081
+ #: view/settings.php:377
1082
  msgid "On each line item"
1083
  msgstr ""
1084
 
1085
+ #: view/settings.php:380
1086
  msgid "On after total"
1087
  msgstr ""
1088
 
1089
+ #: view/settings.php:383
1090
  msgid "Both in line item and after total"
1091
  msgstr ""
1092
 
1093
+ #: view/settings.php:391
1094
  msgid "Savings text to show"
1095
  msgstr ""
1096
 
1097
+ #: view/settings.php:399
1098
  msgid "{{total_discount_price}} -> Total discount applied"
1099
  msgstr ""
1100
 
1101
+ #: view/settings.php:411
1102
  msgid "Cart rules settings"
1103
  msgstr ""
1104
 
1105
+ #: view/settings.php:418
1106
  msgid "Coupon Name to be displayed :"
1107
  msgstr ""
1108
 
1109
+ #: view/settings.php:424
1110
  msgid "Discount Coupon Name"
1111
  msgstr ""
1112
 
1113
+ #: view/settings.php:431
1114
  msgid "Rule Setup for Cart:"
1115
  msgstr ""
1116
 
1117
+ #: view/settings.php:463
1118
  msgid "Enable free shipping option"
1119
  msgstr ""
1120
 
1121
+ #: view/settings.php:470 view/view-pricing-rules.php:300
1122
  #: view/view-pricing-rules.php:357 view/view-pricing-rules.php:422
1123
  #: view/view-pricing-rules.php:468 view/view-pricing-rules.php:497
1124
  msgid "Supported in PRO version"
1125
  msgstr ""
1126
 
1127
+ #: view/settings.php:483
1128
  msgid "Use Woocommerce free shipping"
1129
  msgstr ""
1130
 
1131
+ #: view/settings.php:486
1132
  msgid "Use Woo-Discount free shipping"
1133
  msgstr ""
1134
 
1135
+ #: view/settings.php:500
1136
  msgid "Free shipping text to be displayed"
1137
  msgstr ""
1138
 
1139
+ #: view/settings.php:507
1140
  msgid "Free Shipping title"
1141
  msgstr ""
1142
 
1143
+ #: view/settings.php:514
1144
  msgid "Draft"
1145
  msgstr ""
1146
 
1147
+ #: view/settings.php:524
1148
  msgid "Exclude Draft products in product select box."
1149
  msgstr ""
1150
 
1151
+ #: view/settings.php:534
1152
  msgid "Performance settings"
1153
  msgstr ""
1154
 
1155
+ #: view/settings.php:542
1156
  msgid "Enable cache for variable products table content"
1157
  msgstr ""
1158
 
1159
+ #: view/settings.php:554 view/settings.php:558
1160
  msgid "Clear cache"
1161
  msgstr ""
1162
 
1163
+ #: view/settings.php:568
1164
  msgid "Promotion settings"
1165
  msgstr ""
1166
 
1167
+ #: view/settings.php:575
1168
  msgid "Show a message on applying price rules in cart"
1169
  msgstr ""
1170
 
1171
+ #: view/settings.php:593 view/settings.php:628
1172
  msgid "Message"
1173
  msgstr ""
1174
 
1175
+ #: view/settings.php:601 view/settings.php:636
1176
  msgid "{{title}} -> Rule title"
1177
  msgstr ""
1178
 
1179
+ #: view/settings.php:602 view/settings.php:637
1180
  msgid "{{description}} -> Rule description"
1181
  msgstr ""
1182
 
1183
+ #: view/settings.php:610
1184
  msgid "Show a message on applying cart rules in cart"
1185
  msgstr ""
1186
 
1298
  msgid "in cart to"
1299
  msgstr ""
1300
 
1301
+ #: view/view-cart-rules.php:587 view/view-cart-rules.php:684
1302
  #: view/view-pricing-rules.php:619 view/view-pricing-rules.php:817
1303
  msgid "Previous"
1304
  msgstr ""
1312
  msgstr ""
1313
 
1314
  #: view/view-cart-rules.php:629 view/view-cart-rules.php:631
1315
+ msgid "Product Discount"
1316
+ msgstr ""
1317
+
1318
+ #: view/view-cart-rules.php:638 view/view-cart-rules.php:640
1319
  msgid "Free shipping"
1320
  msgstr ""
1321
 
1322
+ #: view/view-cart-rules.php:649
1323
  msgid "value :"
1324
  msgstr ""
1325
 
1326
+ #: view/view-cart-rules.php:657
1327
+ msgid "Select products :"
1328
+ msgstr ""
1329
+
1330
+ #: view/view-cart-rules.php:671
1331
+ msgid "Quantity :"
1332
+ msgstr ""
1333
+
1334
  #: view/view-pricing-rules.php:43
1335
  msgid "New Price Rule"
1336
  msgstr ""
includes/cart-rules.php CHANGED
@@ -48,6 +48,7 @@ if (!class_exists('FlycartWooDiscountRulesCartRules')) {
48
  * @var int
49
  */
50
  public $discount_total = 0;
 
51
 
52
  public $has_category_in_rule = 0;
53
 
@@ -74,6 +75,7 @@ if (!class_exists('FlycartWooDiscountRulesCartRules')) {
74
  public static $cartRules;
75
 
76
  public $has_free_shipping = 0;
 
77
 
78
  /**
79
  * FlycartWooDiscountRulesCartRules constructor.
@@ -122,6 +124,7 @@ if (!class_exists('FlycartWooDiscountRulesCartRules')) {
122
  $slug = str_replace(' ', '-', $slug);
123
 
124
  $request['rule_descr'] = (isset($request['rule_descr']) ? str_replace('\'', '', $request['rule_descr']) : '');
 
125
  $form = array(
126
  'rule_name',
127
  'rule_descr',
@@ -129,6 +132,8 @@ if (!class_exists('FlycartWooDiscountRulesCartRules')) {
129
  'date_to',
130
  'apply_to',
131
  'discount_type',
 
 
132
  'to_discount',
133
  'discount_rule',
134
  'rule_order',
@@ -264,10 +269,14 @@ if (!class_exists('FlycartWooDiscountRulesCartRules')) {
264
  $flycart_woo_discount_rules->cart_rules = $this;
265
  // Add a Coupon Virtually (Temporary access).
266
  if(!$free_shipping_check)
267
- if ($this->discount_total != 0) {
268
- if(!FlycartWooDiscountRulesGeneralHelper::haveToApplyTheRules()) return false;
269
- add_filter('woocommerce_get_shop_coupon_data', array($this, 'addVirtualCoupon'), 10, 2);
270
- add_action('woocommerce_after_calculate_totals', array($this, 'applyFakeCoupons'));
 
 
 
 
271
  }
272
  }
273
 
@@ -311,7 +320,9 @@ if (!class_exists('FlycartWooDiscountRulesCartRules')) {
311
  if(!$this->has_category_in_rule){
312
  $discount_type = 'percent';
313
  //To calculate the percent from total
314
- $amount = ((100 * $this->discount_total) / $this->sub_total);
 
 
315
  }
316
  }
317
 
@@ -340,7 +351,49 @@ if (!class_exists('FlycartWooDiscountRulesCartRules')) {
340
  } else {
341
  $coupon['type'] = $discount_type;
342
  }
 
 
 
343
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
344
  return $coupon;
345
  }
346
  }
@@ -402,6 +455,37 @@ if (!class_exists('FlycartWooDiscountRulesCartRules')) {
402
  }
403
  }
404
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
405
  /**
406
  * Simply remove or reset the virtual coupon by set "empty" as value
407
  * to "Woo's" session "woo_coupon_removed".
@@ -530,7 +614,13 @@ if (!class_exists('FlycartWooDiscountRulesCartRules')) {
530
  $rule_sets[$index]['discount_rule'] = (isset($rule->discount_rule) ? $rule->discount_rule : false);
531
  $rule_sets[$index]['discount_type'] = (isset($rule->discount_type) ? $rule->discount_type : false);
532
  $rule_sets[$index]['to_discount'] = (isset($rule->to_discount) ? $rule->to_discount : false);
533
- $rule_sets[$index]['enabled'] = $this->validateCart($rule_sets[$index]['discount_rule']);
 
 
 
 
 
 
534
  }
535
  $rule_sets = apply_filters('woo_discount_rules_cart_rule_sets_to_apply', $rule_sets);
536
  $this->rule_sets = $rule_sets;
@@ -570,6 +660,9 @@ if (!class_exists('FlycartWooDiscountRulesCartRules')) {
570
  } else if ($rule['discount_type'] == 'price_discount') {
571
  // Getting the Flat Rate of Discount.
572
  $discounts['to_discount'][$index] = $this->calculateDiscount($this->sub_total, array('type' => 'price', 'value' => $rule['to_discount']));
 
 
 
573
  } else {
574
  //we will have to re-calculate the sub-total if it has category selected
575
  if($this->is_category_specific($rule)) {
@@ -603,6 +696,9 @@ if (!class_exists('FlycartWooDiscountRulesCartRules')) {
603
  } else if ($rule['discount_type'] == 'price_discount') {
604
  // Getting the Flat Rate of Discount.
605
  $discounts['to_discount'][$index] = $this->calculateDiscount($this->sub_total, array('type' => 'price', 'value' => $rule['to_discount']));
 
 
 
606
  } else {
607
  //we will have to re-calculate the sub-total if it has category selected
608
  if($this->is_category_specific($rule)) {
@@ -636,6 +732,9 @@ if (!class_exists('FlycartWooDiscountRulesCartRules')) {
636
  } else if ($rule['discount_type'] == 'price_discount') {
637
  // Getting the Flat Rate of Discount.
638
  $newDiscount = $this->calculateDiscount($this->sub_total, array('type' => 'price', 'value' => $rule['to_discount']));
 
 
 
639
  } else {
640
  //we will have to re-calculate the sub-total if it has category selected
641
  if($this->is_category_specific($rule)) {
@@ -1080,7 +1179,7 @@ if (!class_exists('FlycartWooDiscountRulesCartRules')) {
1080
  $ruleSuccess = $this->validateCartCouponAppliedAnyOne($index, $rule, $rules);
1081
  if($ruleSuccess){
1082
  if(is_string($rule)){
1083
- $coupons = explode(',', $rule);
1084
  } elseif (is_array($rule)){
1085
  $coupons = $rule;
1086
  } else {
@@ -1098,7 +1197,7 @@ if (!class_exists('FlycartWooDiscountRulesCartRules')) {
1098
  $ruleSuccess = $this->validateCartCouponAppliedAllSelected($index, $rule, $rules);
1099
  if($ruleSuccess){
1100
  if(is_string($rule)){
1101
- $coupons = explode(',', $rule);
1102
  } elseif (is_array($rule)){
1103
  $coupons = $rule;
1104
  } else {
@@ -1121,7 +1220,7 @@ if (!class_exists('FlycartWooDiscountRulesCartRules')) {
1121
  global $woocommerce;
1122
  $allowed = 0;
1123
  if(is_string($rule)){
1124
- $coupons = explode(',', $rule);
1125
  } elseif (is_array($rule)){
1126
  $coupons = $rule;
1127
  } else {
@@ -1144,7 +1243,7 @@ if (!class_exists('FlycartWooDiscountRulesCartRules')) {
1144
  global $woocommerce;
1145
  $allowed = 0;
1146
  if(is_string($rule)){
1147
- $coupons = explode(',', $rule);
1148
  } elseif (is_array($rule)){
1149
  $coupons = $rule;
1150
  } else {
@@ -1361,7 +1460,7 @@ if (!class_exists('FlycartWooDiscountRulesCartRules')) {
1361
  // Iterate over all cart items and
1362
  foreach ($this->cart_items as $cart_item_key => $cart_item) {
1363
  $quantity = (isset($cart_item['quantity']) && $cart_item['quantity']) ? $cart_item['quantity'] : 1;
1364
- $cart_subtotal += FlycartWoocommerceProduct::get_price($cart_item['data']) * $quantity;
1365
  }
1366
 
1367
  $this->sub_total = (float)$cart_subtotal;
@@ -1436,5 +1535,479 @@ if (!class_exists('FlycartWooDiscountRulesCartRules')) {
1436
  return ($discount <= 0) ? 0 : $discount;
1437
  }
1438
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1439
  }
1440
- }
48
  * @var int
49
  */
50
  public $discount_total = 0;
51
+ public $product_discount_total = 0;
52
 
53
  public $has_category_in_rule = 0;
54
 
75
  public static $cartRules;
76
 
77
  public $has_free_shipping = 0;
78
+ public $bogo_coupon_codes = array();
79
 
80
  /**
81
  * FlycartWooDiscountRulesCartRules constructor.
124
  $slug = str_replace(' ', '-', $slug);
125
 
126
  $request['rule_descr'] = (isset($request['rule_descr']) ? str_replace('\'', '', $request['rule_descr']) : '');
127
+ $request['cart_discounted_products'] = (isset($request['cart_discounted_products'])) ? json_encode($request['cart_discounted_products']) : '{}';
128
  $form = array(
129
  'rule_name',
130
  'rule_descr',
132
  'date_to',
133
  'apply_to',
134
  'discount_type',
135
+ 'cart_discounted_products',
136
+ 'product_discount_quantity',
137
  'to_discount',
138
  'discount_rule',
139
  'rule_order',
269
  $flycart_woo_discount_rules->cart_rules = $this;
270
  // Add a Coupon Virtually (Temporary access).
271
  if(!$free_shipping_check)
272
+ if ($this->discount_total != 0) {
273
+ if(!FlycartWooDiscountRulesGeneralHelper::haveToApplyTheRules()) return false;
274
+ add_filter('woocommerce_get_shop_coupon_data', array($this, 'addVirtualCoupon'), 10, 2);
275
+ add_action('woocommerce_after_calculate_totals', array($this, 'applyFakeCoupons'));
276
+ }
277
+ if($this->product_discount_total) {
278
+ add_action('woocommerce_after_calculate_totals', array($this, 'applyFakeCouponsForBOGO'));
279
+ add_filter('woocommerce_get_shop_coupon_data', array($this, 'addVirtualCouponForBOGO'), 10, 2);
280
  }
281
  }
282
 
320
  if(!$this->has_category_in_rule){
321
  $discount_type = 'percent';
322
  //To calculate the percent from total
323
+ if($this->sub_total > 0) {
324
+ $amount = ((100 * $this->discount_total) / $this->sub_total);
325
+ }
326
  }
327
  }
328
 
351
  } else {
352
  $coupon['type'] = $discount_type;
353
  }
354
+ return $coupon;
355
+ }
356
+ }
357
 
358
+ public function addVirtualCouponForBOGO($unknown_param, $old_coupon_code)
359
+ {
360
+ $bogo_coupon_codes = $this->bogo_coupon_codes;
361
+ $coupon_codes = array_keys($bogo_coupon_codes);
362
+ // Getting Coupon Remove status from Session.
363
+ $is_removed = WC()->session->get('woo_coupon_removed');
364
+ // If Both are same, then it won't added.
365
+ if (in_array($is_removed, $coupon_codes)) return false;
366
+ if (in_array($old_coupon_code, $coupon_codes) || in_array(wc_strtolower($old_coupon_code), $coupon_codes)) {
367
+ if (in_array($this->postData->get('remove_coupon', false), $coupon_codes)) return false;
368
+ $this->makeLog();
369
+ $discount_type = 'fixed_cart';
370
+ $amount = $bogo_coupon_codes[wc_strtolower($old_coupon_code)]['amount'];
371
+
372
+ $coupon = array(
373
+ 'id' => 321123 . rand(2, 9),
374
+ 'amount' => $amount,
375
+ 'individual_use' => false,
376
+ 'product_ids' => array($bogo_coupon_codes[wc_strtolower($old_coupon_code)]['product_id']),
377
+ 'exclude_product_ids' => array(),
378
+ 'usage_limit' => '',
379
+ 'usage_limit_per_user' => '',
380
+ 'limit_usage_to_x_items' => '',
381
+ 'usage_count' => '',
382
+ 'expiry_date' => '',
383
+ 'apply_before_tax' => 'yes',
384
+ 'free_shipping' => false,
385
+ 'product_categories' => array(),
386
+ 'exclude_product_categories' => array(),
387
+ 'exclude_sale_items' => false,
388
+ 'minimum_amount' => '',
389
+ 'maximum_amount' => '',
390
+ 'customer_email' => '',
391
+ );
392
+ if(FlycartWoocommerceVersion::wcVersion('3.2')) {
393
+ $coupon['discount_type'] = $discount_type;
394
+ } else {
395
+ $coupon['type'] = $discount_type;
396
+ }
397
  return $coupon;
398
  }
399
  }
455
  }
456
  }
457
 
458
+ public function applyFakeCouponsForBOGO()
459
+ {
460
+ global $woocommerce;
461
+ if(!empty($this->bogo_coupon_codes)){
462
+ foreach ($this->bogo_coupon_codes as $coupon_code => $coupon_data){
463
+ // 'newyear' is a temporary coupon for validation.
464
+ $coupon_code = apply_filters('woocommerce_coupon_code', $coupon_code);
465
+ // Getting New Instance with the Coupon Code.
466
+ $the_coupon = FlycartWoocommerceCoupon::wc_get_coupon($coupon_code);
467
+ // Validating the Coupon as Valid and discount status.
468
+ if ($the_coupon->is_valid() && !$woocommerce->cart->has_discount($coupon_code)) {
469
+
470
+ // Do not apply coupon with individual use coupon already applied
471
+ if ($woocommerce->cart->applied_coupons) {
472
+ foreach ($woocommerce->cart->applied_coupons as $code) {
473
+ $coupon = FlycartWoocommerceCoupon::wc_get_coupon($code);
474
+ if (FlycartWoocommerceCoupon::get_individual_use($coupon) == true) {
475
+ return false;
476
+ }
477
+ }
478
+ }
479
+
480
+ // Add coupon
481
+ $woocommerce->cart->applied_coupons[] = $coupon_code;
482
+ do_action('woocommerce_applied_coupon', $coupon_code);
483
+ }
484
+ }
485
+ }
486
+ return true;
487
+ }
488
+
489
  /**
490
  * Simply remove or reset the virtual coupon by set "empty" as value
491
  * to "Woo's" session "woo_coupon_removed".
614
  $rule_sets[$index]['discount_rule'] = (isset($rule->discount_rule) ? $rule->discount_rule : false);
615
  $rule_sets[$index]['discount_type'] = (isset($rule->discount_type) ? $rule->discount_type : false);
616
  $rule_sets[$index]['to_discount'] = (isset($rule->to_discount) ? $rule->to_discount : false);
617
+ $rule_sets[$index]['cart_discounted_products'] = isset($rule->cart_discounted_products) ? json_decode($rule->cart_discounted_products) : array();
618
+ $rule_sets[$index]['product_discount_quantity'] = isset($rule->product_discount_quantity) ? $rule->product_discount_quantity : 1;
619
+ if (in_array($rule->discount_type, array('product_discount'))) {
620
+ $rule_sets[$index]['enabled'] = $this->validateBOGOCart($rule_sets[$index]['discount_rule'],$rule);
621
+ }else{
622
+ $rule_sets[$index]['enabled'] = $this->validateCart($rule_sets[$index]['discount_rule']);
623
+ }
624
  }
625
  $rule_sets = apply_filters('woo_discount_rules_cart_rule_sets_to_apply', $rule_sets);
626
  $this->rule_sets = $rule_sets;
660
  } else if ($rule['discount_type'] == 'price_discount') {
661
  // Getting the Flat Rate of Discount.
662
  $discounts['to_discount'][$index] = $this->calculateDiscount($this->sub_total, array('type' => 'price', 'value' => $rule['to_discount']));
663
+ } else if($rule['discount_type'] == 'product_discount'){
664
+ // Calculate product discount
665
+ $this->calculateProductDiscount($rule['cart_discounted_products'],$rule['product_discount_quantity']);
666
  } else {
667
  //we will have to re-calculate the sub-total if it has category selected
668
  if($this->is_category_specific($rule)) {
696
  } else if ($rule['discount_type'] == 'price_discount') {
697
  // Getting the Flat Rate of Discount.
698
  $discounts['to_discount'][$index] = $this->calculateDiscount($this->sub_total, array('type' => 'price', 'value' => $rule['to_discount']));
699
+ } else if($rule['discount_type'] == 'product_discount'){
700
+ // Calculate product discount
701
+ $this->calculateProductDiscount($rule['cart_discounted_products'],$rule['product_discount_quantity']);
702
  } else {
703
  //we will have to re-calculate the sub-total if it has category selected
704
  if($this->is_category_specific($rule)) {
732
  } else if ($rule['discount_type'] == 'price_discount') {
733
  // Getting the Flat Rate of Discount.
734
  $newDiscount = $this->calculateDiscount($this->sub_total, array('type' => 'price', 'value' => $rule['to_discount']));
735
+ } else if($rule['discount_type'] == 'product_discount'){
736
+ // Calculate product discount
737
+ $this->calculateProductDiscount($rule['cart_discounted_products'],$rule['product_discount_quantity']);
738
  } else {
739
  //we will have to re-calculate the sub-total if it has category selected
740
  if($this->is_category_specific($rule)) {
1179
  $ruleSuccess = $this->validateCartCouponAppliedAnyOne($index, $rule, $rules);
1180
  if($ruleSuccess){
1181
  if(is_string($rule)){
1182
+ $coupons = explode(',', $rule);
1183
  } elseif (is_array($rule)){
1184
  $coupons = $rule;
1185
  } else {
1197
  $ruleSuccess = $this->validateCartCouponAppliedAllSelected($index, $rule, $rules);
1198
  if($ruleSuccess){
1199
  if(is_string($rule)){
1200
+ $coupons = explode(',', $rule);
1201
  } elseif (is_array($rule)){
1202
  $coupons = $rule;
1203
  } else {
1220
  global $woocommerce;
1221
  $allowed = 0;
1222
  if(is_string($rule)){
1223
+ $coupons = explode(',', $rule);
1224
  } elseif (is_array($rule)){
1225
  $coupons = $rule;
1226
  } else {
1243
  global $woocommerce;
1244
  $allowed = 0;
1245
  if(is_string($rule)){
1246
+ $coupons = explode(',', $rule);
1247
  } elseif (is_array($rule)){
1248
  $coupons = $rule;
1249
  } else {
1460
  // Iterate over all cart items and
1461
  foreach ($this->cart_items as $cart_item_key => $cart_item) {
1462
  $quantity = (isset($cart_item['quantity']) && $cart_item['quantity']) ? $cart_item['quantity'] : 1;
1463
+ $cart_subtotal += ((float)FlycartWoocommerceProduct::get_price($cart_item['data'])) * $quantity;
1464
  }
1465
 
1466
  $this->sub_total = (float)$cart_subtotal;
1535
  return ($discount <= 0) ? 0 : $discount;
1536
  }
1537
 
1538
+ /**
1539
+ * @param array $product_ids - list of discount products from admin settings
1540
+ * @param int $discount_quantity - quantity of products to be discount
1541
+ * @param string $rule_text - Text to be shown for coupon code
1542
+ * @return int
1543
+ */
1544
+ public function calculateProductDiscount(array $product_ids = array(), $discount_quantity = 1,$rule_text ="")
1545
+ {
1546
+ if (empty($product_ids))
1547
+ return true;
1548
+ if(empty($rule_text))
1549
+ $rule_text = '{{product_name}} X {{quantity}}';
1550
+ $carts = FlycartWoocommerceCart::get_cart();
1551
+ if(empty($carts))
1552
+ return true;
1553
+ $added_products = array();
1554
+ foreach ($carts as $cart_item_key => $cart_item) {
1555
+ if (empty($cart_item['data'])) {
1556
+ continue;
1557
+ }
1558
+ $added_products[$cart_item['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']));
1559
+ }
1560
+ foreach ($product_ids as $discounted_product_id) {
1561
+ //Check the discounted product already found in cart
1562
+ if (array_key_exists($discounted_product_id, $added_products)) {
1563
+ $old_quantity = isset($added_products[$discounted_product_id]['item_quantity']) ? $added_products[$discounted_product_id]['item_quantity'] : 0;
1564
+ if ($old_quantity < $discount_quantity) {
1565
+ if (isset($added_products[$discounted_product_id]['item']) && !empty($added_products[$discounted_product_id]['item'])) {
1566
+ FlycartWoocommerceCart::set_quantity($added_products[$discounted_product_id]['item'], $discount_quantity);
1567
+ }
1568
+ }
1569
+ $discounted_price = ($discount_quantity * $added_products[$discounted_product_id]['item_price']);
1570
+ $coupon_msg = str_replace(array('{{product_name}}','{{quantity}}'),array($added_products[$discounted_product_id]['item_name'],$discount_quantity),$rule_text);
1571
+ $this->bogo_coupon_codes[wc_strtolower($coupon_msg)] = array('product_id'=>$discounted_product_id,'amount'=>$discounted_price);
1572
+ } else {
1573
+ //If product not in cart,then add to cart
1574
+ $product = FlycartWoocommerceProduct::wc_get_product($discounted_product_id);
1575
+ if($product) {
1576
+ FlycartWoocommerceCart::add_to_cart($discounted_product_id, $discount_quantity);
1577
+ $discounted_price = ($discount_quantity * FlycartWoocommerceProduct::get_price($product));
1578
+ $coupon_msg = str_replace(array('{{product_name}}', '{{quantity}}'), array(FlycartWoocommerceProduct::get_name($product), $discount_quantity), $rule_text);
1579
+ $this->bogo_coupon_codes[wc_strtolower($coupon_msg)] = array('product_id'=>$discounted_product_id,'amount'=>$discounted_price);
1580
+ }
1581
+ }
1582
+ $this->product_discount_total += $discounted_price;
1583
+ }
1584
+ return true;
1585
+ }
1586
+
1587
+ /**
1588
+ * Validate for product discount rules
1589
+ * @param $conditions
1590
+ * @param $rule_set
1591
+ * @return bool
1592
+ */
1593
+ function validateBOGOCart($conditions,$rule_set){
1594
+ $this->calculateCartSubtotal();
1595
+ $rules = (is_string($conditions) ? json_decode($conditions, true) : array());
1596
+ // Simple array helper to re-arrange the structure.
1597
+ FlycartWooDiscountRulesGeneralHelper::reArrangeArray($rules);
1598
+ foreach ($rules as $index => $rule) {
1599
+ // Validating the Rules one by one.
1600
+ if ($this->applyCartBOGORule($index, $rule, $rules,$rule_set) == false) {
1601
+ return false;
1602
+ }
1603
+ }
1604
+ return true;
1605
+ }
1606
+
1607
+ /**
1608
+ * Rules for only BOGO products
1609
+ * @param $index
1610
+ * @param $rule
1611
+ * @param $rules
1612
+ * @param $rule_set
1613
+ * @return bool
1614
+ */
1615
+ function applyCartBOGORule($index, $rule, $rules,$rule_set){
1616
+ //Calculating subtotal, quantity for BOGO Products
1617
+ $cart = array();
1618
+ $free_line_item = 0;
1619
+ $free_quantity = 0;
1620
+ $free_item_price = 0;
1621
+ foreach ($this->cart_items as $cart_items){
1622
+ $cart[$cart_items['product_id']]['quantity'] = $cart_items['quantity'];
1623
+ $cart[$cart_items['product_id']]['price'] = FlycartWoocommerceProduct::get_price($cart_items['data']);
1624
+ $cart[$cart_items['product_id']]['subtotal'] = $cart[$cart_items['product_id']]['price'] * $cart[$cart_items['product_id']]['quantity'];
1625
+ }
1626
+ $discounted_products = (isset($rule_set->cart_discounted_products)) ? $rule_set->cart_discounted_products : '[]';
1627
+ $products = json_decode($discounted_products);
1628
+ $rule_discount_quantity = (isset($rule_set->product_discount_quantity)) ? $rule_set->product_discount_quantity : 0;
1629
+ foreach ($products as $discounted_product_id) {
1630
+ if(array_key_exists($discounted_product_id,$cart))
1631
+ {
1632
+ $free_line_item += 1;
1633
+ $free_quantity += $rule_discount_quantity;
1634
+ $product = FlycartWoocommerceProduct::wc_get_product($discounted_product_id);
1635
+ $product_price = FlycartWoocommerceProduct::get_price($product);
1636
+ $free_item_price += $product_price;
1637
+ }
1638
+ }
1639
+ $cart_quantity_except_free = array_sum(array_column($cart,'quantity')) - $free_quantity;
1640
+ $cart_subtotal_except_free = array_sum(array_column($cart,'subtotal')) - $free_item_price;
1641
+ $cart_line_item_except_free = (count($cart)-$free_line_item);
1642
+
1643
+ $skipRuleType = array('categories_in', 'in_each_category', 'atleast_one_including_sub_categories');
1644
+ $availableRuleToSkip = array_intersect($skipRuleType, array_keys($rules));
1645
+ switch ($index) {
1646
+ // Cart Subtotal.
1647
+ case 'subtotal_least':
1648
+ if(!empty($availableRuleToSkip)){
1649
+ } elseif ($cart_subtotal_except_free < $rule) {
1650
+ return false;
1651
+ }
1652
+ return true;
1653
+ break;
1654
+ case 'subtotal_less':
1655
+ if(!empty($availableRuleToSkip)){
1656
+ } elseif ($cart_subtotal_except_free >= $rule) {
1657
+ return false;
1658
+ }
1659
+ return true;
1660
+ break;
1661
+
1662
+ // Cart Item Count.
1663
+ case 'item_count_least':
1664
+ if(!empty($availableRuleToSkip)){
1665
+ } elseif ($cart_line_item_except_free < $rule) {
1666
+ return false;
1667
+ }
1668
+ return true;
1669
+ break;
1670
+ case 'item_count_less':
1671
+ if(!empty($availableRuleToSkip)){
1672
+ } elseif ($cart_line_item_except_free >= $rule) {
1673
+ return false;
1674
+ }
1675
+ return true;
1676
+ break;
1677
+
1678
+ // Quantity Count.
1679
+ case 'quantity_least':
1680
+ if(!empty($availableRuleToSkip)){
1681
+ } elseif ($cart_quantity_except_free < $rule) {
1682
+ return false;
1683
+ }
1684
+ return true;
1685
+ break;
1686
+ case 'quantity_less':
1687
+ if(!empty($availableRuleToSkip)){
1688
+ } elseif ($cart_quantity_except_free >= $rule) {
1689
+ return false;
1690
+ }
1691
+ return true;
1692
+ break;
1693
+
1694
+ // Logged In Users.
1695
+ case 'users_in':
1696
+ $rule = FlycartWoocommerceVersion::backwardCompatibilityStringToArray($rule);
1697
+ if (get_current_user_id() == 0 || !in_array(get_current_user_id(), $rule)) {
1698
+ return false;
1699
+ }
1700
+ return true;
1701
+ break;
1702
+ case 'shipping_countries_in':
1703
+ // $user_meta = get_user_meta(get_current_user_id());
1704
+ $shippingCountry = WC()->customer->get_shipping_country();
1705
+ // if (!$user_meta || !isset($user_meta['shipping_country']) || empty($user_meta['shipping_country']) || !in_array($user_meta['shipping_country'][0], $rule)) {
1706
+ if (empty($shippingCountry) || !in_array($shippingCountry, $rule)) {
1707
+ return false;
1708
+ }
1709
+ return true;
1710
+ break;
1711
+ case 'roles_in':
1712
+ if (count(array_intersect(FlycartWooDiscountRulesGeneralHelper::getCurrentUserRoles(), $rule)) == 0) {
1713
+ return false;
1714
+ }
1715
+ return true;
1716
+ break;
1717
+ case ($index == 'customer_email_tld' || $index == 'customer_email_domain'):
1718
+ $rule = explode(',', $rule);
1719
+ foreach($rule as $key => $r){
1720
+ $rule[$key] = trim($r);
1721
+ $rule[$key] = trim($rule[$key], '.');
1722
+ }
1723
+ $postData = $this->postData->get('post_data', '', 'raw');
1724
+ $postDataArray = array();
1725
+ if($postData != ''){
1726
+ parse_str($postData, $postDataArray);
1727
+ }
1728
+ $postBillingEmail = $this->postData->get('billing_email', '', 'raw');
1729
+ if($postBillingEmail != ''){
1730
+ $postDataArray['billing_email'] = $postBillingEmail;
1731
+ }
1732
+ if(!get_current_user_id()){
1733
+ $order_id = $this->postData->get('order-received', 0);
1734
+ if($order_id){
1735
+ $order = FlycartWoocommerceOrder::wc_get_order($order_id);
1736
+ $postDataArray['billing_email'] = FlycartWoocommerceOrder::get_billing_email($order);
1737
+ }
1738
+ }
1739
+ if(isset($postDataArray['billing_email']) && $postDataArray['billing_email'] != ''){
1740
+ $user_email = $postDataArray['billing_email'];
1741
+ if(get_current_user_id()){
1742
+ update_user_meta(get_current_user_id(), 'billing_email', $user_email);
1743
+ }
1744
+ if($index == 'customer_email_tld')
1745
+ $tld = $this->getTLDFromEmail($user_email);
1746
+ else
1747
+ $tld = $this->getDomainFromEmail($user_email);
1748
+ if(in_array($tld, $rule)){
1749
+ return true;
1750
+ }
1751
+ } else if(get_current_user_id()){
1752
+ $user_email = get_user_meta( get_current_user_id(), 'billing_email', true );
1753
+ if($user_email != '' && !empty($user_email)){
1754
+ if($index == 'customer_email_tld')
1755
+ $tld = $this->getTLDFromEmail($user_email);
1756
+ else
1757
+ $tld = $this->getDomainFromEmail($user_email);
1758
+ if(in_array($tld, $rule)){
1759
+ return true;
1760
+ }
1761
+ } else {
1762
+ $user_details = get_userdata( get_current_user_id() );
1763
+ if(isset($user_details->data->user_email) && $user_details->data->user_email != ''){
1764
+ $user_email = $user_details->data->user_email;
1765
+ if($index == 'customer_email_tld')
1766
+ $tld = $this->getTLDFromEmail($user_email);
1767
+ else
1768
+ $tld = $this->getDomainFromEmail($user_email);
1769
+ if(in_array($tld, $rule)){
1770
+ return true;
1771
+ }
1772
+ }
1773
+ }
1774
+ }
1775
+ return false;
1776
+ break;
1777
+
1778
+ case 'customer_billing_city':
1779
+ $rule = explode(',', $rule);
1780
+ foreach($rule as $key => $r){
1781
+ $rule[$key] = strtolower(trim($r));
1782
+ }
1783
+ $postData = $this->postData->get('post_data', '', 'raw');
1784
+ $postDataArray = array();
1785
+ if($postData != ''){
1786
+ parse_str($postData, $postDataArray);
1787
+ }
1788
+ $postBillingEmail = $this->postData->get('billing_city', '', 'raw');
1789
+ if($postBillingEmail != ''){
1790
+ $postDataArray['billing_city'] = $postBillingEmail;
1791
+ }
1792
+ if(!get_current_user_id()){
1793
+ $order_id = $this->postData->get('order-received', 0);
1794
+ if($order_id){
1795
+ $order = FlycartWoocommerceOrder::wc_get_order($order_id);
1796
+ $postDataArray['billing_city'] = FlycartWoocommerceOrder::get_billing_city($order);
1797
+ }
1798
+ }
1799
+ if(isset($postDataArray['billing_city']) && $postDataArray['billing_city'] != ''){
1800
+ $billingCity = $postDataArray['billing_city'];
1801
+ if(in_array(strtolower($billingCity), $rule)){
1802
+ return true;
1803
+ }
1804
+ } else if(get_current_user_id()){
1805
+ $billingCity = get_user_meta( get_current_user_id(), 'billing_city', true );
1806
+ if($billingCity != '' && !empty($billingCity)){
1807
+ if(in_array(strtolower($billingCity), $rule)){
1808
+ return true;
1809
+ }
1810
+ }
1811
+ }
1812
+ return false;
1813
+ break;
1814
+ case 'customer_shipping_state':
1815
+ $rule = explode(',', $rule);
1816
+ foreach($rule as $key => $r){
1817
+ $rule[$key] = strtolower(trim($r));
1818
+ }
1819
+ $postData = $this->postData->get('post_data', '', 'raw');
1820
+ $postDataArray = array();
1821
+ if($postData != ''){
1822
+ parse_str($postData, $postDataArray);
1823
+ }
1824
+ if(isset($postDataArray['ship_to_different_address']) && $postDataArray['ship_to_different_address']){
1825
+ $shippingFieldName = 'shipping_state';
1826
+ } else {
1827
+ $shippingFieldName = 'billing_state';
1828
+ }
1829
+ $postShippingState = $this->postData->get($shippingFieldName, '', 'raw');
1830
+ if($postShippingState != ''){
1831
+ $postDataArray[$shippingFieldName] = $postShippingState;
1832
+ }
1833
+ if(!get_current_user_id()){
1834
+ $order_id = $this->postData->get('order-received', 0);
1835
+ if($order_id){
1836
+ $order = FlycartWoocommerceOrder::wc_get_order($order_id);
1837
+ $postDataArray['shipping_state'] = FlycartWoocommerceOrder::get_shipping_state($order);
1838
+ }
1839
+ }
1840
+ if(isset($postDataArray[$shippingFieldName]) && $postDataArray[$shippingFieldName] != ''){
1841
+ $shippingState = $postDataArray[$shippingFieldName];
1842
+ if(in_array(strtolower($shippingState), $rule) || in_array(strtoupper($shippingState), $rule)){
1843
+ return true;
1844
+ }
1845
+ } else if(get_current_user_id()){
1846
+ $shippingState = get_user_meta( get_current_user_id(), 'shipping_state', true );
1847
+ if($shippingState != '' && !empty($shippingState)){
1848
+ if(in_array(strtolower($shippingState), $rule) || in_array(strtoupper($shippingState), $rule)){
1849
+ return true;
1850
+ }
1851
+ }
1852
+ }
1853
+ return false;
1854
+ break;
1855
+ case 'customer_shipping_city':
1856
+ $rule = explode(',', $rule);
1857
+ foreach($rule as $key => $r){
1858
+ $rule[$key] = strtolower(trim($r));
1859
+ }
1860
+ $postData = $this->postData->get('post_data', '', 'raw');
1861
+ $postDataArray = array();
1862
+ if($postData != ''){
1863
+ parse_str($postData, $postDataArray);
1864
+ }
1865
+ if(isset($postDataArray['ship_to_different_address']) && $postDataArray['ship_to_different_address']){
1866
+ $shippingFieldName = 'shipping_city';
1867
+ } else {
1868
+ $shippingFieldName = 'billing_city';
1869
+ }
1870
+ $postShippingState = $this->postData->get($shippingFieldName, '', 'raw');
1871
+ if($postShippingState != ''){
1872
+ $postDataArray[$shippingFieldName] = $postShippingState;
1873
+ }
1874
+ if(!get_current_user_id()){
1875
+ $order_id = $this->postData->get('order-received', 0);
1876
+ if($order_id){
1877
+ $order = FlycartWoocommerceOrder::wc_get_order($order_id);
1878
+ $postDataArray['shipping_city'] = FlycartWoocommerceOrder::get_shipping_city($order);
1879
+ }
1880
+ }
1881
+ if(isset($postDataArray[$shippingFieldName]) && $postDataArray[$shippingFieldName] != ''){
1882
+ $shippingState = $postDataArray[$shippingFieldName];
1883
+ if(in_array(strtolower($shippingState), $rule) || in_array(strtoupper($shippingState), $rule)){
1884
+ return true;
1885
+ }
1886
+ } else if(get_current_user_id()){
1887
+ $shippingState = get_user_meta( get_current_user_id(), 'shipping_city', true );
1888
+ if($shippingState != '' && !empty($shippingState)){
1889
+ if(in_array(strtolower($shippingState), $rule) || in_array(strtoupper($shippingState), $rule)){
1890
+ return true;
1891
+ }
1892
+ }
1893
+ }
1894
+ return false;
1895
+ break;
1896
+ case 'customer_shipping_zip_code':
1897
+ $rule = explode(',', $rule);
1898
+ foreach($rule as $key => $r){
1899
+ $rule[$key] = strtolower(trim($r));
1900
+ }
1901
+ $postData = $this->postData->get('post_data', '', 'raw');
1902
+ $postDataArray = array();
1903
+ if($postData != ''){
1904
+ parse_str($postData, $postDataArray);
1905
+ }
1906
+ if(isset($postDataArray['ship_to_different_address']) && $postDataArray['ship_to_different_address']){
1907
+ $shippingFieldName = 'shipping_postcode';
1908
+ } else {
1909
+ $shippingFieldName = 'billing_postcode';
1910
+ }
1911
+ $postShippingState = $this->postData->get($shippingFieldName, '', 'raw');
1912
+ if($postShippingState != ''){
1913
+ $postDataArray[$shippingFieldName] = $postShippingState;
1914
+ }
1915
+ if(!get_current_user_id()){
1916
+ $order_id = $this->postData->get('order-received', 0);
1917
+ if($order_id){
1918
+ $order = FlycartWoocommerceOrder::wc_get_order($order_id);
1919
+ $postDataArray['shipping_postcode'] = FlycartWoocommerceOrder::get_shipping_city($order);
1920
+ }
1921
+ }
1922
+ if(isset($postDataArray[$shippingFieldName]) && $postDataArray[$shippingFieldName] != ''){
1923
+ $shippingState = $postDataArray[$shippingFieldName];
1924
+ if(in_array(strtolower($shippingState), $rule) || in_array(strtoupper($shippingState), $rule)){
1925
+ return true;
1926
+ }
1927
+ } else if(get_current_user_id()){
1928
+ $shippingState = get_user_meta( get_current_user_id(), 'shipping_postcode', true );
1929
+ if($shippingState != '' && !empty($shippingState)){
1930
+ if(in_array(strtolower($shippingState), $rule) || in_array(strtoupper($shippingState), $rule)){
1931
+ return true;
1932
+ }
1933
+ }
1934
+ }
1935
+ return false;
1936
+ break;
1937
+ case 'categories_in':
1938
+ if(count($rule)){
1939
+ $ruleSuccess = $this->validateCartItemsInSelectedCategory($index, $rule, $rules);
1940
+ if($ruleSuccess){
1941
+ return true;
1942
+ }
1943
+ }
1944
+ return false;
1945
+ break;
1946
+ case 'atleast_one_including_sub_categories':
1947
+ if(count($rule)){
1948
+ $ruleSuccess = $this->validateCartItemsInSelectedCategory($index, $rule, $rules, 1);
1949
+ if($ruleSuccess){
1950
+ return true;
1951
+ }
1952
+ }
1953
+ return false;
1954
+ break;
1955
+ case 'in_each_category':
1956
+ if(count($rule)){
1957
+ $ruleSuccess = $this->validateCartItemsInEachSelectedCategory($index, $rule, $rules);
1958
+ if($ruleSuccess){
1959
+ return true;
1960
+ }
1961
+ }
1962
+ return false;
1963
+ break;
1964
+ case 'customer_based_on_purchase_history':
1965
+ case 'customer_based_on_purchase_history_order_count':
1966
+ case 'customer_based_on_purchase_history_product_order_count':
1967
+ if(count($rule)){
1968
+ $ruleSuccess = $this->validateCartItemsBasedOnPurchaseHistory($index, $rule, $rules);
1969
+ if($ruleSuccess){
1970
+ return true;
1971
+ }
1972
+ }
1973
+ return false;
1974
+ break;
1975
+ case 'coupon_applied_any_one':
1976
+ if(!empty($rule)){
1977
+ $ruleSuccess = $this->validateCartCouponAppliedAnyOne($index, $rule, $rules);
1978
+ if($ruleSuccess){
1979
+ if(is_string($rule)){
1980
+ $coupons = explode(',', $rule);
1981
+ } elseif (is_array($rule)){
1982
+ $coupons = $rule;
1983
+ } else {
1984
+ return false;
1985
+ }
1986
+
1987
+ FlycartWooDiscountRulesGeneralHelper::removeCouponPriceInCart($coupons);
1988
+ return true;
1989
+ }
1990
+ }
1991
+ return false;
1992
+ break;
1993
+ case 'coupon_applied_all_selected':
1994
+ if(!empty($rule)){
1995
+ $ruleSuccess = $this->validateCartCouponAppliedAllSelected($index, $rule, $rules);
1996
+ if($ruleSuccess){
1997
+ if(is_string($rule)){
1998
+ $coupons = explode(',', $rule);
1999
+ } elseif (is_array($rule)){
2000
+ $coupons = $rule;
2001
+ } else {
2002
+ return false;
2003
+ }
2004
+ FlycartWooDiscountRulesGeneralHelper::removeCouponPriceInCart($coupons);
2005
+ return true;
2006
+ }
2007
+ }
2008
+ return false;
2009
+ break;
2010
+ }
2011
+ }
2012
  }
2013
+ }
includes/pricing-rules.php CHANGED
@@ -783,6 +783,7 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
783
  if ($rule->apply_to == 'specific_products') {
784
  if (isset($rule->product_to_apply)) {
785
  $rule_sets[$index]['type']['specific_products'] = $this->checkWithProducts($rule, $woocommerce);
 
786
  }
787
  if (isset($rule->is_cumulative_for_products) && $rule->is_cumulative_for_products) {
788
  $rule_sets[$index]['is_cumulative_for_products'] = 1;
@@ -1336,8 +1337,10 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1336
  $quantity_to = isset($product_based_conditions['product_quantity_to']) ? $product_based_conditions['product_quantity_to'] : '';
1337
  $product_to_buy = isset($product_based_conditions['product_to_buy']) ? $product_based_conditions['product_to_buy'] : array();
1338
  $product_to_buy = FlycartWoocommerceVersion::backwardCompatibilityStringToArray($product_to_buy);
 
1339
  $product_to_apply = isset($product_based_conditions['product_to_apply']) ? $product_based_conditions['product_to_apply'] : array();
1340
  $product_to_apply = FlycartWoocommerceVersion::backwardCompatibilityStringToArray($product_to_apply);
 
1341
  $category_to_apply = isset($product_based_conditions['category_to_apply']) ? $product_based_conditions['category_to_apply'] : array();
1342
  $get_discount_type = isset($product_based_conditions['get_discount_type']) ? $product_based_conditions['get_discount_type'] : 'product';
1343
 
@@ -1608,6 +1611,9 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1608
  $discount_product_option = isset($range->discount_product_option) ? $range->discount_product_option : 'all';
1609
  $productIds = isset($range->discount_product) ? $range->discount_product : array();
1610
  $productIds = FlycartWoocommerceVersion::backwardCompatibilityStringToArray($productIds);
 
 
 
1611
  if($discount_product_option == 'same_product'){
1612
  $productId = FlycartWoocommerceProduct::get_id($item['data']);
1613
  $discount_quantity = isset($range->discount_bogo_qty)? $range->discount_bogo_qty: 1000;
@@ -2247,6 +2253,7 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
2247
  if ($show_discount) {
2248
  $table_data = $this->generateDiscountTableData($product);
2249
  $file_name = 'discount-table';
 
2250
  if($config['show_discount_table'] == 'advance') $file_name .= '-advance';
2251
  $path_from_template = $this->getTemplateOverride($file_name.'.php');
2252
  $path = WOO_DISCOUNT_DIR . '/view/template/'.$file_name.'.php';
@@ -2529,6 +2536,9 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
2529
  if(!is_array($productToExclude)){
2530
  $productToExclude = array();
2531
  }
 
 
 
2532
  return $productToExclude;
2533
  }
2534
 
@@ -3066,7 +3076,10 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
3066
  // Actually adjust price in cart
3067
  // $woocommerce->cart->cart_contents[$item]['data']->price = $amount;
3068
  FlycartWoocommerceProduct::set_price($product, $amount);
3069
- $product->woo_discount_rules_applied = 1;
 
 
 
3070
  // To get the applied discount in cart
3071
  $original_price = $woocommerce->cart->cart_contents[$item]['woo_discount']['original_price'];
3072
  if($amount < $original_price){
@@ -3213,7 +3226,7 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
3213
  if($discountPrice > 0 || ($this->hasDiscountForProductId($product_id))){
3214
  $price_to_display = FlycartWoocommerceProduct::wc_price($discountPrice);
3215
  $item_price = preg_replace('/<del>.*<\/del>/', '', $item_price);
3216
- $item_price = '<del>' . $item_price . '</del> <ins>' . ($price_to_display).$product->get_price_suffix() . '</ins>';
3217
  }
3218
  self::$product_strike_out_price[$product_id] = $item_price;
3219
  }
@@ -3253,10 +3266,10 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
3253
  $price_to_display = $this->checkForHighestVariantIfExists($product, $price_to_display, $show_original);
3254
  if(!$show_original){
3255
  self::$product_has_strike_out[$product_id]['has_strikeout'] = 1;
3256
- self::$product_has_strike_out[$product_id]['new_strikeout_html'] = ($price_to_display).$product->get_price_suffix();
3257
  $item_price = preg_replace('/<del>.*<\/del>/', '', $item_price);
3258
  $item_price = apply_filters('woo_discount_rules_price_strikeout_before_discount_price', $item_price, $product);
3259
- $item_price = '<span class="cart_price"><del>' . $item_price . '</del> <ins>' . ($price_to_display).$product->get_price_suffix() . '</ins></span>';
3260
  $item_price = apply_filters('woo_discount_rules_price_strikeout_after_discount_price', $item_price, $product);
3261
  }
3262
  }
783
  if ($rule->apply_to == 'specific_products') {
784
  if (isset($rule->product_to_apply)) {
785
  $rule_sets[$index]['type']['specific_products'] = $this->checkWithProducts($rule, $woocommerce);
786
+ $rule_sets[$index]['type']['specific_products'] = apply_filters('woo_discount_rule_products_to_include', $rule_sets[$index]['type']['specific_products'], $rule);
787
  }
788
  if (isset($rule->is_cumulative_for_products) && $rule->is_cumulative_for_products) {
789
  $rule_sets[$index]['is_cumulative_for_products'] = 1;
1337
  $quantity_to = isset($product_based_conditions['product_quantity_to']) ? $product_based_conditions['product_quantity_to'] : '';
1338
  $product_to_buy = isset($product_based_conditions['product_to_buy']) ? $product_based_conditions['product_to_buy'] : array();
1339
  $product_to_buy = FlycartWoocommerceVersion::backwardCompatibilityStringToArray($product_to_buy);
1340
+ $product_to_buy = apply_filters('woo_discount_rule_products_to_include', $product_to_buy, $rule);
1341
  $product_to_apply = isset($product_based_conditions['product_to_apply']) ? $product_based_conditions['product_to_apply'] : array();
1342
  $product_to_apply = FlycartWoocommerceVersion::backwardCompatibilityStringToArray($product_to_apply);
1343
+ $product_to_apply = apply_filters('woo_discount_rule_products_to_include', $product_to_apply, $rule);
1344
  $category_to_apply = isset($product_based_conditions['category_to_apply']) ? $product_based_conditions['category_to_apply'] : array();
1345
  $get_discount_type = isset($product_based_conditions['get_discount_type']) ? $product_based_conditions['get_discount_type'] : 'product';
1346
 
1611
  $discount_product_option = isset($range->discount_product_option) ? $range->discount_product_option : 'all';
1612
  $productIds = isset($range->discount_product) ? $range->discount_product : array();
1613
  $productIds = FlycartWoocommerceVersion::backwardCompatibilityStringToArray($productIds);
1614
+ if($discount_product_option == 'more_than_one_cheapest' || $discount_product_option == 'any_cheapest'){
1615
+ $productIds = apply_filters('woo_discount_rule_products_to_include', $productIds, $discount_ranges);
1616
+ }
1617
  if($discount_product_option == 'same_product'){
1618
  $productId = FlycartWoocommerceProduct::get_id($item['data']);
1619
  $discount_quantity = isset($range->discount_bogo_qty)? $range->discount_bogo_qty: 1000;
2253
  if ($show_discount) {
2254
  $table_data = $this->generateDiscountTableData($product);
2255
  $file_name = 'discount-table';
2256
+ if(!isset($config['show_discount_table'])) $config['show_discount_table'] = 'show';
2257
  if($config['show_discount_table'] == 'advance') $file_name .= '-advance';
2258
  $path_from_template = $this->getTemplateOverride($file_name.'.php');
2259
  $path = WOO_DISCOUNT_DIR . '/view/template/'.$file_name.'.php';
2536
  if(!is_array($productToExclude)){
2537
  $productToExclude = array();
2538
  }
2539
+
2540
+ $productToExclude = apply_filters('woo_discount_rule_products_to_exclude', $productToExclude, $rule);
2541
+
2542
  return $productToExclude;
2543
  }
2544
 
3076
  // Actually adjust price in cart
3077
  // $woocommerce->cart->cart_contents[$item]['data']->price = $amount;
3078
  FlycartWoocommerceProduct::set_price($product, $amount);
3079
+ $apply_rules_repeatedly = apply_filters('woo_discount_rules_apply_rules_repeatedly', false, $product);
3080
+ if(!$apply_rules_repeatedly){
3081
+ $product->woo_discount_rules_applied = 1;
3082
+ }
3083
  // To get the applied discount in cart
3084
  $original_price = $woocommerce->cart->cart_contents[$item]['woo_discount']['original_price'];
3085
  if($amount < $original_price){
3226
  if($discountPrice > 0 || ($this->hasDiscountForProductId($product_id))){
3227
  $price_to_display = FlycartWoocommerceProduct::wc_price($discountPrice);
3228
  $item_price = preg_replace('/<del>.*<\/del>/', '', $item_price);
3229
+ $item_price = '<del>' . $item_price . '</del> <ins>' . ($price_to_display).$product->get_price_suffix($discountPrice) . '</ins>';
3230
  }
3231
  self::$product_strike_out_price[$product_id] = $item_price;
3232
  }
3266
  $price_to_display = $this->checkForHighestVariantIfExists($product, $price_to_display, $show_original);
3267
  if(!$show_original){
3268
  self::$product_has_strike_out[$product_id]['has_strikeout'] = 1;
3269
+ self::$product_has_strike_out[$product_id]['new_strikeout_html'] = ($price_to_display).$product->get_price_suffix($discountPrice);
3270
  $item_price = preg_replace('/<del>.*<\/del>/', '', $item_price);
3271
  $item_price = apply_filters('woo_discount_rules_price_strikeout_before_discount_price', $item_price, $product);
3272
+ $item_price = '<span class="cart_price"><del>' . $item_price . '</del> <ins>' . ($price_to_display).$product->get_price_suffix($discountPrice) . '</ins></span>';
3273
  $item_price = apply_filters('woo_discount_rules_price_strikeout_after_discount_price', $item_price, $product);
3274
  }
3275
  }
loader.php CHANGED
@@ -366,6 +366,45 @@ if(!class_exists('FlycartWooDiscountRules')){
366
  add_action('woocommerce_before_checkout_form', array($this, 'displayAppliedDiscountMessagesForCartRules'));
367
  add_action('woocommerce_before_cart', array($this, 'displayAppliedDiscountMessagesForPriceRules'));
368
  add_action('woocommerce_before_cart', array($this, 'displayAppliedDiscountMessagesForCartRules'));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
369
  }
370
 
371
  /**
366
  add_action('woocommerce_before_checkout_form', array($this, 'displayAppliedDiscountMessagesForCartRules'));
367
  add_action('woocommerce_before_cart', array($this, 'displayAppliedDiscountMessagesForPriceRules'));
368
  add_action('woocommerce_before_cart', array($this, 'displayAppliedDiscountMessagesForCartRules'));
369
+
370
+
371
+ add_filter('woo_discount_rule_products_to_exclude', array($this, 'woo_discount_get_variations'));
372
+ add_filter('woo_discount_rule_products_to_include', array($this, 'woo_discount_get_variations'));
373
+ }
374
+
375
+ /**
376
+ * Include the variant product as well while choose parent product
377
+ *
378
+ * @param array $excluded_products
379
+ * @return array
380
+ * */
381
+ public function woo_discount_get_variations($excluded_products = array()) {
382
+ $include_variants_on_select_parent_product = $this->discountBase->getConfigData('include_variants_on_select_parent_product', 0);
383
+ if($include_variants_on_select_parent_product){
384
+ static $sets;
385
+ if (!is_array($sets)) {
386
+ $sets = array();
387
+ }
388
+
389
+ if(count($excluded_products) < 1) return $excluded_products;
390
+ $string = json_encode($excluded_products);
391
+
392
+ if (!isset($sets[$string])) {
393
+ $all_excluded_products = $excluded_products;
394
+ foreach ($excluded_products as $exclude_id) {
395
+ $product = wc_get_product($exclude_id);
396
+ if (is_object($product) && method_exists($product, 'get_type') && $product->get_type() == 'variable') {
397
+ $children_ids = $product->get_children();
398
+ $all_excluded_products = array_merge($all_excluded_products, $children_ids);
399
+ }
400
+ }
401
+ $sets[$string] = $all_excluded_products;
402
+ }
403
+
404
+ return $sets[$string];
405
+ } else {
406
+ return $excluded_products;
407
+ }
408
  }
409
 
410
  /**
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: flycart
3
  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.7.2
8
  License: GPLv3 or later
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -308,9 +308,15 @@ Discount - Enter minimum & Maximum quantity -> Adjustment Type -> Product Discou
308
 
309
  == Changelog ==
310
 
 
 
 
 
 
 
311
  = 1.7.2 - 04/12/18 =
312
  * Fix - Dependent rule not saving
313
- * Improvement - Text improvement
314
 
315
  = 1.7.1 - 29/11/18 =
316
  * Fix - BOGO validation in backend
3
  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.3
8
  License: GPLv3 or later
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
308
 
309
  == Changelog ==
310
 
311
+ = 1.7.3 - 12/12/18 =
312
+ * Fix - Fatal error on discount table when config is not yet save
313
+ * Fix - Warning while the price is in string format
314
+ * Feature - BOGO in Cart rules(pro)
315
+ * Feature - Option to include and variant while choose parent products
316
+
317
  = 1.7.2 - 04/12/18 =
318
  * Fix - Dependent rule not saving
319
+ * Improvement - event woo_discount_rules_apply_rules_repeatedly
320
 
321
  = 1.7.1 - 29/11/18 =
322
  * Fix - BOGO validation in backend
view/settings.php CHANGED
@@ -349,6 +349,18 @@ $isPro = $flycartWooDiscountRulesPurchase->isPro();
349
  <label><input type="radio" name="add_free_product_on_coupon_applied" value="0" <?php echo ($data['add_free_product_on_coupon_applied'] == 0)? 'checked': '' ?> /> <?php esc_html_e('No', 'woo-discount-rules'); ?></label>
350
  </div>
351
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
352
  <div class="row form-group">
353
  <?php $data['display_you_saved_text'] = (isset($data['display_you_saved_text']) ? $data['display_you_saved_text'] : 'no'); ?>
354
  <div class="col-md-2">
349
  <label><input type="radio" name="add_free_product_on_coupon_applied" value="0" <?php echo ($data['add_free_product_on_coupon_applied'] == 0)? 'checked': '' ?> /> <?php esc_html_e('No', 'woo-discount-rules'); ?></label>
350
  </div>
351
  </div>
352
+ <div class="row form-group">
353
+ <div class="col-md-2">
354
+ <label>
355
+ <?php esc_html_e('Include variants when just parent product is chosen in the rules', 'woo-discount-rules'); ?>
356
+ </label>
357
+ </div>
358
+ <?php $data['include_variants_on_select_parent_product'] = (isset($data['include_variants_on_select_parent_product']) ? $data['include_variants_on_select_parent_product'] : 0); ?>
359
+ <div class="col-md-6">
360
+ <label><input type="radio" name="include_variants_on_select_parent_product" value="1" <?php echo ($data['include_variants_on_select_parent_product'] == 1)? 'checked': '' ?>/> <?php esc_html_e('Yes', 'woo-discount-rules'); ?></label>
361
+ <label><input type="radio" name="include_variants_on_select_parent_product" value="0" <?php echo ($data['include_variants_on_select_parent_product'] == 0)? 'checked': '' ?> /> <?php esc_html_e('No', 'woo-discount-rules'); ?></label>
362
+ </div>
363
+ </div>
364
  <div class="row form-group">
365
  <?php $data['display_you_saved_text'] = (isset($data['display_you_saved_text']) ? $data['display_you_saved_text'] : 'no'); ?>
366
  <div class="col-md-2">
view/view-cart-rules.php CHANGED
@@ -622,6 +622,15 @@ $current_date_and_time = FlycartWooDiscountRulesGeneralHelper::getCurrentDateAnd
622
  <?php esc_html_e('Price Discount', 'woo-discount-rules'); ?>
623
  <?php } ?>
624
  </option>
 
 
 
 
 
 
 
 
 
625
  <option
626
  <?php if (!$pro) { ?> disabled <?php } else { ?> value="shipping_price" <?php }
627
  if ($discount_type == 'shipping_price') { ?> selected=selected <?php } ?>>
@@ -643,6 +652,33 @@ $current_date_and_time = FlycartWooDiscountRulesGeneralHelper::getCurrentDateAnd
643
  </label>
644
  </div>
645
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
646
  </div>
647
  <div align="right">
648
  <input type="button" class="btn btn-warning restriction_tab" value="<?php esc_attr_e('Previous', 'woo-discount-rules'); ?>">
622
  <?php esc_html_e('Price Discount', 'woo-discount-rules'); ?>
623
  <?php } ?>
624
  </option>
625
+ <option
626
+ <?php if (!$pro) { ?> disabled <?php } else { ?> value="product_discount" <?php }
627
+ if ($discount_type == 'product_discount') { ?> selected=selected <?php } ?>>
628
+ <?php if (!$pro) { ?>
629
+ <?php esc_html_e('Product Discount', 'woo-discount-rules'); ?> <b><?php echo $suffix; ?></b>
630
+ <?php } else { ?>
631
+ <?php esc_html_e('Product Discount', 'woo-discount-rules'); ?>
632
+ <?php } ?>
633
+ </option>
634
  <option
635
  <?php if (!$pro) { ?> disabled <?php } else { ?> value="shipping_price" <?php }
636
  if ($discount_type == 'shipping_price') { ?> selected=selected <?php } ?>>
652
  </label>
653
  </div>
654
  </div>
655
+ <div id="cart_rule_product_discount_field" class="col-md-10">
656
+ <div class="form-group">
657
+ <label> <?php esc_html_e('Select products :', 'woo-discount-rules'); ?></label>
658
+ <br>
659
+ <?php
660
+ $discounted_product_list = array();
661
+ if(isset($data->cart_discounted_products)){
662
+ if(is_array($data->product_to_discount))
663
+ $discounted_product_list = $data->cart_discounted_products;
664
+ else
665
+ $discounted_product_list = json_decode((isset($data->cart_discounted_products) ? $data->cart_discounted_products : '{}'), true);
666
+ }
667
+ echo FlycartWoocommerceProduct::getProductAjaxSelectBox($discounted_product_list, 'cart_discounted_products');
668
+ ?>
669
+ </div>
670
+ <div class="form-group">
671
+ <label for="product_discount_quantity"> <?php esc_html_e('Quantity :', 'woo-discount-rules'); ?></label>
672
+ <?php
673
+ $product_discount_quantity = 1;
674
+ if (isset($data->product_discount_quantity)) {
675
+ $product_discount_quantity = $data->product_discount_quantity;
676
+ }
677
+ ?>
678
+ <input type="number" min="1" name="product_discount_quantity" id="product_discount_quantity" class="small-text"
679
+ value="<?php echo $product_discount_quantity; ?>">
680
+ </div>
681
+ </div>
682
  </div>
683
  <div align="right">
684
  <input type="button" class="btn btn-warning restriction_tab" value="<?php esc_attr_e('Previous', 'woo-discount-rules'); ?>">
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.2
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.3
9
  * Slug: woo-discount-rules
10
  * Text Domain: woo-discount-rules
11
  * Domain Path: /i18n/languages/