Version Description
- 01/11/22 =
- Improvement: Added applied discount info in order and order item meta _wdr_discounts [Core and Pro].
- Improvement: Loading issue on shop page while having variable price strikeout improvement [Core].
- Improvement: Set 3 for 10 fixed .1 difference on subtotal [Pro].
- Improvement: Doing strikeout on cart while using third-party shortcode [Core].
- Improvement: Show free shipping rule reports since v2.5.0 [Pro].
- Improvement: Added order_item_id and other_discount columns in wdr_order_item_discounts table [Core].
- Add: Show total order count and sales on report section [Core and Pro].
- Fix: Disable coupon option doesn't working with free shipping [Pro].
- Fix: Applied message is not displaying in cart for free shipping [Pro].
- Fix: Limit option is not working with Free shipping [Pro].
- Fix: Warning on PHP 8 [Core and Pro].
- Fix: Fatal error on load order item meta [Core].
Download this release
Release Info
Developer | flycart |
Plugin | Discount Rules for WooCommerce |
Version | 2.5.0 |
Comparing to | |
See all releases |
Code changes from version 2.4.5 to 2.5.0
- i18n/languages/woo-discount-rules.pot +72 -61
- readme.txt +15 -3
- v2/App/Compatibility/CurrencySwitcherByRealmag777.php +1 -1
- v2/App/Compatibility/PriceBasedOnCountryByOscarGare.php +1 -1
- v2/App/Controllers/Admin/Tabs/Compatible.php +2 -2
- v2/App/Controllers/Admin/Tabs/Reports/RuleAmount.php +24 -12
- v2/App/Controllers/Admin/Tabs/Reports/RuleAmountWithCartDiscount.php +1 -1
- v2/App/Controllers/Admin/Tabs/Reports/RuleNameDiscount.php +25 -11
- v2/App/Controllers/Admin/Tabs/Statistics.php +8 -11
- v2/App/Controllers/DiscountCalculator.php +10 -2
- v2/App/Controllers/ManageDiscount.php +296 -146
- v2/App/Helpers/Helper.php +2 -2
- v2/App/Helpers/Rule.php +1 -1
- v2/App/Helpers/Woocommerce.php +134 -58
- v2/App/Models/DBTable.php +97 -30
- v2/App/Router.php +4 -2
- v2/App/Snippets/overrideCustomPrice.php +1 -1
- v2/App/Views/Admin/Tabs/Statistics.php +55 -21
- v2/Assets/Js/admin-statistics.js +14 -4
- v2/Assets/Js/admin-statistics.min.js +1 -1
- v2/Assets/Js/awdr-dynamic-price.min.js +1 -1
- v2/Assets/Js/site_main.min.js +1 -1
- woo-discount-rules.php +3 -3
i18n/languages/woo-discount-rules.pot
CHANGED
@@ -586,14 +586,14 @@ msgstr ""
|
|
586 |
msgid "Recipe"
|
587 |
msgstr ""
|
588 |
|
589 |
-
#: v2/App/Controllers/Admin/Tabs/Reports/RuleAmount.php:
|
590 |
#: v2/App/Controllers/Admin/Tabs/Reports/RuleAmountWithCartDiscount.php:11
|
591 |
-
#: v2/App/Controllers/Admin/Tabs/Reports/RuleNameDiscount.php:
|
592 |
-
msgid "
|
593 |
msgstr ""
|
594 |
|
595 |
-
#: v2/App/Controllers/Admin/Tabs/Reports/RuleAmount.php:
|
596 |
-
#: v2/App/Controllers/Admin/Tabs/Reports/RuleNameDiscount.php:
|
597 |
msgid "Date"
|
598 |
msgstr ""
|
599 |
|
@@ -601,24 +601,24 @@ msgstr ""
|
|
601 |
msgid "Reports"
|
602 |
msgstr ""
|
603 |
|
604 |
-
#: v2/App/Controllers/Admin/Tabs/Statistics.php:
|
605 |
msgid "Rule Name"
|
606 |
msgstr ""
|
607 |
|
608 |
-
#: v2/App/Controllers/Admin/Tabs/Statistics.php:
|
609 |
msgid "All Rules"
|
610 |
msgstr ""
|
611 |
|
612 |
-
#: v2/App/Controllers/Admin/Tabs/Statistics.php:
|
613 |
-
#: v2/App/Controllers/Admin/Tabs/Statistics.php:
|
614 |
msgid "Rule"
|
615 |
msgstr ""
|
616 |
|
617 |
-
#: v2/App/Controllers/Admin/Tabs/Statistics.php:
|
618 |
msgid "All Rules (except cart adjustment type)"
|
619 |
msgstr ""
|
620 |
|
621 |
-
#: v2/App/Controllers/Admin/Tabs/Statistics.php:
|
622 |
#: v2/App/Controllers/Admin/WDRAjax.php:69
|
623 |
#: v2/App/Controllers/Admin/WDRAjax.php:72
|
624 |
msgid "Authentication required"
|
@@ -670,35 +670,35 @@ msgstr ""
|
|
670 |
msgid "<span class=\"onsale\">Sale!</span>"
|
671 |
msgstr ""
|
672 |
|
673 |
-
#: v2/App/Controllers/ManageDiscount.php:
|
674 |
-
#: v2/App/Controllers/ManageDiscount.php:
|
675 |
-
#: v2/App/Controllers/ManageDiscount.php:
|
676 |
#: v2/App/Helpers/Helper.php:272
|
677 |
msgid "Cart discount"
|
678 |
msgstr ""
|
679 |
|
680 |
-
#: v2/App/Controllers/ManageDiscount.php:
|
681 |
#, php-format
|
682 |
msgid "Coupon \"%s\" is currently not available!"
|
683 |
msgstr ""
|
684 |
|
685 |
-
#: v2/App/Controllers/ManageDiscount.php:
|
686 |
#, php-format
|
687 |
msgid ""
|
688 |
"Sorry, it is not possible to apply coupon <b>\"%s\"</b> as you already have "
|
689 |
"a discount applied in cart."
|
690 |
msgstr ""
|
691 |
|
692 |
-
#: v2/App/Controllers/ManageDiscount.php:
|
693 |
msgid "Coupon code applied successfully."
|
694 |
msgstr ""
|
695 |
|
696 |
-
#: v2/App/Controllers/ManageDiscount.php:
|
697 |
#: v2/App/Views/Admin/Tabs/settings.php:441
|
698 |
msgid "Discount <strong>{{title}}</strong> has been applied to your cart."
|
699 |
msgstr ""
|
700 |
|
701 |
-
#: v2/App/Controllers/ManageDiscount.php:
|
702 |
msgid "You saved {{total_discount}}"
|
703 |
msgstr ""
|
704 |
|
@@ -1120,133 +1120,133 @@ msgstr ""
|
|
1120 |
msgid "Validation error"
|
1121 |
msgstr ""
|
1122 |
|
1123 |
-
#: v2/App/Helpers/Woocommerce.php:
|
1124 |
msgid "Sunday"
|
1125 |
msgstr ""
|
1126 |
|
1127 |
-
#: v2/App/Helpers/Woocommerce.php:
|
1128 |
msgid "Monday"
|
1129 |
msgstr ""
|
1130 |
|
1131 |
-
#: v2/App/Helpers/Woocommerce.php:
|
1132 |
msgid "Tuesday"
|
1133 |
msgstr ""
|
1134 |
|
1135 |
-
#: v2/App/Helpers/Woocommerce.php:
|
1136 |
msgid "Wednesday"
|
1137 |
msgstr ""
|
1138 |
|
1139 |
-
#: v2/App/Helpers/Woocommerce.php:
|
1140 |
msgid "Thursday"
|
1141 |
msgstr ""
|
1142 |
|
1143 |
-
#: v2/App/Helpers/Woocommerce.php:
|
1144 |
msgid "Friday"
|
1145 |
msgstr ""
|
1146 |
|
1147 |
-
#: v2/App/Helpers/Woocommerce.php:
|
1148 |
msgid "Saturday"
|
1149 |
msgstr ""
|
1150 |
|
1151 |
-
#: v2/App/Helpers/Woocommerce.php:
|
1152 |
msgid ""
|
1153 |
"Woocommerce before main content(Archive / Shop / Cat Pages / single product)"
|
1154 |
msgstr ""
|
1155 |
|
1156 |
-
#: v2/App/Helpers/Woocommerce.php:
|
1157 |
msgid "Woocommerce archive description(Archive / Shop / Cat Pages)"
|
1158 |
msgstr ""
|
1159 |
|
1160 |
-
#: v2/App/Helpers/Woocommerce.php:
|
1161 |
msgid "Woocommerce before shop loop(Archive / Shop / Cat Pages)"
|
1162 |
msgstr ""
|
1163 |
|
1164 |
-
#: v2/App/Helpers/Woocommerce.php:
|
1165 |
msgid "Woocommerce after shop loop(Archive / Shop / Cat Pages)"
|
1166 |
msgstr ""
|
1167 |
|
1168 |
-
#: v2/App/Helpers/Woocommerce.php:
|
1169 |
msgid ""
|
1170 |
"Woocommerce after main content(Archive / Shop / Cat Pages / single product)"
|
1171 |
msgstr ""
|
1172 |
|
1173 |
-
#: v2/App/Helpers/Woocommerce.php:
|
1174 |
#: v2/App/Views/Admin/Tabs/settings.php:248
|
1175 |
msgid "Woocommerce before single product"
|
1176 |
msgstr ""
|
1177 |
|
1178 |
-
#: v2/App/Helpers/Woocommerce.php:
|
1179 |
#: v2/App/Views/Admin/Tabs/settings.php:250
|
1180 |
msgid "Woocommerce before single product summary"
|
1181 |
msgstr ""
|
1182 |
|
1183 |
-
#: v2/App/Helpers/Woocommerce.php:
|
1184 |
#: v2/App/Views/Admin/Tabs/settings.php:249
|
1185 |
msgid "Woocommerce after single product summary"
|
1186 |
msgstr ""
|
1187 |
|
1188 |
-
#: v2/App/Helpers/Woocommerce.php:
|
1189 |
#: v2/App/Views/Admin/Tabs/settings.php:247
|
1190 |
msgid "Woocommerce after single product"
|
1191 |
msgstr ""
|
1192 |
|
1193 |
-
#: v2/App/Helpers/Woocommerce.php:
|
1194 |
msgid "Woocommerce before cart"
|
1195 |
msgstr ""
|
1196 |
|
1197 |
-
#: v2/App/Helpers/Woocommerce.php:
|
1198 |
msgid "Woocommerce before cart table"
|
1199 |
msgstr ""
|
1200 |
|
1201 |
-
#: v2/App/Helpers/Woocommerce.php:
|
1202 |
msgid "Woocommerce before cart contents"
|
1203 |
msgstr ""
|
1204 |
|
1205 |
-
#: v2/App/Helpers/Woocommerce.php:
|
1206 |
msgid "Woocommerce cart contents"
|
1207 |
msgstr ""
|
1208 |
|
1209 |
-
#: v2/App/Helpers/Woocommerce.php:
|
1210 |
msgid "Woocommerce after cart contents"
|
1211 |
msgstr ""
|
1212 |
|
1213 |
-
#: v2/App/Helpers/Woocommerce.php:
|
1214 |
msgid "Woocommerce after cart table"
|
1215 |
msgstr ""
|
1216 |
|
1217 |
-
#: v2/App/Helpers/Woocommerce.php:
|
1218 |
msgid "Woocommerce after cart"
|
1219 |
msgstr ""
|
1220 |
|
1221 |
-
#: v2/App/Helpers/Woocommerce.php:
|
1222 |
msgid "Woocommerce before checkout form"
|
1223 |
msgstr ""
|
1224 |
|
1225 |
-
#: v2/App/Helpers/Woocommerce.php:
|
1226 |
msgid "Woocommerce before checkout billing form"
|
1227 |
msgstr ""
|
1228 |
|
1229 |
-
#: v2/App/Helpers/Woocommerce.php:
|
1230 |
msgid "Woocommerce after checkout billing form"
|
1231 |
msgstr ""
|
1232 |
|
1233 |
-
#: v2/App/Helpers/Woocommerce.php:
|
1234 |
msgid "Woocommerce before checkout shipping form"
|
1235 |
msgstr ""
|
1236 |
|
1237 |
-
#: v2/App/Helpers/Woocommerce.php:
|
1238 |
msgid "Woocommerce after checkout shipping form"
|
1239 |
msgstr ""
|
1240 |
|
1241 |
-
#: v2/App/Helpers/Woocommerce.php:
|
1242 |
msgid "Woocommerce before order notes"
|
1243 |
msgstr ""
|
1244 |
|
1245 |
-
#: v2/App/Helpers/Woocommerce.php:
|
1246 |
msgid "Woocommerce after order notes"
|
1247 |
msgstr ""
|
1248 |
|
1249 |
-
#: v2/App/Helpers/Woocommerce.php:
|
1250 |
msgid "Coupon already exists in WooCommerce. Please select another name"
|
1251 |
msgstr ""
|
1252 |
|
@@ -2334,35 +2334,46 @@ msgstr ""
|
|
2334 |
msgid "Subtotal tiered discount - sample"
|
2335 |
msgstr ""
|
2336 |
|
2337 |
-
#: v2/App/Views/Admin/Tabs/Statistics.php:
|
2338 |
-
msgid ""
|
2339 |
-
"<strong>Note</strong> : Free Shipping rules will not be shown in reports."
|
2340 |
-
msgstr ""
|
2341 |
-
|
2342 |
-
#: v2/App/Views/Admin/Tabs/Statistics.php:40
|
2343 |
msgid "This Week"
|
2344 |
msgstr ""
|
2345 |
|
2346 |
-
#: v2/App/Views/Admin/Tabs/Statistics.php:
|
2347 |
msgid "This Month"
|
2348 |
msgstr ""
|
2349 |
|
2350 |
-
#: v2/App/Views/Admin/Tabs/Statistics.php:
|
2351 |
msgid "Custom Range"
|
2352 |
msgstr ""
|
2353 |
|
2354 |
-
#: v2/App/Views/Admin/Tabs/Statistics.php:
|
2355 |
msgid "From: yyyy/mm/dd"
|
2356 |
msgstr ""
|
2357 |
|
2358 |
-
#: v2/App/Views/Admin/Tabs/Statistics.php:
|
2359 |
msgid "To: yyyy/mm/dd"
|
2360 |
msgstr ""
|
2361 |
|
2362 |
-
#: v2/App/Views/Admin/Tabs/Statistics.php:
|
2363 |
msgid "Update Chart"
|
2364 |
msgstr ""
|
2365 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2366 |
#: v2/App/Views/Admin/Tabs/compatible.php:12
|
2367 |
msgid "Compatibility for Woo Discount Rules"
|
2368 |
msgstr ""
|
586 |
msgid "Recipe"
|
587 |
msgstr ""
|
588 |
|
589 |
+
#: v2/App/Controllers/Admin/Tabs/Reports/RuleAmount.php:15
|
590 |
#: v2/App/Controllers/Admin/Tabs/Reports/RuleAmountWithCartDiscount.php:11
|
591 |
+
#: v2/App/Controllers/Admin/Tabs/Reports/RuleNameDiscount.php:25
|
592 |
+
msgid "Discounted amount shown in default store currency"
|
593 |
msgstr ""
|
594 |
|
595 |
+
#: v2/App/Controllers/Admin/Tabs/Reports/RuleAmount.php:30
|
596 |
+
#: v2/App/Controllers/Admin/Tabs/Reports/RuleNameDiscount.php:41
|
597 |
msgid "Date"
|
598 |
msgstr ""
|
599 |
|
601 |
msgid "Reports"
|
602 |
msgstr ""
|
603 |
|
604 |
+
#: v2/App/Controllers/Admin/Tabs/Statistics.php:37
|
605 |
msgid "Rule Name"
|
606 |
msgstr ""
|
607 |
|
608 |
+
#: v2/App/Controllers/Admin/Tabs/Statistics.php:44
|
609 |
msgid "All Rules"
|
610 |
msgstr ""
|
611 |
|
612 |
+
#: v2/App/Controllers/Admin/Tabs/Statistics.php:45
|
613 |
+
#: v2/App/Controllers/Admin/Tabs/Statistics.php:51
|
614 |
msgid "Rule"
|
615 |
msgstr ""
|
616 |
|
617 |
+
#: v2/App/Controllers/Admin/Tabs/Statistics.php:50
|
618 |
msgid "All Rules (except cart adjustment type)"
|
619 |
msgstr ""
|
620 |
|
621 |
+
#: v2/App/Controllers/Admin/Tabs/Statistics.php:118
|
622 |
#: v2/App/Controllers/Admin/WDRAjax.php:69
|
623 |
#: v2/App/Controllers/Admin/WDRAjax.php:72
|
624 |
msgid "Authentication required"
|
670 |
msgid "<span class=\"onsale\">Sale!</span>"
|
671 |
msgstr ""
|
672 |
|
673 |
+
#: v2/App/Controllers/ManageDiscount.php:818
|
674 |
+
#: v2/App/Controllers/ManageDiscount.php:1075
|
675 |
+
#: v2/App/Controllers/ManageDiscount.php:1078 v2/App/Helpers/Helper.php:271
|
676 |
#: v2/App/Helpers/Helper.php:272
|
677 |
msgid "Cart discount"
|
678 |
msgstr ""
|
679 |
|
680 |
+
#: v2/App/Controllers/ManageDiscount.php:1144
|
681 |
#, php-format
|
682 |
msgid "Coupon \"%s\" is currently not available!"
|
683 |
msgstr ""
|
684 |
|
685 |
+
#: v2/App/Controllers/ManageDiscount.php:1359
|
686 |
#, php-format
|
687 |
msgid ""
|
688 |
"Sorry, it is not possible to apply coupon <b>\"%s\"</b> as you already have "
|
689 |
"a discount applied in cart."
|
690 |
msgstr ""
|
691 |
|
692 |
+
#: v2/App/Controllers/ManageDiscount.php:1373
|
693 |
msgid "Coupon code applied successfully."
|
694 |
msgstr ""
|
695 |
|
696 |
+
#: v2/App/Controllers/ManageDiscount.php:1744
|
697 |
#: v2/App/Views/Admin/Tabs/settings.php:441
|
698 |
msgid "Discount <strong>{{title}}</strong> has been applied to your cart."
|
699 |
msgstr ""
|
700 |
|
701 |
+
#: v2/App/Controllers/ManageDiscount.php:1874
|
702 |
msgid "You saved {{total_discount}}"
|
703 |
msgstr ""
|
704 |
|
1120 |
msgid "Validation error"
|
1121 |
msgstr ""
|
1122 |
|
1123 |
+
#: v2/App/Helpers/Woocommerce.php:1036
|
1124 |
msgid "Sunday"
|
1125 |
msgstr ""
|
1126 |
|
1127 |
+
#: v2/App/Helpers/Woocommerce.php:1037
|
1128 |
msgid "Monday"
|
1129 |
msgstr ""
|
1130 |
|
1131 |
+
#: v2/App/Helpers/Woocommerce.php:1038
|
1132 |
msgid "Tuesday"
|
1133 |
msgstr ""
|
1134 |
|
1135 |
+
#: v2/App/Helpers/Woocommerce.php:1039
|
1136 |
msgid "Wednesday"
|
1137 |
msgstr ""
|
1138 |
|
1139 |
+
#: v2/App/Helpers/Woocommerce.php:1040
|
1140 |
msgid "Thursday"
|
1141 |
msgstr ""
|
1142 |
|
1143 |
+
#: v2/App/Helpers/Woocommerce.php:1041
|
1144 |
msgid "Friday"
|
1145 |
msgstr ""
|
1146 |
|
1147 |
+
#: v2/App/Helpers/Woocommerce.php:1042
|
1148 |
msgid "Saturday"
|
1149 |
msgstr ""
|
1150 |
|
1151 |
+
#: v2/App/Helpers/Woocommerce.php:1053
|
1152 |
msgid ""
|
1153 |
"Woocommerce before main content(Archive / Shop / Cat Pages / single product)"
|
1154 |
msgstr ""
|
1155 |
|
1156 |
+
#: v2/App/Helpers/Woocommerce.php:1054
|
1157 |
msgid "Woocommerce archive description(Archive / Shop / Cat Pages)"
|
1158 |
msgstr ""
|
1159 |
|
1160 |
+
#: v2/App/Helpers/Woocommerce.php:1055
|
1161 |
msgid "Woocommerce before shop loop(Archive / Shop / Cat Pages)"
|
1162 |
msgstr ""
|
1163 |
|
1164 |
+
#: v2/App/Helpers/Woocommerce.php:1056
|
1165 |
msgid "Woocommerce after shop loop(Archive / Shop / Cat Pages)"
|
1166 |
msgstr ""
|
1167 |
|
1168 |
+
#: v2/App/Helpers/Woocommerce.php:1057
|
1169 |
msgid ""
|
1170 |
"Woocommerce after main content(Archive / Shop / Cat Pages / single product)"
|
1171 |
msgstr ""
|
1172 |
|
1173 |
+
#: v2/App/Helpers/Woocommerce.php:1058 v2/App/Views/Admin/Tabs/settings.php:230
|
1174 |
#: v2/App/Views/Admin/Tabs/settings.php:248
|
1175 |
msgid "Woocommerce before single product"
|
1176 |
msgstr ""
|
1177 |
|
1178 |
+
#: v2/App/Helpers/Woocommerce.php:1059 v2/App/Views/Admin/Tabs/settings.php:232
|
1179 |
#: v2/App/Views/Admin/Tabs/settings.php:250
|
1180 |
msgid "Woocommerce before single product summary"
|
1181 |
msgstr ""
|
1182 |
|
1183 |
+
#: v2/App/Helpers/Woocommerce.php:1060 v2/App/Views/Admin/Tabs/settings.php:231
|
1184 |
#: v2/App/Views/Admin/Tabs/settings.php:249
|
1185 |
msgid "Woocommerce after single product summary"
|
1186 |
msgstr ""
|
1187 |
|
1188 |
+
#: v2/App/Helpers/Woocommerce.php:1061 v2/App/Views/Admin/Tabs/settings.php:229
|
1189 |
#: v2/App/Views/Admin/Tabs/settings.php:247
|
1190 |
msgid "Woocommerce after single product"
|
1191 |
msgstr ""
|
1192 |
|
1193 |
+
#: v2/App/Helpers/Woocommerce.php:1062
|
1194 |
msgid "Woocommerce before cart"
|
1195 |
msgstr ""
|
1196 |
|
1197 |
+
#: v2/App/Helpers/Woocommerce.php:1063
|
1198 |
msgid "Woocommerce before cart table"
|
1199 |
msgstr ""
|
1200 |
|
1201 |
+
#: v2/App/Helpers/Woocommerce.php:1064
|
1202 |
msgid "Woocommerce before cart contents"
|
1203 |
msgstr ""
|
1204 |
|
1205 |
+
#: v2/App/Helpers/Woocommerce.php:1065
|
1206 |
msgid "Woocommerce cart contents"
|
1207 |
msgstr ""
|
1208 |
|
1209 |
+
#: v2/App/Helpers/Woocommerce.php:1066
|
1210 |
msgid "Woocommerce after cart contents"
|
1211 |
msgstr ""
|
1212 |
|
1213 |
+
#: v2/App/Helpers/Woocommerce.php:1067
|
1214 |
msgid "Woocommerce after cart table"
|
1215 |
msgstr ""
|
1216 |
|
1217 |
+
#: v2/App/Helpers/Woocommerce.php:1068
|
1218 |
msgid "Woocommerce after cart"
|
1219 |
msgstr ""
|
1220 |
|
1221 |
+
#: v2/App/Helpers/Woocommerce.php:1069
|
1222 |
msgid "Woocommerce before checkout form"
|
1223 |
msgstr ""
|
1224 |
|
1225 |
+
#: v2/App/Helpers/Woocommerce.php:1071
|
1226 |
msgid "Woocommerce before checkout billing form"
|
1227 |
msgstr ""
|
1228 |
|
1229 |
+
#: v2/App/Helpers/Woocommerce.php:1072
|
1230 |
msgid "Woocommerce after checkout billing form"
|
1231 |
msgstr ""
|
1232 |
|
1233 |
+
#: v2/App/Helpers/Woocommerce.php:1073
|
1234 |
msgid "Woocommerce before checkout shipping form"
|
1235 |
msgstr ""
|
1236 |
|
1237 |
+
#: v2/App/Helpers/Woocommerce.php:1074
|
1238 |
msgid "Woocommerce after checkout shipping form"
|
1239 |
msgstr ""
|
1240 |
|
1241 |
+
#: v2/App/Helpers/Woocommerce.php:1075
|
1242 |
msgid "Woocommerce before order notes"
|
1243 |
msgstr ""
|
1244 |
|
1245 |
+
#: v2/App/Helpers/Woocommerce.php:1076
|
1246 |
msgid "Woocommerce after order notes"
|
1247 |
msgstr ""
|
1248 |
|
1249 |
+
#: v2/App/Helpers/Woocommerce.php:1642
|
1250 |
msgid "Coupon already exists in WooCommerce. Please select another name"
|
1251 |
msgstr ""
|
1252 |
|
2334 |
msgid "Subtotal tiered discount - sample"
|
2335 |
msgstr ""
|
2336 |
|
2337 |
+
#: v2/App/Views/Admin/Tabs/Statistics.php:73
|
|
|
|
|
|
|
|
|
|
|
2338 |
msgid "This Week"
|
2339 |
msgstr ""
|
2340 |
|
2341 |
+
#: v2/App/Views/Admin/Tabs/Statistics.php:74
|
2342 |
msgid "This Month"
|
2343 |
msgstr ""
|
2344 |
|
2345 |
+
#: v2/App/Views/Admin/Tabs/Statistics.php:75
|
2346 |
msgid "Custom Range"
|
2347 |
msgstr ""
|
2348 |
|
2349 |
+
#: v2/App/Views/Admin/Tabs/Statistics.php:82
|
2350 |
msgid "From: yyyy/mm/dd"
|
2351 |
msgstr ""
|
2352 |
|
2353 |
+
#: v2/App/Views/Admin/Tabs/Statistics.php:92
|
2354 |
msgid "To: yyyy/mm/dd"
|
2355 |
msgstr ""
|
2356 |
|
2357 |
+
#: v2/App/Views/Admin/Tabs/Statistics.php:111
|
2358 |
msgid "Update Chart"
|
2359 |
msgstr ""
|
2360 |
|
2361 |
+
#: v2/App/Views/Admin/Tabs/Statistics.php:118
|
2362 |
+
msgid "Discounted orders"
|
2363 |
+
msgstr ""
|
2364 |
+
|
2365 |
+
#: v2/App/Views/Admin/Tabs/Statistics.php:122
|
2366 |
+
msgid "Total sales"
|
2367 |
+
msgstr ""
|
2368 |
+
|
2369 |
+
#: v2/App/Views/Admin/Tabs/Statistics.php:126
|
2370 |
+
msgid "Discounted Amount"
|
2371 |
+
msgstr ""
|
2372 |
+
|
2373 |
+
#: v2/App/Views/Admin/Tabs/Statistics.php:131
|
2374 |
+
msgid "Orders used free shipping rule"
|
2375 |
+
msgstr ""
|
2376 |
+
|
2377 |
#: v2/App/Views/Admin/Tabs/compatible.php:12
|
2378 |
msgid "Compatibility for Woo Discount Rules"
|
2379 |
msgstr ""
|
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: 6.0
|
7 |
-
Stable tag: 2.
|
8 |
License: GPLv3 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
10 |
|
@@ -336,6 +336,20 @@ Note : Enable recursive checkbox if the discounts should be applied in sequentia
|
|
336 |
|
337 |
== Changelog ==
|
338 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
339 |
= 2.4.5 - 27/09/22 =
|
340 |
* Improvement: Additional param on the event advanced_woo_discount_rules_strikeout_price_html [Core].
|
341 |
* Improvement: Backend field validation [Core and Pro].
|
@@ -369,8 +383,6 @@ Note : Enable recursive checkbox if the discounts should be applied in sequentia
|
|
369 |
* Improvement: Event: advanced_woo_discount_rules_after_save_rule
|
370 |
* Fix: Onsale page query improvement for on-sale filter.
|
371 |
* Fix: Redirecting to list page on create rule instead of edit page.
|
372 |
-
|
373 |
-
= 2.4.3 - 28/06/22 =
|
374 |
* Fix: Sale page doesn't filters based on selected rules.
|
375 |
* Improvement: Event: advanced_woo_discount_rules_get_price_of_cart_item_on_find_cheapest_item
|
376 |
|
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: 6.0
|
7 |
+
Stable tag: 2.5.0
|
8 |
License: GPLv3 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
10 |
|
336 |
|
337 |
== Changelog ==
|
338 |
|
339 |
+
= 2.5.0 - 01/11/22 =
|
340 |
+
* Improvement: Added applied discount info in order and order item meta _wdr_discounts [Core and Pro].
|
341 |
+
* Improvement: Loading issue on shop page while having variable price strikeout improvement [Core].
|
342 |
+
* Improvement: Set 3 for 10 fixed .1 difference on subtotal [Pro].
|
343 |
+
* Improvement: Doing strikeout on cart while using third-party shortcode [Core].
|
344 |
+
* Improvement: Show free shipping rule reports since v2.5.0 [Pro].
|
345 |
+
* Improvement: Added order_item_id and other_discount columns in wdr_order_item_discounts table [Core].
|
346 |
+
* Add: Show total order count and sales on report section [Core and Pro].
|
347 |
+
* Fix: Disable coupon option doesn't working with free shipping [Pro].
|
348 |
+
* Fix: Applied message is not displaying in cart for free shipping [Pro].
|
349 |
+
* Fix: Limit option is not working with Free shipping [Pro].
|
350 |
+
* Fix: Warning on PHP 8 [Core and Pro].
|
351 |
+
* Fix: Fatal error on load order item meta [Core].
|
352 |
+
|
353 |
= 2.4.5 - 27/09/22 =
|
354 |
* Improvement: Additional param on the event advanced_woo_discount_rules_strikeout_price_html [Core].
|
355 |
* Improvement: Backend field validation [Core and Pro].
|
383 |
* Improvement: Event: advanced_woo_discount_rules_after_save_rule
|
384 |
* Fix: Onsale page query improvement for on-sale filter.
|
385 |
* Fix: Redirecting to list page on create rule instead of edit page.
|
|
|
|
|
386 |
* Fix: Sale page doesn't filters based on selected rules.
|
387 |
* Improvement: Event: advanced_woo_discount_rules_get_price_of_cart_item_on_find_cheapest_item
|
388 |
|
v2/App/Compatibility/CurrencySwitcherByRealmag777.php
CHANGED
@@ -18,7 +18,7 @@ class CurrencySwitcherByRealmag777 extends Base
|
|
18 |
if(!empty($discount_prices) && isset($discount_prices['discounted_price'])){
|
19 |
global $WOOCS;
|
20 |
if(isset($WOOCS)){
|
21 |
-
if (method_exists($WOOCS, 'get_currencies')){
|
22 |
$currencies = $WOOCS->get_currencies();
|
23 |
$convert_to_current_currency = false;
|
24 |
if(isset($WOOCS->is_geoip_manipulation) && $WOOCS->is_geoip_manipulation){
|
18 |
if(!empty($discount_prices) && isset($discount_prices['discounted_price'])){
|
19 |
global $WOOCS;
|
20 |
if(isset($WOOCS)){
|
21 |
+
if (is_object($WOOCS) && method_exists($WOOCS, 'get_currencies')){
|
22 |
$currencies = $WOOCS->get_currencies();
|
23 |
$convert_to_current_currency = false;
|
24 |
if(isset($WOOCS->is_geoip_manipulation) && $WOOCS->is_geoip_manipulation){
|
v2/App/Compatibility/PriceBasedOnCountryByOscarGare.php
CHANGED
@@ -19,7 +19,7 @@ class PriceBasedOnCountryByOscarGare extends Base
|
|
19 |
// Pass the price to the currency conversion function provided by the Currency Switcher. This
|
20 |
// will ensure that the discount is converted correctly
|
21 |
if(function_exists('wcpbc_the_zone')) {
|
22 |
-
if(method_exists(wcpbc_the_zone(), 'get_exchange_rate_price')) {
|
23 |
// Return a price calculate by exchange rate
|
24 |
$price = wcpbc_the_zone()->get_exchange_rate_price($price, true, 'generic', null);
|
25 |
}
|
19 |
// Pass the price to the currency conversion function provided by the Currency Switcher. This
|
20 |
// will ensure that the discount is converted correctly
|
21 |
if(function_exists('wcpbc_the_zone')) {
|
22 |
+
if(is_object(wcpbc_the_zone()) && method_exists(wcpbc_the_zone(), 'get_exchange_rate_price')) {
|
23 |
// Return a price calculate by exchange rate
|
24 |
$price = wcpbc_the_zone()->get_exchange_rate_price($price, true, 'generic', null);
|
25 |
}
|
v2/App/Controllers/Admin/Tabs/Compatible.php
CHANGED
@@ -103,7 +103,7 @@ class Compatible extends Base
|
|
103 |
$available_classes = $this->getAvailableCompatibilityClasses();
|
104 |
if(!empty($available_classes)){
|
105 |
foreach ($available_classes as $available_class){
|
106 |
-
if(method_exists($available_class, 'loadFields')){
|
107 |
$available_class->loadFields($has_compatibility_plugin);
|
108 |
}
|
109 |
}
|
@@ -117,7 +117,7 @@ class Compatible extends Base
|
|
117 |
$available_classes = $this->getAvailableCompatibilityClasses();
|
118 |
if(!empty($available_classes)){
|
119 |
foreach ($available_classes as $available_class){
|
120 |
-
if(method_exists($available_class, 'run')){
|
121 |
$available_class->run();
|
122 |
}
|
123 |
}
|
103 |
$available_classes = $this->getAvailableCompatibilityClasses();
|
104 |
if(!empty($available_classes)){
|
105 |
foreach ($available_classes as $available_class){
|
106 |
+
if(is_object($available_class) && method_exists($available_class, 'loadFields')){
|
107 |
$available_class->loadFields($has_compatibility_plugin);
|
108 |
}
|
109 |
}
|
117 |
$available_classes = $this->getAvailableCompatibilityClasses();
|
118 |
if(!empty($available_classes)){
|
119 |
foreach ($available_classes as $available_class){
|
120 |
+
if(is_object($available_class) && method_exists($available_class, 'run')){
|
121 |
$available_class->run();
|
122 |
}
|
123 |
}
|
v2/App/Controllers/Admin/Tabs/Reports/RuleAmount.php
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
<?php
|
2 |
namespace Wdr\App\Controllers\Admin\Tabs\Reports;
|
3 |
|
|
|
4 |
use Wdr\App\Models\DBTable;
|
5 |
|
6 |
if ( ! defined( 'ABSPATH' ) ) {
|
@@ -11,7 +12,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|
11 |
class RuleAmount extends Base {
|
12 |
|
13 |
public function get_subtitle() {
|
14 |
-
return __( '
|
15 |
}
|
16 |
|
17 |
public function get_type() {
|
@@ -22,7 +23,8 @@ class RuleAmount extends Base {
|
|
22 |
|
23 |
$params = $this->prepare_params( $params );
|
24 |
|
25 |
-
|
|
|
26 |
|
27 |
$rules = array_unique( array_column( $rule_amount_stats, 'title' ) );
|
28 |
$columns = array_merge( array( __( 'Date', 'woo-discount-rules' ) ), $rules );
|
@@ -48,29 +50,39 @@ class RuleAmount extends Base {
|
|
48 |
$rows[ $date ][ $column_key ] = (float) $rule_amount_item->value;
|
49 |
}
|
50 |
|
51 |
-
$
|
52 |
|
53 |
-
return $
|
54 |
}
|
55 |
|
56 |
-
protected function prepare_data( $columns, $rows ) {
|
57 |
-
$
|
58 |
'subtitle' => $this->get_subtitle(),
|
59 |
'type' => $this->get_type(),
|
60 |
'columns' => $columns,
|
61 |
'rows' => $rows,
|
62 |
);
|
63 |
|
64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
}
|
66 |
|
67 |
protected function load_raw_data( $params ) {
|
68 |
-
$
|
69 |
-
if ( empty( $
|
70 |
-
|
71 |
}
|
72 |
-
|
73 |
-
|
|
|
|
|
74 |
}
|
75 |
|
76 |
protected function prepare_params( $params ) {
|
1 |
<?php
|
2 |
namespace Wdr\App\Controllers\Admin\Tabs\Reports;
|
3 |
|
4 |
+
use Wdr\App\Helpers\Woocommerce;
|
5 |
use Wdr\App\Models\DBTable;
|
6 |
|
7 |
if ( ! defined( 'ABSPATH' ) ) {
|
12 |
class RuleAmount extends Base {
|
13 |
|
14 |
public function get_subtitle() {
|
15 |
+
return __( 'Discounted amount shown in default store currency', 'woo-discount-rules' );
|
16 |
}
|
17 |
|
18 |
public function get_type() {
|
23 |
|
24 |
$params = $this->prepare_params( $params );
|
25 |
|
26 |
+
$data = $this->load_raw_data( $params );
|
27 |
+
$rule_amount_stats = $data['stats'];
|
28 |
|
29 |
$rules = array_unique( array_column( $rule_amount_stats, 'title' ) );
|
30 |
$columns = array_merge( array( __( 'Date', 'woo-discount-rules' ) ), $rules );
|
50 |
$rows[ $date ][ $column_key ] = (float) $rule_amount_item->value;
|
51 |
}
|
52 |
|
53 |
+
$res = $this->prepare_data( $columns, $rows, $data['other'] );
|
54 |
|
55 |
+
return $res;
|
56 |
}
|
57 |
|
58 |
+
protected function prepare_data( $columns, $rows, $other ) {
|
59 |
+
$data['chart'] = array(
|
60 |
'subtitle' => $this->get_subtitle(),
|
61 |
'type' => $this->get_type(),
|
62 |
'columns' => $columns,
|
63 |
'rows' => $rows,
|
64 |
);
|
65 |
|
66 |
+
if (!empty($other)) {
|
67 |
+
$data['other'] = [
|
68 |
+
'total_orders' => (int) $other->total_orders,
|
69 |
+
'revenue' => Woocommerce::formatPrice($other->revenue),
|
70 |
+
'discounted_amount' => Woocommerce::formatPrice($other->discounted_amount),
|
71 |
+
'total_free_shipping' => (int) $other->total_free_shipping,
|
72 |
+
];
|
73 |
+
}
|
74 |
+
return $data;
|
75 |
}
|
76 |
|
77 |
protected function load_raw_data( $params ) {
|
78 |
+
$data = DBTable::get_rules_rows_summary( $params );
|
79 |
+
if ( empty( $data['stats'] ) ) {
|
80 |
+
$data['stats'] = array();
|
81 |
}
|
82 |
+
if ( empty( $data['other'] ) ) {
|
83 |
+
$data['other'] = array();
|
84 |
+
}
|
85 |
+
return $data;
|
86 |
}
|
87 |
|
88 |
protected function prepare_params( $params ) {
|
v2/App/Controllers/Admin/Tabs/Reports/RuleAmountWithCartDiscount.php
CHANGED
@@ -8,7 +8,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|
8 |
class RuleAmountWithCartDiscount extends RuleAmount {
|
9 |
|
10 |
public function get_subtitle() {
|
11 |
-
return __( '
|
12 |
}
|
13 |
|
14 |
protected function prepare_params( $params ) {
|
8 |
class RuleAmountWithCartDiscount extends RuleAmount {
|
9 |
|
10 |
public function get_subtitle() {
|
11 |
+
return __( 'Discounted amount shown in default store currency', 'woo-discount-rules' );
|
12 |
}
|
13 |
|
14 |
protected function prepare_params( $params ) {
|
v2/App/Controllers/Admin/Tabs/Reports/RuleNameDiscount.php
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
<?php
|
2 |
namespace Wdr\App\Controllers\Admin\Tabs\Reports;
|
3 |
|
|
|
4 |
use Wdr\App\Models\DBTable;
|
5 |
|
6 |
if ( ! defined( 'ABSPATH' ) ) {
|
@@ -21,7 +22,7 @@ class RuleNameDiscount extends Base {
|
|
21 |
}
|
22 |
|
23 |
public function get_subtitle() {
|
24 |
-
return __( '
|
25 |
}
|
26 |
|
27 |
public function get_type() {
|
@@ -33,7 +34,8 @@ class RuleNameDiscount extends Base {
|
|
33 |
|
34 |
$params = $this->prepare_params( $params );
|
35 |
|
36 |
-
$
|
|
|
37 |
|
38 |
$rules = array_unique( array_column( $rule_amount_stats, 'title' ) );
|
39 |
$columns = array_merge( array( __( 'Date', 'woo-discount-rules' ) ), $rules );
|
@@ -59,28 +61,40 @@ class RuleNameDiscount extends Base {
|
|
59 |
$rows[ $date ][ $column_key ] = (float) $rule_amount_item->value;
|
60 |
}
|
61 |
|
62 |
-
$
|
63 |
|
64 |
-
return $
|
65 |
}
|
66 |
|
67 |
-
protected function prepare_data( $columns, $rows ) {
|
68 |
-
$
|
69 |
'title' => $this->get_title(),
|
70 |
'subtitle' => $this->get_subtitle(),
|
71 |
'type' => $this->get_type(),
|
72 |
'columns' => $columns,
|
73 |
'rows' => $rows,
|
74 |
);
|
75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
}
|
77 |
|
78 |
protected function load_raw_data( $params, $rule_id = 0 ) {
|
79 |
-
$
|
80 |
-
if ( empty( $
|
81 |
-
$
|
|
|
|
|
|
|
82 |
}
|
83 |
-
return $
|
84 |
}
|
85 |
|
86 |
protected function prepare_params( $params ) {
|
1 |
<?php
|
2 |
namespace Wdr\App\Controllers\Admin\Tabs\Reports;
|
3 |
|
4 |
+
use Wdr\App\Helpers\Woocommerce;
|
5 |
use Wdr\App\Models\DBTable;
|
6 |
|
7 |
if ( ! defined( 'ABSPATH' ) ) {
|
22 |
}
|
23 |
|
24 |
public function get_subtitle() {
|
25 |
+
return __( 'Discounted amount shown in default store currency', 'woo-discount-rules' );
|
26 |
}
|
27 |
|
28 |
public function get_type() {
|
34 |
|
35 |
$params = $this->prepare_params( $params );
|
36 |
|
37 |
+
$data = $this->load_raw_data( $params, $rule_id);
|
38 |
+
$rule_amount_stats = $data['stats'];
|
39 |
|
40 |
$rules = array_unique( array_column( $rule_amount_stats, 'title' ) );
|
41 |
$columns = array_merge( array( __( 'Date', 'woo-discount-rules' ) ), $rules );
|
61 |
$rows[ $date ][ $column_key ] = (float) $rule_amount_item->value;
|
62 |
}
|
63 |
|
64 |
+
$res = $this->prepare_data( $columns, $rows, $data['other'] );
|
65 |
|
66 |
+
return $res;
|
67 |
}
|
68 |
|
69 |
+
protected function prepare_data( $columns, $rows, $other ) {
|
70 |
+
$data['chart'] = array(
|
71 |
'title' => $this->get_title(),
|
72 |
'subtitle' => $this->get_subtitle(),
|
73 |
'type' => $this->get_type(),
|
74 |
'columns' => $columns,
|
75 |
'rows' => $rows,
|
76 |
);
|
77 |
+
|
78 |
+
if (!empty($other)) {
|
79 |
+
$data['other'] = [
|
80 |
+
'total_orders' => (int) $other->total_orders,
|
81 |
+
'revenue' => Woocommerce::formatPrice($other->revenue),
|
82 |
+
'discounted_amount' => Woocommerce::formatPrice($other->discounted_amount),
|
83 |
+
'total_free_shipping' => (int) $other->total_free_shipping,
|
84 |
+
];
|
85 |
+
}
|
86 |
+
return $data;
|
87 |
}
|
88 |
|
89 |
protected function load_raw_data( $params, $rule_id = 0 ) {
|
90 |
+
$data = DBTable::get_rule_rows_summary( $params, $rule_id );
|
91 |
+
if ( empty( $data['stats'] ) ) {
|
92 |
+
$data['stats'] = array();
|
93 |
+
}
|
94 |
+
if ( empty( $data['other'] ) ) {
|
95 |
+
$data['other'] = array();
|
96 |
}
|
97 |
+
return $data;
|
98 |
}
|
99 |
|
100 |
protected function prepare_params( $params ) {
|
v2/App/Controllers/Admin/Tabs/Statistics.php
CHANGED
@@ -29,17 +29,14 @@ class Statistics extends Base
|
|
29 |
$available_conditions = $this->getAvailableConditions();
|
30 |
$rules = $rule_helper->getAllRules($available_conditions);
|
31 |
foreach ($rules as $rule){
|
32 |
-
$
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
$
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
'rule_id' => $rule_id,
|
41 |
-
);
|
42 |
-
}
|
43 |
}
|
44 |
$this->reports = array(
|
45 |
'rule_amount_extra' => array(
|
29 |
$available_conditions = $this->getAvailableConditions();
|
30 |
$rules = $rule_helper->getAllRules($available_conditions);
|
31 |
foreach ($rules as $rule){
|
32 |
+
$rule_id = $rule->getId();
|
33 |
+
$rule_title = $rule->getTitle();
|
34 |
+
$this->rule_details[$rule_id] = array(
|
35 |
+
'handler' => new Reports\RuleNameDiscount($rule),
|
36 |
+
'label' => __( $rule_title , 'woo-discount-rules' ),
|
37 |
+
'group' => __( 'Rule Name', 'woo-discount-rules' ),
|
38 |
+
'rule_id' => $rule_id,
|
39 |
+
);
|
|
|
|
|
|
|
40 |
}
|
41 |
$this->reports = array(
|
42 |
'rule_amount_extra' => array(
|
v2/App/Controllers/DiscountCalculator.php
CHANGED
@@ -643,6 +643,7 @@ class DiscountCalculator extends Base
|
|
643 |
if(!empty($cart_item)) {
|
644 |
$price_as_cart_discount[$rule_id][$product_id] = array(
|
645 |
'discount_type' => 'wdr_simple_discount',
|
|
|
646 |
'discount_label' => wp_unslash($simple_discount->cart_label),
|
647 |
'discount_value' => $simple_discount->value,
|
648 |
'discounted_price' => $cart_discounted_price,
|
@@ -680,10 +681,12 @@ class DiscountCalculator extends Base
|
|
680 |
if (isset($bulk_discount->apply_as_cart_rule) && !empty($bulk_discount->apply_as_cart_rule)) {
|
681 |
$this_apply_as_cart_rule = true;
|
682 |
if(!empty($cart_item)) {
|
|
|
683 |
$price_as_cart_discount[$rule_id][$product_id] = array(
|
684 |
'discount_type' => 'wdr_bulk_discount',
|
|
|
685 |
'discount_label' => wp_unslash($bulk_discount->cart_label),
|
686 |
-
'discount_value' => 0,
|
687 |
'discounted_price' => $cart_discounted_price,
|
688 |
'rule_name' => $rule->getTitle(),
|
689 |
'cart_item_key' => isset($cart_item['key']) ? $cart_item['key'] : '',
|
@@ -1053,6 +1056,7 @@ class DiscountCalculator extends Base
|
|
1053 |
$label = (isset($detail['discount_label']) && !empty($detail['discount_label'])) ? $detail['discount_label'] : $detail['rule_name'];
|
1054 |
$value = (isset($detail['discount_value']) && !empty($detail['discount_value'])) ? $detail['discount_value'] : 0;
|
1055 |
$product_id = isset($detail['product_id']) ? $detail['product_id'] : 0;
|
|
|
1056 |
$rule_applied_product_id = array_merge($rule_applied_product_id, array($product_id));
|
1057 |
$current_discounted_price = isset($detail['discounted_price']) ? $detail['discounted_price'] : 0 ;
|
1058 |
$cart_discount_against_product[$product_id][$rule_id] = $current_discounted_price;
|
@@ -1062,6 +1066,7 @@ class DiscountCalculator extends Base
|
|
1062 |
}
|
1063 |
self::$cart_adjustments[$rule_id]['cart_discount'] = isset($value) ? $value : '';
|
1064 |
self::$cart_adjustments[$rule_id]['cart_shipping'] = 'no';
|
|
|
1065 |
self::$cart_adjustments[$rule_id]['cart_discount_label'] = isset($label) ? $label : '';
|
1066 |
self::$cart_adjustments[$rule_id]['cart_discount_price'] = $discount_value;
|
1067 |
self::$cart_adjustments[$rule_id]['cart_discount_product_price'] = $cart_discount_against_product;
|
@@ -1107,7 +1112,10 @@ class DiscountCalculator extends Base
|
|
1107 |
continue;
|
1108 |
}
|
1109 |
}
|
1110 |
-
|
|
|
|
|
|
|
1111 |
return array('free_shipping'=>1);
|
1112 |
//}
|
1113 |
}
|
643 |
if(!empty($cart_item)) {
|
644 |
$price_as_cart_discount[$rule_id][$product_id] = array(
|
645 |
'discount_type' => 'wdr_simple_discount',
|
646 |
+
'apply_type' => $simple_discount->type,
|
647 |
'discount_label' => wp_unslash($simple_discount->cart_label),
|
648 |
'discount_value' => $simple_discount->value,
|
649 |
'discounted_price' => $cart_discounted_price,
|
681 |
if (isset($bulk_discount->apply_as_cart_rule) && !empty($bulk_discount->apply_as_cart_rule)) {
|
682 |
$this_apply_as_cart_rule = true;
|
683 |
if(!empty($cart_item)) {
|
684 |
+
$product_bulk_discount = $rule->calculateProductBulkDiscount($product_price, $quantity, $product, $price_display_condition, $is_cart, $manual_request);
|
685 |
$price_as_cart_discount[$rule_id][$product_id] = array(
|
686 |
'discount_type' => 'wdr_bulk_discount',
|
687 |
+
'apply_type' => isset($product_bulk_discount['discount_type']) ? $product_bulk_discount['discount_type'] : '',
|
688 |
'discount_label' => wp_unslash($bulk_discount->cart_label),
|
689 |
+
'discount_value' => isset($product_bulk_discount['discount_value']) ? $product_bulk_discount['discount_value'] : 0,
|
690 |
'discounted_price' => $cart_discounted_price,
|
691 |
'rule_name' => $rule->getTitle(),
|
692 |
'cart_item_key' => isset($cart_item['key']) ? $cart_item['key'] : '',
|
1056 |
$label = (isset($detail['discount_label']) && !empty($detail['discount_label'])) ? $detail['discount_label'] : $detail['rule_name'];
|
1057 |
$value = (isset($detail['discount_value']) && !empty($detail['discount_value'])) ? $detail['discount_value'] : 0;
|
1058 |
$product_id = isset($detail['product_id']) ? $detail['product_id'] : 0;
|
1059 |
+
$apply_type = isset($detail['apply_type']) ? $detail['apply_type'] : '';
|
1060 |
$rule_applied_product_id = array_merge($rule_applied_product_id, array($product_id));
|
1061 |
$current_discounted_price = isset($detail['discounted_price']) ? $detail['discounted_price'] : 0 ;
|
1062 |
$cart_discount_against_product[$product_id][$rule_id] = $current_discounted_price;
|
1066 |
}
|
1067 |
self::$cart_adjustments[$rule_id]['cart_discount'] = isset($value) ? $value : '';
|
1068 |
self::$cart_adjustments[$rule_id]['cart_shipping'] = 'no';
|
1069 |
+
self::$cart_adjustments[$rule_id]['cart_discount_type'] = isset($apply_type) ? $apply_type : '';
|
1070 |
self::$cart_adjustments[$rule_id]['cart_discount_label'] = isset($label) ? $label : '';
|
1071 |
self::$cart_adjustments[$rule_id]['cart_discount_price'] = $discount_value;
|
1072 |
self::$cart_adjustments[$rule_id]['cart_discount_product_price'] = $cart_discount_against_product;
|
1112 |
continue;
|
1113 |
}
|
1114 |
}
|
1115 |
+
|
1116 |
+
if (self::$woocommerce_helper->isCartNeedsShipping()) {
|
1117 |
+
self::$applied_rules[$rule_id] = self::$rules[$rule_id];
|
1118 |
+
}
|
1119 |
return array('free_shipping'=>1);
|
1120 |
//}
|
1121 |
}
|
v2/App/Controllers/ManageDiscount.php
CHANGED
@@ -11,7 +11,7 @@ if (!defined('ABSPATH')) exit; // Exit if accessed directly
|
|
11 |
|
12 |
class ManageDiscount extends Base
|
13 |
{
|
14 |
-
public static $apply_as_coupon_values = array(), $available_rules = array(), $calculator, $on_sale_products = array(), $calculated_cart_item_discount = array(), $calculated_cart_discount = array(), $calculated_product_discount = array(), $cart_discounts = array(), $set_total_quantity = 0, $categories_slug = array(), $cart_tot_qty = array();
|
15 |
public $free_shipping = false, $shipping_obj;
|
16 |
|
17 |
/**
|
@@ -493,11 +493,22 @@ class ManageDiscount extends Base
|
|
493 |
}
|
494 |
|
495 |
$original_prices_list = $sale_prices_lists = $discount_prices_lists = array();
|
496 |
-
$
|
497 |
|
498 |
-
if (!empty($
|
499 |
$consider_out_of_stock_variants = apply_filters('advanced_woo_discount_rules_do_strikeout_for_out_of_stock_variants', false);
|
500 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
501 |
foreach ($variations as $variation_id) {
|
502 |
if (empty($variation_id)) {
|
503 |
continue;
|
@@ -745,6 +756,7 @@ class ManageDiscount extends Base
|
|
745 |
$total_combined_discounts = 0;
|
746 |
$apply_as_cart_fee_details = DiscountCalculator::$price_discount_apply_as_cart_discount;
|
747 |
$flat_in_subtotal = array();
|
|
|
748 |
if(!empty($apply_as_cart_fee_details)){
|
749 |
foreach ($apply_as_cart_fee_details as $rule_id => $product_id){
|
750 |
$discount_value = 0;
|
@@ -758,11 +770,22 @@ class ManageDiscount extends Base
|
|
758 |
$discount_value += $detail['discounted_price'];
|
759 |
$label = (isset($detail['discount_label']) && !empty($detail['discount_label'])) ? $detail['discount_label'] : $detail['rule_name'];
|
760 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
761 |
}
|
762 |
if ($discount_value > 0) {
|
763 |
if (empty($combine_all_discounts)) {
|
764 |
$discount_value = -1 * $discount_value;
|
765 |
-
|
|
|
|
|
|
|
766 |
}else{
|
767 |
$total_combined_discounts += $discount_value;
|
768 |
}
|
@@ -771,11 +794,14 @@ class ManageDiscount extends Base
|
|
771 |
}
|
772 |
}
|
773 |
if (!empty($flat_in_subtotal)) {
|
774 |
-
foreach ($flat_in_subtotal as $discount){
|
775 |
if(empty($combine_all_discounts)){
|
776 |
$discount_value = -1 * $discount['value'];
|
777 |
$label = $discount['label'];
|
778 |
-
|
|
|
|
|
|
|
779 |
}else{
|
780 |
$total_combined_discounts += $discount['value'];
|
781 |
}
|
@@ -788,7 +814,10 @@ class ManageDiscount extends Base
|
|
788 |
$label = Helper::getCleanHtml($label);
|
789 |
if ($discount_apply_type == 'fee') {
|
790 |
$total_combined_discounts = -1 * $total_combined_discounts;
|
791 |
-
|
|
|
|
|
|
|
792 |
}
|
793 |
}
|
794 |
DiscountCalculator::$price_discount_apply_as_cart_discount = array();
|
@@ -906,12 +935,40 @@ class ManageDiscount extends Base
|
|
906 |
/**
|
907 |
* Set coupon values
|
908 |
* */
|
909 |
-
public static function setCartCouponValues($label, $discount_value, $cart_item_keys){
|
910 |
$coupon_code = apply_filters('woocommerce_coupon_code', $label);
|
911 |
$discount_value = apply_filters('advanced_woo_discount_rules_coupon_value', $discount_value, $label, $cart_item_keys);
|
912 |
self::$apply_as_coupon_values[$coupon_code]['value'] = $discount_value;
|
913 |
self::$apply_as_coupon_values[$coupon_code]['cart_item_keys'] = $cart_item_keys;
|
914 |
self::$apply_as_coupon_values[$coupon_code]['display_text'] = $label;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
915 |
}
|
916 |
|
917 |
/**
|
@@ -952,8 +1009,10 @@ class ManageDiscount extends Base
|
|
952 |
}
|
953 |
$apply_as_cart_fee_details = DiscountCalculator::$price_discount_apply_as_cart_discount;
|
954 |
DiscountCalculator::$price_discount_apply_as_cart_discount = array();
|
|
|
955 |
$apply_as_cart_fee_details = self::removeDuplicateValues($apply_as_cart_fee_details);
|
956 |
$flat_in_subtotal = array();
|
|
|
957 |
if(!empty($apply_as_cart_fee_details)){
|
958 |
foreach ($apply_as_cart_fee_details as $rule_id => $product_id){
|
959 |
$cart_item_keys = array();
|
@@ -972,12 +1031,19 @@ class ManageDiscount extends Base
|
|
972 |
$label = (isset($detail['discount_label']) && !empty($detail['discount_label'])) ? $detail['discount_label'] : $detail['rule_name'];
|
973 |
$cart_item_keys[] = $detail['cart_item_key'];
|
974 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
975 |
}
|
976 |
if ($discount_value > 0) {
|
977 |
if (empty($combine_all_discounts)) {
|
978 |
-
$discount_value = $discount_value;
|
979 |
$label = __($label, 'woo-discount-rules');
|
980 |
-
self::setCartCouponValues($label, $discount_value, $cart_item_keys);
|
981 |
$this->applyFakeCouponsForCartRules($label);
|
982 |
}else{
|
983 |
$total_combined_discounts += $discount_value;
|
@@ -988,12 +1054,12 @@ class ManageDiscount extends Base
|
|
988 |
}
|
989 |
}
|
990 |
if (!empty($flat_in_subtotal)) {
|
991 |
-
foreach ($flat_in_subtotal as $discount){
|
992 |
if(empty($combine_all_discounts)){
|
993 |
$discount_value = $discount['value'];
|
994 |
$label = $discount['label'];
|
995 |
$label = __($label, 'woo-discount-rules');
|
996 |
-
self::setCartCouponValues($label, $discount_value, $discount['cart_item_keys']);
|
997 |
$this->applyFakeCouponsForCartRules($label);
|
998 |
}else{
|
999 |
$total_combined_discounts += $discount['value'];
|
@@ -1010,7 +1076,7 @@ class ManageDiscount extends Base
|
|
1010 |
$label = __('Cart discount', 'woo-discount-rules');
|
1011 |
}
|
1012 |
$label = __($label, 'woo-discount-rules');
|
1013 |
-
self::setCartCouponValues($label, $total_combined_discounts, $combined_discounts_cart_items);
|
1014 |
$this->applyFakeCouponsForCartRules($label);
|
1015 |
}
|
1016 |
add_action('woocommerce_after_calculate_totals', array($this, 'applyVirtualCouponForCartRules'), 10);
|
@@ -1026,7 +1092,7 @@ class ManageDiscount extends Base
|
|
1026 |
|
1027 |
// Validating the Coupon as Valid and discount status.
|
1028 |
if(isset($woocommerce->cart)){
|
1029 |
-
if(method_exists($woocommerce->cart, 'has_discount')){
|
1030 |
if (!$woocommerce->cart->has_discount($coupon_code)) {
|
1031 |
// Do not apply coupon with individual use coupon already applied
|
1032 |
if ($woocommerce->cart->applied_coupons) {
|
@@ -1055,12 +1121,12 @@ class ManageDiscount extends Base
|
|
1055 |
global $woocommerce;
|
1056 |
|
1057 |
if (isset($_GET['wdr_coupon']) && !empty($_GET['wdr_coupon']) && isset($woocommerce->cart)) {
|
1058 |
-
if ( method_exists( $woocommerce->cart, 'has_discount' ) && method_exists( $woocommerce->cart, 'add_discount' ) ) {
|
1059 |
$rule_helper = new Rule();
|
1060 |
$available_url_coupons = $rule_helper->getAllUrlCoupons();
|
1061 |
$available_url_coupons = array_map('\Wdr\App\Helpers\Woocommerce::formatStringToLower', $available_url_coupons);
|
1062 |
$coupons = explode(",", $_GET['wdr_coupon']);
|
1063 |
-
if (isset($woocommerce->session) && method_exists($woocommerce->session, 'has_session')) {
|
1064 |
if ( ! $woocommerce->session->has_session() && method_exists($woocommerce->session, 'set_customer_session_cookie')) {
|
1065 |
$woocommerce->session->set_customer_session_cookie( true );
|
1066 |
}
|
@@ -1502,153 +1568,110 @@ class ManageDiscount extends Base
|
|
1502 |
*
|
1503 |
* @param $order_id
|
1504 |
* @param $items
|
1505 |
-
* @return
|
1506 |
*/
|
1507 |
function orderItemsSaved($order_id, $items)
|
1508 |
{
|
1509 |
-
$
|
|
|
|
|
|
|
1510 |
|
1511 |
-
$
|
1512 |
-
if(
|
1513 |
-
$
|
1514 |
}
|
1515 |
|
1516 |
-
$
|
1517 |
-
if(!empty(
|
1518 |
-
$
|
|
|
|
|
|
|
|
|
1519 |
}
|
1520 |
|
1521 |
-
|
1522 |
-
|
1523 |
-
|
1524 |
-
|
1525 |
-
|
|
|
1526 |
}
|
1527 |
-
$
|
1528 |
-
$
|
1529 |
-
$
|
1530 |
-
$
|
1531 |
-
$
|
1532 |
-
$
|
1533 |
-
|
1534 |
-
$
|
1535 |
-
|
1536 |
-
|
1537 |
-
|
1538 |
-
|
1539 |
-
|
1540 |
-
|
1541 |
-
|
1542 |
-
|
1543 |
-
|
1544 |
-
|
1545 |
-
|
1546 |
-
|
1547 |
-
|
1548 |
-
|
1549 |
-
$bulk_discount = isset($value['bulk_discount']) ? $value['bulk_discount'] : 0;
|
1550 |
-
if(is_array($bulk_discount)){
|
1551 |
-
$bulk_discount = $bulk_discount['discount_price'] * $cart_quantity;
|
1552 |
-
} else {
|
1553 |
-
$bulk_discount = $bulk_discount * $cart_quantity;
|
1554 |
-
}
|
1555 |
-
$set_discount = isset($value['set_discount']['discount_value']) ? $value['set_discount']['discount_value'] : 0;
|
1556 |
-
$set_discounted_price_quantity = isset($value['set_discount']['discounted_price_quantity']) ? $value['set_discount']['discounted_price_quantity'] : 0;
|
1557 |
-
if(!empty($set_discounted_price_quantity)){
|
1558 |
-
$set_discount = $set_discount * $set_discounted_price_quantity;
|
1559 |
-
}else{
|
1560 |
-
$set_discount = $set_discount * $cart_quantity;
|
1561 |
-
}
|
1562 |
-
|
1563 |
-
$bxgx_discount_price = isset($value['buy_x_get_x_discount']['discount_price_per_quantity']) ? $value['buy_x_get_x_discount']['discount_price_per_quantity'] : 0;
|
1564 |
-
$bxgx_discount_qty = isset($value['buy_x_get_x_discount']['discount_quantity']) ? $value['buy_x_get_x_discount']['discount_quantity'] : 0;
|
1565 |
-
$bxgx_discount = $bxgx_discount_price * $bxgx_discount_qty;
|
1566 |
-
$bxgy_discount_price = isset($value['buy_x_get_y_discount']['discount_price_per_quantity']) ? $value['buy_x_get_y_discount']['discount_price_per_quantity'] : 0;
|
1567 |
-
$bxgy_discount_qty = isset($value['buy_x_get_y_discount']['discount_quantity']) ? $value['buy_x_get_y_discount']['discount_quantity'] : 0;
|
1568 |
-
$bxgy_discount = $bxgy_discount_price * $bxgy_discount_qty;
|
1569 |
-
$bxgy_cheapest_discount_price = isset($value['buy_x_get_y_cheapest_in_cart_discount']['discount_price_per_quantity']) ? $value['buy_x_get_y_cheapest_in_cart_discount']['discount_price_per_quantity'] : 0;
|
1570 |
-
$bxgy_cheapest_discount_qty = isset($value['buy_x_get_y_cheapest_in_cart_discount']['discount_quantity']) ? $value['buy_x_get_y_cheapest_in_cart_discount']['discount_quantity'] : 0;
|
1571 |
-
$bxgy_cheapest_discount = $bxgy_cheapest_discount_price * $bxgy_cheapest_discount_qty;
|
1572 |
-
$buy_x_get_y_cheapest_additional = isset($value['buy_x_get_y_cheapest_in_cart_discount']['additional_discounts']) ? $value['buy_x_get_y_cheapest_in_cart_discount']['additional_discounts'] : '';
|
1573 |
-
$bxgy_cheapest_from_product_discount_price = isset($value['buy_x_get_y_cheapest_from_products_discount']['discount_price_per_quantity']) ? $value['buy_x_get_y_cheapest_from_products_discount']['discount_price_per_quantity'] : 0;
|
1574 |
-
$bxgy_cheapest_from_product_discount_qty = isset($value['buy_x_get_y_cheapest_from_products_discount']['discount_quantity']) ? $value['buy_x_get_y_cheapest_from_products_discount']['discount_quantity'] : 0;
|
1575 |
-
$bxgy_cheapest_from_product_discount = $bxgy_cheapest_from_product_discount_price * $bxgy_cheapest_from_product_discount_qty;
|
1576 |
-
$bxgy_cheapest_from_categories_discount_price = isset($value['buy_x_get_y_cheapest_from_categories_discount']['discount_price_per_quantity']) ? $value['buy_x_get_y_cheapest_from_categories_discount']['discount_price_per_quantity'] : 0;
|
1577 |
-
$bxgy_cheapest_from_categories_discount_qty = isset($value['buy_x_get_y_cheapest_from_categories_discount']['discount_quantity']) ? $value['buy_x_get_y_cheapest_from_categories_discount']['discount_quantity'] : 0;
|
1578 |
-
$bxgy_cheapest_from_categories_discount = $bxgy_cheapest_from_categories_discount_price * $bxgy_cheapest_from_categories_discount_qty;
|
1579 |
-
$bogo_cheapest_aditional_sum = 0;
|
1580 |
-
if(!empty($buy_x_get_y_cheapest_additional)) {
|
1581 |
-
$bogo_cheapest_aditional = array();
|
1582 |
-
foreach ($buy_x_get_y_cheapest_additional as $aditional) {
|
1583 |
-
$bogo_cheapest_discount_aditional = isset($aditional['discount_price_per_quantity']) ? $aditional['discount_price_per_quantity'] : 0;
|
1584 |
-
$bogo_cheapest_quantity_aditional = isset($aditional['discount_quantity']) ? $aditional['discount_quantity'] : 0;
|
1585 |
-
$bogo_cheapest_aditional[] = $bogo_cheapest_discount_aditional * $bogo_cheapest_quantity_aditional;
|
1586 |
-
}
|
1587 |
-
$bogo_cheapest_aditional_sum = array_sum($bogo_cheapest_aditional);
|
1588 |
-
}
|
1589 |
-
|
1590 |
-
$discount_price = $simple_discount + $bulk_discount + $set_discount + $bxgx_discount + $bxgy_discount + $bxgy_cheapest_discount + $bogo_cheapest_aditional_sum + $bxgy_cheapest_from_product_discount + $bxgy_cheapest_from_categories_discount;
|
1591 |
-
if ($discount_price < 0) {
|
1592 |
-
$discount_price = 0;
|
1593 |
-
}
|
1594 |
-
if($discount_price != 0){
|
1595 |
-
$applied_rules[] = $rule_id;
|
1596 |
-
}
|
1597 |
-
DBTable::saveOrderItemDiscounts($order_id, $product_id, $initial_price, $discounted_price, $discount_price, $cart_quantity, $rule_id, $simple_discount, $bulk_discount, $set_discount, $cart_discount, $cart_discount_label, $cart_shipping);
|
1598 |
-
}
|
1599 |
-
if (!empty($cart_discount_details)) {
|
1600 |
-
foreach ($cart_discount_details as $key => $value) {
|
1601 |
-
if (!in_array($key, $applied_rules)) {
|
1602 |
-
$rule_id = $key;
|
1603 |
-
//$cart_discount = isset($cart_discount_details[$rule_id]['cart_discount']) ? $cart_discount_details[$rule_id]['cart_discount'] : '';
|
1604 |
-
$cart_shipping = (isset($cart_discount_details[$rule_id]['cart_shipping']) && !empty($cart_discount_details[$rule_id]['cart_shipping'])) ? $cart_discount_details[$rule_id]['cart_shipping'] : 'no';
|
1605 |
-
$cart_discount_label = isset($cart_discount_details[$rule_id]['cart_discount_label']) ? $cart_discount_details[$rule_id]['cart_discount_label'] : '';
|
1606 |
-
$cart_discount = isset($cart_discount_details[$rule_id]['cart_discount_price']) ? $cart_discount_details[$rule_id]['cart_discount_price'] : 0;
|
1607 |
-
if($cart_discount != 0){
|
1608 |
-
$applied_rules[] = $rule_id;
|
1609 |
-
}
|
1610 |
-
DBTable::saveOrderItemDiscounts($order_id, 0, 0, $discounted_price, 0, 0, $rule_id, 0, 0, 0, $cart_discount, $cart_discount_label, $cart_shipping);
|
1611 |
-
}
|
1612 |
}
|
|
|
|
|
1613 |
}
|
1614 |
}
|
1615 |
}
|
1616 |
-
}
|
1617 |
-
|
1618 |
-
|
1619 |
-
|
1620 |
-
|
1621 |
-
$
|
1622 |
-
$
|
1623 |
-
$
|
1624 |
-
$cart_discount_label = isset($cart_discount_details[$rule_id]['cart_discount_label']) ? $cart_discount_details[$rule_id]['cart_discount_label'] : '';
|
1625 |
-
DBTable::saveOrderItemDiscounts($order_id, 0, 0, $discount_price, 0, 0, $rule_id, $simple_discount, $bulk_discount, $set_discount, $cart_discount, $cart_discount_label, $cart_shipping);
|
1626 |
}
|
1627 |
}
|
|
|
1628 |
$calc = self::$calculator;
|
1629 |
-
|
1630 |
-
|
1631 |
-
foreach ($applied_rules as $rule) {
|
1632 |
$used_limits = intval($rule->getUsedLimits()) + 1;
|
1633 |
DBTable::updateRuleUsedCount($rule->getId(), $used_limits);
|
|
|
|
|
|
|
1634 |
}
|
1635 |
}
|
|
|
|
|
1636 |
if (!empty(self::$calculated_cart_discount)) {
|
1637 |
if (isset(self::$calculated_cart_discount["discount"]) && !empty(self::$calculated_cart_discount["discount"])) {
|
1638 |
-
$discount_details =
|
1639 |
-
$free_shipping = 'no';
|
1640 |
-
self::$calculated_cart_discount["free_shipping"] = apply_filters('advanced_woo_discount_rules_isset_free_shipping','no');
|
1641 |
-
if (isset(self::$calculated_cart_discount["free_shipping"]) && self::$calculated_cart_discount["free_shipping"] == 'yes') {
|
1642 |
-
$order = self::$woocommerce_helper->getOrder($order_id);
|
1643 |
-
if (!empty($order)) {
|
1644 |
-
if (self::$woocommerce_helper->orderHasShippingMethod($order, 'wdr_free_shipping')) {
|
1645 |
-
$free_shipping = 'yes';
|
1646 |
-
}
|
1647 |
-
}
|
1648 |
-
}
|
1649 |
-
DBTable::saveOrderDiscounts($order_id, $free_shipping, $discount_details);
|
1650 |
}
|
1651 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1652 |
}
|
1653 |
|
1654 |
/**
|
@@ -1808,7 +1831,7 @@ class ManageDiscount extends Base
|
|
1808 |
if($has_non_applied_lines == false && $discount_line_count === 2){
|
1809 |
$new_item_price_html .= '<div class="awdr_cart_strikeout_line">'.$this->getStrikeoutPrice($initial_price_with_tax_call, $discounted_price_with_tax_call).'</div>';
|
1810 |
} else {
|
1811 |
-
|
1812 |
$new_item_price_html .= '<div class="awdr_cart_strikeout_line">'.$this->getStrikeoutPrice($initial_price_with_tax_call, $discounted_price_with_tax_call).$item_quantity_html.'</div>';
|
1813 |
}
|
1814 |
}
|
@@ -1817,7 +1840,7 @@ class ManageDiscount extends Base
|
|
1817 |
if(isset($discount_lines['non_applied']) && !empty($discount_lines['non_applied'])){
|
1818 |
if(isset($discount_lines['non_applied']['quantity']) && $discount_lines['non_applied']['quantity'] > 0){
|
1819 |
$discounted_qty = $discount_lines['non_applied']['quantity'];
|
1820 |
-
|
1821 |
$new_item_price_html .= '<div class="awdr_cart_strikeout_line">'.self::$woocommerce_helper->formatPrice($initial_price_with_tax_call).$item_quantity_html.'</div>';
|
1822 |
}
|
1823 |
}
|
@@ -1978,6 +2001,122 @@ class ManageDiscount extends Base
|
|
1978 |
|
1979 |
self::$woocommerce_helper->setOrderItemMeta($item, '_advanced_woo_discount_item_total_discount', $meta_discount_details);
|
1980 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1981 |
}
|
1982 |
|
1983 |
|
@@ -2001,13 +2140,23 @@ class ManageDiscount extends Base
|
|
2001 |
{
|
2002 |
if (function_exists('WC')) {
|
2003 |
if(isset(WC()->cart) && WC()->cart != null){
|
2004 |
-
if (method_exists(WC()->cart, 'calculate_totals')) {
|
2005 |
WC()->cart->calculate_totals();
|
2006 |
}
|
2007 |
}
|
2008 |
}
|
2009 |
}
|
2010 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011 |
/**
|
2012 |
* @param $discount_details
|
2013 |
* @param $initial_price
|
@@ -2501,14 +2650,15 @@ class ManageDiscount extends Base
|
|
2501 |
* Show order discount details
|
2502 |
* @param $item_id
|
2503 |
* @param $item
|
2504 |
-
* @param $
|
2505 |
*/
|
2506 |
-
public function orderItemMetaDiscountDetails($item_id, $item, $
|
2507 |
{
|
2508 |
$discount_details = self::$woocommerce_helper->getOrderItemMeta($item, '_advanced_woo_discount_item_total_discount');
|
2509 |
if (!empty($discount_details)) {
|
2510 |
$total_discount = $this->getDiscountPerItem($discount_details);
|
2511 |
-
|
|
|
2512 |
$total_discounted_price = self::$woocommerce_helper->formatPrice($total_discount, array('currency' => self::$woocommerce_helper->getOrderCurrency($order)));
|
2513 |
$subtotal_additional_text = $this->getYouSavedText($total_discounted_price);
|
2514 |
echo apply_filters('advanced_woo_discount_rules_order_saved_text', $subtotal_additional_text, $total_discounted_price, $total_discount);
|
11 |
|
12 |
class ManageDiscount extends Base
|
13 |
{
|
14 |
+
public static $apply_as_coupon_values = array(), $available_rules = array(), $calculator, $on_sale_products = array(), $calculated_cart_item_discount = array(), $calculated_cart_discount = array(), $calculated_product_discount = array(), $cart_discounts = array(), $set_total_quantity = 0, $categories_slug = array(), $cart_tot_qty = array(), $applied_cart_coupon_discounts = array();
|
15 |
public $free_shipping = false, $shipping_obj;
|
16 |
|
17 |
/**
|
493 |
}
|
494 |
|
495 |
$original_prices_list = $sale_prices_lists = $discount_prices_lists = array();
|
496 |
+
$available_variations = Woocommerce::getProductChildren($product);
|
497 |
|
498 |
+
if (!empty($available_variations)) {
|
499 |
$consider_out_of_stock_variants = apply_filters('advanced_woo_discount_rules_do_strikeout_for_out_of_stock_variants', false);
|
500 |
+
$variants_check_limit = (int) apply_filters('advanced_woo_discount_rules_check variants_limit_for_variable_strikeout', 20);
|
501 |
+
|
502 |
+
$variations = [];
|
503 |
+
if (count($available_variations) > $variants_check_limit) {
|
504 |
+
$variation_prices = self::$woocommerce_helper->getVariationPrices($product);
|
505 |
+
$calculate_discount_from = self::$config->getConfig('calculate_discount_from', 'sale_price');
|
506 |
+
$original_prices = ($calculate_discount_from) == 'regular_price' ? $variation_prices['regular_price'] : $variation_prices['price'];
|
507 |
+
$variations[] = array_keys($original_prices, min($original_prices))[0];
|
508 |
+
$variations[] = array_keys($original_prices, max($original_prices))[0];
|
509 |
+
} else {
|
510 |
+
$variations = $available_variations;
|
511 |
+
}
|
512 |
foreach ($variations as $variation_id) {
|
513 |
if (empty($variation_id)) {
|
514 |
continue;
|
756 |
$total_combined_discounts = 0;
|
757 |
$apply_as_cart_fee_details = DiscountCalculator::$price_discount_apply_as_cart_discount;
|
758 |
$flat_in_subtotal = array();
|
759 |
+
$discount_coupons = array();
|
760 |
if(!empty($apply_as_cart_fee_details)){
|
761 |
foreach ($apply_as_cart_fee_details as $rule_id => $product_id){
|
762 |
$discount_value = 0;
|
770 |
$discount_value += $detail['discounted_price'];
|
771 |
$label = (isset($detail['discount_label']) && !empty($detail['discount_label'])) ? $detail['discount_label'] : $detail['rule_name'];
|
772 |
}
|
773 |
+
if (isset($discount_coupons[$rule_id])) {
|
774 |
+
$discount_coupons[$rule_id]['discount_value'] += $detail['discounted_price'];
|
775 |
+
} else {
|
776 |
+
$discount_coupons[$rule_id] = [
|
777 |
+
'discount_label' => (isset($detail['discount_label']) && !empty($detail['discount_label'])) ? $detail['discount_label'] : $detail['rule_name'],
|
778 |
+
'discount_value' => $detail['discounted_price'],
|
779 |
+
];
|
780 |
+
}
|
781 |
}
|
782 |
if ($discount_value > 0) {
|
783 |
if (empty($combine_all_discounts)) {
|
784 |
$discount_value = -1 * $discount_value;
|
785 |
+
$fee_name = apply_filters('advanced_woo_discount_rules_additional_fee_label', $label, $cart);
|
786 |
+
$fee_amount = apply_filters('advanced_woo_discount_rules_additional_fee_amount', $discount_value, $cart);
|
787 |
+
self::setCartCouponDiscountDetails($fee_name, $label, -1 * $fee_amount, array($rule_id), $discount_coupons);
|
788 |
+
Woocommerce::addCartFee($cart, $fee_name, $fee_amount);
|
789 |
}else{
|
790 |
$total_combined_discounts += $discount_value;
|
791 |
}
|
794 |
}
|
795 |
}
|
796 |
if (!empty($flat_in_subtotal)) {
|
797 |
+
foreach ($flat_in_subtotal as $rule_id => $discount){
|
798 |
if(empty($combine_all_discounts)){
|
799 |
$discount_value = -1 * $discount['value'];
|
800 |
$label = $discount['label'];
|
801 |
+
$fee_name = apply_filters('advanced_woo_discount_rules_additional_fee_label', $label, $cart);
|
802 |
+
$fee_amount = apply_filters('advanced_woo_discount_rules_additional_fee_amount', $discount_value, $cart);
|
803 |
+
self::setCartCouponDiscountDetails($fee_name, $label, -1 * $fee_amount, array($rule_id), $discount_coupons);
|
804 |
+
Woocommerce::addCartFee($cart, $fee_name, $fee_amount);
|
805 |
}else{
|
806 |
$total_combined_discounts += $discount['value'];
|
807 |
}
|
814 |
$label = Helper::getCleanHtml($label);
|
815 |
if ($discount_apply_type == 'fee') {
|
816 |
$total_combined_discounts = -1 * $total_combined_discounts;
|
817 |
+
$fee_name = apply_filters('advanced_woo_discount_rules_additional_fee_label', $label, $cart);
|
818 |
+
$fee_amount = apply_filters('advanced_woo_discount_rules_additional_fee_amount', $total_combined_discounts, $cart);
|
819 |
+
self::setCartCouponDiscountDetails($fee_name, $label, -1 * $fee_amount, array_keys($discount_coupons), $discount_coupons);
|
820 |
+
Woocommerce::addCartFee($cart, $fee_name, $fee_amount);
|
821 |
}
|
822 |
}
|
823 |
DiscountCalculator::$price_discount_apply_as_cart_discount = array();
|
935 |
/**
|
936 |
* Set coupon values
|
937 |
* */
|
938 |
+
public static function setCartCouponValues($label, $discount_value, $cart_item_keys, $rule_ids, $discount_details){
|
939 |
$coupon_code = apply_filters('woocommerce_coupon_code', $label);
|
940 |
$discount_value = apply_filters('advanced_woo_discount_rules_coupon_value', $discount_value, $label, $cart_item_keys);
|
941 |
self::$apply_as_coupon_values[$coupon_code]['value'] = $discount_value;
|
942 |
self::$apply_as_coupon_values[$coupon_code]['cart_item_keys'] = $cart_item_keys;
|
943 |
self::$apply_as_coupon_values[$coupon_code]['display_text'] = $label;
|
944 |
+
|
945 |
+
self::setCartCouponDiscountDetails($coupon_code, $label, $discount_value, $rule_ids, $discount_details);
|
946 |
+
}
|
947 |
+
|
948 |
+
/**
|
949 |
+
* Set discount coupons details
|
950 |
+
*/
|
951 |
+
public static function setCartCouponDiscountDetails($name, $label, $value, $rule_ids, $discount_details)
|
952 |
+
{
|
953 |
+
$rules = [];
|
954 |
+
foreach ($rule_ids as $rule_id) {
|
955 |
+
if (isset(self::$available_rules[$rule_id])) {
|
956 |
+
$data = [
|
957 |
+
'id' => $rule_id,
|
958 |
+
'title' => self::$available_rules[$rule_id]->getTitle(),
|
959 |
+
];
|
960 |
+
if (isset($discount_details[$rule_id])) {
|
961 |
+
$data['discount'] = [
|
962 |
+
'discount_label' => $discount_details[$rule_id]['discount_label'],
|
963 |
+
'discount_value' => round($discount_details[$rule_id]['discount_value'], 4),
|
964 |
+
];
|
965 |
+
}
|
966 |
+
$rules[] = $data;
|
967 |
+
}
|
968 |
+
}
|
969 |
+
if (!empty($rules)) {
|
970 |
+
self::$applied_cart_coupon_discounts[] = ['name' => $name, 'value' => round($value, 4), 'rules' => $rules];
|
971 |
+
}
|
972 |
}
|
973 |
|
974 |
/**
|
1009 |
}
|
1010 |
$apply_as_cart_fee_details = DiscountCalculator::$price_discount_apply_as_cart_discount;
|
1011 |
DiscountCalculator::$price_discount_apply_as_cart_discount = array();
|
1012 |
+
self::$applied_cart_coupon_discounts = array();
|
1013 |
$apply_as_cart_fee_details = self::removeDuplicateValues($apply_as_cart_fee_details);
|
1014 |
$flat_in_subtotal = array();
|
1015 |
+
$discount_coupons = array();
|
1016 |
if(!empty($apply_as_cart_fee_details)){
|
1017 |
foreach ($apply_as_cart_fee_details as $rule_id => $product_id){
|
1018 |
$cart_item_keys = array();
|
1031 |
$label = (isset($detail['discount_label']) && !empty($detail['discount_label'])) ? $detail['discount_label'] : $detail['rule_name'];
|
1032 |
$cart_item_keys[] = $detail['cart_item_key'];
|
1033 |
}
|
1034 |
+
if (isset($discount_coupons[$rule_id])) {
|
1035 |
+
$discount_coupons[$rule_id]['discount_value'] += $detail['discounted_price'];
|
1036 |
+
} else {
|
1037 |
+
$discount_coupons[$rule_id] = [
|
1038 |
+
'discount_label' => (isset($detail['discount_label']) && !empty($detail['discount_label'])) ? $detail['discount_label'] : $detail['rule_name'],
|
1039 |
+
'discount_value' => $detail['discounted_price'],
|
1040 |
+
];
|
1041 |
+
}
|
1042 |
}
|
1043 |
if ($discount_value > 0) {
|
1044 |
if (empty($combine_all_discounts)) {
|
|
|
1045 |
$label = __($label, 'woo-discount-rules');
|
1046 |
+
self::setCartCouponValues($label, $discount_value, $cart_item_keys, array($rule_id), $discount_coupons);
|
1047 |
$this->applyFakeCouponsForCartRules($label);
|
1048 |
}else{
|
1049 |
$total_combined_discounts += $discount_value;
|
1054 |
}
|
1055 |
}
|
1056 |
if (!empty($flat_in_subtotal)) {
|
1057 |
+
foreach ($flat_in_subtotal as $rule_id => $discount){
|
1058 |
if(empty($combine_all_discounts)){
|
1059 |
$discount_value = $discount['value'];
|
1060 |
$label = $discount['label'];
|
1061 |
$label = __($label, 'woo-discount-rules');
|
1062 |
+
self::setCartCouponValues($label, $discount_value, $discount['cart_item_keys'], array($rule_id), $discount_coupons);
|
1063 |
$this->applyFakeCouponsForCartRules($label);
|
1064 |
}else{
|
1065 |
$total_combined_discounts += $discount['value'];
|
1076 |
$label = __('Cart discount', 'woo-discount-rules');
|
1077 |
}
|
1078 |
$label = __($label, 'woo-discount-rules');
|
1079 |
+
self::setCartCouponValues($label, $total_combined_discounts, $combined_discounts_cart_items, array_keys($discount_coupons), $discount_coupons);
|
1080 |
$this->applyFakeCouponsForCartRules($label);
|
1081 |
}
|
1082 |
add_action('woocommerce_after_calculate_totals', array($this, 'applyVirtualCouponForCartRules'), 10);
|
1092 |
|
1093 |
// Validating the Coupon as Valid and discount status.
|
1094 |
if(isset($woocommerce->cart)){
|
1095 |
+
if(is_object($woocommerce->cart) && method_exists($woocommerce->cart, 'has_discount')){
|
1096 |
if (!$woocommerce->cart->has_discount($coupon_code)) {
|
1097 |
// Do not apply coupon with individual use coupon already applied
|
1098 |
if ($woocommerce->cart->applied_coupons) {
|
1121 |
global $woocommerce;
|
1122 |
|
1123 |
if (isset($_GET['wdr_coupon']) && !empty($_GET['wdr_coupon']) && isset($woocommerce->cart)) {
|
1124 |
+
if ( is_object($woocommerce->cart) && method_exists( $woocommerce->cart, 'has_discount' ) && method_exists( $woocommerce->cart, 'add_discount' ) ) {
|
1125 |
$rule_helper = new Rule();
|
1126 |
$available_url_coupons = $rule_helper->getAllUrlCoupons();
|
1127 |
$available_url_coupons = array_map('\Wdr\App\Helpers\Woocommerce::formatStringToLower', $available_url_coupons);
|
1128 |
$coupons = explode(",", $_GET['wdr_coupon']);
|
1129 |
+
if (isset($woocommerce->session) && is_object($woocommerce->session) && method_exists($woocommerce->session, 'has_session')) {
|
1130 |
if ( ! $woocommerce->session->has_session() && method_exists($woocommerce->session, 'set_customer_session_cookie')) {
|
1131 |
$woocommerce->session->set_customer_session_cookie( true );
|
1132 |
}
|
1568 |
*
|
1569 |
* @param $order_id
|
1570 |
* @param $items
|
1571 |
+
* @return void
|
1572 |
*/
|
1573 |
function orderItemsSaved($order_id, $items)
|
1574 |
{
|
1575 |
+
$order = self::$woocommerce_helper->getOrder($order_id);
|
1576 |
+
if (empty($order)) {
|
1577 |
+
return;
|
1578 |
+
}
|
1579 |
|
1580 |
+
$free_shipping = false;
|
1581 |
+
if (self::$woocommerce_helper->orderHasShippingMethod($order, 'wdr_free_shipping')) {
|
1582 |
+
$free_shipping = true;
|
1583 |
}
|
1584 |
|
1585 |
+
$cart_discounts = [];
|
1586 |
+
if (!empty(self::$applied_cart_coupon_discounts)) {
|
1587 |
+
$cart_discounts = [
|
1588 |
+
'applied_as' => self::$config->getConfig('apply_cart_discount_as', 'coupon'),
|
1589 |
+
'combine_all_discounts' => (bool) self::$config->getConfig('combine_all_cart_discounts', 0),
|
1590 |
+
'applied_coupons' => self::$applied_cart_coupon_discounts,
|
1591 |
+
];
|
1592 |
}
|
1593 |
|
1594 |
+
$product_discount_total = $product_discount_total_with_tax = $cart_discount_total = 0;
|
1595 |
+
foreach (self::$woocommerce_helper->getOrderItems($order) as $item_id => $item) {
|
1596 |
+
if ($details = self::$woocommerce_helper->getOrderItemMeta($item, '_wdr_discounts')) {
|
1597 |
+
$item_data = self::$woocommerce_helper->getOrderItemData($item);
|
1598 |
+
if (empty($item_data)) {
|
1599 |
+
continue;
|
1600 |
}
|
1601 |
+
$quantity = $item_data['quantity'];
|
1602 |
+
$product_id = $item_data['variation_id'] > 0 ? $item_data['variation_id'] : $item_data['product_id'];
|
1603 |
+
$initial_price = isset($details['initial_price_based_on_tax_settings']) ? $details['initial_price_based_on_tax_settings'] : 0;
|
1604 |
+
$discounted_price = isset($details['discounted_price_based_on_tax_settings']) ? $details['discounted_price_based_on_tax_settings'] : 0;
|
1605 |
+
$product_discount_total += isset($details['saved_amount']) ? $details['saved_amount'] : 0;
|
1606 |
+
$product_discount_total_with_tax += isset($details['saved_amount_based_on_tax_settings']) ? $details['saved_amount_based_on_tax_settings'] : 0;
|
1607 |
+
foreach ($details['applied_rules'] as $rule) {
|
1608 |
+
$simple_discount = $bulk_discount = $set_discount = $other_discount = 0;
|
1609 |
+
$discount = $rule['discount'];
|
1610 |
+
if ($discount['applied_in'] == 'product_level') {
|
1611 |
+
switch ($rule['type']) {
|
1612 |
+
case 'simple_discount':
|
1613 |
+
$simple_discount = $discount['discount_price'] * $quantity;
|
1614 |
+
break;
|
1615 |
+
case 'bulk_discount':
|
1616 |
+
$bulk_discount = $discount['discount_price'] * $quantity;
|
1617 |
+
break;
|
1618 |
+
case 'set_discount':
|
1619 |
+
$set_discount = $discount['discount_price'] * $discount['discount_quantity'];
|
1620 |
+
break;
|
1621 |
+
default:
|
1622 |
+
$other_discount = $discount['discount_price'] * $quantity;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1623 |
}
|
1624 |
+
$discount_price = $simple_discount + $bulk_discount + $set_discount + $other_discount;
|
1625 |
+
DBTable::saveOrderItemDiscounts($order_id, $item_id, $product_id, $initial_price, $discounted_price, $discount_price, $quantity, $rule['id'], $simple_discount, $bulk_discount, $set_discount, 0, $other_discount, null);
|
1626 |
}
|
1627 |
}
|
1628 |
}
|
1629 |
+
}
|
1630 |
+
|
1631 |
+
foreach (self::$applied_cart_coupon_discounts as $coupon) {
|
1632 |
+
foreach ($coupon['rules'] as $rule) {
|
1633 |
+
$cart_discount = $rule['discount']['discount_value'];
|
1634 |
+
$cart_discount_label = $rule['discount']['discount_label'];
|
1635 |
+
$cart_discount_total += $cart_discount;
|
1636 |
+
DBTable::saveOrderItemDiscounts($order_id, 0, 0, 0, 0, 0, 0, $rule['id'], 0, 0, 0, $cart_discount, 0, $cart_discount_label);
|
|
|
|
|
1637 |
}
|
1638 |
}
|
1639 |
+
|
1640 |
$calc = self::$calculator;
|
1641 |
+
if (!empty($calc::$applied_rules)) {
|
1642 |
+
foreach ($calc::$applied_rules as $rule) {
|
|
|
1643 |
$used_limits = intval($rule->getUsedLimits()) + 1;
|
1644 |
DBTable::updateRuleUsedCount($rule->getId(), $used_limits);
|
1645 |
+
if ($free_shipping && $rule->getRuleDiscountType() == 'wdr_free_shipping') {
|
1646 |
+
DBTable::saveOrderItemDiscounts($order_id, 0, 0, 0, 0, 0, 0, $rule->getId(), 0, 0, 0, 0, 0, null, true);
|
1647 |
+
}
|
1648 |
}
|
1649 |
}
|
1650 |
+
|
1651 |
+
$discount_details = [];
|
1652 |
if (!empty(self::$calculated_cart_discount)) {
|
1653 |
if (isset(self::$calculated_cart_discount["discount"]) && !empty(self::$calculated_cart_discount["discount"])) {
|
1654 |
+
$discount_details = self::$calculated_cart_discount["discount"];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1655 |
}
|
1656 |
}
|
1657 |
+
if (!empty($discount_details) || $free_shipping) {
|
1658 |
+
$discount_details = json_encode($discount_details);
|
1659 |
+
$has_free_shipping = $free_shipping ? 'yes' : 'no';
|
1660 |
+
DBTable::saveOrderDiscounts($order_id, $has_free_shipping, $discount_details);
|
1661 |
+
}
|
1662 |
+
|
1663 |
+
$order_discount_info = [
|
1664 |
+
'free_shipping' => $free_shipping,
|
1665 |
+
'cart_discounts' => $cart_discounts,
|
1666 |
+
'saved_amount' => [
|
1667 |
+
'product_level' => round($product_discount_total, 4),
|
1668 |
+
'product_level_based_on_tax_settings' => round($product_discount_total_with_tax, 4),
|
1669 |
+
'cart_level' => round($cart_discount_total, 4),
|
1670 |
+
'total' => round($product_discount_total + $cart_discount_total, 4),
|
1671 |
+
'total_based_on_tax_settings' => round($product_discount_total_with_tax + $cart_discount_total, 4),
|
1672 |
+
]
|
1673 |
+
];
|
1674 |
+
self::$woocommerce_helper->setOrderMeta($order, '_wdr_discounts', $order_discount_info);
|
1675 |
}
|
1676 |
|
1677 |
/**
|
1831 |
if($has_non_applied_lines == false && $discount_line_count === 2){
|
1832 |
$new_item_price_html .= '<div class="awdr_cart_strikeout_line">'.$this->getStrikeoutPrice($initial_price_with_tax_call, $discounted_price_with_tax_call).'</div>';
|
1833 |
} else {
|
1834 |
+
$item_quantity_html = apply_filters('advanced_woo_discount_rules_cart_strikeout_quantity_html', ' x '.$discounted_qty, $discounted_qty);
|
1835 |
$new_item_price_html .= '<div class="awdr_cart_strikeout_line">'.$this->getStrikeoutPrice($initial_price_with_tax_call, $discounted_price_with_tax_call).$item_quantity_html.'</div>';
|
1836 |
}
|
1837 |
}
|
1840 |
if(isset($discount_lines['non_applied']) && !empty($discount_lines['non_applied'])){
|
1841 |
if(isset($discount_lines['non_applied']['quantity']) && $discount_lines['non_applied']['quantity'] > 0){
|
1842 |
$discounted_qty = $discount_lines['non_applied']['quantity'];
|
1843 |
+
$item_quantity_html = apply_filters('advanced_woo_discount_rules_cart_strikeout_quantity_html', ' x '.$discounted_qty, $discounted_qty);
|
1844 |
$new_item_price_html .= '<div class="awdr_cart_strikeout_line">'.self::$woocommerce_helper->formatPrice($initial_price_with_tax_call).$item_quantity_html.'</div>';
|
1845 |
}
|
1846 |
}
|
2001 |
|
2002 |
self::$woocommerce_helper->setOrderItemMeta($item, '_advanced_woo_discount_item_total_discount', $meta_discount_details);
|
2003 |
}
|
2004 |
+
|
2005 |
+
// to store improved discount info to order item meta
|
2006 |
+
self::setDiscountInfoToOrderItemMeta($item, $cart_item_key, $values, $order);
|
2007 |
+
}
|
2008 |
+
|
2009 |
+
private static function setDiscountInfoToOrderItemMeta($order_item, $cart_item_key, $cart_item, $order)
|
2010 |
+
{
|
2011 |
+
$item_discount_info = [];
|
2012 |
+
$product_id = $cart_item['variation_id'] > 0 ? $cart_item['variation_id'] : $cart_item['product_id'];
|
2013 |
+
$cart_item_discounts = isset(self::$calculated_cart_item_discount[$cart_item_key]) ? self::$calculated_cart_item_discount[$cart_item_key] : array();
|
2014 |
+
if (isset($cart_item['wdr_free_product'])) { // for free products
|
2015 |
+
$product = self::$woocommerce_helper->getProduct($product_id);
|
2016 |
+
if ($product) {
|
2017 |
+
$product_price = self::$calculator->getProductPriceFromConfig($product, self::$config->getConfig('calculate_discount_from', 'sale_price'), false);
|
2018 |
+
$product_price_with_tax = self::$calculator->mayHaveTax($product, $product_price);
|
2019 |
+
$cart_item_discounts['initial_price'] = $product_price;
|
2020 |
+
$cart_item_discounts['initial_price_with_tax'] = $product_price_with_tax;
|
2021 |
+
$cart_item_discounts['discounted_price'] = $cart_item_discounts['discounted_price_with_tax'] = 0;
|
2022 |
+
$cart_item_discounts['is_free_product'] = true;
|
2023 |
+
if (isset($cart_item['wdr_for_cart_item'])) { // for bxgx free
|
2024 |
+
foreach ($cart_item['wdr_for_cart_item'] as $parent_item_key) {
|
2025 |
+
$buy_x_get_x_free_discounts = isset(Rule::$additional_discounts['buy_x_get_x_discounts']) ? Rule::$additional_discounts['buy_x_get_x_discounts'] : '';
|
2026 |
+
if (isset($buy_x_get_x_free_discounts[$parent_item_key]['rule_id'])) {
|
2027 |
+
$details = $buy_x_get_x_free_discounts[$parent_item_key];
|
2028 |
+
$rule_id = $details['rule_id'];
|
2029 |
+
$details['discount_type'] = 'free_product';
|
2030 |
+
$details['discount_price'] = $product_price;
|
2031 |
+
$cart_item_discounts['total_discount_details'][$cart_item_key][$rule_id] = $details;
|
2032 |
+
}
|
2033 |
+
}
|
2034 |
+
}
|
2035 |
+
if (isset($cart_item['wdr_for_rule'])) { // for bxgy free
|
2036 |
+
$buy_x_get_y_free_discounts = isset(Rule::$additional_discounts['buy_x_get_y_discounts']) ? Rule::$additional_discounts['buy_x_get_y_discounts'] : '';
|
2037 |
+
if (!empty($buy_x_get_y_free_discounts)) {
|
2038 |
+
foreach ($buy_x_get_y_free_discounts as $rule_id => $details) {
|
2039 |
+
$details['discount_type'] = 'free_product';
|
2040 |
+
$details['discount_price'] = $product_price;
|
2041 |
+
$cart_item_discounts['total_discount_details'][$cart_item_key][$rule_id] = $details;
|
2042 |
+
}
|
2043 |
+
}
|
2044 |
+
}
|
2045 |
+
}
|
2046 |
+
}
|
2047 |
+
|
2048 |
+
if (!empty($cart_item_discounts)) {
|
2049 |
+
$item_discount_info['initial_price'] = (float) $cart_item_discounts['initial_price'];
|
2050 |
+
$item_discount_info['discounted_price'] = (float) $cart_item_discounts['discounted_price'];
|
2051 |
+
$item_discount_info['initial_price_based_on_tax_settings'] = round($cart_item_discounts['initial_price_with_tax'], 4);
|
2052 |
+
$item_discount_info['discounted_price_based_on_tax_settings'] = round($cart_item_discounts['discounted_price_with_tax'], 4);
|
2053 |
+
$item_discount_info['is_free_product'] = isset($cart_item_discounts['is_free_product']) && $cart_item_discounts['is_free_product'];
|
2054 |
+
if (isset($cart_item_discounts['total_discount_details'][$cart_item_key])) { // for product adjustment
|
2055 |
+
foreach ($cart_item_discounts['total_discount_details'][$cart_item_key] as $rule_id => $details) {
|
2056 |
+
if (!isset(self::$available_rules[$rule_id])) { continue; }
|
2057 |
+
$rule = self::$available_rules[$rule_id];
|
2058 |
+
$rule_type = substr($rule->getRuleDiscountType(), 4); // without prefix (wdr_)
|
2059 |
+
if ($rule_type == 'buy_x_get_y_discount') {
|
2060 |
+
if (isset($details['buy_x_get_y_cheapest_in_cart_discount'])) {
|
2061 |
+
$rule_type = 'buy_x_get_y_cheapest_in_cart_discount';
|
2062 |
+
} elseif (isset($details['buy_x_get_y_cheapest_from_products_discount'])) {
|
2063 |
+
$rule_type = 'buy_x_get_y_cheapest_from_products_discount';
|
2064 |
+
} elseif (isset($details['buy_x_get_y_cheapest_from_categories_discount'])) {
|
2065 |
+
$rule_type = 'buy_x_get_y_cheapest_from_categories_discount';
|
2066 |
+
}
|
2067 |
+
}
|
2068 |
+
if (isset($details[$rule_type])) {
|
2069 |
+
$discount_info = $details[$rule_type];
|
2070 |
+
} elseif (isset($details['discount_type'])) {
|
2071 |
+
$discount_info = $details;
|
2072 |
+
}
|
2073 |
+
if (empty($discount_info) || !is_array($discount_info)) {
|
2074 |
+
continue;
|
2075 |
+
}
|
2076 |
+
$discount = [
|
2077 |
+
'applied_in' => 'product_level',
|
2078 |
+
'discount_type' => isset($discount_info['discount_type']) ? $discount_info['discount_type'] : '',
|
2079 |
+
'discount_value' => isset($discount_info['discount_value']) ? round($discount_info['discount_value'], 4) : 0,
|
2080 |
+
'discount_quantity' => isset($discount_info['discount_quantity']) ? round($discount_info['discount_quantity'], 4) : 0,
|
2081 |
+
'discount_price' => isset($discount_info['discount_price']) ? round($discount_info['discount_price'], 4) : 0,
|
2082 |
+
];
|
2083 |
+
$item_discount_info['applied_rules'][] = [
|
2084 |
+
'id' => $rule_id,
|
2085 |
+
'title' => $rule->getTitle(),
|
2086 |
+
'type' => $rule_type,
|
2087 |
+
'discount' => $discount,
|
2088 |
+
];
|
2089 |
+
}
|
2090 |
+
}
|
2091 |
+
if (isset($cart_item_discounts['cart_discount_details'])) {
|
2092 |
+
foreach($cart_item_discounts['cart_discount_details'] as $rule_id => $details) {
|
2093 |
+
if (!isset(self::$available_rules[$rule_id])) { continue; }
|
2094 |
+
$rule = self::$available_rules[$rule_id];
|
2095 |
+
$rule_type = substr($rule->getRuleDiscountType(), 4); // without prefix (wdr_)
|
2096 |
+
$discount = [
|
2097 |
+
'applied_in' => 'cart_level',
|
2098 |
+
'discount_type' => isset($details['cart_discount_type']) ? $details['cart_discount_type'] : '',
|
2099 |
+
'discount_value' => isset($details['cart_discount']) ? round($details['cart_discount']) : 0,
|
2100 |
+
'discount_label' => isset($details['cart_discount_label']) ? $details['cart_discount_label'] : '',
|
2101 |
+
'discount_price' => isset($details['cart_discount_product_price'][$product_id][$rule_id])
|
2102 |
+
? round($details['cart_discount_product_price'][$product_id][$rule_id], 4)
|
2103 |
+
: 0,
|
2104 |
+
];
|
2105 |
+
$item_discount_info['applied_rules'][] = [
|
2106 |
+
'id' => $rule_id,
|
2107 |
+
'title' => $rule->getTitle(),
|
2108 |
+
'type' => $rule_type,
|
2109 |
+
'discount' => $discount,
|
2110 |
+
];
|
2111 |
+
}
|
2112 |
+
}
|
2113 |
+
$item_discount_info['saved_amount'] = round(($cart_item_discounts['initial_price'] - $cart_item_discounts['discounted_price']) * $cart_item['quantity'], 4);
|
2114 |
+
$item_discount_info['saved_amount_based_on_tax_settings'] = round(($cart_item_discounts['initial_price_with_tax'] - $cart_item_discounts['discounted_price_with_tax']) * $cart_item['quantity'], 4);
|
2115 |
+
}
|
2116 |
+
|
2117 |
+
if (!empty($item_discount_info)) {
|
2118 |
+
self::$woocommerce_helper->setOrderItemMeta($order_item, '_wdr_discounts', $item_discount_info);
|
2119 |
+
}
|
2120 |
}
|
2121 |
|
2122 |
|
2140 |
{
|
2141 |
if (function_exists('WC')) {
|
2142 |
if(isset(WC()->cart) && WC()->cart != null){
|
2143 |
+
if (is_object(WC()->cart) && method_exists(WC()->cart, 'calculate_totals')) {
|
2144 |
WC()->cart->calculate_totals();
|
2145 |
}
|
2146 |
}
|
2147 |
}
|
2148 |
}
|
2149 |
|
2150 |
+
/**
|
2151 |
+
* Calculate cart totals if is not calculated already
|
2152 |
+
* */
|
2153 |
+
public static function calculateCartTotalIfIsNotCalculated()
|
2154 |
+
{
|
2155 |
+
if (!did_action('woocommerce_before_calculate_totals')) {
|
2156 |
+
self::reCalculateCartTotal();
|
2157 |
+
}
|
2158 |
+
}
|
2159 |
+
|
2160 |
/**
|
2161 |
* @param $discount_details
|
2162 |
* @param $initial_price
|
2650 |
* Show order discount details
|
2651 |
* @param $item_id
|
2652 |
* @param $item
|
2653 |
+
* @param $product
|
2654 |
*/
|
2655 |
+
public function orderItemMetaDiscountDetails($item_id, $item, $product)
|
2656 |
{
|
2657 |
$discount_details = self::$woocommerce_helper->getOrderItemMeta($item, '_advanced_woo_discount_item_total_discount');
|
2658 |
if (!empty($discount_details)) {
|
2659 |
$total_discount = $this->getDiscountPerItem($discount_details);
|
2660 |
+
$order = self::$woocommerce_helper->getOrderByItem($item);
|
2661 |
+
if (!empty($order) && !empty($total_discount)) {
|
2662 |
$total_discounted_price = self::$woocommerce_helper->formatPrice($total_discount, array('currency' => self::$woocommerce_helper->getOrderCurrency($order)));
|
2663 |
$subtotal_additional_text = $this->getYouSavedText($total_discounted_price);
|
2664 |
echo apply_filters('advanced_woo_discount_rules_order_saved_text', $subtotal_additional_text, $total_discounted_price, $total_discount);
|
v2/App/Helpers/Helper.php
CHANGED
@@ -332,9 +332,9 @@ class Helper
|
|
332 |
|
333 |
public static function displayCompatibleCheckMessages()
|
334 |
{
|
335 |
-
if (version_compare(WDR_VERSION, '2.
|
336 |
if (defined('WDR_PRO_VERSION')) {
|
337 |
-
if (version_compare(WDR_PRO_VERSION, '2.
|
338 |
$url = esc_url(admin_url() . "plugins.php");
|
339 |
$plugin_page = '<a target="_blank" href="' . $url . '">' . __('Update now', 'woo-discount-rules') . '</a>';
|
340 |
?>
|
332 |
|
333 |
public static function displayCompatibleCheckMessages()
|
334 |
{
|
335 |
+
if (version_compare(WDR_VERSION, '2.5.0', '>=')) {
|
336 |
if (defined('WDR_PRO_VERSION')) {
|
337 |
+
if (version_compare(WDR_PRO_VERSION, '2.5.0', '<')) {
|
338 |
$url = esc_url(admin_url() . "plugins.php");
|
339 |
$plugin_page = '<a target="_blank" href="' . $url . '">' . __('Update now', 'woo-discount-rules') . '</a>';
|
340 |
?>
|
v2/App/Helpers/Rule.php
CHANGED
@@ -1547,7 +1547,7 @@ class Rule
|
|
1547 |
if (!empty($product_ids)) {
|
1548 |
foreach ($product_ids as $product_id) {
|
1549 |
$product = Woocommerce::getProduct($product_id);
|
1550 |
-
if (!empty($product) && method_exists($product, 'is_type')) {
|
1551 |
if ($product->is_type(array('variable', 'variable-subscription'))) {
|
1552 |
$additional_variants = Woocommerce::getProductChildren($product);
|
1553 |
if (!empty($additional_variants) && is_array($additional_variants)) {
|
1547 |
if (!empty($product_ids)) {
|
1548 |
foreach ($product_ids as $product_id) {
|
1549 |
$product = Woocommerce::getProduct($product_id);
|
1550 |
+
if (!empty($product) && is_object($product) && method_exists($product, 'is_type')) {
|
1551 |
if ($product->is_type(array('variable', 'variable-subscription'))) {
|
1552 |
$additional_variants = Woocommerce::getProductChildren($product);
|
1553 |
if (!empty($additional_variants) && is_array($additional_variants)) {
|
v2/App/Helpers/Woocommerce.php
CHANGED
@@ -29,7 +29,7 @@ class Woocommerce
|
|
29 |
static function productTypeIs($product, $type)
|
30 |
{
|
31 |
if(!empty($product))
|
32 |
-
if (method_exists($product, 'is_type')) {
|
33 |
return $product->is_type($type);
|
34 |
}
|
35 |
return false;
|
@@ -48,7 +48,7 @@ class Woocommerce
|
|
48 |
*/
|
49 |
static function orderHasShippingMethod($order, $method)
|
50 |
{
|
51 |
-
if (method_exists($order, 'has_shipping_method')) {
|
52 |
return $order->has_shipping_method($method);
|
53 |
}
|
54 |
return false;
|
@@ -61,7 +61,7 @@ class Woocommerce
|
|
61 |
*/
|
62 |
static function getOrderTotal($order)
|
63 |
{
|
64 |
-
if (method_exists($order, 'get_total')) {
|
65 |
return $order->get_total();
|
66 |
}
|
67 |
return 0;
|
@@ -83,6 +83,19 @@ class Woocommerce
|
|
83 |
return array();
|
84 |
}
|
85 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
/**
|
87 |
* get the product ID
|
88 |
* @param $product - woocommerce product object
|
@@ -91,7 +104,7 @@ class Woocommerce
|
|
91 |
static function getProductId($product)
|
92 |
{
|
93 |
if(!empty($product)){
|
94 |
-
if (method_exists($product, 'get_id')) {
|
95 |
return $product->get_id();
|
96 |
} elseif (isset($product->id)) {
|
97 |
$product_id = $product->id;
|
@@ -177,7 +190,7 @@ class Woocommerce
|
|
177 |
{
|
178 |
if(!empty($product))
|
179 |
if (self::isProductInSale($product)) {
|
180 |
-
if (method_exists($product, 'get_sale_price')) {
|
181 |
$price = $product->get_sale_price();
|
182 |
return apply_filters('advanced_woo_discount_rules_get_sale_price', $price, $product);
|
183 |
}
|
@@ -194,7 +207,7 @@ class Woocommerce
|
|
194 |
static function isProductInSale($product)
|
195 |
{
|
196 |
if(!empty($product))
|
197 |
-
if (method_exists($product, 'is_on_sale') && method_exists($product, 'get_sale_price')) {
|
198 |
if($product->is_on_sale('')){
|
199 |
if($product->get_sale_price()){
|
200 |
return apply_filters('advanced_woo_discount_rules_is_on_sale', true, $product);
|
@@ -213,7 +226,7 @@ class Woocommerce
|
|
213 |
*/
|
214 |
static function isProductHasStock($product)
|
215 |
{
|
216 |
-
if(!empty($product) && method_exists($product, 'is_in_stock')) {
|
217 |
return $product->is_in_stock();
|
218 |
}
|
219 |
return false;
|
@@ -227,7 +240,7 @@ class Woocommerce
|
|
227 |
static function getProductRegularPrice($product)
|
228 |
{
|
229 |
if(!empty($product))
|
230 |
-
if (method_exists($product, 'get_regular_price')) {
|
231 |
$price = $product->get_regular_price();
|
232 |
return apply_filters('advanced_woo_discount_rules_get_regular_price', $price, $product);
|
233 |
}
|
@@ -242,7 +255,7 @@ class Woocommerce
|
|
242 |
static function getProductPrice($product)
|
243 |
{
|
244 |
if(!empty($product))
|
245 |
-
if (method_exists($product, 'get_price')) {
|
246 |
$price = $product->get_price();
|
247 |
return apply_filters('advanced_woo_discount_rules_get_price', $price, $product);
|
248 |
}
|
@@ -258,7 +271,7 @@ class Woocommerce
|
|
258 |
{
|
259 |
$categories = $variant = array();
|
260 |
if(!empty($product))
|
261 |
-
if (method_exists($product, 'get_category_ids')) {
|
262 |
if (self::productTypeIs($product, 'variation')) {
|
263 |
$variant = $product;
|
264 |
$parent_id = self::getProductParentId($product);
|
@@ -277,7 +290,7 @@ class Woocommerce
|
|
277 |
static function getProductTags($product)
|
278 |
{
|
279 |
if(!empty($product))
|
280 |
-
if (method_exists($product, 'get_tag_ids')) {
|
281 |
return $product->get_tag_ids();
|
282 |
}
|
283 |
return array();
|
@@ -291,7 +304,7 @@ class Woocommerce
|
|
291 |
static function getProductAttributes($product)
|
292 |
{
|
293 |
if(!empty($product))
|
294 |
-
if (method_exists($product, 'get_attributes')) {
|
295 |
return $product->get_attributes();
|
296 |
}
|
297 |
return array();
|
@@ -305,7 +318,7 @@ class Woocommerce
|
|
305 |
static function getProductChildren($product)
|
306 |
{
|
307 |
if(!empty($product))
|
308 |
-
if (method_exists($product, 'get_children')) {
|
309 |
return $product->get_children();
|
310 |
}
|
311 |
return array();
|
@@ -319,7 +332,7 @@ class Woocommerce
|
|
319 |
static function getProductSku($product)
|
320 |
{
|
321 |
if(!empty($product))
|
322 |
-
if (method_exists($product, 'get_sku')) {
|
323 |
return $product->get_sku();
|
324 |
}
|
325 |
return NULL;
|
@@ -335,7 +348,7 @@ class Woocommerce
|
|
335 |
static function getProductPriceSuffix($product, $price = '', $discount_prices = array())
|
336 |
{
|
337 |
if(!empty($product))
|
338 |
-
if (method_exists($product, 'get_price_suffix')) {
|
339 |
return apply_filters('advanced_woo_discount_rules_price_suffix', $product->get_price_suffix($price), $product, $price, $discount_prices);
|
340 |
}
|
341 |
return NULL;
|
@@ -348,7 +361,7 @@ class Woocommerce
|
|
348 |
*/
|
349 |
static function getAttributeName($attribute)
|
350 |
{
|
351 |
-
if (method_exists($attribute, 'get_name')) {
|
352 |
return $attribute->get_name();
|
353 |
}
|
354 |
return NULL;
|
@@ -361,7 +374,7 @@ class Woocommerce
|
|
361 |
*/
|
362 |
static function getAttributeOption($attribute)
|
363 |
{
|
364 |
-
if (method_exists($attribute, 'get_options')) {
|
365 |
return $attribute->get_options();
|
366 |
}
|
367 |
return array();
|
@@ -374,12 +387,26 @@ class Woocommerce
|
|
374 |
*/
|
375 |
static function getAttributeVariation($attribute)
|
376 |
{
|
377 |
-
if (method_exists($attribute, 'get_variation')) {
|
378 |
return $attribute->get_variation();
|
379 |
}
|
380 |
return true;
|
381 |
}
|
382 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
383 |
/**
|
384 |
* Get product custom taxonomy
|
385 |
* @return array|null
|
@@ -502,7 +529,7 @@ class Woocommerce
|
|
502 |
$cart = array();
|
503 |
if (function_exists('WC')) {
|
504 |
if(isset(WC()->cart) && WC()->cart != null){
|
505 |
-
if (method_exists(WC()->cart, 'get_cart')) {
|
506 |
if (did_action('wp_loaded')) {
|
507 |
$cart = WC()->cart->get_cart();
|
508 |
}
|
@@ -520,7 +547,7 @@ class Woocommerce
|
|
520 |
{
|
521 |
if (function_exists('WC')) {
|
522 |
if(isset(WC()->cart) && WC()->cart != null){
|
523 |
-
if (method_exists(WC()->cart, 'calculate_totals')) {
|
524 |
WC()->cart->calculate_totals();
|
525 |
}
|
526 |
}
|
@@ -541,7 +568,7 @@ class Woocommerce
|
|
541 |
{
|
542 |
if (function_exists('WC')) {
|
543 |
if(isset(WC()->cart) && WC()->cart != null) {
|
544 |
-
if (method_exists(WC()->cart, 'get_shipping_packages')) {
|
545 |
return WC()->cart->get_shipping_packages();
|
546 |
}
|
547 |
}
|
@@ -572,7 +599,7 @@ class Woocommerce
|
|
572 |
{
|
573 |
if (function_exists('WC')) {
|
574 |
if(isset(WC()->cart) && WC()->cart != null) {
|
575 |
-
if (method_exists(WC()->cart, 'add_to_cart')) {
|
576 |
return WC()->cart->add_to_cart($product_id, $quantity, $variation_id, $variation, $cart_item_data);
|
577 |
}
|
578 |
}
|
@@ -593,7 +620,7 @@ class Woocommerce
|
|
593 |
public static function set_quantity( $cart_item_key, $quantity = 1, $refresh_totals = true ){
|
594 |
if (function_exists('WC')) {
|
595 |
if(isset(WC()->cart) && WC()->cart != null) {
|
596 |
-
if (method_exists(WC()->cart, 'set_quantity')) {
|
597 |
return WC()->cart->set_quantity($cart_item_key, $quantity, $refresh_totals);
|
598 |
}
|
599 |
}
|
@@ -612,7 +639,7 @@ class Woocommerce
|
|
612 |
{
|
613 |
if (function_exists('WC')) {
|
614 |
if(isset(WC()->cart) && WC()->cart != null) {
|
615 |
-
if (method_exists(WC()->cart, 'remove_cart_item')) {
|
616 |
return WC()->cart->remove_cart_item($_cart_item_key);
|
617 |
}
|
618 |
}
|
@@ -632,7 +659,7 @@ class Woocommerce
|
|
632 |
{
|
633 |
if (function_exists('WC')) {
|
634 |
if(isset(WC()->cart) && WC()->cart != null) {
|
635 |
-
if (method_exists(WC()->cart, 'remove_coupon')) {
|
636 |
return WC()->cart->remove_coupon($code);
|
637 |
}
|
638 |
}
|
@@ -699,7 +726,7 @@ class Woocommerce
|
|
699 |
$product = self::getProduct($product);
|
700 |
}
|
701 |
if(!empty($product))
|
702 |
-
if (method_exists($product, 'get_parent_id')) {
|
703 |
$parent_id = $product->get_parent_id();
|
704 |
}
|
705 |
return apply_filters('advanced_woo_discount_rules_get_product_parent_id', $parent_id, $product);
|
@@ -713,7 +740,7 @@ class Woocommerce
|
|
713 |
static function getCartItems($cart)
|
714 |
{
|
715 |
$cart_items = array();
|
716 |
-
if (method_exists($cart, 'get_cart_contents')) {
|
717 |
$cart_items = $cart->get_cart_contents();
|
718 |
}
|
719 |
return apply_filters('advanced_woo_discount_rules_get_cart_items', $cart_items, $cart);
|
@@ -728,13 +755,13 @@ class Woocommerce
|
|
728 |
if (function_exists('WC')) {
|
729 |
$subtotal = 0;
|
730 |
if(isset(WC()->cart) && WC()->cart != null) {
|
731 |
-
if (method_exists(WC()->cart, 'get_subtotal')) {
|
732 |
$tax_display_type = get_option('woocommerce_tax_display_cart');
|
733 |
if ($tax_display_type === 'excl') {
|
734 |
$subtotal = WC()->cart->get_subtotal();
|
735 |
} else {
|
736 |
$subtotal = WC()->cart->get_subtotal();
|
737 |
-
if (method_exists(WC()->cart, 'get_subtotal_tax')) {
|
738 |
$subtotal_tax = WC()->cart->get_subtotal_tax();
|
739 |
$subtotal = $subtotal+$subtotal_tax;
|
740 |
}
|
@@ -776,7 +803,7 @@ class Woocommerce
|
|
776 |
*/
|
777 |
static function addCartFee($cart, $name, $fee)
|
778 |
{
|
779 |
-
if (method_exists($cart, 'add_fee')) {
|
780 |
if(apply_filters('advanced_discount_rules_do_add_fee', true, $cart)){
|
781 |
if(!apply_filters('advanced_discount_rules_calculate_tax_with_fee', true, $name, $cart)){
|
782 |
add_filter('woocommerce_cart_totals_get_fees_from_cart_taxes', function ($fee_taxes, $fee, $cart) use ($name) {
|
@@ -820,7 +847,7 @@ class Woocommerce
|
|
820 |
*/
|
821 |
static function getCouponCode($coupon)
|
822 |
{
|
823 |
-
if (method_exists($coupon, 'get_code')) {
|
824 |
return $coupon->get_code();
|
825 |
}
|
826 |
return NULL;
|
@@ -834,7 +861,7 @@ class Woocommerce
|
|
834 |
{
|
835 |
if (function_exists('WC')) {
|
836 |
if(isset(WC()->cart) && WC()->cart != null) {
|
837 |
-
if (method_exists(WC()->cart, 'get_applied_coupons')) {
|
838 |
return WC()->cart->get_applied_coupons();
|
839 |
}
|
840 |
}
|
@@ -850,7 +877,7 @@ class Woocommerce
|
|
850 |
*/
|
851 |
static function addCouponDiscount($cart, $code)
|
852 |
{
|
853 |
-
if (method_exists($cart, 'add_discount')) {
|
854 |
return $cart->add_discount($code);
|
855 |
}
|
856 |
return array();
|
@@ -864,7 +891,7 @@ class Woocommerce
|
|
864 |
*/
|
865 |
static function hasCouponInCart($cart, $code)
|
866 |
{
|
867 |
-
if (method_exists($cart, 'has_discount')) {
|
868 |
return $cart->has_discount($code);
|
869 |
}
|
870 |
return array();
|
@@ -878,7 +905,7 @@ class Woocommerce
|
|
878 |
*/
|
879 |
static function setCartProductPrice($cart_item_object, $price)
|
880 |
{
|
881 |
-
if (method_exists($cart_item_object, 'set_price')) {
|
882 |
return $cart_item_object->set_price($price);
|
883 |
}
|
884 |
return false;
|
@@ -908,7 +935,7 @@ class Woocommerce
|
|
908 |
if(!empty($product)){
|
909 |
if (function_exists('wc_get_price_including_tax')) {
|
910 |
$price = wc_get_price_including_tax($product, array('qty' => $quantity, 'price' => $original_price));
|
911 |
-
} else if (method_exists($product, 'get_price_including_tax')) {
|
912 |
$price = $product->get_price_including_tax($quantity, $original_price);
|
913 |
} else {
|
914 |
$price = $original_price;
|
@@ -932,7 +959,7 @@ class Woocommerce
|
|
932 |
if(!empty($product)){
|
933 |
if (function_exists('wc_get_price_excluding_tax')) {
|
934 |
$price = wc_get_price_excluding_tax($product, array('qty' => $quantity, 'price' => $original_price));
|
935 |
-
} else if (method_exists($product, 'get_price_excluding_tax')) {
|
936 |
$price = $product->get_price_excluding_tax($quantity, $original_price);
|
937 |
} else {
|
938 |
$price = $original_price;
|
@@ -964,7 +991,7 @@ class Woocommerce
|
|
964 |
static function getCountriesList()
|
965 |
{
|
966 |
if (function_exists('WC')) {
|
967 |
-
if (isset(WC()->countries) && method_exists(WC()->countries, 'get_countries')) {
|
968 |
return WC()->countries->get_countries();
|
969 |
}
|
970 |
}
|
@@ -978,7 +1005,7 @@ class Woocommerce
|
|
978 |
static function getStatesList()
|
979 |
{
|
980 |
if (function_exists('WC')) {
|
981 |
-
if (isset(WC()->countries) && method_exists(WC()->countries, 'get_states')) {
|
982 |
return WC()->countries->get_states();
|
983 |
}
|
984 |
}
|
@@ -992,7 +1019,7 @@ class Woocommerce
|
|
992 |
static function getPaymentMethodList()
|
993 |
{
|
994 |
if (function_exists('WC')) {
|
995 |
-
if (method_exists(WC()->payment_gateways, 'payment_gateways')) {
|
996 |
return WC()->payment_gateways->payment_gateways();
|
997 |
}
|
998 |
}
|
@@ -1063,7 +1090,7 @@ class Woocommerce
|
|
1063 |
static function getWeight($item)
|
1064 |
{
|
1065 |
if (!empty($item)) {
|
1066 |
-
if (method_exists($item, 'get_weight')) {
|
1067 |
return $item->get_weight();
|
1068 |
}
|
1069 |
}
|
@@ -1100,7 +1127,7 @@ class Woocommerce
|
|
1100 |
{
|
1101 |
if (function_exists('WC')) {
|
1102 |
if(isset(WC()->session) && WC()->session != null) {
|
1103 |
-
if (method_exists(WC()->session, 'get')) {
|
1104 |
return WC()->session->get($key);
|
1105 |
}
|
1106 |
}
|
@@ -1117,7 +1144,7 @@ class Woocommerce
|
|
1117 |
{
|
1118 |
if (function_exists('WC')) {
|
1119 |
if(isset(WC()->session) && WC()->session != null) {
|
1120 |
-
if (method_exists(WC()->session, 'set')) {
|
1121 |
WC()->session->set($key, $value);
|
1122 |
}
|
1123 |
}
|
@@ -1144,7 +1171,7 @@ class Woocommerce
|
|
1144 |
static function getShippingCountry()
|
1145 |
{
|
1146 |
if (function_exists('WC') && WC()->customer) {
|
1147 |
-
if (method_exists(WC()->customer, 'get_shipping_country')) {
|
1148 |
return WC()->customer->get_shipping_country();
|
1149 |
}
|
1150 |
}
|
@@ -1158,7 +1185,7 @@ class Woocommerce
|
|
1158 |
static function getShippingState()
|
1159 |
{
|
1160 |
if (function_exists('WC') && WC()->customer) {
|
1161 |
-
if (method_exists(WC()->customer, 'get_shipping_state')) {
|
1162 |
return WC()->customer->get_shipping_state();
|
1163 |
}
|
1164 |
}
|
@@ -1172,7 +1199,7 @@ class Woocommerce
|
|
1172 |
static function getShippingCity()
|
1173 |
{
|
1174 |
if (function_exists('WC') && WC()->customer) {
|
1175 |
-
if (method_exists(WC()->customer, 'get_shipping_city')) {
|
1176 |
return WC()->customer->get_shipping_city();
|
1177 |
}
|
1178 |
}
|
@@ -1186,7 +1213,7 @@ class Woocommerce
|
|
1186 |
static function getBillingCity()
|
1187 |
{
|
1188 |
if (function_exists('WC') && WC()->customer) {
|
1189 |
-
if (method_exists(WC()->customer, 'get_billing_city')) {
|
1190 |
return WC()->customer->get_billing_city();
|
1191 |
}
|
1192 |
}
|
@@ -1200,7 +1227,7 @@ class Woocommerce
|
|
1200 |
static function getShippingZipCode()
|
1201 |
{
|
1202 |
if (function_exists('WC') && WC()->customer) {
|
1203 |
-
if (method_exists(WC()->customer, 'get_shipping_postcode')) {
|
1204 |
return WC()->customer->get_shipping_postcode();
|
1205 |
}
|
1206 |
}
|
@@ -1312,7 +1339,7 @@ class Woocommerce
|
|
1312 |
*/
|
1313 |
static function getOrderItems($order)
|
1314 |
{
|
1315 |
-
if (method_exists($order, 'get_items')) {
|
1316 |
return $order->get_items();
|
1317 |
}
|
1318 |
return array();
|
@@ -1325,12 +1352,31 @@ class Woocommerce
|
|
1325 |
*/
|
1326 |
static function getOrderCurrency($order)
|
1327 |
{
|
1328 |
-
if (method_exists($order, 'get_currency')) {
|
1329 |
return $order->get_currency();
|
1330 |
}
|
1331 |
return NULL;
|
1332 |
}
|
1333 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1334 |
/**
|
1335 |
* Set order item meta
|
1336 |
* @param $item
|
@@ -1340,12 +1386,25 @@ class Woocommerce
|
|
1340 |
*/
|
1341 |
static function setOrderItemMeta($item, $key, $value)
|
1342 |
{
|
1343 |
-
if (method_exists($item, 'add_meta_data')) {
|
1344 |
return $item->add_meta_data($key, $value, true);
|
1345 |
}
|
1346 |
return NULL;
|
1347 |
}
|
1348 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1349 |
/**
|
1350 |
* Set order item meta
|
1351 |
* @param $item
|
@@ -1354,7 +1413,7 @@ class Woocommerce
|
|
1354 |
*/
|
1355 |
static function getOrderItemMeta($item, $key)
|
1356 |
{
|
1357 |
-
if (method_exists($item, 'get_meta')) {
|
1358 |
return $item->get_meta($key);
|
1359 |
}
|
1360 |
return NULL;
|
@@ -1367,7 +1426,7 @@ class Woocommerce
|
|
1367 |
*/
|
1368 |
static function getItemId($item)
|
1369 |
{
|
1370 |
-
if (method_exists($item, 'get_product_id') && method_exists($item, 'get_variation_id')) {
|
1371 |
if ($product_id = $item->get_variation_id()) {
|
1372 |
return $product_id;
|
1373 |
} else {
|
@@ -1597,7 +1656,7 @@ class Woocommerce
|
|
1597 |
static function getPriceHtml($product){
|
1598 |
$html = false;
|
1599 |
if(!empty($product))
|
1600 |
-
if (method_exists($product, 'get_price_html')) {
|
1601 |
$html = $product->get_price_html();
|
1602 |
}
|
1603 |
return apply_filters('advanced_woo_discount_rules_get_price_html', $html, $product);
|
@@ -1645,7 +1704,7 @@ class Woocommerce
|
|
1645 |
if(function_exists('WC')){
|
1646 |
$session = WC()->session;
|
1647 |
if(!empty($session)){
|
1648 |
-
if(method_exists($session, 'get')){
|
1649 |
$customer = $session->get('customer');
|
1650 |
if(isset($customer['email']) && !empty($customer['email'])){
|
1651 |
$user_email = $customer['email'];
|
@@ -1693,7 +1752,7 @@ class Woocommerce
|
|
1693 |
*/
|
1694 |
public static function get_variation_regular_price($product, $min_or_max = 'min', $for_display = false){
|
1695 |
if(!empty($product))
|
1696 |
-
if(method_exists($product, 'get_variation_regular_price')){
|
1697 |
return $product->get_variation_regular_price($min_or_max, $for_display);
|
1698 |
}
|
1699 |
return 0;
|
@@ -1719,7 +1778,7 @@ class Woocommerce
|
|
1719 |
$available_variations = array();
|
1720 |
$is_variable_product = self::productTypeIs($product, 'variable');
|
1721 |
if(!empty($product))
|
1722 |
-
if ($is_variable_product && method_exists($product, 'get_available_variations')){
|
1723 |
$available_variations = $product->get_available_variations();
|
1724 |
}
|
1725 |
self::$product_variations[$product_id] = $available_variations;
|
@@ -1744,7 +1803,7 @@ class Woocommerce
|
|
1744 |
static function variationIsVisible($product)
|
1745 |
{
|
1746 |
if(!empty($product)){
|
1747 |
-
if (method_exists($product, 'variation_is_visible')) {
|
1748 |
return $product->variation_is_visible();
|
1749 |
}
|
1750 |
}
|
@@ -1792,4 +1851,21 @@ class Woocommerce
|
|
1792 |
|
1793 |
return $product_title;
|
1794 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1795 |
}
|
29 |
static function productTypeIs($product, $type)
|
30 |
{
|
31 |
if(!empty($product))
|
32 |
+
if (is_object($product) && method_exists($product, 'is_type')) {
|
33 |
return $product->is_type($type);
|
34 |
}
|
35 |
return false;
|
48 |
*/
|
49 |
static function orderHasShippingMethod($order, $method)
|
50 |
{
|
51 |
+
if (is_object($order) && method_exists($order, 'has_shipping_method')) {
|
52 |
return $order->has_shipping_method($method);
|
53 |
}
|
54 |
return false;
|
61 |
*/
|
62 |
static function getOrderTotal($order)
|
63 |
{
|
64 |
+
if (is_object($order) && method_exists($order, 'get_total')) {
|
65 |
return $order->get_total();
|
66 |
}
|
67 |
return 0;
|
83 |
return array();
|
84 |
}
|
85 |
|
86 |
+
/**
|
87 |
+
* get order object from order item
|
88 |
+
* @param $order_item
|
89 |
+
* @return null|WC_Order|WC_Order_Refund
|
90 |
+
*/
|
91 |
+
static function getOrderByItem($order_item)
|
92 |
+
{
|
93 |
+
if (is_object($order_item) && method_exists($order_item, 'get_order')) {
|
94 |
+
return $order_item->get_order();
|
95 |
+
}
|
96 |
+
return NULL;
|
97 |
+
}
|
98 |
+
|
99 |
/**
|
100 |
* get the product ID
|
101 |
* @param $product - woocommerce product object
|
104 |
static function getProductId($product)
|
105 |
{
|
106 |
if(!empty($product)){
|
107 |
+
if (is_object($product) && method_exists($product, 'get_id')) {
|
108 |
return $product->get_id();
|
109 |
} elseif (isset($product->id)) {
|
110 |
$product_id = $product->id;
|
190 |
{
|
191 |
if(!empty($product))
|
192 |
if (self::isProductInSale($product)) {
|
193 |
+
if (is_object($product) && method_exists($product, 'get_sale_price')) {
|
194 |
$price = $product->get_sale_price();
|
195 |
return apply_filters('advanced_woo_discount_rules_get_sale_price', $price, $product);
|
196 |
}
|
207 |
static function isProductInSale($product)
|
208 |
{
|
209 |
if(!empty($product))
|
210 |
+
if (is_object($product) && method_exists($product, 'is_on_sale') && method_exists($product, 'get_sale_price')) {
|
211 |
if($product->is_on_sale('')){
|
212 |
if($product->get_sale_price()){
|
213 |
return apply_filters('advanced_woo_discount_rules_is_on_sale', true, $product);
|
226 |
*/
|
227 |
static function isProductHasStock($product)
|
228 |
{
|
229 |
+
if(!empty($product) && is_object($product) && method_exists($product, 'is_in_stock')) {
|
230 |
return $product->is_in_stock();
|
231 |
}
|
232 |
return false;
|
240 |
static function getProductRegularPrice($product)
|
241 |
{
|
242 |
if(!empty($product))
|
243 |
+
if (is_object($product) && method_exists($product, 'get_regular_price')) {
|
244 |
$price = $product->get_regular_price();
|
245 |
return apply_filters('advanced_woo_discount_rules_get_regular_price', $price, $product);
|
246 |
}
|
255 |
static function getProductPrice($product)
|
256 |
{
|
257 |
if(!empty($product))
|
258 |
+
if (is_object($product) && method_exists($product, 'get_price')) {
|
259 |
$price = $product->get_price();
|
260 |
return apply_filters('advanced_woo_discount_rules_get_price', $price, $product);
|
261 |
}
|
271 |
{
|
272 |
$categories = $variant = array();
|
273 |
if(!empty($product))
|
274 |
+
if (is_object($product) && method_exists($product, 'get_category_ids')) {
|
275 |
if (self::productTypeIs($product, 'variation')) {
|
276 |
$variant = $product;
|
277 |
$parent_id = self::getProductParentId($product);
|
290 |
static function getProductTags($product)
|
291 |
{
|
292 |
if(!empty($product))
|
293 |
+
if (is_object($product) && method_exists($product, 'get_tag_ids')) {
|
294 |
return $product->get_tag_ids();
|
295 |
}
|
296 |
return array();
|
304 |
static function getProductAttributes($product)
|
305 |
{
|
306 |
if(!empty($product))
|
307 |
+
if (is_object($product) && method_exists($product, 'get_attributes')) {
|
308 |
return $product->get_attributes();
|
309 |
}
|
310 |
return array();
|
318 |
static function getProductChildren($product)
|
319 |
{
|
320 |
if(!empty($product))
|
321 |
+
if (is_object($product) && method_exists($product, 'get_children')) {
|
322 |
return $product->get_children();
|
323 |
}
|
324 |
return array();
|
332 |
static function getProductSku($product)
|
333 |
{
|
334 |
if(!empty($product))
|
335 |
+
if (is_object($product) && method_exists($product, 'get_sku')) {
|
336 |
return $product->get_sku();
|
337 |
}
|
338 |
return NULL;
|
348 |
static function getProductPriceSuffix($product, $price = '', $discount_prices = array())
|
349 |
{
|
350 |
if(!empty($product))
|
351 |
+
if (is_object($product) && method_exists($product, 'get_price_suffix')) {
|
352 |
return apply_filters('advanced_woo_discount_rules_price_suffix', $product->get_price_suffix($price), $product, $price, $discount_prices);
|
353 |
}
|
354 |
return NULL;
|
361 |
*/
|
362 |
static function getAttributeName($attribute)
|
363 |
{
|
364 |
+
if (is_object($attribute) && method_exists($attribute, 'get_name')) {
|
365 |
return $attribute->get_name();
|
366 |
}
|
367 |
return NULL;
|
374 |
*/
|
375 |
static function getAttributeOption($attribute)
|
376 |
{
|
377 |
+
if (is_object($attribute) && method_exists($attribute, 'get_options')) {
|
378 |
return $attribute->get_options();
|
379 |
}
|
380 |
return array();
|
387 |
*/
|
388 |
static function getAttributeVariation($attribute)
|
389 |
{
|
390 |
+
if (is_object($attribute) && method_exists($attribute, 'get_variation')) {
|
391 |
return $attribute->get_variation();
|
392 |
}
|
393 |
return true;
|
394 |
}
|
395 |
|
396 |
+
/**
|
397 |
+
* Get variation prices for variable product
|
398 |
+
* @param \WC_Product_Variable $product
|
399 |
+
* @param bool $for_display
|
400 |
+
* @return array|false
|
401 |
+
*/
|
402 |
+
static function getVariationPrices($product, $for_display = false)
|
403 |
+
{
|
404 |
+
if (is_object($product) && method_exists($product, 'get_variation_prices')) {
|
405 |
+
return $product->get_variation_prices($for_display);
|
406 |
+
}
|
407 |
+
return false;
|
408 |
+
}
|
409 |
+
|
410 |
/**
|
411 |
* Get product custom taxonomy
|
412 |
* @return array|null
|
529 |
$cart = array();
|
530 |
if (function_exists('WC')) {
|
531 |
if(isset(WC()->cart) && WC()->cart != null){
|
532 |
+
if (is_object(WC()->cart) && method_exists(WC()->cart, 'get_cart')) {
|
533 |
if (did_action('wp_loaded')) {
|
534 |
$cart = WC()->cart->get_cart();
|
535 |
}
|
547 |
{
|
548 |
if (function_exists('WC')) {
|
549 |
if(isset(WC()->cart) && WC()->cart != null){
|
550 |
+
if (is_object(WC()->cart) && method_exists(WC()->cart, 'calculate_totals')) {
|
551 |
WC()->cart->calculate_totals();
|
552 |
}
|
553 |
}
|
568 |
{
|
569 |
if (function_exists('WC')) {
|
570 |
if(isset(WC()->cart) && WC()->cart != null) {
|
571 |
+
if (is_object(WC()->cart) && method_exists(WC()->cart, 'get_shipping_packages')) {
|
572 |
return WC()->cart->get_shipping_packages();
|
573 |
}
|
574 |
}
|
599 |
{
|
600 |
if (function_exists('WC')) {
|
601 |
if(isset(WC()->cart) && WC()->cart != null) {
|
602 |
+
if (is_object(WC()->cart) && method_exists(WC()->cart, 'add_to_cart')) {
|
603 |
return WC()->cart->add_to_cart($product_id, $quantity, $variation_id, $variation, $cart_item_data);
|
604 |
}
|
605 |
}
|
620 |
public static function set_quantity( $cart_item_key, $quantity = 1, $refresh_totals = true ){
|
621 |
if (function_exists('WC')) {
|
622 |
if(isset(WC()->cart) && WC()->cart != null) {
|
623 |
+
if (is_object(WC()->cart) && method_exists(WC()->cart, 'set_quantity')) {
|
624 |
return WC()->cart->set_quantity($cart_item_key, $quantity, $refresh_totals);
|
625 |
}
|
626 |
}
|
639 |
{
|
640 |
if (function_exists('WC')) {
|
641 |
if(isset(WC()->cart) && WC()->cart != null) {
|
642 |
+
if (is_object(WC()->cart) && method_exists(WC()->cart, 'remove_cart_item')) {
|
643 |
return WC()->cart->remove_cart_item($_cart_item_key);
|
644 |
}
|
645 |
}
|
659 |
{
|
660 |
if (function_exists('WC')) {
|
661 |
if(isset(WC()->cart) && WC()->cart != null) {
|
662 |
+
if (is_object(WC()->cart) && method_exists(WC()->cart, 'remove_coupon')) {
|
663 |
return WC()->cart->remove_coupon($code);
|
664 |
}
|
665 |
}
|
726 |
$product = self::getProduct($product);
|
727 |
}
|
728 |
if(!empty($product))
|
729 |
+
if (is_object($product) && method_exists($product, 'get_parent_id')) {
|
730 |
$parent_id = $product->get_parent_id();
|
731 |
}
|
732 |
return apply_filters('advanced_woo_discount_rules_get_product_parent_id', $parent_id, $product);
|
740 |
static function getCartItems($cart)
|
741 |
{
|
742 |
$cart_items = array();
|
743 |
+
if (is_object($cart) && method_exists($cart, 'get_cart_contents')) {
|
744 |
$cart_items = $cart->get_cart_contents();
|
745 |
}
|
746 |
return apply_filters('advanced_woo_discount_rules_get_cart_items', $cart_items, $cart);
|
755 |
if (function_exists('WC')) {
|
756 |
$subtotal = 0;
|
757 |
if(isset(WC()->cart) && WC()->cart != null) {
|
758 |
+
if (is_object(WC()->cart) && method_exists(WC()->cart, 'get_subtotal')) {
|
759 |
$tax_display_type = get_option('woocommerce_tax_display_cart');
|
760 |
if ($tax_display_type === 'excl') {
|
761 |
$subtotal = WC()->cart->get_subtotal();
|
762 |
} else {
|
763 |
$subtotal = WC()->cart->get_subtotal();
|
764 |
+
if (is_object(WC()->cart) && method_exists(WC()->cart, 'get_subtotal_tax')) {
|
765 |
$subtotal_tax = WC()->cart->get_subtotal_tax();
|
766 |
$subtotal = $subtotal+$subtotal_tax;
|
767 |
}
|
803 |
*/
|
804 |
static function addCartFee($cart, $name, $fee)
|
805 |
{
|
806 |
+
if (is_object($cart) && method_exists($cart, 'add_fee')) {
|
807 |
if(apply_filters('advanced_discount_rules_do_add_fee', true, $cart)){
|
808 |
if(!apply_filters('advanced_discount_rules_calculate_tax_with_fee', true, $name, $cart)){
|
809 |
add_filter('woocommerce_cart_totals_get_fees_from_cart_taxes', function ($fee_taxes, $fee, $cart) use ($name) {
|
847 |
*/
|
848 |
static function getCouponCode($coupon)
|
849 |
{
|
850 |
+
if (is_object($coupon) && method_exists($coupon, 'get_code')) {
|
851 |
return $coupon->get_code();
|
852 |
}
|
853 |
return NULL;
|
861 |
{
|
862 |
if (function_exists('WC')) {
|
863 |
if(isset(WC()->cart) && WC()->cart != null) {
|
864 |
+
if (is_object(WC()->cart) && method_exists(WC()->cart, 'get_applied_coupons')) {
|
865 |
return WC()->cart->get_applied_coupons();
|
866 |
}
|
867 |
}
|
877 |
*/
|
878 |
static function addCouponDiscount($cart, $code)
|
879 |
{
|
880 |
+
if (is_object($cart) && method_exists($cart, 'add_discount')) {
|
881 |
return $cart->add_discount($code);
|
882 |
}
|
883 |
return array();
|
891 |
*/
|
892 |
static function hasCouponInCart($cart, $code)
|
893 |
{
|
894 |
+
if (is_object($cart) && method_exists($cart, 'has_discount')) {
|
895 |
return $cart->has_discount($code);
|
896 |
}
|
897 |
return array();
|
905 |
*/
|
906 |
static function setCartProductPrice($cart_item_object, $price)
|
907 |
{
|
908 |
+
if (is_object($cart_item_object) && method_exists($cart_item_object, 'set_price')) {
|
909 |
return $cart_item_object->set_price($price);
|
910 |
}
|
911 |
return false;
|
935 |
if(!empty($product)){
|
936 |
if (function_exists('wc_get_price_including_tax')) {
|
937 |
$price = wc_get_price_including_tax($product, array('qty' => $quantity, 'price' => $original_price));
|
938 |
+
} else if (is_object($product) && method_exists($product, 'get_price_including_tax')) {
|
939 |
$price = $product->get_price_including_tax($quantity, $original_price);
|
940 |
} else {
|
941 |
$price = $original_price;
|
959 |
if(!empty($product)){
|
960 |
if (function_exists('wc_get_price_excluding_tax')) {
|
961 |
$price = wc_get_price_excluding_tax($product, array('qty' => $quantity, 'price' => $original_price));
|
962 |
+
} else if (is_object($product) && method_exists($product, 'get_price_excluding_tax')) {
|
963 |
$price = $product->get_price_excluding_tax($quantity, $original_price);
|
964 |
} else {
|
965 |
$price = $original_price;
|
991 |
static function getCountriesList()
|
992 |
{
|
993 |
if (function_exists('WC')) {
|
994 |
+
if (isset(WC()->countries) && is_object(WC()->countries) && method_exists(WC()->countries, 'get_countries')) {
|
995 |
return WC()->countries->get_countries();
|
996 |
}
|
997 |
}
|
1005 |
static function getStatesList()
|
1006 |
{
|
1007 |
if (function_exists('WC')) {
|
1008 |
+
if (isset(WC()->countries) && is_object(WC()->countries) && method_exists(WC()->countries, 'get_states')) {
|
1009 |
return WC()->countries->get_states();
|
1010 |
}
|
1011 |
}
|
1019 |
static function getPaymentMethodList()
|
1020 |
{
|
1021 |
if (function_exists('WC')) {
|
1022 |
+
if (is_object(WC()->payment_gateways) && method_exists(WC()->payment_gateways, 'payment_gateways')) {
|
1023 |
return WC()->payment_gateways->payment_gateways();
|
1024 |
}
|
1025 |
}
|
1090 |
static function getWeight($item)
|
1091 |
{
|
1092 |
if (!empty($item)) {
|
1093 |
+
if (is_object($item) && method_exists($item, 'get_weight')) {
|
1094 |
return $item->get_weight();
|
1095 |
}
|
1096 |
}
|
1127 |
{
|
1128 |
if (function_exists('WC')) {
|
1129 |
if(isset(WC()->session) && WC()->session != null) {
|
1130 |
+
if (is_object(WC()->session) && method_exists(WC()->session, 'get')) {
|
1131 |
return WC()->session->get($key);
|
1132 |
}
|
1133 |
}
|
1144 |
{
|
1145 |
if (function_exists('WC')) {
|
1146 |
if(isset(WC()->session) && WC()->session != null) {
|
1147 |
+
if (is_object(WC()->session) && method_exists(WC()->session, 'set')) {
|
1148 |
WC()->session->set($key, $value);
|
1149 |
}
|
1150 |
}
|
1171 |
static function getShippingCountry()
|
1172 |
{
|
1173 |
if (function_exists('WC') && WC()->customer) {
|
1174 |
+
if (is_object(WC()->customer) && method_exists(WC()->customer, 'get_shipping_country')) {
|
1175 |
return WC()->customer->get_shipping_country();
|
1176 |
}
|
1177 |
}
|
1185 |
static function getShippingState()
|
1186 |
{
|
1187 |
if (function_exists('WC') && WC()->customer) {
|
1188 |
+
if (is_object(WC()->customer) && method_exists(WC()->customer, 'get_shipping_state')) {
|
1189 |
return WC()->customer->get_shipping_state();
|
1190 |
}
|
1191 |
}
|
1199 |
static function getShippingCity()
|
1200 |
{
|
1201 |
if (function_exists('WC') && WC()->customer) {
|
1202 |
+
if (is_object(WC()->customer) && method_exists(WC()->customer, 'get_shipping_city')) {
|
1203 |
return WC()->customer->get_shipping_city();
|
1204 |
}
|
1205 |
}
|
1213 |
static function getBillingCity()
|
1214 |
{
|
1215 |
if (function_exists('WC') && WC()->customer) {
|
1216 |
+
if (is_object(WC()->customer) && method_exists(WC()->customer, 'get_billing_city')) {
|
1217 |
return WC()->customer->get_billing_city();
|
1218 |
}
|
1219 |
}
|
1227 |
static function getShippingZipCode()
|
1228 |
{
|
1229 |
if (function_exists('WC') && WC()->customer) {
|
1230 |
+
if (is_object(WC()->customer) && method_exists(WC()->customer, 'get_shipping_postcode')) {
|
1231 |
return WC()->customer->get_shipping_postcode();
|
1232 |
}
|
1233 |
}
|
1339 |
*/
|
1340 |
static function getOrderItems($order)
|
1341 |
{
|
1342 |
+
if (is_object($order) && method_exists($order, 'get_items')) {
|
1343 |
return $order->get_items();
|
1344 |
}
|
1345 |
return array();
|
1352 |
*/
|
1353 |
static function getOrderCurrency($order)
|
1354 |
{
|
1355 |
+
if (is_object($order) && method_exists($order, 'get_currency')) {
|
1356 |
return $order->get_currency();
|
1357 |
}
|
1358 |
return NULL;
|
1359 |
}
|
1360 |
|
1361 |
+
/**
|
1362 |
+
* Set order meta
|
1363 |
+
* @param $order
|
1364 |
+
* @param $key
|
1365 |
+
* @param $value
|
1366 |
+
* @return array
|
1367 |
+
*/
|
1368 |
+
static function setOrderMeta($order, $key, $value)
|
1369 |
+
{
|
1370 |
+
if (is_object($order) && method_exists($order, 'add_meta_data')) {
|
1371 |
+
$status = $order->add_meta_data($key, $value, true);
|
1372 |
+
if (method_exists($order, 'save_meta_data')) {
|
1373 |
+
$order->save_meta_data();
|
1374 |
+
}
|
1375 |
+
return $status;
|
1376 |
+
}
|
1377 |
+
return NULL;
|
1378 |
+
}
|
1379 |
+
|
1380 |
/**
|
1381 |
* Set order item meta
|
1382 |
* @param $item
|
1386 |
*/
|
1387 |
static function setOrderItemMeta($item, $key, $value)
|
1388 |
{
|
1389 |
+
if (is_object($item) && method_exists($item, 'add_meta_data')) {
|
1390 |
return $item->add_meta_data($key, $value, true);
|
1391 |
}
|
1392 |
return NULL;
|
1393 |
}
|
1394 |
|
1395 |
+
/**
|
1396 |
+
* Get order item data
|
1397 |
+
* @param $item
|
1398 |
+
* @return array
|
1399 |
+
*/
|
1400 |
+
static function getOrderItemData($item)
|
1401 |
+
{
|
1402 |
+
if (is_object($item) && method_exists($item, 'get_data')) {
|
1403 |
+
return $item->get_data();
|
1404 |
+
}
|
1405 |
+
return NULL;
|
1406 |
+
}
|
1407 |
+
|
1408 |
/**
|
1409 |
* Set order item meta
|
1410 |
* @param $item
|
1413 |
*/
|
1414 |
static function getOrderItemMeta($item, $key)
|
1415 |
{
|
1416 |
+
if (is_object($item) && method_exists($item, 'get_meta')) {
|
1417 |
return $item->get_meta($key);
|
1418 |
}
|
1419 |
return NULL;
|
1426 |
*/
|
1427 |
static function getItemId($item)
|
1428 |
{
|
1429 |
+
if (is_object($item) && method_exists($item, 'get_product_id') && method_exists($item, 'get_variation_id')) {
|
1430 |
if ($product_id = $item->get_variation_id()) {
|
1431 |
return $product_id;
|
1432 |
} else {
|
1656 |
static function getPriceHtml($product){
|
1657 |
$html = false;
|
1658 |
if(!empty($product))
|
1659 |
+
if (is_object($product) && method_exists($product, 'get_price_html')) {
|
1660 |
$html = $product->get_price_html();
|
1661 |
}
|
1662 |
return apply_filters('advanced_woo_discount_rules_get_price_html', $html, $product);
|
1704 |
if(function_exists('WC')){
|
1705 |
$session = WC()->session;
|
1706 |
if(!empty($session)){
|
1707 |
+
if(is_object($session) && method_exists($session, 'get')){
|
1708 |
$customer = $session->get('customer');
|
1709 |
if(isset($customer['email']) && !empty($customer['email'])){
|
1710 |
$user_email = $customer['email'];
|
1752 |
*/
|
1753 |
public static function get_variation_regular_price($product, $min_or_max = 'min', $for_display = false){
|
1754 |
if(!empty($product))
|
1755 |
+
if(is_object($product) && method_exists($product, 'get_variation_regular_price')){
|
1756 |
return $product->get_variation_regular_price($min_or_max, $for_display);
|
1757 |
}
|
1758 |
return 0;
|
1778 |
$available_variations = array();
|
1779 |
$is_variable_product = self::productTypeIs($product, 'variable');
|
1780 |
if(!empty($product))
|
1781 |
+
if ($is_variable_product && is_object($product) && method_exists($product, 'get_available_variations')){
|
1782 |
$available_variations = $product->get_available_variations();
|
1783 |
}
|
1784 |
self::$product_variations[$product_id] = $available_variations;
|
1803 |
static function variationIsVisible($product)
|
1804 |
{
|
1805 |
if(!empty($product)){
|
1806 |
+
if (is_object($product) && method_exists($product, 'variation_is_visible')) {
|
1807 |
return $product->variation_is_visible();
|
1808 |
}
|
1809 |
}
|
1851 |
|
1852 |
return $product_title;
|
1853 |
}
|
1854 |
+
|
1855 |
+
/**
|
1856 |
+
* Check cart needs shipping
|
1857 |
+
*
|
1858 |
+
* @return bool
|
1859 |
+
*/
|
1860 |
+
static function isCartNeedsShipping()
|
1861 |
+
{
|
1862 |
+
if (function_exists('WC')) {
|
1863 |
+
if(isset(WC()->cart) && WC()->cart != null){
|
1864 |
+
if (is_object(WC()->cart) && method_exists(WC()->cart, 'needs_shipping')) {
|
1865 |
+
return WC()->cart->needs_shipping();
|
1866 |
+
}
|
1867 |
+
}
|
1868 |
+
}
|
1869 |
+
return false;
|
1870 |
+
}
|
1871 |
}
|
v2/App/Models/DBTable.php
CHANGED
@@ -90,6 +90,7 @@ class DBTable
|
|
90 |
$order_item_discount_table_query = "CREATE TABLE $order_item_discount_table_name (
|
91 |
`id` int(11) NOT NULL AUTO_INCREMENT,
|
92 |
`order_id` int(11) DEFAULT NULL,
|
|
|
93 |
`rule_id` int(11) DEFAULT NULL,
|
94 |
`item_id` int(11) DEFAULT NULL,
|
95 |
`item_price` float NOT NULL,
|
@@ -100,13 +101,17 @@ class DBTable
|
|
100 |
`bulk_discount` float NOT NULL,
|
101 |
`set_discount` float NOT NULL,
|
102 |
`cart_discount` float NOT NULL,
|
|
|
103 |
`has_free_shipping` enum('yes','no') NOT NULL DEFAULT 'no',
|
104 |
`cart_discount_label` varchar(255) DEFAULT NULL,
|
105 |
`other_price` float NOT NULL DEFAULT '0',
|
106 |
`created_at` datetime DEFAULT NULL,
|
107 |
`updated_at` datetime DEFAULT NULL,
|
108 |
`extra` longtext DEFAULT NULL,
|
109 |
-
PRIMARY KEY (`id`)
|
|
|
|
|
|
|
110 |
) $charset_collate;";
|
111 |
if(strtolower($wpdb->get_var("show tables like '$rules_table_name'")) != strtolower($rules_table_name)){
|
112 |
dbDelta($rules_table_query);
|
@@ -335,18 +340,28 @@ class DBTable
|
|
335 |
/**
|
336 |
* save the order item discount
|
337 |
* @param $order_id
|
|
|
338 |
* @param $item_id
|
339 |
* @param $item_price
|
340 |
* @param $discounted_price
|
341 |
* @param $discount
|
342 |
* @param $quantity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
343 |
* @return int
|
344 |
*/
|
345 |
-
static function saveOrderItemDiscounts($order_id, $item_id, $item_price, $discounted_price, $discount, $quantity, $rule_id, $simple_discount, $bulk_discount, $set_discount, $cart_discount, $cart_discount_label, $
|
346 |
{
|
347 |
global $wpdb;
|
348 |
$order_item_discount_table_name = $wpdb->prefix . self::ORDER_ITEM_DISCOUNT_TABLE_NAME;
|
349 |
$order_id = intval($order_id);
|
|
|
350 |
$rule_id = intval($rule_id);
|
351 |
$item_id = intval($item_id);
|
352 |
$item_price = floatval($item_price);
|
@@ -357,19 +372,20 @@ class DBTable
|
|
357 |
$bulk_discount = floatval($bulk_discount);
|
358 |
$set_discount = floatval($set_discount);
|
359 |
$cart_discount = floatval($cart_discount);
|
|
|
360 |
$cart_discount_label = esc_sql($cart_discount_label);
|
361 |
-
$
|
362 |
-
$select_query = "SELECT id FROM {$order_item_discount_table_name} WHERE order_id=
|
363 |
$order_discounts = $wpdb->get_row($select_query, OBJECT);
|
364 |
$current_time = current_time('mysql', true);
|
365 |
|
366 |
if (empty($order_discounts)) {
|
367 |
-
$insert_query = "INSERT INTO {$order_item_discount_table_name} (order_id, rule_id, item_id, item_price, discounted_price, discount, quantity, simple_discount, bulk_discount, set_discount, cart_discount, has_free_shipping, cart_discount_label, created_at, updated_at) VALUES ({$order_id}, {$rule_id}, {$item_id}, {$item_price}, {$discounted_price}, {$discount}, {$quantity}, {$simple_discount}, {$bulk_discount}, {$set_discount}, {$cart_discount}, '{$
|
368 |
$wpdb->query($insert_query);
|
369 |
$row_id = $wpdb->insert_id;
|
370 |
} else {
|
371 |
$row_id = $order_discounts->id;
|
372 |
-
$update_query = "UPDATE {$order_item_discount_table_name} SET order_id={$order_id}, rule_id={$rule_id}, item_id={$item_id}, item_price={$item_price}, discounted_price={$discounted_price}, discount={$discount}, quantity={$quantity}, simple_discount={$simple_discount}, bulk_discount={$bulk_discount}, set_discount={$set_discount}, cart_discount={$cart_discount}, has_free_shipping='{$
|
373 |
$wpdb->query($update_query);
|
374 |
}
|
375 |
return $row_id;
|
@@ -435,7 +451,7 @@ class DBTable
|
|
435 |
FROM {$table_items} AS rules LEFT JOIN {$table_stats} AS rules_stats
|
436 |
ON rules.id = rules_stats.rule_id
|
437 |
WHERE DATE(rules_stats.created_at) BETWEEN %s AND %s AND rules.id IN ({$placeholders})
|
438 |
-
GROUP BY date_rep, rule_id
|
439 |
HAVING value>0
|
440 |
ORDER BY value DESC",
|
441 |
array_merge( array( $params['from'], $params['to'] ), $top )
|
@@ -443,7 +459,24 @@ class DBTable
|
|
443 |
|
444 |
$rows = $wpdb->get_results( $query );
|
445 |
|
446 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
447 |
}
|
448 |
|
449 |
/**
|
@@ -480,38 +513,36 @@ class DBTable
|
|
480 |
$table_items = $wpdb->prefix.self::RULES_TABLE_NAME;
|
481 |
$table_stats = $wpdb->prefix.self::ORDER_ITEM_DISCOUNT_TABLE_NAME;
|
482 |
|
483 |
-
$query_total = $wpdb->prepare(
|
484 |
-
"SELECT rules.id AS rule_id, SUM({$summary_field}) AS value
|
485 |
-
FROM {$table_items} AS rules LEFT JOIN {$table_stats} AS rules_stats
|
486 |
-
ON rules.id = rules_stats.rule_id
|
487 |
-
WHERE rules.id={$rule_id} AND DATE(rules_stats.created_at) BETWEEN %s AND %s
|
488 |
-
GROUP BY rules.id
|
489 |
-
HAVING value>0
|
490 |
-
ORDER BY value DESC
|
491 |
-
LIMIT %d",
|
492 |
-
array( $params['from'], $params['to'], (int) $params['limit'] )
|
493 |
-
);
|
494 |
-
$top = $wpdb->get_col( $query_total );
|
495 |
-
if ( empty( $top ) ) {
|
496 |
-
return false;
|
497 |
-
}
|
498 |
-
|
499 |
-
$placeholders = array_fill( 0, count( $top ), '%d' );
|
500 |
-
$placeholders = implode( ', ', $placeholders );
|
501 |
$query = $wpdb->prepare(
|
502 |
"SELECT DATE(rules_stats.created_at) as date_rep, rules.id AS rule_id, CONCAT('#', rules.id, ' ', rules.title) AS title, SUM({$summary_field}) AS value
|
503 |
FROM {$table_items} AS rules LEFT JOIN {$table_stats} AS rules_stats
|
504 |
ON rules.id = rules_stats.rule_id
|
505 |
-
WHERE rules.id={$rule_id} AND DATE(rules_stats.created_at) BETWEEN %s AND %s
|
506 |
GROUP BY date_rep, rule_id, title
|
507 |
-
HAVING value>0
|
508 |
ORDER BY value DESC",
|
509 |
-
|
510 |
);
|
511 |
|
512 |
$rows = $wpdb->get_results( $query );
|
513 |
|
514 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
515 |
}
|
516 |
|
517 |
/**
|
@@ -584,6 +615,42 @@ class DBTable
|
|
584 |
) $charset_collate;";
|
585 |
dbDelta($rules_table_query);
|
586 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
587 |
update_option('awdr_activity_log_version', $current_version);
|
588 |
}
|
589 |
}
|
90 |
$order_item_discount_table_query = "CREATE TABLE $order_item_discount_table_name (
|
91 |
`id` int(11) NOT NULL AUTO_INCREMENT,
|
92 |
`order_id` int(11) DEFAULT NULL,
|
93 |
+
`order_item_id` int(11) DEFAULT NULL,
|
94 |
`rule_id` int(11) DEFAULT NULL,
|
95 |
`item_id` int(11) DEFAULT NULL,
|
96 |
`item_price` float NOT NULL,
|
101 |
`bulk_discount` float NOT NULL,
|
102 |
`set_discount` float NOT NULL,
|
103 |
`cart_discount` float NOT NULL,
|
104 |
+
`other_discount` float NOT NULL DEFAULT '0',
|
105 |
`has_free_shipping` enum('yes','no') NOT NULL DEFAULT 'no',
|
106 |
`cart_discount_label` varchar(255) DEFAULT NULL,
|
107 |
`other_price` float NOT NULL DEFAULT '0',
|
108 |
`created_at` datetime DEFAULT NULL,
|
109 |
`updated_at` datetime DEFAULT NULL,
|
110 |
`extra` longtext DEFAULT NULL,
|
111 |
+
PRIMARY KEY (`id`),
|
112 |
+
INDEX `index_rule_id` (`rule_id`),
|
113 |
+
INDEX `index_created_at` (`created_at`),
|
114 |
+
INDEX `index_rule_order_id` (`rule_id`, `order_id`)
|
115 |
) $charset_collate;";
|
116 |
if(strtolower($wpdb->get_var("show tables like '$rules_table_name'")) != strtolower($rules_table_name)){
|
117 |
dbDelta($rules_table_query);
|
340 |
/**
|
341 |
* save the order item discount
|
342 |
* @param $order_id
|
343 |
+
* @param $order_item_id
|
344 |
* @param $item_id
|
345 |
* @param $item_price
|
346 |
* @param $discounted_price
|
347 |
* @param $discount
|
348 |
* @param $quantity
|
349 |
+
* @param $rule_id
|
350 |
+
* @param $simple_discount
|
351 |
+
* @param $bulk_discount
|
352 |
+
* @param $set_discount
|
353 |
+
* @param $cart_discount
|
354 |
+
* @param $other_discount
|
355 |
+
* @param $cart_discount_label
|
356 |
+
* @param bool $is_free_shipping
|
357 |
* @return int
|
358 |
*/
|
359 |
+
static function saveOrderItemDiscounts($order_id, $order_item_id, $item_id, $item_price, $discounted_price, $discount, $quantity, $rule_id, $simple_discount, $bulk_discount, $set_discount, $cart_discount, $other_discount, $cart_discount_label, $is_free_shipping = false)
|
360 |
{
|
361 |
global $wpdb;
|
362 |
$order_item_discount_table_name = $wpdb->prefix . self::ORDER_ITEM_DISCOUNT_TABLE_NAME;
|
363 |
$order_id = intval($order_id);
|
364 |
+
$order_item_id = intval($order_item_id);
|
365 |
$rule_id = intval($rule_id);
|
366 |
$item_id = intval($item_id);
|
367 |
$item_price = floatval($item_price);
|
372 |
$bulk_discount = floatval($bulk_discount);
|
373 |
$set_discount = floatval($set_discount);
|
374 |
$cart_discount = floatval($cart_discount);
|
375 |
+
$other_discount = floatval($other_discount);
|
376 |
$cart_discount_label = esc_sql($cart_discount_label);
|
377 |
+
$has_free_shipping = $is_free_shipping ? "yes" : "no";
|
378 |
+
$select_query = "SELECT id FROM {$order_item_discount_table_name} WHERE order_id={$order_id} AND item_id={$item_id} AND rule_id={$rule_id}";
|
379 |
$order_discounts = $wpdb->get_row($select_query, OBJECT);
|
380 |
$current_time = current_time('mysql', true);
|
381 |
|
382 |
if (empty($order_discounts)) {
|
383 |
+
$insert_query = "INSERT INTO {$order_item_discount_table_name} (order_id, order_item_id, rule_id, item_id, item_price, discounted_price, discount, quantity, simple_discount, bulk_discount, set_discount, cart_discount, other_discount, has_free_shipping, cart_discount_label, created_at, updated_at) VALUES ({$order_id}, {$order_item_id}, {$rule_id}, {$item_id}, {$item_price}, {$discounted_price}, {$discount}, {$quantity}, {$simple_discount}, {$bulk_discount}, {$set_discount}, {$cart_discount}, {$other_discount}, '{$has_free_shipping}', '{$cart_discount_label}', '{$current_time}', '{$current_time}')";
|
384 |
$wpdb->query($insert_query);
|
385 |
$row_id = $wpdb->insert_id;
|
386 |
} else {
|
387 |
$row_id = $order_discounts->id;
|
388 |
+
$update_query = "UPDATE {$order_item_discount_table_name} SET order_id={$order_id}, order_item_id={$order_item_id}, rule_id={$rule_id}, item_id={$item_id}, item_price={$item_price}, discounted_price={$discounted_price}, discount={$discount}, quantity={$quantity}, simple_discount={$simple_discount}, bulk_discount={$bulk_discount}, set_discount={$set_discount}, cart_discount={$cart_discount}, other_discount={$other_discount}, has_free_shipping='{$has_free_shipping}', cart_discount_label='{$cart_discount_label}', updated_at='{$current_time}' WHERE id={$row_id}";
|
389 |
$wpdb->query($update_query);
|
390 |
}
|
391 |
return $row_id;
|
451 |
FROM {$table_items} AS rules LEFT JOIN {$table_stats} AS rules_stats
|
452 |
ON rules.id = rules_stats.rule_id
|
453 |
WHERE DATE(rules_stats.created_at) BETWEEN %s AND %s AND rules.id IN ({$placeholders})
|
454 |
+
GROUP BY date_rep, rule_id
|
455 |
HAVING value>0
|
456 |
ORDER BY value DESC",
|
457 |
array_merge( array( $params['from'], $params['to'] ), $top )
|
459 |
|
460 |
$rows = $wpdb->get_results( $query );
|
461 |
|
462 |
+
$query_info = $wpdb->prepare(
|
463 |
+
"SELECT COUNT(results.order_id) AS total_orders,
|
464 |
+
SUM(results.discounted_amount) AS discounted_amount,
|
465 |
+
SUM(results.revenue) AS revenue, SUM(results.free_shipping) as total_free_shipping
|
466 |
+
FROM (
|
467 |
+
SELECT rules_stats.order_id,
|
468 |
+
SUM({$summary_field}) AS discounted_amount, post_meta.meta_value as revenue,
|
469 |
+
SUM(CASE WHEN rules_stats.has_free_shipping = 'yes' THEN 1 ELSE 0 END) as free_shipping
|
470 |
+
FROM {$table_stats} AS rules_stats LEFT JOIN {$wpdb->postmeta} as post_meta
|
471 |
+
ON (rules_stats.order_id = post_meta.post_id AND post_meta.meta_key = '_order_total')
|
472 |
+
WHERE DATE(rules_stats.created_at) BETWEEN %s AND %s
|
473 |
+
GROUP BY rules_stats.order_id
|
474 |
+
) AS results",
|
475 |
+
array( $params['from'], $params['to'])
|
476 |
+
);
|
477 |
+
$info = $wpdb->get_row( $query_info );
|
478 |
+
|
479 |
+
return ['stats' => $rows, 'other' => $info];
|
480 |
}
|
481 |
|
482 |
/**
|
513 |
$table_items = $wpdb->prefix.self::RULES_TABLE_NAME;
|
514 |
$table_stats = $wpdb->prefix.self::ORDER_ITEM_DISCOUNT_TABLE_NAME;
|
515 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
516 |
$query = $wpdb->prepare(
|
517 |
"SELECT DATE(rules_stats.created_at) as date_rep, rules.id AS rule_id, CONCAT('#', rules.id, ' ', rules.title) AS title, SUM({$summary_field}) AS value
|
518 |
FROM {$table_items} AS rules LEFT JOIN {$table_stats} AS rules_stats
|
519 |
ON rules.id = rules_stats.rule_id
|
520 |
+
WHERE rules.id={$rule_id} AND DATE(rules_stats.created_at) BETWEEN %s AND %s
|
521 |
GROUP BY date_rep, rule_id, title
|
|
|
522 |
ORDER BY value DESC",
|
523 |
+
array( $params['from'], $params['to'] )
|
524 |
);
|
525 |
|
526 |
$rows = $wpdb->get_results( $query );
|
527 |
|
528 |
+
$query_info = $wpdb->prepare(
|
529 |
+
"SELECT COUNT(results.order_id) AS total_orders,
|
530 |
+
SUM(results.discounted_amount) AS discounted_amount,
|
531 |
+
SUM(results.revenue) AS revenue, SUM(results.free_shipping) as total_free_shipping
|
532 |
+
FROM (
|
533 |
+
SELECT rules_stats.order_id,
|
534 |
+
SUM({$summary_field}) AS discounted_amount, post_meta.meta_value as revenue,
|
535 |
+
SUM(CASE WHEN rules_stats.has_free_shipping = 'yes' THEN 1 ELSE 0 END) as free_shipping
|
536 |
+
FROM {$table_stats} AS rules_stats LEFT JOIN {$wpdb->postmeta} as post_meta
|
537 |
+
ON (rules_stats.order_id = post_meta.post_id AND post_meta.meta_key = '_order_total')
|
538 |
+
WHERE rules_stats.rule_id={$rule_id} AND DATE(rules_stats.created_at) BETWEEN %s AND %s
|
539 |
+
GROUP BY rules_stats.order_id
|
540 |
+
) AS results",
|
541 |
+
array($params['from'], $params['to'])
|
542 |
+
);
|
543 |
+
$info = $wpdb->get_row( $query_info );
|
544 |
+
|
545 |
+
return ['stats' => $rows, 'other' => $info];
|
546 |
}
|
547 |
|
548 |
/**
|
615 |
) $charset_collate;";
|
616 |
dbDelta($rules_table_query);
|
617 |
|
618 |
+
$order_item_discount_table_name = $wpdb->prefix . self::ORDER_ITEM_DISCOUNT_TABLE_NAME;
|
619 |
+
/**
|
620 |
+
* Added `order_item_id` column (since v2.5.0)
|
621 |
+
* Added `other_discount` column (since v2.5.0)
|
622 |
+
* Added `index_rule_id` index (since v2.5.0)
|
623 |
+
* Added `index_created_at` index (since v2.5.0)
|
624 |
+
* Added `index_rule_order_id` index (since v2.5.0)
|
625 |
+
*/
|
626 |
+
$order_item_discount_table_query = "CREATE TABLE $order_item_discount_table_name (
|
627 |
+
`id` int(11) NOT NULL AUTO_INCREMENT,
|
628 |
+
`order_id` int(11) DEFAULT NULL,
|
629 |
+
`order_item_id` int(11) DEFAULT NULL,
|
630 |
+
`rule_id` int(11) DEFAULT NULL,
|
631 |
+
`item_id` int(11) DEFAULT NULL,
|
632 |
+
`item_price` float NOT NULL,
|
633 |
+
`discounted_price` float NOT NULL,
|
634 |
+
`discount` float NOT NULL,
|
635 |
+
`quantity` int(11) NOT NULL,
|
636 |
+
`simple_discount` float NOT NULL,
|
637 |
+
`bulk_discount` float NOT NULL,
|
638 |
+
`set_discount` float NOT NULL,
|
639 |
+
`cart_discount` float NOT NULL,
|
640 |
+
`other_discount` float NOT NULL DEFAULT '0',
|
641 |
+
`has_free_shipping` enum('yes','no') NOT NULL DEFAULT 'no',
|
642 |
+
`cart_discount_label` varchar(255) DEFAULT NULL,
|
643 |
+
`other_price` float NOT NULL DEFAULT '0',
|
644 |
+
`created_at` datetime DEFAULT NULL,
|
645 |
+
`updated_at` datetime DEFAULT NULL,
|
646 |
+
`extra` longtext DEFAULT NULL,
|
647 |
+
PRIMARY KEY (`id`),
|
648 |
+
INDEX `index_rule_id` (`rule_id`),
|
649 |
+
INDEX `index_created_at` (`created_at`),
|
650 |
+
INDEX `index_rule_order_id` (`rule_id`, `order_id`)
|
651 |
+
) $charset_collate;";
|
652 |
+
dbDelta($order_item_discount_table_query);
|
653 |
+
|
654 |
update_option('awdr_activity_log_version', $current_version);
|
655 |
}
|
656 |
}
|
v2/App/Router.php
CHANGED
@@ -144,8 +144,10 @@ class Router
|
|
144 |
}
|
145 |
}
|
146 |
|
147 |
-
//
|
148 |
-
add_action('
|
|
|
|
|
149 |
//cart
|
150 |
add_action('woocommerce_before_calculate_totals', array(self::$manage_discount, 'applyCartProductDiscount'), 1000);
|
151 |
add_action('woocommerce_cart_item_price', array(self::$manage_discount, 'getCartPriceHtml'), 1000, 3);
|
144 |
}
|
145 |
}
|
146 |
|
147 |
+
// ensure cart and mini-cart price and strikeout display
|
148 |
+
add_action('woocommerce_before_cart', array(self::$manage_discount, 'calculateCartTotalIfIsNotCalculated'), 10);
|
149 |
+
add_action('woocommerce_before_mini_cart', array(self::$manage_discount, 'calculateCartTotalIfIsNotCalculated'), 10);
|
150 |
+
add_action('woocommerce_before_mini_cart_contents', array(self::$manage_discount, 'calculateCartTotalIfIsNotCalculated'), 10);
|
151 |
//cart
|
152 |
add_action('woocommerce_before_calculate_totals', array(self::$manage_discount, 'applyCartProductDiscount'), 1000);
|
153 |
add_action('woocommerce_cart_item_price', array(self::$manage_discount, 'getCartPriceHtml'), 1000, 3);
|
v2/App/Snippets/overrideCustomPrice.php
CHANGED
@@ -25,7 +25,7 @@ add_action('plugins_loaded', function (){
|
|
25 |
|
26 |
add_action('advanced_woo_discount_rules_after_apply_discount', function (){
|
27 |
if (function_exists('WC')) {
|
28 |
-
if (method_exists(WC()->cart, 'get_cart')) {
|
29 |
$cart_items = WC()->cart->get_cart();
|
30 |
if(!empty($cart_items)){
|
31 |
foreach ($cart_items as $key => $item){
|
25 |
|
26 |
add_action('advanced_woo_discount_rules_after_apply_discount', function (){
|
27 |
if (function_exists('WC')) {
|
28 |
+
if (is_object(WC()->cart) && method_exists(WC()->cart, 'get_cart')) {
|
29 |
$cart_items = WC()->cart->get_cart();
|
30 |
if(!empty($cart_items)){
|
31 |
foreach ($cart_items as $key => $item){
|
v2/App/Views/Admin/Tabs/Statistics.php
CHANGED
@@ -2,6 +2,8 @@
|
|
2 |
if (!defined('ABSPATH')) {
|
3 |
exit; // Exit if accessed directly
|
4 |
}
|
|
|
|
|
5 |
?>
|
6 |
<style>
|
7 |
.chart-options select {
|
@@ -29,8 +31,39 @@ if (!defined('ABSPATH')) {
|
|
29 |
background: rgba(255, 255, 255, .6);
|
30 |
content: '';
|
31 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
</style>
|
33 |
-
<p class="wdr_settings_desc_text text-info"><?php _e('<strong>Note</strong> : Free Shipping rules will not be shown in reports.', 'woo-discount-rules'); ?></p>
|
34 |
<br>
|
35 |
<div id="wpbody-content" class="awdr-container">
|
36 |
<form method="post" name="wdr-statistics" class="chart-options">
|
@@ -41,7 +74,6 @@ if (!defined('ABSPATH')) {
|
|
41 |
<option value="this_month"><?php _e('This Month', 'woo-discount-rules'); ?></option>
|
42 |
<option value="custom"><?php _e('Custom Range', 'woo-discount-rules'); ?></option>
|
43 |
</select>
|
44 |
-
<!-- <span class="wdr_desc_text"><?php /*_e('Report Period', 'woo-discount-rules'); */?></span>-->
|
45 |
</div>
|
46 |
<div class="wdr-dateandtime-value">
|
47 |
<input type="text"
|
@@ -52,7 +84,6 @@ if (!defined('ABSPATH')) {
|
|
52 |
id="rule_datetime_from" value="<?php if (isset($date[0]) && !empty($date[0])) {
|
53 |
echo esc_attr($date[0]);
|
54 |
} ?>" style="height: 34px;">
|
55 |
-
<!--<span class="wdr_desc_text"><?php /*_e('From', 'woo-discount-rules'); */?></span>-->
|
56 |
</div>
|
57 |
<div class="wdr-dateandtime-value">
|
58 |
<input type="text"
|
@@ -63,7 +94,6 @@ if (!defined('ABSPATH')) {
|
|
63 |
id="rule_datetime_to" value="<?php if (isset($date[1]) && !empty($date[1])) {
|
64 |
echo esc_attr($date[1]);
|
65 |
} ?>" style="height: 34px;">
|
66 |
-
<!--<span class="wdr_desc_text"><?php /*_e('To', 'woo-discount-rules'); */?></span>-->
|
67 |
</div>
|
68 |
<div class="awdr-report-type" >
|
69 |
<select name="type" class="chart-type awdr-show-report-limit" style="height: 33px">
|
@@ -75,30 +105,34 @@ if (!defined('ABSPATH')) {
|
|
75 |
</optgroup>
|
76 |
<?php endforeach; ?>
|
77 |
</select>
|
78 |
-
<!--<span class="wdr_desc_text"><?php /*_e('Select Rule', 'woo-discount-rules'); */?></span>-->
|
79 |
</div>
|
80 |
-
|
81 |
-
<input type="number"
|
82 |
-
name="limit"
|
83 |
-
class="number_only_field"
|
84 |
-
min="1"
|
85 |
-
placeholder="<?php /*_e('5', 'woo-discount-rules'); */?>"
|
86 |
-
autocomplete="off"
|
87 |
-
value="" style="height: 34px;">
|
88 |
-
<span class="wdr_desc_text"><?php /*_e('Report Limit (Eg: Top 5)', 'woo-discount-rules'); */?></span>
|
89 |
-
</div>-->
|
90 |
-
<div> <!--class="awdr-toggle-report-update"--> <!--style="display: none;>"-->
|
91 |
<input type="hidden" name="awdr_nonce" value="<?php echo esc_attr(\Wdr\App\Helpers\Helper::create_nonce('wdr_ajax_report')); ?>">
|
92 |
<button type="submit" class="update-chart btn btn-success"><?php _e('Update Chart', 'woo-discount-rules'); ?></button>
|
93 |
</div>
|
94 |
</div>
|
95 |
-
<!-- <div class="wdr-rule-statistics awdr-report-update">
|
96 |
-
<div class="">
|
97 |
-
<button type="submit" class="btn btn-success"><?php /*_e('Update Chart', 'woo-discount-rules'); */?></button>
|
98 |
-
</div>
|
99 |
-
</div>-->
|
100 |
</form>
|
101 |
<br/>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
<div id="chart-container"></div>
|
103 |
<div class="clear"></div>
|
104 |
</div>
|
2 |
if (!defined('ABSPATH')) {
|
3 |
exit; // Exit if accessed directly
|
4 |
}
|
5 |
+
|
6 |
+
$is_pro = Wdr\App\Helpers\Helper::hasPro();
|
7 |
?>
|
8 |
<style>
|
9 |
.chart-options select {
|
31 |
background: rgba(255, 255, 255, .6);
|
32 |
content: '';
|
33 |
}
|
34 |
+
#chart-container{
|
35 |
+
padding: 20px;
|
36 |
+
background: #fff;
|
37 |
+
}
|
38 |
+
#info-container{
|
39 |
+
display: flex;
|
40 |
+
margin-bottom: 10px;
|
41 |
+
gap: 10px;
|
42 |
+
}
|
43 |
+
#info-container .wdr-card {
|
44 |
+
width: 100%;
|
45 |
+
padding: 0.5rem 1.5rem;
|
46 |
+
min-width: 255px;
|
47 |
+
box-shadow: 0 1px 1px rgb(0 0 0 / 4%);
|
48 |
+
background: #fff;
|
49 |
+
box-sizing: border-box;
|
50 |
+
}
|
51 |
+
#info-container .total-orders {
|
52 |
+
border-left: 3px solid #0092e1;
|
53 |
+
}
|
54 |
+
#info-container .total-revenue {
|
55 |
+
border-left: 3px solid #45cc7a;
|
56 |
+
}
|
57 |
+
#info-container .discounted-amount {
|
58 |
+
border-left: 3px solid #e59b42;
|
59 |
+
}
|
60 |
+
#info-container .total-free-shipping {
|
61 |
+
border-left: 3px solid #4f31d5;
|
62 |
+
}
|
63 |
+
#info-container .wdr-card h4 {
|
64 |
+
margin: 4px 0;
|
65 |
+
}
|
66 |
</style>
|
|
|
67 |
<br>
|
68 |
<div id="wpbody-content" class="awdr-container">
|
69 |
<form method="post" name="wdr-statistics" class="chart-options">
|
74 |
<option value="this_month"><?php _e('This Month', 'woo-discount-rules'); ?></option>
|
75 |
<option value="custom"><?php _e('Custom Range', 'woo-discount-rules'); ?></option>
|
76 |
</select>
|
|
|
77 |
</div>
|
78 |
<div class="wdr-dateandtime-value">
|
79 |
<input type="text"
|
84 |
id="rule_datetime_from" value="<?php if (isset($date[0]) && !empty($date[0])) {
|
85 |
echo esc_attr($date[0]);
|
86 |
} ?>" style="height: 34px;">
|
|
|
87 |
</div>
|
88 |
<div class="wdr-dateandtime-value">
|
89 |
<input type="text"
|
94 |
id="rule_datetime_to" value="<?php if (isset($date[1]) && !empty($date[1])) {
|
95 |
echo esc_attr($date[1]);
|
96 |
} ?>" style="height: 34px;">
|
|
|
97 |
</div>
|
98 |
<div class="awdr-report-type" >
|
99 |
<select name="type" class="chart-type awdr-show-report-limit" style="height: 33px">
|
105 |
</optgroup>
|
106 |
<?php endforeach; ?>
|
107 |
</select>
|
|
|
108 |
</div>
|
109 |
+
<div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
<input type="hidden" name="awdr_nonce" value="<?php echo esc_attr(\Wdr\App\Helpers\Helper::create_nonce('wdr_ajax_report')); ?>">
|
111 |
<button type="submit" class="update-chart btn btn-success"><?php _e('Update Chart', 'woo-discount-rules'); ?></button>
|
112 |
</div>
|
113 |
</div>
|
|
|
|
|
|
|
|
|
|
|
114 |
</form>
|
115 |
<br/>
|
116 |
+
<div id="info-container" style="display: none;">
|
117 |
+
<div class="wdr-card total-orders">
|
118 |
+
<h4><?php esc_html_e("Discounted orders", 'woo-discount-rules'); ?></h4>
|
119 |
+
<h4 id="total-orders">-</h4>
|
120 |
+
</div>
|
121 |
+
<div class="wdr-card total-revenue">
|
122 |
+
<h4><?php esc_html_e("Total sales", 'woo-discount-rules'); ?></h4>
|
123 |
+
<h4 id="total-revenue">-</h4>
|
124 |
+
</div>
|
125 |
+
<div class="wdr-card discounted-amount">
|
126 |
+
<h4><?php esc_html_e("Discounted amount", 'woo-discount-rules'); ?></h4>
|
127 |
+
<h4 id="discounted-amount">-</h4>
|
128 |
+
</div>
|
129 |
+
<?php if ($is_pro) { ?>
|
130 |
+
<div class="wdr-card total-free-shipping">
|
131 |
+
<h4><?php esc_html_e("Orders with free shipping", 'woo-discount-rules'); ?></h4>
|
132 |
+
<h4 id="total-free-shipping">-</h4>
|
133 |
+
</div>
|
134 |
+
<?php } ?>
|
135 |
+
</div>
|
136 |
<div id="chart-container"></div>
|
137 |
<div class="clear"></div>
|
138 |
</div>
|
v2/Assets/Js/admin-statistics.js
CHANGED
@@ -54,8 +54,8 @@ function init() {
|
|
54 |
});
|
55 |
|
56 |
jQuery(window).resize(function () {
|
57 |
-
if (response_content.data.columns.length > 1) {
|
58 |
-
renderChart(response_content.data);
|
59 |
}
|
60 |
});
|
61 |
|
@@ -110,6 +110,8 @@ function showChart(params) {
|
|
110 |
let loader = jQuery('.woo_discount_loader');
|
111 |
loader.show();
|
112 |
|
|
|
|
|
113 |
jQuery.post(
|
114 |
ajaxurl,
|
115 |
{
|
@@ -122,11 +124,19 @@ function showChart(params) {
|
|
122 |
/*jQuery('.update-chart').prop('disabled', false);*/
|
123 |
/* jQuery('.chart-placeholder').removeClass('loading');*/
|
124 |
if (response.success) {
|
125 |
-
if (response.data.columns.length > 1) {
|
126 |
response_content = response;
|
127 |
-
renderChart(response.data);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
} else {
|
129 |
jQuery('#chart-container').html(wdr_data.localization_data.chart_data);
|
|
|
130 |
}
|
131 |
}else {
|
132 |
jQuery('#chart-container').html(wdr_data.localization_data.chart_data);
|
54 |
});
|
55 |
|
56 |
jQuery(window).resize(function () {
|
57 |
+
if (response_content && response_content.data.chart.columns.length > 1) {
|
58 |
+
renderChart(response_content.data.chart);
|
59 |
}
|
60 |
});
|
61 |
|
110 |
let loader = jQuery('.woo_discount_loader');
|
111 |
loader.show();
|
112 |
|
113 |
+
jQuery("#info-container").find("#total-orders, #total-revenue, #discounted-amount, #total-free-shipping").html("-");
|
114 |
+
|
115 |
jQuery.post(
|
116 |
ajaxurl,
|
117 |
{
|
124 |
/*jQuery('.update-chart').prop('disabled', false);*/
|
125 |
/* jQuery('.chart-placeholder').removeClass('loading');*/
|
126 |
if (response.success) {
|
127 |
+
if (response.data.chart.columns && response.data.chart.columns.length > 1) {
|
128 |
response_content = response;
|
129 |
+
renderChart(response.data.chart);
|
130 |
+
jQuery("#info-container").show();
|
131 |
+
if (response.data.other) {
|
132 |
+
jQuery("#info-container #total-orders").html(response.data.other.total_orders);
|
133 |
+
jQuery("#info-container #total-revenue").html(response.data.other.revenue);
|
134 |
+
jQuery("#info-container #discounted-amount").html(response.data.other.discounted_amount);
|
135 |
+
jQuery("#info-container #total-free-shipping").html(response.data.other.total_free_shipping);
|
136 |
+
}
|
137 |
} else {
|
138 |
jQuery('#chart-container').html(wdr_data.localization_data.chart_data);
|
139 |
+
jQuery("#info-container").hide();
|
140 |
}
|
141 |
}else {
|
142 |
jQuery('#chart-container').html(wdr_data.localization_data.chart_data);
|
v2/Assets/Js/admin-statistics.min.js
CHANGED
@@ -1 +1 @@
|
|
1 |
-
var response_content,isjQueryReady=!1,isGoogleChartsReady=!1,isInitialized=!1;function googleChartsLoadCallback(){isGoogleChartsReady=!0,init()}function init(){isjQueryReady&&isGoogleChartsReady&&!isInitialized&&(isInitialized=!0,jQuery(".chart-period").change(function(){var
|
1 |
+
var response_content,isjQueryReady=!1,isGoogleChartsReady=!1,isInitialized=!1;function googleChartsLoadCallback(){isGoogleChartsReady=!0,init()}function init(){isjQueryReady&&isGoogleChartsReady&&!isInitialized&&(isInitialized=!0,jQuery(".chart-period").change(function(){var t=jQuery(".chart-period").val(),a=new Date;if("this_week"===t)a.setDate(a.getDate()-a.getDay()+1),jQuery(".chart-period-start").val(format_date(a)),a.setDate(a.getDate()+6),jQuery(".chart-period-end").val(format_date(a));else if("this_month"===t){var e=new Date(a.getFullYear(),a.getMonth(),1);jQuery(".chart-period-start").val(format_date(e));var n=new Date(a.getFullYear(),a.getMonth()+1,-1);jQuery(".chart-period-end").val(format_date(n))}}),jQuery(".chart-period-start, .chart-period-end").change(function(){jQuery(".chart-period").val("custom")}),jQuery(".chart-options").submit(function(t){return t.preventDefault(),showChart(jQuery(this).serialize()),!1}),jQuery(window).resize(function(){response_content&&response_content.data.chart.columns.length>1&&renderChart(response_content.data.chart)}),jQuery(".chart-period").change(),jQuery(".chart-options").submit())}function renderChart(t){var a=new google.visualization.DataTable;t.columns&&t.columns.forEach(function(t,e){a.addColumn(0===e?"string":"number",t)}),t.rows&&(a.addRows(Object.values(t.rows)),new google.visualization.NumberFormat({fractionDigits:2}).format(a,1));var e=jQuery("#chart-container").width(),n=jQuery(window).height()-jQuery("#chart-container").offset().top;200>n&&(n=200);var o={chart:{title:t.title?t.title:"",subtitle:t.subtitle?t.subtitle:""},width:e,height:n};new google.charts.Line(document.getElementById("chart-container")).draw(a,o)}function showChart(t){let a=jQuery(".woo_discount_loader");a.show(),jQuery("#info-container").find("#total-orders, #total-revenue, #discounted-amount, #total-free-shipping").html("-"),jQuery.post(ajaxurl,{action:"wdr_admin_statistics",method:"get_chart_data",params:t},function(t){a.hide(),t.success?t.data.chart.columns&&t.data.chart.columns.length>1?(response_content=t,renderChart(t.data.chart),jQuery("#info-container").show(),t.data.other&&(jQuery("#info-container #total-orders").html(t.data.other.total_orders),jQuery("#info-container #total-revenue").html(t.data.other.revenue),jQuery("#info-container #discounted-amount").html(t.data.other.discounted_amount),jQuery("#info-container #total-free-shipping").html(t.data.other.total_free_shipping))):(jQuery("#chart-container").html(wdr_data.localization_data.chart_data),jQuery("#info-container").hide()):jQuery("#chart-container").html(wdr_data.localization_data.chart_data)},"json")}function to2Digits(t){return t<10?"0"+t:t}function format_date(t){return[to2Digits(t.getFullYear()),to2Digits(t.getMonth()+1),to2Digits(t.getDate())].join("-")}google.charts.load("current",{packages:["line"]}),google.charts.setOnLoadCallback(googleChartsLoadCallback),jQuery(document).ready(function(){isjQueryReady=!0,jQuery(".chart-type").select2(),init()});
|
v2/Assets/Js/awdr-dynamic-price.min.js
CHANGED
@@ -1 +1 @@
|
|
1 |
-
!function(
|
1 |
+
!function(t){t.extend({AdvanceWooDiscountRules:{form:null,product_id:null,quantity:0,options:[],target:null,getDynamicDiscountPriceFromCartForm:function(t,o,r){void 0!==r&&(this.options=r),void 0!==o&&(this.target=o),void 0!==t&&t.is("form")?this.form=t:this.logError("Incorrect form provided"),this.product_id=this.getProductIdFromForm(),this.quantity=this.getProductQuantityFromForm(),this.getDiscountPriceForProduct()},getDiscountPriceForProduct:function(){if(null===this.product_id||0==this.product_id)return this.logError("Invalid product"),[];var o={action:"awdr_get_product_discount",product_id:this.product_id,qty:this.quantity,awdr_nonce:awdr_params.nonce};void 0!==this.options.custom_price&&(o.custom_price=this.options.custom_price);var r=this.target,i=this.options;t.ajax({url:awdr_params.ajaxurl,data:o,type:"POST",success:function(o){t(document.body).trigger("advanced_woo_discount_rules_on_get_response_for_dynamic_discount",[o,r,i])},error:function(t){}})},getProductIdFromForm:function(){var t=this.form.find('[name="variation_id"]'),o=this.form.find('[name="add-to-cart"]');return t.length?parseInt(t.val()):!!o.length&&parseInt(o.val())},getProductQuantityFromForm:function(){var t=this.form.find('input[name="quantity"]');return 0===t.length?0:t.val()},logError:function(t){console.error("Advance discount rule error: %s",t)}}})}(jQuery);
|
v2/Assets/Js/site_main.min.js
CHANGED
@@ -1 +1 @@
|
|
1 |
-
!function(
|
1 |
+
!function(t){function i(){t("body").trigger("update_checkout")}"1"==awdr_params.refresh_order_review&&(t(document).on("change",'input[name="payment_method"],input[name="billing_city"],input[name="billing_postcode"]',function(){i()}),t(document).on("blur",'input[name="billing_email"], select#billing_state',function(){i()})),t(document).ready(function(t){function i(){"show_dynamically"==awdr_params.enable_update_price_with_qty&&t(document).on("change",'[name="quantity"]',function(){var i=t(this);setTimeout(function(){var e=i.val(),a=0,o="",r=i.closest("form");if(r.find('button[name="add-to-cart"]').length){a=r.find('button[name="add-to-cart"]').val();var c="div.product p.price";void 0!=awdr_params.custom_target_simple_product&&""!=awdr_params.custom_target_simple_product&&(c=awdr_params.custom_target_simple_product),o=t(c).first()}else if(r.find('input[name="variation_id"]').length){a=r.find('input[name="variation_id"]').val();var c="div.product .woocommerce-variation-price";void 0!=awdr_params.custom_target_variable_product&&""!=awdr_params.custom_target_variable_product&&(c=awdr_params.custom_target_variable_product),o=t(c),t(c+" .price").length||o.html("<div class='price'></div>"),o=t(c+" .price")}if(!a||0==a){if(void 0!=awdr_params.custom_simple_product_id_selector&&""!=awdr_params.custom_simple_product_id_selector){a=t(awdr_params.custom_simple_product_id_selector).val();let n="div.product p.price";void 0!=awdr_params.custom_target_simple_product&&""!=awdr_params.custom_target_simple_product&&(n=awdr_params.custom_target_simple_product),o=t(n).first()}if(void 0!=awdr_params.custom_variable_product_id_selector&&""!=awdr_params.custom_variable_product_id_selector){a=t(awdr_params.custom_variable_product_id_selector).val();let l="div.product .woocommerce-variation-price";void 0!=awdr_params.custom_target_variable_product&&""!=awdr_params.custom_target_variable_product&&(l=awdr_params.custom_target_variable_product),t(l+" .price").length||o.html("<div class='price'></div>"),o=t(l+" .price")}}if(a&&o&&0!=a){var u={action:"wdr_ajax",method:"get_price_html",product_id:a,qty:e,awdr_nonce:awdr_params.nonce};t.ajax({url:awdr_params.ajaxurl,data:u,type:"POST",success:function(t){t.price_html?o.html(t.price_html):void 0!=t.original_price_html&&o.html(t.original_price_html)},error:function(t){o.html("")}})}},0)})}if(awdr_params.js_init_trigger&&t(document).on(awdr_params.js_init_trigger,function(){i()}),i(),"1"==awdr_params.awdr_dynamic_bulk_table_status&&"on"==awdr_params.awdr_dynamic_bulk_table_off){function e(i){setTimeout(function(){if(""!=i&&"0"!=i){var e={action:"wdr_ajax",method:"get_variable_product_bulk_table",product_id:i,awdr_nonce:awdr_params.nonce};let a="div.awdr-bulk-customizable-table";void 0!=awdr_params.awdr_opacity_to_bulk_table&&""!=awdr_params.awdr_opacity_to_bulk_table&&(a=awdr_params.awdr_opacity_to_bulk_table),t.ajax({url:awdr_params.ajaxurl,data:e,type:"POST",beforeSend:function(){t(a).css("opacity","0.5")},complete:function(){t(a).css("opacity","1")},success:function(i){i.bulk_table&&t(".awdr-bulk-customizable-table").html(i.bulk_table)},error:function(i){t(".awdr-bulk-customizable-table").html("")}})}},100)}t(".single_variation_wrap").on("hide_variation",function(i){e(t(this).closest("form").find('input[name="product_id"]').val())}),t(".single_variation_wrap").on("show_variation",function(t,i,a){let o=i.variation_id;(void 0==i.is_bundled||!0!=i.is_bundled)&&e(o)})}})}(jQuery);
|
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
|
7 |
* Author URI: https://www.flycart.org
|
8 |
-
* Version: 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:
|
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.
|
25 |
}
|
26 |
|
27 |
global $awdr_load_version;
|
5 |
* Description: Simple to complex discount rules for your WooCommerce store. Core package.
|
6 |
* Author: Flycart
|
7 |
* Author URI: https://www.flycart.org
|
8 |
+
* Version: 2.5.0
|
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: 7.0
|
15 |
*/
|
16 |
if (!defined('ABSPATH')) {
|
17 |
exit;
|
21 |
* Current version of our app
|
22 |
*/
|
23 |
if (!defined('WDR_VERSION')) {
|
24 |
+
define('WDR_VERSION', '2.5.0');
|
25 |
}
|
26 |
|
27 |
global $awdr_load_version;
|