From 39e0717541f74cbb0f524b49ae1ae9b5f48d4f8c Mon Sep 17 00:00:00 2001 From: Tony Volpe Date: Mon, 17 Jun 2024 16:29:48 -0400 Subject: [PATCH] woocommerce-smart-coupons --- ...MIT-license-jquery-ui-timepicker-addon.txt | 22 + .../assets/css/cbl-admin.css | 427 + .../assets/css/cbl-admin.min.css | 2 + .../assets/css/jquery-ui-timepicker-addon.css | 30 + .../css/jquery-ui-timepicker-addon.min.css | 6 + .../assets/css/smart-coupon-designs.css | 2 + .../assets/css/smart-coupon.css | 438 + .../assets/css/smart-coupon.min.css | 2 + .../assets/css/smart-coupons-admin.css | 50 + .../assets/css/smart-coupons-admin.min.css | 2 + .../assets/css/wc-sc-style-email-coupon.css | 22 + .../css/wc-sc-style-email-coupon.min.css | 2 + .../assets/images/cart-discount-alt.svg | 1 + .../assets/images/cart-discount.svg | 1 + .../assets/images/chosen-sprite.png | Bin 0 -> 592 bytes .../assets/images/chosen-sprite@2x.png | Bin 0 -> 871 bytes .../assets/images/delivery-motorcyle.svg | 1 + .../assets/images/discount-coupon.svg | 1 + .../assets/images/gift-card-alt.svg | 1 + .../assets/images/gift-voucher-credit-alt.svg | 1 + .../assets/images/giftbox-color.svg | 1 + .../images/megaphone-announce-color-alt.svg | 1 + .../assets/images/product-discount-alt.svg | 1 + .../assets/images/product-package-box.svg | 1 + .../assets/images/sale-splash-tag.svg | 1 + .../assets/images/subs-calendar-discount.svg | 1 + .../assets/images/subs-discount-voucher.svg | 1 + .../assets/js/chosen.jquery.js | 1236 +++ .../assets/js/chosen.jquery.min.js | 2 + .../assets/js/jquery-ui-timepicker-addon.js | 2355 +++++ .../js/jquery-ui-timepicker-addon.min.js | 6 + .../assets/js/sc-shortcode.js | 44 + .../blocks/blocks.php | 56 + .../blocks/build/index.asset.php | 1 + .../blocks/build/index.js | 1 + .../build/js/available-coupons/block.json | 29 + .../build/js/send-coupon-form/block.json | 28 + ...-smart-coupons-available-coupons-block.css | 1 + ...e-smart-coupons-send-coupon-form-block.css | 1 + ...available-coupons-block-frontend.asset.php | 1 + ...oupons-available-coupons-block-frontend.js | 7 + ...-coupons-available-coupons-block.asset.php | 1 + ...e-smart-coupons-available-coupons-block.js | 7 + ...-send-coupon-form-block-frontend.asset.php | 1 + ...coupons-send-coupon-form-block-frontend.js | 1 + ...t-coupons-send-coupon-form-block.asset.php | 1 + ...ce-smart-coupons-send-coupon-form-block.js | 1 + .../blocks/class-wc-sc-blocks-integration.php | 675 ++ .../class-wc-sc-extend-store-endpoint.php | 168 + .../woocommerce-smart-coupons/changelog.txt | 1923 ++++ .../class-wc-sc-gutenberg-coupon-block.php | 156 + .../includes/blocks/sc-gutenberg-block.js | 120 + .../includes/class-wc-sc-act-deact.php | 273 + ...-wc-sc-admin-coupons-dashboard-actions.php | 426 + .../class-wc-sc-admin-notifications.php | 485 + .../includes/class-wc-sc-admin-pages.php | 1659 ++++ .../includes/class-wc-sc-admin-welcome.php | 504 ++ .../includes/class-wc-sc-ajax.php | 402 + .../includes/class-wc-sc-apply-before-tax.php | 633 ++ .../class-wc-sc-auto-apply-coupon.php | 751 ++ ...class-wc-sc-background-coupon-importer.php | 1269 +++ .../class-wc-sc-background-upgrade.php | 433 + .../includes/class-wc-sc-coupon-actions.php | 865 ++ .../class-wc-sc-coupon-categories.php | 253 + .../includes/class-wc-sc-coupon-columns.php | 200 + .../includes/class-wc-sc-coupon-fields.php | 1464 +++ .../includes/class-wc-sc-coupon-import.php | 1135 +++ .../includes/class-wc-sc-coupon-message.php | 528 ++ .../includes/class-wc-sc-coupon-parser.php | 454 + .../includes/class-wc-sc-coupon-process.php | 1864 ++++ .../class-wc-sc-coupon-refund-process.php | 862 ++ .../class-wc-sc-coupons-by-excluded-email.php | 573 ++ .../class-wc-sc-coupons-by-location.php | 710 ++ .../class-wc-sc-coupons-by-payment-method.php | 420 + ...ass-wc-sc-coupons-by-product-attribute.php | 644 ++ ...lass-wc-sc-coupons-by-product-quantity.php | 1025 +++ ...class-wc-sc-coupons-by-shipping-method.php | 394 + .../class-wc-sc-coupons-by-taxonomy.php | 880 ++ .../class-wc-sc-coupons-by-user-role.php | 547 ++ .../includes/class-wc-sc-display-coupons.php | 2695 ++++++ .../includes/class-wc-sc-global-coupons.php | 347 + .../includes/class-wc-sc-order-fields.php | 602 ++ .../includes/class-wc-sc-print-coupon.php | 470 + .../includes/class-wc-sc-privacy.php | 835 ++ .../includes/class-wc-sc-product-columns.php | 258 + .../includes/class-wc-sc-product-fields.php | 524 ++ .../includes/class-wc-sc-purchase-credit.php | 1549 ++++ .../class-wc-sc-rest-coupons-controller.php | 236 + .../includes/class-wc-sc-settings.php | 1071 +++ .../includes/class-wc-sc-shortcode.php | 970 ++ .../includes/class-wc-sc-url-coupon.php | 623 ++ .../includes/class-wc-smart-coupons.php | 7844 +++++++++++++++++ .../compat/class-sa-wc-compatibility-4-4.php | 203 + .../compat/class-sa-wc-compatibility-8-7.php | 33 + .../class-wc-sc-aelia-cs-compatibility.php | 89 + .../compat/class-wc-sc-kco-compatibility.php | 140 + .../compat/class-wc-sc-pnr-compatibility.php | 107 + .../compat/class-wc-sc-wmc-compatibility.php | 88 + .../class-wc-sc-woopayments-compatibility.php | 137 + .../compat/class-wc-sc-wpml-compatibility.php | 72 + .../compat/class-wc-sc-wscp-compatibility.php | 103 + .../compat/class-wcopc-sc-compatibility.php | 166 + .../compat/class-wcs-sc-compatibility.php | 1370 +++ .../class-wc-sc-acknowledgement-email.php | 350 + .../class-wc-sc-combined-email-coupon.php | 267 + .../emails/class-wc-sc-email-coupon.php | 508 ++ .../includes/emails/class-wc-sc-email.php | 149 + .../action-scheduler/action-scheduler.php | 69 + .../libraries/action-scheduler/changelog.txt | 135 + .../classes/ActionScheduler_ActionClaim.php | 24 + .../classes/ActionScheduler_ActionFactory.php | 358 + .../classes/ActionScheduler_AdminView.php | 253 + ...tionScheduler_AsyncRequest_QueueRunner.php | 98 + .../classes/ActionScheduler_Compatibility.php | 106 + .../ActionScheduler_DataController.php | 188 + .../classes/ActionScheduler_DateTime.php | 80 + .../classes/ActionScheduler_Exception.php | 12 + .../ActionScheduler_FatalErrorMonitor.php | 56 + ...ActionScheduler_InvalidActionException.php | 48 + .../classes/ActionScheduler_ListTable.php | 671 ++ .../classes/ActionScheduler_LogEntry.php | 68 + .../classes/ActionScheduler_NullLogEntry.php | 12 + .../classes/ActionScheduler_OptionLock.php | 136 + .../classes/ActionScheduler_QueueCleaner.php | 234 + .../classes/ActionScheduler_QueueRunner.php | 230 + .../classes/ActionScheduler_Versions.php | 63 + .../ActionScheduler_WPCommentCleaner.php | 116 + .../ActionScheduler_wcSystemStatus.php | 167 + .../ActionScheduler_WPCLI_Clean_Command.php | 126 + .../ActionScheduler_WPCLI_QueueRunner.php | 198 + ...ctionScheduler_WPCLI_Scheduler_command.php | 211 + .../classes/WP_CLI/Migration_Command.php | 149 + .../classes/WP_CLI/ProgressBar.php | 120 + .../classes/abstracts/ActionScheduler.php | 338 + .../ActionScheduler_Abstract_ListTable.php | 777 ++ .../ActionScheduler_Abstract_QueueRunner.php | 373 + ...onScheduler_Abstract_RecurringSchedule.php | 103 + .../ActionScheduler_Abstract_Schedule.php | 84 + .../ActionScheduler_Abstract_Schema.php | 178 + .../abstracts/ActionScheduler_Lock.php | 65 + .../abstracts/ActionScheduler_Logger.php | 177 + .../abstracts/ActionScheduler_Store.php | 451 + .../ActionScheduler_TimezoneHelper.php | 153 + .../actions/ActionScheduler_Action.php | 136 + .../ActionScheduler_CanceledAction.php | 24 + .../ActionScheduler_FinishedAction.php | 17 + .../actions/ActionScheduler_NullAction.php | 17 + .../data-stores/ActionScheduler_DBLogger.php | 155 + .../data-stores/ActionScheduler_DBStore.php | 1181 +++ .../ActionScheduler_HybridStore.php | 427 + .../ActionScheduler_wpCommentLogger.php | 241 + .../ActionScheduler_wpPostStore.php | 1089 +++ ...eduler_wpPostStore_PostStatusRegistrar.php | 59 + ...cheduler_wpPostStore_PostTypeRegistrar.php | 51 + ...cheduler_wpPostStore_TaxonomyRegistrar.php | 27 + .../classes/migration/ActionMigrator.php | 110 + .../ActionScheduler_DBStoreMigrator.php | 48 + .../classes/migration/BatchFetcher.php | 87 + .../classes/migration/Config.php | 169 + .../classes/migration/Controller.php | 227 + .../migration/DryRun_ActionMigrator.php | 29 + .../classes/migration/DryRun_LogMigrator.php | 24 + .../classes/migration/LogMigrator.php | 50 + .../classes/migration/Runner.php | 137 + .../classes/migration/Scheduler.php | 129 + .../ActionScheduler_CanceledSchedule.php | 58 + .../ActionScheduler_CronSchedule.php | 103 + .../ActionScheduler_IntervalSchedule.php | 82 + .../ActionScheduler_NullSchedule.php | 32 + .../schedules/ActionScheduler_Schedule.php | 19 + .../ActionScheduler_SimpleSchedule.php | 72 + .../schema/ActionScheduler_LoggerSchema.php | 91 + .../schema/ActionScheduler_StoreSchema.php | 132 + ...eduler_Abstract_QueueRunner_Deprecated.php | 28 + .../ActionScheduler_AdminView_Deprecated.php | 148 + .../ActionScheduler_Schedule_Deprecated.php | 30 + .../ActionScheduler_Store_Deprecated.php | 50 + .../action-scheduler/deprecated/functions.php | 127 + .../libraries/action-scheduler/functions.php | 494 ++ .../action-scheduler/lib/WP_Async_Request.php | 192 + .../lib/cron-expression/CronExpression.php | 319 + .../CronExpression_AbstractField.php | 101 + .../CronExpression_DayOfMonthField.php | 111 + .../CronExpression_DayOfWeekField.php | 125 + .../CronExpression_FieldFactory.php | 56 + .../CronExpression_FieldInterface.php | 40 + .../CronExpression_HoursField.php | 48 + .../CronExpression_MinutesField.php | 40 + .../CronExpression_MonthField.php | 56 + .../CronExpression_YearField.php | 44 + .../lib/cron-expression/LICENSE | 19 + .../libraries/action-scheduler/license.txt | 674 ++ .../libraries/action-scheduler/readme.txt | 177 + ...e_DE-035dc61797ac8bfb6d6ed258fe72ad8c.json | 1 + ...e_DE-0fac2f3b919d34656822c41cb1ed8c2c.json | 1 + ...e_DE-88ba117fdcd48887044ec0ca59856410.json | 1 + ...e_DE-9b3491f4c368ce2ad4994aa24713559a.json | 1 + ...e_DE-b8d31255012dc50a25232a24e5b093ad.json | 1 + ...e_DE-d811137fe50d78464704a484441a64be.json | 1 + ...e_DE-fd0f2ef4bb9ad5ddc0e7e6898a11a573.json | 1 + .../woocommerce-smart-coupons-de_DE.mo | Bin 0 -> 5003 bytes .../woocommerce-smart-coupons-de_DE.po | 4549 ++++++++++ ...r_FR-035dc61797ac8bfb6d6ed258fe72ad8c.json | 1 + ...r_FR-0fac2f3b919d34656822c41cb1ed8c2c.json | 1 + ...r_FR-88ba117fdcd48887044ec0ca59856410.json | 1 + ...r_FR-9b3491f4c368ce2ad4994aa24713559a.json | 1 + ...r_FR-b8d31255012dc50a25232a24e5b093ad.json | 1 + ...r_FR-d811137fe50d78464704a484441a64be.json | 1 + ...r_FR-fd0f2ef4bb9ad5ddc0e7e6898a11a573.json | 1 + .../woocommerce-smart-coupons-fr_FR.mo | Bin 0 -> 89265 bytes .../woocommerce-smart-coupons-fr_FR.po | 4557 ++++++++++ .../languages/woocommerce-smart-coupons.pot | 4548 ++++++++++ .../woocommerce-smart-coupons/readme.txt | 66 + .../woocommerce-smart-coupons/sample.csv | 9 + .../templates/acknowledgement-email.php | 81 + .../templates/call-for-credit-form.php | 37 + .../templates/combined-email.php | 253 + .../templates/coupon-design/basic.php | 48 + .../templates/coupon-design/clipper.php | 47 + .../templates/coupon-design/custom-design.php | 61 + .../templates/coupon-design/cutout.php | 67 + .../templates/coupon-design/deal.php | 44 + .../templates/coupon-design/deliver.php | 44 + .../templates/coupon-design/email-coupon.php | 67 + .../templates/coupon-design/festive.php | 88 + .../templates/coupon-design/flat.php | 64 + .../templates/coupon-design/promotion.php | 76 + .../templates/coupon-design/shipment.php | 66 + .../templates/coupon-design/special.php | 67 + .../templates/coupon-design/ticket.php | 53 + .../templates/email.php | 235 + .../templates/plain/acknowledgement-email.php | 61 + .../templates/plain/combined-email.php | 139 + .../templates/plain/email.php | 132 + .../templates/print-coupons-default.php | 213 + .../woocommerce-smart-coupons.php | 95 + .../woocommerce-smart-coupons/wpml-config.xml | 15 + 237 files changed, 79624 insertions(+) create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/assets/MIT-license-jquery-ui-timepicker-addon.txt create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/assets/css/cbl-admin.css create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/assets/css/cbl-admin.min.css create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/assets/css/jquery-ui-timepicker-addon.css create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/assets/css/jquery-ui-timepicker-addon.min.css create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/assets/css/smart-coupon-designs.css create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/assets/css/smart-coupon.css create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/assets/css/smart-coupon.min.css create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/assets/css/smart-coupons-admin.css create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/assets/css/smart-coupons-admin.min.css create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/assets/css/wc-sc-style-email-coupon.css create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/assets/css/wc-sc-style-email-coupon.min.css create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/cart-discount-alt.svg create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/cart-discount.svg create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/chosen-sprite.png create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/chosen-sprite@2x.png create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/delivery-motorcyle.svg create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/discount-coupon.svg create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/gift-card-alt.svg create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/gift-voucher-credit-alt.svg create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/giftbox-color.svg create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/megaphone-announce-color-alt.svg create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/product-discount-alt.svg create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/product-package-box.svg create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/sale-splash-tag.svg create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/subs-calendar-discount.svg create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/subs-discount-voucher.svg create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/assets/js/chosen.jquery.js create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/assets/js/chosen.jquery.min.js create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/assets/js/jquery-ui-timepicker-addon.js create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/assets/js/jquery-ui-timepicker-addon.min.js create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/assets/js/sc-shortcode.js create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/blocks/blocks.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/blocks/build/index.asset.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/blocks/build/index.js create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/blocks/build/js/available-coupons/block.json create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/blocks/build/js/send-coupon-form/block.json create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/blocks/build/style-woocommerce-smart-coupons-available-coupons-block.css create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/blocks/build/style-woocommerce-smart-coupons-send-coupon-form-block.css create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/blocks/build/woocommerce-smart-coupons-available-coupons-block-frontend.asset.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/blocks/build/woocommerce-smart-coupons-available-coupons-block-frontend.js create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/blocks/build/woocommerce-smart-coupons-available-coupons-block.asset.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/blocks/build/woocommerce-smart-coupons-available-coupons-block.js create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/blocks/build/woocommerce-smart-coupons-send-coupon-form-block-frontend.asset.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/blocks/build/woocommerce-smart-coupons-send-coupon-form-block-frontend.js create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/blocks/build/woocommerce-smart-coupons-send-coupon-form-block.asset.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/blocks/build/woocommerce-smart-coupons-send-coupon-form-block.js create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/blocks/class-wc-sc-blocks-integration.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/blocks/class-wc-sc-extend-store-endpoint.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/changelog.txt create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/blocks/class-wc-sc-gutenberg-coupon-block.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/blocks/sc-gutenberg-block.js create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-act-deact.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-admin-coupons-dashboard-actions.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-admin-notifications.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-admin-pages.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-admin-welcome.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-ajax.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-apply-before-tax.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-auto-apply-coupon.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-background-coupon-importer.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-background-upgrade.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupon-actions.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupon-categories.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupon-columns.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupon-fields.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupon-import.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupon-message.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupon-parser.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupon-process.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupon-refund-process.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupons-by-excluded-email.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupons-by-location.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupons-by-payment-method.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupons-by-product-attribute.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupons-by-product-quantity.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupons-by-shipping-method.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupons-by-taxonomy.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupons-by-user-role.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-display-coupons.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-global-coupons.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-order-fields.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-print-coupon.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-privacy.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-product-columns.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-product-fields.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-purchase-credit.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-rest-coupons-controller.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-settings.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-shortcode.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-url-coupon.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-smart-coupons.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/compat/class-sa-wc-compatibility-4-4.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/compat/class-sa-wc-compatibility-8-7.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/compat/class-wc-sc-aelia-cs-compatibility.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/compat/class-wc-sc-kco-compatibility.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/compat/class-wc-sc-pnr-compatibility.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/compat/class-wc-sc-wmc-compatibility.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/compat/class-wc-sc-woopayments-compatibility.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/compat/class-wc-sc-wpml-compatibility.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/compat/class-wc-sc-wscp-compatibility.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/compat/class-wcopc-sc-compatibility.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/compat/class-wcs-sc-compatibility.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/emails/class-wc-sc-acknowledgement-email.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/emails/class-wc-sc-combined-email-coupon.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/emails/class-wc-sc-email-coupon.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/emails/class-wc-sc-email.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/action-scheduler.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/changelog.txt create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_ActionClaim.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_ActionFactory.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_AdminView.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_AsyncRequest_QueueRunner.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_Compatibility.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_DataController.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_DateTime.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_Exception.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_FatalErrorMonitor.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_InvalidActionException.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_ListTable.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_LogEntry.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_NullLogEntry.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_OptionLock.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_QueueCleaner.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_QueueRunner.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_Versions.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_WPCommentCleaner.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_wcSystemStatus.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/WP_CLI/ActionScheduler_WPCLI_Clean_Command.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/WP_CLI/ActionScheduler_WPCLI_QueueRunner.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/WP_CLI/ActionScheduler_WPCLI_Scheduler_command.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/WP_CLI/Migration_Command.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/WP_CLI/ProgressBar.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_ListTable.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_QueueRunner.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_RecurringSchedule.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_Schedule.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_Schema.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Lock.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Logger.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Store.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_TimezoneHelper.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/actions/ActionScheduler_Action.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/actions/ActionScheduler_CanceledAction.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/actions/ActionScheduler_FinishedAction.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/actions/ActionScheduler_NullAction.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_DBLogger.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_DBStore.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_HybridStore.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpCommentLogger.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpPostStore.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpPostStore_PostStatusRegistrar.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpPostStore_PostTypeRegistrar.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpPostStore_TaxonomyRegistrar.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/migration/ActionMigrator.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/migration/ActionScheduler_DBStoreMigrator.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/migration/BatchFetcher.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/migration/Config.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/migration/Controller.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/migration/DryRun_ActionMigrator.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/migration/DryRun_LogMigrator.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/migration/LogMigrator.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/migration/Runner.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/migration/Scheduler.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/schedules/ActionScheduler_CanceledSchedule.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/schedules/ActionScheduler_CronSchedule.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/schedules/ActionScheduler_IntervalSchedule.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/schedules/ActionScheduler_NullSchedule.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/schedules/ActionScheduler_Schedule.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/schedules/ActionScheduler_SimpleSchedule.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/schema/ActionScheduler_LoggerSchema.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/schema/ActionScheduler_StoreSchema.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/deprecated/ActionScheduler_Abstract_QueueRunner_Deprecated.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/deprecated/ActionScheduler_AdminView_Deprecated.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/deprecated/ActionScheduler_Schedule_Deprecated.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/deprecated/ActionScheduler_Store_Deprecated.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/deprecated/functions.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/functions.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/lib/WP_Async_Request.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/lib/cron-expression/CronExpression.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_AbstractField.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_DayOfMonthField.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_DayOfWeekField.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_FieldFactory.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_FieldInterface.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_HoursField.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_MinutesField.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_MonthField.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_YearField.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/lib/cron-expression/LICENSE create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/license.txt create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/readme.txt create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-de_DE-035dc61797ac8bfb6d6ed258fe72ad8c.json create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-de_DE-0fac2f3b919d34656822c41cb1ed8c2c.json create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-de_DE-88ba117fdcd48887044ec0ca59856410.json create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-de_DE-9b3491f4c368ce2ad4994aa24713559a.json create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-de_DE-b8d31255012dc50a25232a24e5b093ad.json create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-de_DE-d811137fe50d78464704a484441a64be.json create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-de_DE-fd0f2ef4bb9ad5ddc0e7e6898a11a573.json create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-de_DE.mo create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-de_DE.po create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-fr_FR-035dc61797ac8bfb6d6ed258fe72ad8c.json create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-fr_FR-0fac2f3b919d34656822c41cb1ed8c2c.json create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-fr_FR-88ba117fdcd48887044ec0ca59856410.json create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-fr_FR-9b3491f4c368ce2ad4994aa24713559a.json create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-fr_FR-b8d31255012dc50a25232a24e5b093ad.json create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-fr_FR-d811137fe50d78464704a484441a64be.json create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-fr_FR-fd0f2ef4bb9ad5ddc0e7e6898a11a573.json create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-fr_FR.mo create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-fr_FR.po create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons.pot create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/readme.txt create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/sample.csv create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/templates/acknowledgement-email.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/templates/call-for-credit-form.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/templates/combined-email.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/basic.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/clipper.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/custom-design.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/cutout.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/deal.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/deliver.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/email-coupon.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/festive.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/flat.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/promotion.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/shipment.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/special.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/ticket.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/templates/email.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/templates/plain/acknowledgement-email.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/templates/plain/combined-email.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/templates/plain/email.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/templates/print-coupons-default.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/woocommerce-smart-coupons.php create mode 100644 wp/wp-content/plugins/woocommerce-smart-coupons/wpml-config.xml diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/assets/MIT-license-jquery-ui-timepicker-addon.txt b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/MIT-license-jquery-ui-timepicker-addon.txt new file mode 100644 index 00000000..957a11c7 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/MIT-license-jquery-ui-timepicker-addon.txt @@ -0,0 +1,22 @@ +Copyright (c) 2013 Trent Richardson + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/assets/css/cbl-admin.css b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/css/cbl-admin.css new file mode 100644 index 00000000..3e320e00 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/css/cbl-admin.css @@ -0,0 +1,427 @@ +/* Coupons By Location styles */ +span.search label{ + font-size: 1em !important; + float:left !important; +} + +label.billing{ + width: 75px !important; + margin-left: 1px !important; +} + +label.shipping{ + margin-left: 0px !important; +} + +.chosen-container-multi .chosen-choices .search-field input{ + height: 21px !important; +} + +/*============================== +CHOSEN CSS - Added from woo 2.6 +================================*/ + +.chosen-container { + position: relative; + display: inline-block; + vertical-align: middle; + font-size: 13px; + zoom: 1; + user-select: none +} +.chosen-container .chosen-drop { + position: absolute; + top: 100%; + left: -9999px; + z-index: 1010; + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + box-sizing: border-box; + width: 100%; + border: 1px solid #aaa; + border-top: 0; + background: #fff; + box-shadow: 0 4px 5px rgba(0, 0, 0, .15) +} +.chosen-container.chosen-with-drop .chosen-drop { + left: 0 +} +.chosen-container a { + cursor: pointer +} +.chosen-container-single .chosen-single { + position: relative; + display: block; + overflow: hidden; + padding: 0 0 0 8px; + height: 26px; + border: 1px solid #aaa; + border-radius: 5px; + background-color: #fff; + background: -webkit-gradient(linear, 50% 0, 50% 100%, color-stop(20%, #fff), color-stop(50%, #f6f6f6), color-stop(52%, #eee), color-stop(100%, #f4f4f4)); + background: -webkit-linear-gradient(top, #fff 20%, #f6f6f6 50%, #eee 52%, #f4f4f4 100%); + background: -moz-linear-gradient(top, #fff 20%, #f6f6f6 50%, #eee 52%, #f4f4f4 100%); + background: -o-linear-gradient(top, #fff 20%, #f6f6f6 50%, #eee 52%, #f4f4f4 100%); + background: linear-gradient(top, #fff 20%, #f6f6f6 50%, #eee 52%, #f4f4f4 100%); + background-clip: padding-box; + box-shadow: 0 0 3px #fff inset, 0 1px 1px rgba(0, 0, 0, .1); + color: #444; + text-decoration: none; + white-space: nowrap; + line-height: 26px +} +.chosen-container-single .chosen-default { + color: #999 +} +.chosen-container-single .chosen-single span { + display: block; + overflow: hidden; + margin-right: 26px; + text-overflow: ellipsis; + white-space: nowrap +} +.chosen-container-single .chosen-single-with-deselect span { + margin-right: 38px +} +.chosen-container-single .chosen-single abbr { + position: absolute; + top: 6px; + right: 26px; + display: block; + width: 12px; + height: 12px; + background: url(../images/chosen-sprite.png) -42px 1px no-repeat; + font-size: 1px +} +.chosen-container-single .chosen-single abbr:hover, +.chosen-container-single.chosen-disabled .chosen-single abbr:hover { + background-position: -42px -10px +} +.chosen-container-single .chosen-single div { + position: absolute; + top: 0; + right: 0; + display: block; + width: 18px; + height: 100% +} +.chosen-container-single .chosen-single div b { + display: block; + width: 100%; + height: 100%; + background: url(../images/chosen-sprite.png) 0 2px no-repeat +} +.chosen-container-single .chosen-search { + position: relative; + z-index: 1010; + margin: 0; + padding: 3px 4px; + white-space: nowrap +} +.chosen-container-single .chosen-search input[type=text] { + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + box-sizing: border-box; + margin: 1px 0; + padding: 4px 20px 4px 5px; + width: 100%; + height: auto; + outline: 0; + border: 1px solid #aaa; + background: url(../images/chosen-sprite.png) 100% -20px no-repeat #fff; + background: url(../images/chosen-sprite.png) 100% -20px no-repeat, -webkit-gradient(linear, 50% 0, 50% 100%, color-stop(1%, #eee), color-stop(15%, #fff)); + background: url(../images/chosen-sprite.png) 100% -20px no-repeat, -webkit-linear-gradient(#eee 1%, #fff 15%); + background: url(../images/chosen-sprite.png) 100% -20px no-repeat, -moz-linear-gradient(#eee 1%, #fff 15%); + background: url(../images/chosen-sprite.png) 100% -20px no-repeat, -o-linear-gradient(#eee 1%, #fff 15%); + background: url(../images/chosen-sprite.png) 100% -20px no-repeat, linear-gradient(#eee 1%, #fff 15%); + font-size: 1em; + font-family: sans-serif; + line-height: normal; + border-radius: 0 +} +.chosen-container-single .chosen-drop { + margin-top: -1px; + border-radius: 0 0 4px 4px; + background-clip: padding-box +} +.chosen-container-single.chosen-container-single-nosearch .chosen-search { + position: absolute; + left: -9999px +} +.chosen-container .chosen-results { + position: relative; + overflow-x: hidden; + overflow-y: auto; + margin: 0 4px 4px 0; + padding: 0 0 0 4px; + max-height: 240px; + -webkit-overflow-scrolling: touch +} +.chosen-container .chosen-results li { + display: none; + margin: 0; + padding: 5px 6px; + list-style: none; + line-height: 15px +} +.chosen-container .chosen-results li.active-result { + display: list-item; + cursor: pointer +} +.chosen-container .chosen-results li.disabled-result { + display: list-item; + color: #ccc; + cursor: default +} +.chosen-container .chosen-results li.highlighted { + background-color: #3875d7; + background-image: -webkit-gradient(linear, 50% 0, 50% 100%, color-stop(20%, #3875d7), color-stop(90%, #2a62bc)); + background-image: -webkit-linear-gradient(#3875d7 20%, #2a62bc 90%); + background-image: -moz-linear-gradient(#3875d7 20%, #2a62bc 90%); + background-image: -o-linear-gradient(#3875d7 20%, #2a62bc 90%); + background-image: linear-gradient(#3875d7 20%, #2a62bc 90%); + color: #fff +} +.chosen-container .chosen-results li.no-results { + display: list-item; + background: #f4f4f4 +} +.chosen-container .chosen-results li.group-result { + display: list-item; + font-weight: 700; + cursor: default +} +.chosen-container .chosen-results li.group-option { + padding-left: 15px +} +.chosen-container .chosen-results li em { + font-style: normal; + text-decoration: underline +} +.chosen-container-multi .chosen-choices { + position: relative; + overflow: hidden; + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + box-sizing: border-box; + margin: 0; + padding: 0; + width: 100%; + height: auto!important; + height: 1%; + border: 1px solid #aaa; + background-color: #fff; + background-image: -webkit-gradient(linear, 50% 0, 50% 100%, color-stop(1%, #eee), color-stop(15%, #fff)); + background-image: -webkit-linear-gradient(#eee 1%, #fff 15%); + background-image: -moz-linear-gradient(#eee 1%, #fff 15%); + background-image: -o-linear-gradient(#eee 1%, #fff 15%); + background-image: linear-gradient(#eee 1%, #fff 15%); + cursor: text +} +.chosen-container-multi .chosen-choices li { + float: left; + list-style: none +} +.chosen-container-multi .chosen-choices li.search-field { + margin: 0; + padding: 0; + white-space: nowrap +} +.chosen-container-multi .chosen-choices li.search-field input[type=text] { + margin: 1px 0; + padding: 5px; + height: 15px; + outline: 0; + border: 0!important; + background: 0 0!important; + box-shadow: none; + color: #666; + font-size: 100%; + font-family: sans-serif; + line-height: normal; + border-radius: 0 +} +.chosen-container-multi .chosen-choices li.search-field .default { + color: #999 +} +.chosen-container-multi .chosen-choices li.search-choice { + position: relative; + margin: 3px 0 3px 5px; + padding: 3px 20px 3px 5px; + border: 1px solid #aaa; + border-radius: 3px; + background-color: #e4e4e4; + background-image: -webkit-gradient(linear, 50% 0, 50% 100%, color-stop(20%, #f4f4f4), color-stop(50%, #f0f0f0), color-stop(52%, #e8e8e8), color-stop(100%, #eee)); + background-image: -webkit-linear-gradient(#f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eee 100%); + background-image: -moz-linear-gradient(#f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eee 100%); + background-image: -o-linear-gradient(#f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eee 100%); + background-image: linear-gradient(#f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eee 100%); + background-clip: padding-box; + box-shadow: 0 0 2px #fff inset, 0 1px 0 rgba(0, 0, 0, .05); + color: #333; + line-height: 13px; + cursor: default +} +.chosen-container-multi .chosen-choices li.search-choice .search-choice-close { + position: absolute; + top: 4px; + right: 3px; + display: block; + width: 12px; + height: 12px; + background: url(../images/chosen-sprite.png) -42px 1px no-repeat; + font-size: 1px +} +.chosen-container-multi .chosen-choices li.search-choice .search-choice-close:hover { + background-position: -42px -10px +} +.chosen-container-multi .chosen-choices li.search-choice-disabled { + padding-right: 5px; + border: 1px solid #ccc; + background-color: #e4e4e4; + background-image: -webkit-gradient(linear, 50% 0, 50% 100%, color-stop(20%, #f4f4f4), color-stop(50%, #f0f0f0), color-stop(52%, #e8e8e8), color-stop(100%, #eee)); + background-image: -webkit-linear-gradient(top, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eee 100%); + background-image: -moz-linear-gradient(top, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eee 100%); + background-image: -o-linear-gradient(top, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eee 100%); + background-image: linear-gradient(top, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eee 100%); + color: #666 +} +.chosen-container-multi .chosen-choices li.search-choice-focus { + background: #d4d4d4 +} +.chosen-container-multi .chosen-choices li.search-choice-focus .search-choice-close { + background-position: -42px -10px +} +.chosen-container-multi .chosen-results { + margin: 0; + padding: 0 +} +.chosen-container-multi .chosen-drop .result-selected { + display: list-item; + color: #ccc; + cursor: default +} +.chosen-container-active .chosen-single { + border: 1px solid #5897fb; + box-shadow: 0 0 5px rgba(0, 0, 0, .3) +} +.chosen-container-active.chosen-with-drop .chosen-single { + border: 1px solid #aaa; + -moz-border-radius-bottomright: 0; + border-bottom-right-radius: 0; + -moz-border-radius-bottomleft: 0; + border-bottom-left-radius: 0; + background-image: -webkit-gradient(linear, 50% 0, 50% 100%, color-stop(20%, #eee), color-stop(80%, #fff)); + background-image: -webkit-linear-gradient(#eee 20%, #fff 80%); + background-image: -moz-linear-gradient(#eee 20%, #fff 80%); + background-image: -o-linear-gradient(#eee 20%, #fff 80%); + background-image: linear-gradient(#eee 20%, #fff 80%); + box-shadow: 0 1px 0 #fff inset +} +.chosen-container-active.chosen-with-drop .chosen-single div { + border-left: none; + background: 0 0 +} +.chosen-container-active.chosen-with-drop .chosen-single div b { + background-position: -18px 2px +} +.chosen-container-active .chosen-choices { + border: 1px solid #5897fb; + box-shadow: 0 0 5px rgba(0, 0, 0, .3) +} +.chosen-container-active .chosen-choices li.search-field input[type=text] { + color: #111!important +} +.chosen-disabled { + opacity: .5!important; + cursor: default +} +.chosen-disabled .chosen-choices .search-choice .search-choice-close, +.chosen-disabled .chosen-single { + cursor: default +} +.chosen-rtl { + text-align: right +} +.chosen-rtl .chosen-single { + overflow: visible; + padding: 0 8px 0 0 +} +.chosen-rtl .chosen-single span { + margin-right: 0; + margin-left: 26px; + direction: rtl +} +.chosen-rtl .chosen-single-with-deselect span { + margin-left: 38px +} +.chosen-rtl .chosen-single div { + right: auto; + left: 3px +} +.chosen-rtl .chosen-single abbr { + right: auto; + left: 26px +} +.chosen-rtl .chosen-choices li { + float: right +} +.chosen-rtl .chosen-choices li.search-field input[type=text] { + direction: rtl +} +.chosen-rtl .chosen-choices li.search-choice { + margin: 3px 5px 3px 0; + padding: 3px 5px 3px 19px +} +.chosen-rtl .chosen-choices li.search-choice .search-choice-close { + right: auto; + left: 4px +} +.chosen-rtl .chosen-drop, +.chosen-rtl.chosen-container-single-nosearch .chosen-search { + left: 9999px +} +.chosen-rtl.chosen-container-single .chosen-results { + margin: 0 0 4px 4px; + padding: 0 4px 0 0 +} +.chosen-rtl .chosen-results li.group-option { + padding-right: 15px; + padding-left: 0 +} +.chosen-rtl.chosen-container-active.chosen-with-drop .chosen-single div { + border-right: none +} +.chosen-rtl .chosen-search input[type=text] { + padding: 4px 5px 4px 20px; + background: url(../images/chosen-sprite.png) -30px -20px no-repeat #fff; + background: url(../images/chosen-sprite.png) -30px -20px no-repeat, -webkit-gradient(linear, 50% 0, 50% 100%, color-stop(1%, #eee), color-stop(15%, #fff)); + background: url(../images/chosen-sprite.png) -30px -20px no-repeat, -webkit-linear-gradient(#eee 1%, #fff 15%); + background: url(../images/chosen-sprite.png) -30px -20px no-repeat, -moz-linear-gradient(#eee 1%, #fff 15%); + background: url(../images/chosen-sprite.png) -30px -20px no-repeat, -o-linear-gradient(#eee 1%, #fff 15%); + background: url(../images/chosen-sprite.png) -30px -20px no-repeat, linear-gradient(#eee 1%, #fff 15%); + direction: rtl +} +.chosen-rtl.chosen-container-single .chosen-single div b { + background-position: 6px 2px +} +.chosen-rtl.chosen-container-single.chosen-with-drop .chosen-single div b { + background-position: -12px 2px +} +@media only screen and (-webkit-min-device-pixel-ratio: 2), +only screen and (min-resolution: 144dpi) { + .chosen-container .chosen-results-scroll-down span, + .chosen-container .chosen-results-scroll-up span, + .chosen-container-multi .chosen-choices .search-choice .search-choice-close, + .chosen-container-single .chosen-search input[type=text], + .chosen-container-single .chosen-single abbr, + .chosen-container-single .chosen-single div b, + .chosen-rtl .chosen-search input[type=text] { + background-image: url(../images/chosen-sprite@2x.png)!important; + background-size: 52px 37px!important; + background-repeat: no-repeat!important + } +} +#cc_list_chosen .search-field input { + width: 100% !important; +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/assets/css/cbl-admin.min.css b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/css/cbl-admin.min.css new file mode 100644 index 00000000..ae867f4f --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/css/cbl-admin.min.css @@ -0,0 +1,2 @@ +/* phpcs:ignoreFile */ +span.search label{font-size:1em !important;float:left !important}label.billing{width:75px !important;margin-left:1px !important}label.shipping{margin-left:0 !important}.chosen-container-multi .chosen-choices .search-field input{height:21px !important}.chosen-container{position:relative;display:inline-block;vertical-align:middle;font-size:13px;zoom:1;user-select:none}.chosen-container .chosen-drop{position:absolute;top:100%;left:-9999px;z-index:1010;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;width:100%;border:1px solid #aaa;border-top:0;background:#fff;box-shadow:0 4px 5px rgba(0,0,0,.15)}.chosen-container.chosen-with-drop .chosen-drop{left:0}.chosen-container a{cursor:pointer}.chosen-container-single .chosen-single{position:relative;display:block;overflow:hidden;padding:0 0 0 8px;height:26px;border:1px solid #aaa;border-radius:5px;background-color:#fff;background:-webkit-gradient(linear,50% 0,50% 100%,color-stop(20%,#fff),color-stop(50%,#f6f6f6),color-stop(52%,#eee),color-stop(100%,#f4f4f4));background:-webkit-linear-gradient(top,#fff 20%,#f6f6f6 50%,#eee 52%,#f4f4f4 100%);background:-moz-linear-gradient(top,#fff 20%,#f6f6f6 50%,#eee 52%,#f4f4f4 100%);background:-o-linear-gradient(top,#fff 20%,#f6f6f6 50%,#eee 52%,#f4f4f4 100%);background:linear-gradient(top,#fff 20%,#f6f6f6 50%,#eee 52%,#f4f4f4 100%);background-clip:padding-box;box-shadow:0 0 3px #fff inset,0 1px 1px rgba(0,0,0,.1);color:#444;text-decoration:none;white-space:nowrap;line-height:26px}.chosen-container-single .chosen-default{color:#999}.chosen-container-single .chosen-single span{display:block;overflow:hidden;margin-right:26px;text-overflow:ellipsis;white-space:nowrap}.chosen-container-single .chosen-single-with-deselect span{margin-right:38px}.chosen-container-single .chosen-single abbr{position:absolute;top:6px;right:26px;display:block;width:12px;height:12px;background:url(../images/chosen-sprite.png) -42px 1px no-repeat;font-size:1px}.chosen-container-single .chosen-single abbr:hover,.chosen-container-single.chosen-disabled .chosen-single abbr:hover{background-position:-42px -10px}.chosen-container-single .chosen-single div{position:absolute;top:0;right:0;display:block;width:18px;height:100%}.chosen-container-single .chosen-single div b{display:block;width:100%;height:100%;background:url(../images/chosen-sprite.png) 0 2px no-repeat}.chosen-container-single .chosen-search{position:relative;z-index:1010;margin:0;padding:3px 4px;white-space:nowrap}.chosen-container-single .chosen-search input[type=text]{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;margin:1px 0;padding:4px 20px 4px 5px;width:100%;height:auto;outline:0;border:1px solid #aaa;background:url(../images/chosen-sprite.png) 100% -20px no-repeat #fff;background:url(../images/chosen-sprite.png) 100% -20px no-repeat,-webkit-gradient(linear,50% 0,50% 100%,color-stop(1%,#eee),color-stop(15%,#fff));background:url(../images/chosen-sprite.png) 100% -20px no-repeat,-webkit-linear-gradient(#eee 1%,#fff 15%);background:url(../images/chosen-sprite.png) 100% -20px no-repeat,-moz-linear-gradient(#eee 1%,#fff 15%);background:url(../images/chosen-sprite.png) 100% -20px no-repeat,-o-linear-gradient(#eee 1%,#fff 15%);background:url(../images/chosen-sprite.png) 100% -20px no-repeat,linear-gradient(#eee 1%,#fff 15%);font-size:1em;font-family:sans-serif;line-height:normal;border-radius:0}.chosen-container-single .chosen-drop{margin-top:-1px;border-radius:0 0 4px 4px;background-clip:padding-box}.chosen-container-single.chosen-container-single-nosearch .chosen-search{position:absolute;left:-9999px}.chosen-container .chosen-results{position:relative;overflow-x:hidden;overflow-y:auto;margin:0 4px 4px 0;padding:0 0 0 4px;max-height:240px;-webkit-overflow-scrolling:touch}.chosen-container .chosen-results li{display:none;margin:0;padding:5px 6px;list-style:none;line-height:15px}.chosen-container .chosen-results li.active-result{display:list-item;cursor:pointer}.chosen-container .chosen-results li.disabled-result{display:list-item;color:#ccc;cursor:default}.chosen-container .chosen-results li.highlighted{background-color:#3875d7;background-image:-webkit-gradient(linear,50% 0,50% 100%,color-stop(20%,#3875d7),color-stop(90%,#2a62bc));background-image:-webkit-linear-gradient(#3875d7 20%,#2a62bc 90%);background-image:-moz-linear-gradient(#3875d7 20%,#2a62bc 90%);background-image:-o-linear-gradient(#3875d7 20%,#2a62bc 90%);background-image:linear-gradient(#3875d7 20%,#2a62bc 90%);color:#fff}.chosen-container .chosen-results li.no-results{display:list-item;background:#f4f4f4}.chosen-container .chosen-results li.group-result{display:list-item;font-weight:700;cursor:default}.chosen-container .chosen-results li.group-option{padding-left:15px}.chosen-container .chosen-results li em{font-style:normal;text-decoration:underline}.chosen-container-multi .chosen-choices{position:relative;overflow:hidden;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;margin:0;padding:0;width:100%;height:auto !important;height:1%;border:1px solid #aaa;background-color:#fff;background-image:-webkit-gradient(linear,50% 0,50% 100%,color-stop(1%,#eee),color-stop(15%,#fff));background-image:-webkit-linear-gradient(#eee 1%,#fff 15%);background-image:-moz-linear-gradient(#eee 1%,#fff 15%);background-image:-o-linear-gradient(#eee 1%,#fff 15%);background-image:linear-gradient(#eee 1%,#fff 15%);cursor:text}.chosen-container-multi .chosen-choices li{float:left;list-style:none}.chosen-container-multi .chosen-choices li.search-field{margin:0;padding:0;white-space:nowrap}.chosen-container-multi .chosen-choices li.search-field input[type=text]{margin:1px 0;padding:5px;height:15px;outline:0;border:0 !important;background:0 0 !important;box-shadow:none;color:#666;font-size:100%;font-family:sans-serif;line-height:normal;border-radius:0}.chosen-container-multi .chosen-choices li.search-field .default{color:#999}.chosen-container-multi .chosen-choices li.search-choice{position:relative;margin:3px 0 3px 5px;padding:3px 20px 3px 5px;border:1px solid #aaa;border-radius:3px;background-color:#e4e4e4;background-image:-webkit-gradient(linear,50% 0,50% 100%,color-stop(20%,#f4f4f4),color-stop(50%,#f0f0f0),color-stop(52%,#e8e8e8),color-stop(100%,#eee));background-image:-webkit-linear-gradient(#f4f4f4 20%,#f0f0f0 50%,#e8e8e8 52%,#eee 100%);background-image:-moz-linear-gradient(#f4f4f4 20%,#f0f0f0 50%,#e8e8e8 52%,#eee 100%);background-image:-o-linear-gradient(#f4f4f4 20%,#f0f0f0 50%,#e8e8e8 52%,#eee 100%);background-image:linear-gradient(#f4f4f4 20%,#f0f0f0 50%,#e8e8e8 52%,#eee 100%);background-clip:padding-box;box-shadow:0 0 2px #fff inset,0 1px 0 rgba(0,0,0,.05);color:#333;line-height:13px;cursor:default}.chosen-container-multi .chosen-choices li.search-choice .search-choice-close{position:absolute;top:4px;right:3px;display:block;width:12px;height:12px;background:url(../images/chosen-sprite.png) -42px 1px no-repeat;font-size:1px}.chosen-container-multi .chosen-choices li.search-choice .search-choice-close:hover{background-position:-42px -10px}.chosen-container-multi .chosen-choices li.search-choice-disabled{padding-right:5px;border:1px solid #ccc;background-color:#e4e4e4;background-image:-webkit-gradient(linear,50% 0,50% 100%,color-stop(20%,#f4f4f4),color-stop(50%,#f0f0f0),color-stop(52%,#e8e8e8),color-stop(100%,#eee));background-image:-webkit-linear-gradient(top,#f4f4f4 20%,#f0f0f0 50%,#e8e8e8 52%,#eee 100%);background-image:-moz-linear-gradient(top,#f4f4f4 20%,#f0f0f0 50%,#e8e8e8 52%,#eee 100%);background-image:-o-linear-gradient(top,#f4f4f4 20%,#f0f0f0 50%,#e8e8e8 52%,#eee 100%);background-image:linear-gradient(top,#f4f4f4 20%,#f0f0f0 50%,#e8e8e8 52%,#eee 100%);color:#666}.chosen-container-multi .chosen-choices li.search-choice-focus{background:#d4d4d4}.chosen-container-multi .chosen-choices li.search-choice-focus .search-choice-close{background-position:-42px -10px}.chosen-container-multi .chosen-results{margin:0;padding:0}.chosen-container-multi .chosen-drop .result-selected{display:list-item;color:#ccc;cursor:default}.chosen-container-active .chosen-single{border:1px solid #5897fb;box-shadow:0 0 5px rgba(0,0,0,.3)}.chosen-container-active.chosen-with-drop .chosen-single{border:1px solid #aaa;-moz-border-radius-bottomright:0;border-bottom-right-radius:0;-moz-border-radius-bottomleft:0;border-bottom-left-radius:0;background-image:-webkit-gradient(linear,50% 0,50% 100%,color-stop(20%,#eee),color-stop(80%,#fff));background-image:-webkit-linear-gradient(#eee 20%,#fff 80%);background-image:-moz-linear-gradient(#eee 20%,#fff 80%);background-image:-o-linear-gradient(#eee 20%,#fff 80%);background-image:linear-gradient(#eee 20%,#fff 80%);box-shadow:0 1px 0 #fff inset}.chosen-container-active.chosen-with-drop .chosen-single div{border-left:0;background:0}.chosen-container-active.chosen-with-drop .chosen-single div b{background-position:-18px 2px}.chosen-container-active .chosen-choices{border:1px solid #5897fb;box-shadow:0 0 5px rgba(0,0,0,.3)}.chosen-container-active .chosen-choices li.search-field input[type=text]{color:#111 !important}.chosen-disabled{opacity:.5 !important;cursor:default}.chosen-disabled .chosen-choices .search-choice .search-choice-close,.chosen-disabled .chosen-single{cursor:default}.chosen-rtl{text-align:right}.chosen-rtl .chosen-single{overflow:visible;padding:0 8px 0 0}.chosen-rtl .chosen-single span{margin-right:0;margin-left:26px;direction:rtl}.chosen-rtl .chosen-single-with-deselect span{margin-left:38px}.chosen-rtl .chosen-single div{right:auto;left:3px}.chosen-rtl .chosen-single abbr{right:auto;left:26px}.chosen-rtl .chosen-choices li{float:right}.chosen-rtl .chosen-choices li.search-field input[type=text]{direction:rtl}.chosen-rtl .chosen-choices li.search-choice{margin:3px 5px 3px 0;padding:3px 5px 3px 19px}.chosen-rtl .chosen-choices li.search-choice .search-choice-close{right:auto;left:4px}.chosen-rtl .chosen-drop,.chosen-rtl.chosen-container-single-nosearch .chosen-search{left:9999px}.chosen-rtl.chosen-container-single .chosen-results{margin:0 0 4px 4px;padding:0 4px 0 0}.chosen-rtl .chosen-results li.group-option{padding-right:15px;padding-left:0}.chosen-rtl.chosen-container-active.chosen-with-drop .chosen-single div{border-right:0}.chosen-rtl .chosen-search input[type=text]{padding:4px 5px 4px 20px;background:url(../images/chosen-sprite.png) -30px -20px no-repeat #fff;background:url(../images/chosen-sprite.png) -30px -20px no-repeat,-webkit-gradient(linear,50% 0,50% 100%,color-stop(1%,#eee),color-stop(15%,#fff));background:url(../images/chosen-sprite.png) -30px -20px no-repeat,-webkit-linear-gradient(#eee 1%,#fff 15%);background:url(../images/chosen-sprite.png) -30px -20px no-repeat,-moz-linear-gradient(#eee 1%,#fff 15%);background:url(../images/chosen-sprite.png) -30px -20px no-repeat,-o-linear-gradient(#eee 1%,#fff 15%);background:url(../images/chosen-sprite.png) -30px -20px no-repeat,linear-gradient(#eee 1%,#fff 15%);direction:rtl}.chosen-rtl.chosen-container-single .chosen-single div b{background-position:6px 2px}.chosen-rtl.chosen-container-single.chosen-with-drop .chosen-single div b{background-position:-12px 2px}@media only screen and (-webkit-min-device-pixel-ratio:2),only screen and (min-resolution:144dpi){.chosen-container .chosen-results-scroll-down span,.chosen-container .chosen-results-scroll-up span,.chosen-container-multi .chosen-choices .search-choice .search-choice-close,.chosen-container-single .chosen-search input[type=text],.chosen-container-single .chosen-single abbr,.chosen-container-single .chosen-single div b,.chosen-rtl .chosen-search input[type=text]{background-image:url(../images/chosen-sprite@2x.png) !important;background-size:52px 37px !important;background-repeat:no-repeat !important}}#cc_list_chosen .search-field input{width:100% !important} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/assets/css/jquery-ui-timepicker-addon.css b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/css/jquery-ui-timepicker-addon.css new file mode 100644 index 00000000..7c62ee84 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/css/jquery-ui-timepicker-addon.css @@ -0,0 +1,30 @@ +.ui-timepicker-div .ui-widget-header { margin-bottom: 8px; } +.ui-timepicker-div dl { text-align: left; } +.ui-timepicker-div dl dt { float: left; clear:left; padding: 0 0 0 5px; } +.ui-timepicker-div dl dd { margin: 0 10px 10px 40%; } +.ui-timepicker-div td { font-size: 90%; } +.ui-tpicker-grid-label { background: none; border: none; margin: 0; padding: 0; } +.ui-timepicker-div .ui_tpicker_unit_hide{ display: none; } + +.ui-timepicker-div .ui_tpicker_time .ui_tpicker_time_input { background: none; color: inherit; border: none; outline: none; border-bottom: solid 1px #555; width: 95%; } +.ui-timepicker-div .ui_tpicker_time .ui_tpicker_time_input:focus { border-bottom-color: #aaa; } + +.ui-timepicker-rtl{ direction: rtl; } +.ui-timepicker-rtl dl { text-align: right; padding: 0 5px 0 0; } +.ui-timepicker-rtl dl dt{ float: right; clear: right; } +.ui-timepicker-rtl dl dd { margin: 0 40% 10px 10px; } + +/* Shortened version style */ +.ui-timepicker-div.ui-timepicker-oneLine { padding-right: 2px; } +.ui-timepicker-div.ui-timepicker-oneLine .ui_tpicker_time, +.ui-timepicker-div.ui-timepicker-oneLine dt { display: none; } +.ui-timepicker-div.ui-timepicker-oneLine .ui_tpicker_time_label { display: block; padding-top: 2px; } +.ui-timepicker-div.ui-timepicker-oneLine dl { text-align: right; } +.ui-timepicker-div.ui-timepicker-oneLine dl dd, +.ui-timepicker-div.ui-timepicker-oneLine dl dd > div { display:inline-block; margin:0; } +.ui-timepicker-div.ui-timepicker-oneLine dl dd.ui_tpicker_minute:before, +.ui-timepicker-div.ui-timepicker-oneLine dl dd.ui_tpicker_second:before { content:':'; display:inline-block; } +.ui-timepicker-div.ui-timepicker-oneLine dl dd.ui_tpicker_millisec:before, +.ui-timepicker-div.ui-timepicker-oneLine dl dd.ui_tpicker_microsec:before { content:'.'; display:inline-block; } +.ui-timepicker-div.ui-timepicker-oneLine .ui_tpicker_unit_hide, +.ui-timepicker-div.ui-timepicker-oneLine .ui_tpicker_unit_hide:before{ display: none; } diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/assets/css/jquery-ui-timepicker-addon.min.css b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/css/jquery-ui-timepicker-addon.min.css new file mode 100644 index 00000000..bd5f9c00 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/css/jquery-ui-timepicker-addon.min.css @@ -0,0 +1,6 @@ +/* phpcs:ignoreFile */ +/*! jQuery Timepicker Addon - v1.6.3 - 2016-04-20 +* http://trentrichardson.com/examples/timepicker +* Copyright (c) 2016 Trent Richardson; Licensed MIT */ + +.ui-timepicker-div .ui-widget-header{margin-bottom:8px}.ui-timepicker-div dl{text-align:left}.ui-timepicker-div dl dt{float:left;clear:left;padding:0 0 0 5px}.ui-timepicker-div dl dd{margin:0 10px 10px 40%}.ui-timepicker-div td{font-size:90%}.ui-tpicker-grid-label{background:0 0;border:0;margin:0;padding:0}.ui-timepicker-div .ui_tpicker_unit_hide{display:none}.ui-timepicker-div .ui_tpicker_time .ui_tpicker_time_input{background:0 0;color:inherit;border:0;outline:0;border-bottom:solid 1px #555;width:95%}.ui-timepicker-div .ui_tpicker_time .ui_tpicker_time_input:focus{border-bottom-color:#aaa}.ui-timepicker-rtl{direction:rtl}.ui-timepicker-rtl dl{text-align:right;padding:0 5px 0 0}.ui-timepicker-rtl dl dt{float:right;clear:right}.ui-timepicker-rtl dl dd{margin:0 40% 10px 10px}.ui-timepicker-div.ui-timepicker-oneLine{padding-right:2px}.ui-timepicker-div.ui-timepicker-oneLine .ui_tpicker_time,.ui-timepicker-div.ui-timepicker-oneLine dt{display:none}.ui-timepicker-div.ui-timepicker-oneLine .ui_tpicker_time_label{display:block;padding-top:2px}.ui-timepicker-div.ui-timepicker-oneLine dl{text-align:right}.ui-timepicker-div.ui-timepicker-oneLine dl dd,.ui-timepicker-div.ui-timepicker-oneLine dl dd>div{display:inline-block;margin:0}.ui-timepicker-div.ui-timepicker-oneLine dl dd.ui_tpicker_minute:before,.ui-timepicker-div.ui-timepicker-oneLine dl dd.ui_tpicker_second:before{content:':';display:inline-block}.ui-timepicker-div.ui-timepicker-oneLine dl dd.ui_tpicker_millisec:before,.ui-timepicker-div.ui-timepicker-oneLine dl dd.ui_tpicker_microsec:before{content:'.';display:inline-block}.ui-timepicker-div.ui-timepicker-oneLine .ui_tpicker_unit_hide,.ui-timepicker-div.ui-timepicker-oneLine .ui_tpicker_unit_hide:before{display:none} \ No newline at end of file diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/assets/css/smart-coupon-designs.css b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/css/smart-coupon-designs.css new file mode 100644 index 00000000..e6a40451 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/css/smart-coupon-designs.css @@ -0,0 +1,2 @@ +/* phpcs:ignoreFile */ +#sc-cc html{line-height:1.15;-webkit-text-size-adjust:100%}#sc-cc body{margin:0}#sc-cc a{background-color:transparent}#sc-cc b{font-weight:bolder}#sc-cc sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline;top:-.5em}#sc-cc img{border-style:none}#sc-cc button,#sc-cc input{font-family:inherit;font-size:100%;line-height:1.15;margin:0;overflow:visible}#sc-cc button{text-transform:none}#sc-cc [type=button],#sc-cc button{-webkit-appearance:button}#sc-cc [type=button]::-moz-focus-inner,#sc-cc button::-moz-focus-inner{border-style:none;padding:0}#sc-cc [type=button]:-moz-focusring,#sc-cc button:-moz-focusring{outline:1px dotted ButtonText}#sc-cc [hidden]{display:none}#sc-cc h2{margin:0}#sc-cc button{background-color:transparent;background-image:none}#sc-cc button:focus{outline:1px dotted;outline:5px auto -webkit-focus-ring-color}#sc-cc html{font-family:system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;line-height:1.5}#sc-cc *,#sc-cc :after,#sc-cc :before{box-sizing:border-box;border:0 solid #d2d6dc}#sc-cc img{border-style:solid}#sc-cc input::-moz-placeholder{color:#a0aec0}#sc-cc input:-ms-input-placeholder{color:#a0aec0}#sc-cc input::placeholder{color:#a0aec0}#sc-cc button{cursor:pointer}#sc-cc h2{font-size:inherit;font-weight:inherit}#sc-cc a{color:inherit;text-decoration:inherit}#sc-cc button,#sc-cc input{padding:0;line-height:inherit;color:inherit}#sc-cc img,#sc-cc svg{display:block;vertical-align:middle}#sc-cc img{max-width:100%;height:auto}#sc-cc .space-y-0>:not(template)~:not(template){--space-y-reverse:0;margin-top:calc(0px*(1 - var(--space-y-reverse)));margin-bottom:calc(0px*var(--space-y-reverse))}#sc-cc .space-y-1>:not(template)~:not(template){--space-y-reverse:0;margin-top:calc(0.25rem*(1 - var(--space-y-reverse)));margin-bottom:calc(0.25rem*var(--space-y-reverse))}#sc-cc .space-x-1>:not(template)~:not(template){--space-x-reverse:0;margin-right:calc(0.25rem*var(--space-x-reverse));margin-left:calc(0.25rem*(1 - var(--space-x-reverse)))}#sc-cc .space-y-0\.5>:not(template)~:not(template){--space-y-reverse:0;margin-top:calc(0.125rem*(1 - var(--space-y-reverse)));margin-bottom:calc(0.125rem*var(--space-y-reverse))}#sc-cc .bg-white{--bg-opacity:1;background-color:#fff;background-color:rgba(255,255,255,var(--bg-opacity))}#sc-cc .border-transparent{border-color:transparent}#sc-cc .hover\:border-gray-600:hover{--border-opacity:1;border-color:#4b5563;border-color:rgba(75,85,99,var(--border-opacity))}#sc-cc .hover\:border-gray-700:hover{--border-opacity:1;border-color:#374151;border-color:rgba(55,65,81,var(--border-opacity))}#sc-cc .rounded-sm{border-radius:.125rem}#sc-cc .rounded{border-radius:.25rem}#sc-cc .rounded-md{border-radius:.375rem}#sc-cc .rounded-full{border-radius:9999px}#sc-cc .border-dashed{border-style:dashed}#sc-cc .border-dotted{border-style:dotted}#sc-cc .hover\:border-solid:hover{border-style:solid}#sc-cc .hover\:border-dashed:hover{border-style:dashed}#sc-cc .border-2{border-width:2px}#sc-cc .border{border-width:1px}#sc-cc .border-t{border-top-width:1px}#sc-cc .border-b{border-bottom-width:1px}#sc-cc .border-l{border-left-width:1px}#sc-cc .cursor-pointer{cursor:pointer}#sc-cc .inline-block{display:inline-block}#sc-cc .flex{display:flex}#sc-cc .inline-flex{display:inline-flex}#sc-cc .hidden{display:none}#sc-cc .flex-row-reverse{flex-direction:row-reverse}#sc-cc .flex-col{flex-direction:column}#sc-cc .items-start{align-items:flex-start}#sc-cc .items-center{align-items:center}#sc-cc .justify-between{justify-content:space-between}#sc-cc .flex-1{flex:1 1 0%}#sc-cc .flex-shrink-0{flex-shrink:0}#sc-cc .float-right{float:right}#sc-cc .font-mono{font-family:Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace}#sc-cc .font-semibold{font-weight:600}#sc-cc .font-bold{font-weight:700}#sc-cc .h-5{height:1.25rem}#sc-cc .h-6{height:1.5rem}#sc-cc .h-7{height:1.75rem}#sc-cc .h-8{height:2rem}#sc-cc .h-9{height:2.25rem}#sc-cc .h-15{height:3.75rem}#sc-cc .h-24{height:6rem}#sc-cc .h-full{height:100%}#sc-cc .text-xs{font-size:.75rem}#sc-cc .text-sm{font-size:.875rem}#sc-cc .text-base{font-size:1rem}#sc-cc .text-lg{font-size:1.125rem}#sc-cc .text-xl{font-size:1.25rem}#sc-cc .text-4xl{font-size:2.25rem}#sc-cc .leading-4{line-height:1rem}#sc-cc .leading-6{line-height:1.5rem}#sc-cc .leading-none{line-height:1}#sc-cc .leading-tight{line-height:1.25}#sc-cc .m-1{margin:.25rem}#sc-cc .mx-1{margin-left:.25rem;margin-right:.25rem}#sc-cc .mx-2{margin-left:.5rem;margin-right:.5rem}#sc-cc .my-5{margin-top:1.25rem;margin-bottom:1.25rem}#sc-cc .mx-auto{margin-left:auto;margin-right:auto}#sc-cc .mx-1\/12{margin-left:8.333333%;margin-right:8.333333%}#sc-cc .mt-0{margin-top:0}#sc-cc .mt-1{margin-top:.25rem}#sc-cc .mr-1{margin-right:.25rem}#sc-cc .mb-1{margin-bottom:.25rem}#sc-cc .ml-1{margin-left:.25rem}#sc-cc .mr-2{margin-right:.5rem}#sc-cc .mb-2{margin-bottom:.5rem}#sc-cc .ml-2{margin-left:.5rem}#sc-cc .mr-3{margin-right:.75rem}#sc-cc .ml-3{margin-left:.75rem}#sc-cc .mb-4{margin-bottom:1rem}#sc-cc .mt-0\.5{margin-top:.125rem}#sc-cc .mb-1\.5{margin-bottom:.375rem}#sc-cc .-mt-1{margin-top:-.25rem}#sc-cc .-mb-1{margin-bottom:-.25rem}#sc-cc .-mt-0\.5{margin-top:-.125rem}#sc-cc .-mb-1\.5{margin-bottom:-.375rem}#sc-cc .max-w-xs{max-width:20rem}#sc-cc .max-w-sm{max-width:24rem}#sc-cc .max-w-7xl{max-width:80rem}#sc-cc .object-cover{-o-object-fit:cover;object-fit:cover}#sc-cc .overflow-hidden{overflow:hidden}#sc-cc .p-0{padding:0}#sc-cc .p-1{padding:.25rem}#sc-cc .p-2{padding:.5rem}#sc-cc .p-8{padding:2rem}#sc-cc .p-0\.5{padding:.125rem}#sc-cc .py-0{padding-top:0;padding-bottom:0}#sc-cc .py-1{padding-top:.25rem;padding-bottom:.25rem}#sc-cc .px-1{padding-left:.25rem;padding-right:.25rem}#sc-cc .px-2{padding-left:.5rem;padding-right:.5rem}#sc-cc .py-0\.5{padding-top:.125rem;padding-bottom:.125rem}#sc-cc .pt-0{padding-top:0}#sc-cc .pb-0{padding-bottom:0}#sc-cc .pt-1{padding-top:.25rem}#sc-cc .pl-2{padding-left:.5rem}#sc-cc .pt-4{padding-top:1rem}#sc-cc .pt-0\.5{padding-top:.125rem}#sc-cc .pb-0\.5{padding-bottom:.125rem}#sc-cc .pl-2\.5{padding-left:.625rem}#sc-cc .absolute{position:absolute}#sc-cc .relative{position:relative}#sc-cc .right-0{right:0}#sc-cc .bottom-0{bottom:0}#sc-cc .top-2{top:.5rem}#sc-cc .left-14{left:3.5rem}#sc-cc .hover\:shadow:hover,#sc-cc .shadow{box-shadow:0 1px 3px 0 rgba(0,0,0,.1),0 1px 2px 0 rgba(0,0,0,.06)}#sc-cc .text-center{text-align:center}#sc-cc .text-gray-600{--text-opacity:1;color:#4b5563;color:rgba(75,85,99,var(--text-opacity))}#sc-cc .text-gray-800{--text-opacity:1;color:#252f3f;color:rgba(37,47,63,var(--text-opacity))}#sc-cc .text-blue-600{--text-opacity:1;color:#1c64f2;color:rgba(28,100,242,var(--text-opacity))}#sc-cc .uppercase{text-transform:uppercase}#sc-cc .underline{text-decoration:underline}#sc-cc .whitespace-no-wrap{white-space:nowrap}#sc-cc .w-5{width:1.25rem}#sc-cc .w-6{width:1.5rem}#sc-cc .w-8{width:2rem}#sc-cc .w-9{width:2.25rem}#sc-cc .w-15{width:3.75rem}#sc-cc .w-16{width:4rem}#sc-cc .w-24{width:6rem}#sc-cc .w-full{width:100%}#sc-cc .z-10{z-index:10}#sc-cc .gap-1{grid-gap:.25rem;gap:.25rem}#sc-cc .gap-2{grid-gap:.5rem;gap:.5rem}#sc-cc .gap-3{grid-gap:.75rem;gap:.75rem}#sc-cc .transform{--transform-translate-x:0;--transform-translate-y:0;--transform-rotate:0;--transform-skew-x:0;--transform-skew-y:0;--transform-scale-x:1;--transform-scale-y:1;transform:translateX(var(--transform-translate-x)) translateY(var(--transform-translate-y)) rotate(var(--transform-rotate)) skewX(var(--transform-skew-x)) skewY(var(--transform-skew-y)) scaleX(var(--transform-scale-x)) scaleY(var(--transform-scale-y))}#sc-cc .hover\:scale-105:hover{--transform-scale-x:1.05;--transform-scale-y:1.05}#sc-cc .-rotate-90{--transform-rotate:-90deg}#sc-cc .hover\:-translate-y-1:hover{--transform-translate-y:-0.25rem}#sc-cc .transition{transition-property:background-color,border-color,color,fill,stroke,opacity,box-shadow,transform}#sc-cc .ease-in-out{transition-timing-function:cubic-bezier(.4,0,.2,1)}#sc-cc .duration-100{transition-duration:.1s}@-webkit-keyframes spin{to{transform:rotate(1turn)}}@keyframes spin{to{transform:rotate(1turn)}}@-webkit-keyframes ping{75%,to{transform:scale(2);opacity:0}}@keyframes ping{75%,to{transform:scale(2);opacity:0}}@-webkit-keyframes pulse{50%{opacity:.5}}@keyframes pulse{50%{opacity:.5}}@-webkit-keyframes bounce{0%,to{transform:translateY(-25%);-webkit-animation-timing-function:cubic-bezier(.8,0,1,1);animation-timing-function:cubic-bezier(.8,0,1,1)}50%{transform:none;-webkit-animation-timing-function:cubic-bezier(0,0,.2,1);animation-timing-function:cubic-bezier(0,0,.2,1)}}@keyframes bounce{0%,to{transform:translateY(-25%);-webkit-animation-timing-function:cubic-bezier(.8,0,1,1);animation-timing-function:cubic-bezier(.8,0,1,1)}50%{transform:none;-webkit-animation-timing-function:cubic-bezier(0,0,.2,1);animation-timing-function:cubic-bezier(0,0,.2,1)}}#sc-cc{line-height:1.15;-webkit-text-size-adjust:100%;margin:0}#sc-cc .sc-coupons-list{display:flex;flex-wrap:wrap;align-items:center;grid-gap:1rem;gap:1rem}@media (min-width:768px){#sc-cc .sc-coupons-list{grid-gap:2rem;gap:2rem}}#sc-cc .sc-coupon{position:relative;overflow:hidden;font-family:system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;cursor:pointer;min-width:160px;max-width:300px}@media print{#sc-cc .wc-sc-print-coupons-wrapper{display:table}#sc-cc .sc-coupon{display:inline-block;page-break-inside:avoid;margin:.8rem 1rem;border:1px solid #ccc !important}} \ No newline at end of file diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/assets/css/smart-coupon.css b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/css/smart-coupon.css new file mode 100644 index 00000000..722a08d8 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/css/smart-coupon.css @@ -0,0 +1,438 @@ +/* phpcs:ignoreFile */ +/* Smart Coupons Style */ +.coupon-container { + line-height: 1.4em; + position: relative; + display: inline-table; + margin: 2px; + padding: .55em; + cursor: pointer; + text-align: center; + box-shadow: 0 0 5px #e0e0e0; +} + +.coupon-container.previews { + cursor: inherit; +} + +.coupon-content { + padding: .2em 1.2em; +} + +.coupon-content .code { + font-family: monospace; + font-size: 1.2em; + font-weight: 700; +} + +.coupon-content .coupon-expire, +.coupon-content .discount-info { + font-family: Helvetica, Arial, sans-serif; + font-size: 1em; +} +.coupon-content .discount-description { + font: .7em/1 Helvetica, Arial, sans-serif; + display: inline-block; + margin: 10px inherit; +} + +.wc-sc-coupon-style-preview .coupon-container { + display: inline-block; +} + +span.wc-sc-coupon-preview-container { + position: absolute; + display: inline-block; + margin: 0 0 0 1em; + font-size: initial; +} + +.wc_sc_custom_design_css_doc_div { + margin: 15px 0; +} + +/*Shortcode fields*/ +#coupon-selector #coupon-option label span { + display: inline-block; + width: 100px; +} +#coupon-selector #coupon-option label select { + width: 175px; + margin-bottom: 6px; + margin-left: -.2em; +} +div#sc_shortcode_update { + float: right; + + margin-top: -5px; +} +form#sc_coupons_attributes { + padding: 0 1em 1em; +} +div#coupon-selector { + float: left; + padding: 1em 1em 1em 0; + border-right: 1px solid #e6e6e6; +} +.coupon-preview { + float: left; + width: 175px; + padding: 1em 0 1em 1em; +} +.preview-heading { + font-size: 15px; + padding-bottom: 10px; + text-align: center; +} +#search-panel { + overflow-x: hidden; + width: 275px; + min-height: 80px; + max-height: 110px; + margin: 5px 0; + color: #333; + border: 1px solid #d4d4d4; + background-color: #fff; +} +#coupon-option #search-panel #search-results span { + width: 100%; + margin-left: 10px; +} +#search-results ul { + margin: 5px -2px; +} +#search-results ul li { + font-size: 12px; + margin-bottom: -1px; + padding: 3px 15px; + cursor: pointer; + border: 1px solid #f2f2f2; +} +#search-results ul li:hover { + color: #000; + background-color: #eaf2fa; +} +#coupon-option #search-panel #search-results ul li span { + width: 0; + color: #f00; +} +#sc_coupons_attributes .submitbox { + clear: both; +} +#default-text { + font-style: italic; + margin-bottom: -5px; + padding: 2px; + text-align: center; + background-color: #f2f2f2; +} + +/* Gift Cerificate form */ +input.gift_receiver_email, input.gift_sending_date_time { + min-width: 100%; + margin: 1% 0; +} +div#gift-certificate-receiver-form thead th { + text-align: center; +} +input#deliver_on_date { + text-align: center; +} +.email_sending_date_time_wrapper:not(.show), +.wc_sc_schedule_gift_sending_wrapper:not(.show) { + display: none; +} + +.wc_sc_schedule_gift_sending_wrapper.show { + margin-left: 2em; +} + +/* Coupon generation form */ +form#generate_coupons p.form-field input[type=text] { + width: 30%; +} +form#generate_coupons p.form-field input[type=number] { + width: 15%; +} +form#generate_coupons p.form-field input[name="wc_sc_max_discount"] { + width: 30%; +} +div.gift-certificate-receiver-detail-form, +div#gift-certificate-receiver-form-multi { + display: none; +} +a#single_multi { + float: right; +} + +.sc_info_box { + overflow: hidden; + margin-bottom: 2em !important; + padding: .5em 1em 0 !important; + background-color: #f7f6f7; +} +tr.wc_sc_custom_design_css_wrapper .CodeMirror + span.wc-sc-coupon-preview-container { + top: 15px; +} + +tr.wc_sc_custom_design_css_wrapper td.forminp.forminp-textarea { + position: relative; +} + +tr.wc_sc_custom_design_css_wrapper .CodeMirror { + width: 100%; + max-width: 400px; + height: 200px; +} + +.sc-coupons-list details > summary { + list-style: none; +} + +.sc-coupons-list details > summary::marker, /* Latest Chrome, Edge, Firefox */ +.sc-coupons-list details > summary::-webkit-details-marker /* Safari */ { + display: none; +} + +@media (min-width: 768px) { + .sc_info_box { + float: unset !important; + width: unset !important; + margin-right: unset !important; + padding: .5em 1em 0 !important; + } + + .page-template-template-fullwidth-php .sc_info_box { + float: unset !important; + width: unset !important; + margin-right: unset !important; + margin-left: unset !important; + padding: .5em 1em 0 !important; + } + + /* Fix for positioning 'Sell store credit at less price?' settings' tooltip */ + label[for="smart_coupons_sell_store_credit_at_less_price"] span.woocommerce-help-tip, + label[for="smart_coupons_schedule_store_credit"] span.woocommerce-help-tip { + float: left; + margin: 1px 4px 1px -1.7em !important; + } + + tr.wc_sc_custom_design_css_wrapper .CodeMirror + span.wc-sc-coupon-preview-container { + left: 415px; + } +} + +textarea.gift_receiver_message { + width: 100%; +} + +.form_table { + width: 97%; + padding: 20px 10px; + + border-top: 2px; + border-top-style: solid; + border-top-color: #dbdbdb; +} +.message_row { + width: 100%; +} +.sc_message { + width: 100%; +} +.email_amount { + width: 100%; +} +.gift-certificate-show-form p { + margin: 0; +} +.gift-certificate-show-form lable { + display: inline; +} +.gift-certificate-show-form input[type=radio] { + margin-left: 1em; +} +.show_hide_list { + padding-left: 0; + margin-left: 25px; +} +.single_multi_list { + display: none; +} +div.mce-smart-coupon-shortcode { + cursor: pointer; +} +div.mce-smart-coupon-shortcode i:before { + font-family: 'WooCommerce'; + + content: '\e600'; +} +div[aria-describedby='sc_coupons_attributes'] { + z-index: 1000; +} +.wc_sc_total_available_store_credit { + padding: 1em 0; + + text-align: right; +} +.wc_sc_total_available_store_credit .amount { + font-size: 1.5em; + font-weight: bold; +} +div#invalid_coupons_list div#all_coupon_container .coupon-container { + cursor: initial !important; + + opacity: .5; +} +div#invalid_coupons_list div#all_coupon_container .coupon-container .coupon-content .coupon-expire { + display: none; +} +.variation-sc_called_credit { + display: none; +} + +/* Bulk Generate tab - Coupon Description */ +.sc_bulk_description textarea#woocommerce-coupon-description { + width: 90%; + margin-left: 0.5em; +} + +#call_for_credit { + position: relative; +} + +input#credit_called { + position: absolute; + top: 50%; + transform: translateY(-50%); +} + +.wc-sc-call-for-credit-container .wc-sc-label, +.wc-sc-call-for-credit-container .wc-sc-input { + width: 48%; + float: left; +} + +.wc-sc-call-for-credit-container .wc-sc-row { + position: relative; + margin-top: 1em; +} + +.wc-sc-call-for-credit-container .wc-sc-row:after { + content: ""; + display: table; + clear: both; +} + +.wc-sc-description { + display: inline-block; +} + +#sc-cc input { + border: 1px solid #7e8993; +} + +#sc-cc .sc-truncate { + overflow: hidden; + text-overflow: ellipsis; + height: 2rem; +} + +.forminp-wc_sc_radio_with_html { + border-collapse: initial; +} + +.forminp-wc_sc_radio_with_html .wc_sc_setting_coupon_design li { + padding: 10px 10px 5px 5px; +} + +.forminp-wc_sc_radio_with_html .wc_sc_setting_coupon_design li input, +.forminp-wc_sc_radio_with_html .wc_sc_setting_coupon_design_colors li input { + vertical-align: top; +} + +.forminp-wc_sc_radio_with_html .wc_sc_setting_coupon_design_colors.custom li input[type="color"] { + opacity: 0; + display: block; + width: 32px; + height: 20px; + border: none; + cursor: pointer; +} + +.forminp-wc_sc_radio_with_html .wc_sc_setting_coupon_design_colors li span { + display: inline-block; + width: 32px; + height: 20px; + vertical-align: middle; +} + +.forminp-wc_sc_radio_with_html .wc_sc_setting_coupon_design, +.forminp-wc_sc_radio_with_html .wc_sc_setting_coupon_design_colors { + margin-top: unset; +} + +.forminp-wc_sc_radio_with_html .wc_sc_setting_coupon_design li, +.forminp-wc_sc_radio_with_html .wc_sc_setting_coupon_design_colors li { + cursor: pointer; +} + +.forminp-wc_sc_radio_with_html .wc_sc_setting_coupon_design_colors li { + display: inline-block; + width: 150px; + padding: 5px; +} + +.forminp-wc_sc_radio_with_html ul li:hover, +.forminp-wc_sc_radio_with_html ul li.selected { + background: #ddd; +} + +.forminp-wc_sc_radio_with_html .wc_sc_setting_coupon_design { + align-items: unset !important; +} + +@media screen and (max-width: 767px) { + .wc-sc-description { + margin-left: 0; + } + tr.wc_sc_custom_design_css_wrapper .CodeMirror + span.wc-sc-coupon-preview-container { + position: static; + margin-top: 15px; + } +} +@media screen and (min-width: 768px) and (max-width: 799px) { + .wc-sc-description { + margin-left: 5%; + } +} +@media screen and (min-width: 800px) and (max-width: 1023px) { + .wc-sc-description { + margin-left: 7%; + } +} +@media screen and (min-width: 1024px) and (max-width: 1199px) { + .wc-sc-description { + margin-left: 11%; + } +} +@media screen and (min-width: 1200px) and (max-width: 1279px) { + .wc-sc-description { + margin-left: 14%; + } +} +@media screen and (min-width: 1280px) and (max-width: 1365px) { + .wc-sc-description { + margin-left: 15%; + } +} +@media screen and (min-width: 1366px) and (max-width: 1599px) { + .wc-sc-description { + margin-left: 16%; + } +} +@media screen and (min-width: 1600px) { + .wc-sc-description { + margin-left: 20%; + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/assets/css/smart-coupon.min.css b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/css/smart-coupon.min.css new file mode 100644 index 00000000..fe71dead --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/css/smart-coupon.min.css @@ -0,0 +1,2 @@ +/* phpcs:ignoreFile */ +.coupon-container{line-height:1.4em;position:relative;display:inline-table;margin:2px;padding:.55em;cursor:pointer;text-align:center;box-shadow:0 0 5px #e0e0e0}.coupon-container.previews{cursor:inherit}.coupon-content{padding:.2em 1.2em}.coupon-content .code{font-family:monospace;font-size:1.2em;font-weight:700}.coupon-content .coupon-expire,.coupon-content .discount-info{font-family:Helvetica,Arial,sans-serif;font-size:1em}.coupon-content .discount-description{font:.7em/1 Helvetica,Arial,sans-serif;display:inline-block;margin:10px inherit}.wc-sc-coupon-style-preview .coupon-container{display:inline-block}span.wc-sc-coupon-preview-container{position:absolute;display:inline-block;margin:0 0 0 1em;font-size:initial}.wc_sc_custom_design_css_doc_div{margin:15px 0}#coupon-selector #coupon-option label span{display:inline-block;width:100px}#coupon-selector #coupon-option label select{width:175px;margin-bottom:6px;margin-left:-.2em}div#sc_shortcode_update{float:right;margin-top:-5px}form#sc_coupons_attributes{padding:0 1em 1em}div#coupon-selector{float:left;padding:1em 1em 1em 0;border-right:1px solid #e6e6e6}.coupon-preview{float:left;width:175px;padding:1em 0 1em 1em}.preview-heading{font-size:15px;padding-bottom:10px;text-align:center}#search-panel{overflow-x:hidden;width:275px;min-height:80px;max-height:110px;margin:5px 0;color:#333;border:1px solid #d4d4d4;background-color:#fff}#coupon-option #search-panel #search-results span{width:100%;margin-left:10px}#search-results ul{margin:5px -2px}#search-results ul li{font-size:12px;margin-bottom:-1px;padding:3px 15px;cursor:pointer;border:1px solid #f2f2f2}#search-results ul li:hover{color:#000;background-color:#eaf2fa}#coupon-option #search-panel #search-results ul li span{width:0;color:red}#sc_coupons_attributes .submitbox{clear:both}#default-text{font-style:italic;margin-bottom:-5px;padding:2px;text-align:center;background-color:#f2f2f2}input.gift_receiver_email,input.gift_sending_date_time{min-width:100%;margin:1% 0}div#gift-certificate-receiver-form thead th{text-align:center}input#deliver_on_date{text-align:center}.email_sending_date_time_wrapper:not(.show),.wc_sc_schedule_gift_sending_wrapper:not(.show){display:none}.wc_sc_schedule_gift_sending_wrapper.show{margin-left:2em}form#generate_coupons p.form-field input[type=text]{width:30%}form#generate_coupons p.form-field input[type=number]{width:15%}form#generate_coupons p.form-field input[name=wc_sc_max_discount]{width:30%}div.gift-certificate-receiver-detail-form,div#gift-certificate-receiver-form-multi{display:none}a#single_multi{float:right}.sc_info_box{overflow:hidden;margin-bottom:2em!important;padding:.5em 1em 0!important;background-color:#f7f6f7}tr.wc_sc_custom_design_css_wrapper .CodeMirror+span.wc-sc-coupon-preview-container{top:15px}tr.wc_sc_custom_design_css_wrapper td.forminp.forminp-textarea{position:relative}tr.wc_sc_custom_design_css_wrapper .CodeMirror{width:100%;max-width:400px;height:200px}.sc-coupons-list details>summary{list-style:none}.sc-coupons-list details>summary::marker,.sc-coupons-list details>summary::-webkit-details-marker{display:none}@media(min-width:768px){.sc_info_box{float:unset!important;width:unset!important;margin-right:unset!important;padding:.5em 1em 0!important}.page-template-template-fullwidth-php .sc_info_box{float:unset!important;width:unset!important;margin-right:unset!important;margin-left:unset!important;padding:.5em 1em 0!important}label[for=smart_coupons_sell_store_credit_at_less_price] span.woocommerce-help-tip,label[for=smart_coupons_schedule_store_credit] span.woocommerce-help-tip{float:left;margin:1px 4px 1px -1.7em!important}tr.wc_sc_custom_design_css_wrapper .CodeMirror+span.wc-sc-coupon-preview-container{left:415px}}textarea.gift_receiver_message{width:100%}.form_table{width:97%;padding:20px 10px;border-top:2px;border-top-style:solid;border-top-color:#dbdbdb}.message_row{width:100%}.sc_message{width:100%}.email_amount{width:100%}.gift-certificate-show-form p{margin:0}.gift-certificate-show-form lable{display:inline}.gift-certificate-show-form input[type=radio]{margin-left:1em}.show_hide_list{padding-left:0;margin-left:25px}.single_multi_list{display:none}div.mce-smart-coupon-shortcode{cursor:pointer}div.mce-smart-coupon-shortcode i:before{font-family:woocommerce;content:'\e600'}div[aria-describedby=sc_coupons_attributes]{z-index:1000}.wc_sc_total_available_store_credit{padding:1em 0;text-align:right}.wc_sc_total_available_store_credit .amount{font-size:1.5em;font-weight:700}div#invalid_coupons_list div#all_coupon_container .coupon-container{cursor:initial!important;opacity:.5}div#invalid_coupons_list div#all_coupon_container .coupon-container .coupon-content .coupon-expire{display:none}.variation-sc_called_credit{display:none}.sc_bulk_description textarea#woocommerce-coupon-description{width:90%;margin-left:.5em}#call_for_credit{position:relative}input#credit_called{position:absolute;top:50%;transform:translateY(-50%)}.wc-sc-call-for-credit-container .wc-sc-label,.wc-sc-call-for-credit-container .wc-sc-input{width:48%;float:left}.wc-sc-call-for-credit-container .wc-sc-row{position:relative;margin-top:1em}.wc-sc-call-for-credit-container .wc-sc-row:after{content:"";display:table;clear:both}.wc-sc-description{display:inline-block}#sc-cc input{border:1px solid #7e8993}#sc-cc .sc-truncate{overflow:hidden;text-overflow:ellipsis;height:2rem}.forminp-wc_sc_radio_with_html{border-collapse:initial}.forminp-wc_sc_radio_with_html .wc_sc_setting_coupon_design li{padding:10px 10px 5px 5px}.forminp-wc_sc_radio_with_html .wc_sc_setting_coupon_design li input,.forminp-wc_sc_radio_with_html .wc_sc_setting_coupon_design_colors li input{vertical-align:top}.forminp-wc_sc_radio_with_html .wc_sc_setting_coupon_design_colors.custom li input[type=color]{opacity:0;display:block;width:32px;height:20px;border:none;cursor:pointer}.forminp-wc_sc_radio_with_html .wc_sc_setting_coupon_design_colors li span{display:inline-block;width:32px;height:20px;vertical-align:middle}.forminp-wc_sc_radio_with_html .wc_sc_setting_coupon_design,.forminp-wc_sc_radio_with_html .wc_sc_setting_coupon_design_colors{margin-top:unset}.forminp-wc_sc_radio_with_html .wc_sc_setting_coupon_design li,.forminp-wc_sc_radio_with_html .wc_sc_setting_coupon_design_colors li{cursor:pointer}.forminp-wc_sc_radio_with_html .wc_sc_setting_coupon_design_colors li{display:inline-block;width:150px;padding:5px}.forminp-wc_sc_radio_with_html ul li:hover,.forminp-wc_sc_radio_with_html ul li.selected{background:#ddd}.forminp-wc_sc_radio_with_html .wc_sc_setting_coupon_design{align-items:unset!important}@media screen and (max-width:767px){.wc-sc-description{margin-left:0}tr.wc_sc_custom_design_css_wrapper .CodeMirror+span.wc-sc-coupon-preview-container{position:static;margin-top:15px}}@media screen and (min-width:768px) and (max-width:799px){.wc-sc-description{margin-left:5%}}@media screen and (min-width:800px) and (max-width:1023px){.wc-sc-description{margin-left:7%}}@media screen and (min-width:1024px) and (max-width:1199px){.wc-sc-description{margin-left:11%}}@media screen and (min-width:1200px) and (max-width:1279px){.wc-sc-description{margin-left:14%}}@media screen and (min-width:1280px) and (max-width:1365px){.wc-sc-description{margin-left:15%}}@media screen and (min-width:1366px) and (max-width:1599px){.wc-sc-description{margin-left:16%}}@media screen and (min-width:1600px){.wc-sc-description{margin-left:20%}} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/assets/css/smart-coupons-admin.css b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/css/smart-coupons-admin.css new file mode 100644 index 00000000..0e662c55 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/css/smart-coupons-admin.css @@ -0,0 +1,50 @@ +/* phpcs:ignoreFile */ +/* Smart Coupons Admin CSS */ +.smart-coupons-field, +#sc-share-link, +#sc_coupon_categorydiv, +#sc_coupon_categorydiv ul.category-tabs li.tabs, +#sc_coupon_categorydiv ul.add-menu-item-tabs li.tabs, +#sc_coupon_categorydiv .wp-tab-active, +#sc_coupon_categorydiv div.tabs-panel, +button#export_coupons, +a#wc_sc_print_coupons, +a#sc-manage-category, +#wc-sc-copy-coupon-code { + background-color: #f0fff0; +} +button#export_coupons > span.dashicons, +a#wc_sc_print_coupons > span.dashicons, +a#sc-manage-category > span.dashicons { + transform: translateX(-15%) translateY(15%); +} +div#smart_coupons_tabs h2 { + margin-bottom: 10px; +} +div#smart_coupons_tabs h2 .sc-quick-links { + text-align: right; + font-size: 0.8em; +} +.coupon_title_prefix_suffix_field input { + height: 2em; +} +li.wc_sc_actions_tab a::before { + font-family: WooCommerce !important; + content: '\e01c' !important; +} +div.sc-manage-category { + margin: 10px 0; +} +div.sc-manage-category a { + font-weight: 600; +} +div.smart_coupons_product_options_variable { + display: flow-root; +} +table.wp-list-table .column-wc_sc_linked_coupons { + width: 10% !important; +} +#sc-generated-coupon-data, +#woocommerce-order-actions select[name="wc_order_action"] option[value^="wc_sc_"] { + background-color: #f0fff0; +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/assets/css/smart-coupons-admin.min.css b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/css/smart-coupons-admin.min.css new file mode 100644 index 00000000..c1a23781 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/css/smart-coupons-admin.min.css @@ -0,0 +1,2 @@ +/* phpcs:ignoreFile */ +.smart-coupons-field,#sc-share-link,#sc_coupon_categorydiv,#sc_coupon_categorydiv ul.category-tabs li.tabs,#sc_coupon_categorydiv ul.add-menu-item-tabs li.tabs,#sc_coupon_categorydiv .wp-tab-active,#sc_coupon_categorydiv div.tabs-panel,button#export_coupons,a#wc_sc_print_coupons,a#sc-manage-category,#wc-sc-copy-coupon-code{background-color:#f0fff0}button#export_coupons>span.dashicons,a#wc_sc_print_coupons>span.dashicons,a#sc-manage-category>span.dashicons{transform:translateX(-15%) translateY(15%)}div#smart_coupons_tabs h2{margin-bottom:10px}div#smart_coupons_tabs h2 .sc-quick-links{text-align:right;font-size:.8em}.coupon_title_prefix_suffix_field input{height:2em}li.wc_sc_actions_tab a::before{font-family:WooCommerce!important;content:'\e01c'!important}div.sc-manage-category{margin:10px 0}div.sc-manage-category a{font-weight:600}div.smart_coupons_product_options_variable{display:flow-root}table.wp-list-table .column-wc_sc_linked_coupons{width:10%!important}#sc-generated-coupon-data,#woocommerce-order-actions select[name=wc_order_action] option[value^=wc_sc_]{background-color:#f0fff0} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/assets/css/wc-sc-style-email-coupon.css b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/css/wc-sc-style-email-coupon.css new file mode 100644 index 00000000..e25a73ff --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/css/wc-sc-style-email-coupon.css @@ -0,0 +1,22 @@ +/* Coupon style for email-coupon */ +.coupon-container.email-coupon .coupon-content { + border: 1px solid !important; + border-style: dashed !important; +} + +.coupon-container.email-coupon { + transition-duration: .3s !important; + transition-property: border-radius !important; + -webkit-transform: perspective(1px) translateZ(0) !important; + transform: perspective(1px) translateZ(0) !important; + + border-radius: .8em !important; + box-shadow: 0 0 1px rgba(0, 0, 0, 0) !important; + display: table; + margin: 0 auto; +} +.coupon-container.email-coupon:hover, +.coupon-container.email-coupon:focus, +.coupon-container.email-coupon:active { + border-radius: 0 !important; +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/assets/css/wc-sc-style-email-coupon.min.css b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/css/wc-sc-style-email-coupon.min.css new file mode 100644 index 00000000..6225290b --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/css/wc-sc-style-email-coupon.min.css @@ -0,0 +1,2 @@ +/* phpcs:ignoreFile */ +.coupon-container.email-coupon .coupon-content{border:1px solid !important;border-style:dashed !important}.coupon-container.email-coupon{transition-duration:.3s !important;transition-property:border-radius !important;-webkit-transform:perspective(1px) translateZ(0) !important;transform:perspective(1px) translateZ(0) !important;border-radius:.8em !important;box-shadow:0 0 1px rgba(0,0,0,0) !important;display:table;margin:0 auto}.coupon-container.email-coupon:hover,.coupon-container.email-coupon:focus,.coupon-container.email-coupon:active{border-radius:0 !important} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/cart-discount-alt.svg b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/cart-discount-alt.svg new file mode 100644 index 00000000..855aaea9 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/cart-discount-alt.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/cart-discount.svg b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/cart-discount.svg new file mode 100644 index 00000000..5c5a7f3b --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/cart-discount.svg @@ -0,0 +1 @@ + diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/chosen-sprite.png b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/chosen-sprite.png new file mode 100644 index 0000000000000000000000000000000000000000..4cb687bc231dc93fee3c62eb9ea4625f7c76d526 GIT binary patch literal 592 zcmV-W0S;E*2JoAZQaf zI0&47L9nqDf=c9IAP_8cpT%yHB_!tsog(v^h4*$oJ2P*WHMjpA7)FgXGK%X4J;p5& z)WwNp7)>HhHx)F)4o+mAh_gjK6=Y1Yjg#Z_sblFNV}Tqer-fnFL?w>Ac|gs9+Gb@% z+3}&#A)$ha%n=K!NUY*}@ooS#&KE8Y1$A&D4UCLFPOnIeu~{;GCI&!naXLdmH99oP z$~x;z>?USQ=+=O(yI$7Z84T&r*niqpoc9CHXpF5Aid^^?XpD_wf+L_em2+JCD^$~( zvJz>ir|}^>>NxE!lc_6LR3=kXQLgSWCmAMWGR4l(yx{CTulPCFY$}mo?Se(G!hp1 z&9_HqQgz);JUE~ETK>K)Cwq^=mGGKRY=oz@aXhRff~q4t!SV1Sj3$Q6!aaWC%qEA- e!UvrCe$5}ph{~A{;*)Lw0000hQBP{j4uqq`I2WP9&Sn{}I8xJi*&v*QL&+Dw-Bf-CQLyLk0Ht2-;T zynum$iNn*yF{I+w+pE|67CQ*ECWbR^Yfnj@W1E<6_I%FgkH7a{7V~zFkLV6_d!D57 zKfLy+`qr*jjOr5$1-i6(jxmQBvH2A7IZQsYa>=oWo{UnOCGJ8ZW8{M zUArDQaxS=De*b>`hu;^^ooHcQ%2-nSK4#5x|7)upy_$@!-gRDC{k3BC36BdwkC&f6 zQd+lI!&6|v%q@F6LNf#YTyidd=JVn!efy{QC2B)JE@2ZI6Yw*Wcgw|Hsel)ePqAsR#X_7y^C#b!F#W`Y>0U-pRP9oPBtK1cu>0_r@rz9-%LAiZkANwR!PC{xWt~$( F69Dj>nkN7N literal 0 HcmV?d00001 diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/delivery-motorcyle.svg b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/delivery-motorcyle.svg new file mode 100644 index 00000000..71c708a3 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/delivery-motorcyle.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/discount-coupon.svg b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/discount-coupon.svg new file mode 100644 index 00000000..4f0bc603 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/discount-coupon.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/gift-card-alt.svg b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/gift-card-alt.svg new file mode 100644 index 00000000..f384551f --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/gift-card-alt.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/gift-voucher-credit-alt.svg b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/gift-voucher-credit-alt.svg new file mode 100644 index 00000000..5c41b027 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/gift-voucher-credit-alt.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/giftbox-color.svg b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/giftbox-color.svg new file mode 100644 index 00000000..a2399f8e --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/giftbox-color.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/megaphone-announce-color-alt.svg b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/megaphone-announce-color-alt.svg new file mode 100644 index 00000000..735f8904 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/megaphone-announce-color-alt.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/product-discount-alt.svg b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/product-discount-alt.svg new file mode 100644 index 00000000..08803cbc --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/product-discount-alt.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/product-package-box.svg b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/product-package-box.svg new file mode 100644 index 00000000..349b69dd --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/product-package-box.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/sale-splash-tag.svg b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/sale-splash-tag.svg new file mode 100644 index 00000000..ea25989f --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/sale-splash-tag.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/subs-calendar-discount.svg b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/subs-calendar-discount.svg new file mode 100644 index 00000000..3a3a8d6a --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/subs-calendar-discount.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/subs-discount-voucher.svg b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/subs-discount-voucher.svg new file mode 100644 index 00000000..dd9d927e --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/images/subs-discount-voucher.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/assets/js/chosen.jquery.js b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/js/chosen.jquery.js new file mode 100644 index 00000000..884a041e --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/js/chosen.jquery.js @@ -0,0 +1,1236 @@ +/* phpcs:ignoreFile */ +/*! +Chosen, a Select Box Enhancer for jQuery and Prototype +by Patrick Filler for Harvest, http://getharvest.com + +Version 1.1.0 +Full source at https://github.com/harvesthq/chosen +Copyright (c) 2011 Harvest http://getharvest.com + +MIT License, https://github.com/harvesthq/chosen/blob/master/LICENSE.md +This file is generated by `grunt build`, do not edit it by hand. +*/ + +(function() { + var $, AbstractChosen, Chosen, SelectParser, _ref, + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; + + SelectParser = (function() { + function SelectParser() { + this.options_index = 0; + this.parsed = []; + } + + SelectParser.prototype.add_node = function(child) { + if (child.nodeName.toUpperCase() === "OPTGROUP") { + return this.add_group(child); + } else { + return this.add_option(child); + } + }; + + SelectParser.prototype.add_group = function(group) { + var group_position, option, _i, _len, _ref, _results; + group_position = this.parsed.length; + this.parsed.push({ + array_index: group_position, + group: true, + label: this.escapeExpression(group.label), + children: 0, + disabled: group.disabled + }); + _ref = group.childNodes; + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + option = _ref[_i]; + _results.push(this.add_option(option, group_position, group.disabled)); + } + return _results; + }; + + SelectParser.prototype.add_option = function(option, group_position, group_disabled) { + if (option.nodeName.toUpperCase() === "OPTION") { + if (option.text !== "") { + if (group_position != null) { + this.parsed[group_position].children += 1; + } + this.parsed.push({ + array_index: this.parsed.length, + options_index: this.options_index, + value: option.value, + text: option.text, + html: option.innerHTML, + selected: option.selected, + disabled: group_disabled === true ? group_disabled : option.disabled, + group_array_index: group_position, + classes: option.className, + style: option.style.cssText + }); + } else { + this.parsed.push({ + array_index: this.parsed.length, + options_index: this.options_index, + empty: true + }); + } + return this.options_index += 1; + } + }; + + SelectParser.prototype.escapeExpression = function(text) { + var map, unsafe_chars; + if ((text == null) || text === false) { + return ""; + } + if (!/[\&\<\>\"\'\`]/.test(text)) { + return text; + } + map = { + "<": "<", + ">": ">", + '"': """, + "'": "'", + "`": "`" + }; + unsafe_chars = /&(?!\w+;)|[\<\>\"\'\`]/g; + return text.replace(unsafe_chars, function(chr) { + return map[chr] || "&"; + }); + }; + + return SelectParser; + + })(); + + SelectParser.select_to_array = function(select) { + var child, parser, _i, _len, _ref; + parser = new SelectParser(); + _ref = select.childNodes; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + child = _ref[_i]; + parser.add_node(child); + } + return parser.parsed; + }; + + AbstractChosen = (function() { + function AbstractChosen(form_field, options) { + this.form_field = form_field; + this.options = options != null ? options : {}; + if (!AbstractChosen.browser_is_supported()) { + return; + } + this.is_multiple = this.form_field.multiple; + this.set_default_text(); + this.set_default_values(); + this.setup(); + this.set_up_html(); + this.register_observers(); + } + + AbstractChosen.prototype.set_default_values = function() { + var _this = this; + this.click_test_action = function(evt) { + return _this.test_active_click(evt); + }; + this.activate_action = function(evt) { + return _this.activate_field(evt); + }; + this.active_field = false; + this.mouse_on_container = false; + this.results_showing = false; + this.result_highlighted = null; + this.allow_single_deselect = (this.options.allow_single_deselect != null) && (this.form_field.options[0] != null) && this.form_field.options[0].text === "" ? this.options.allow_single_deselect : false; + this.disable_search_threshold = this.options.disable_search_threshold || 0; + this.disable_search = this.options.disable_search || false; + this.enable_split_word_search = this.options.enable_split_word_search != null ? this.options.enable_split_word_search : true; + this.group_search = this.options.group_search != null ? this.options.group_search : true; + this.search_contains = this.options.search_contains || false; + this.single_backstroke_delete = this.options.single_backstroke_delete != null ? this.options.single_backstroke_delete : true; + this.max_selected_options = this.options.max_selected_options || Infinity; + this.inherit_select_classes = this.options.inherit_select_classes || false; + this.display_selected_options = this.options.display_selected_options != null ? this.options.display_selected_options : true; + return this.display_disabled_options = this.options.display_disabled_options != null ? this.options.display_disabled_options : true; + }; + + AbstractChosen.prototype.set_default_text = function() { + if (this.form_field.getAttribute("data-placeholder")) { + this.default_text = this.form_field.getAttribute("data-placeholder"); + } else if (this.is_multiple) { + this.default_text = this.options.placeholder_text_multiple || this.options.placeholder_text || AbstractChosen.default_multiple_text; + } else { + this.default_text = this.options.placeholder_text_single || this.options.placeholder_text || AbstractChosen.default_single_text; + } + return this.results_none_found = this.form_field.getAttribute("data-no_results_text") || this.options.no_results_text || AbstractChosen.default_no_result_text; + }; + + AbstractChosen.prototype.mouse_enter = function() { + return this.mouse_on_container = true; + }; + + AbstractChosen.prototype.mouse_leave = function() { + return this.mouse_on_container = false; + }; + + AbstractChosen.prototype.input_focus = function(evt) { + var _this = this; + if (this.is_multiple) { + if (!this.active_field) { + return setTimeout((function() { + return _this.container_mousedown(); + }), 50); + } + } else { + if (!this.active_field) { + return this.activate_field(); + } + } + }; + + AbstractChosen.prototype.input_blur = function(evt) { + var _this = this; + if (!this.mouse_on_container) { + this.active_field = false; + return setTimeout((function() { + return _this.blur_test(); + }), 100); + } + }; + + AbstractChosen.prototype.results_option_build = function(options) { + var content, data, _i, _len, _ref; + content = ''; + _ref = this.results_data; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + data = _ref[_i]; + if (data.group) { + content += this.result_add_group(data); + } else { + content += this.result_add_option(data); + } + if (options != null ? options.first : void 0) { + if (data.selected && this.is_multiple) { + this.choice_build(data); + } else if (data.selected && !this.is_multiple) { + this.single_set_selected_text(data.text); + } + } + } + return content; + }; + + AbstractChosen.prototype.result_add_option = function(option) { + var classes, option_el; + if (!option.search_match) { + return ''; + } + if (!this.include_option_in_results(option)) { + return ''; + } + classes = []; + if (!option.disabled && !(option.selected && this.is_multiple)) { + classes.push("active-result"); + } + if (option.disabled && !(option.selected && this.is_multiple)) { + classes.push("disabled-result"); + } + if (option.selected) { + classes.push("result-selected"); + } + if (option.group_array_index != null) { + classes.push("group-option"); + } + if (option.classes !== "") { + classes.push(option.classes); + } + option_el = document.createElement("li"); + option_el.className = classes.join(" "); + option_el.style.cssText = option.style; + option_el.setAttribute("data-option-array-index", option.array_index); + option_el.innerHTML = option.search_text; + return this.outerHTML(option_el); + }; + + AbstractChosen.prototype.result_add_group = function(group) { + var group_el; + if (!(group.search_match || group.group_match)) { + return ''; + } + if (!(group.active_options > 0)) { + return ''; + } + group_el = document.createElement("li"); + group_el.className = "group-result"; + group_el.innerHTML = group.search_text; + return this.outerHTML(group_el); + }; + + AbstractChosen.prototype.results_update_field = function() { + this.set_default_text(); + if (!this.is_multiple) { + this.results_reset_cleanup(); + } + this.result_clear_highlight(); + this.results_build(); + if (this.results_showing) { + return this.winnow_results(); + } + }; + + AbstractChosen.prototype.reset_single_select_options = function() { + var result, _i, _len, _ref, _results; + _ref = this.results_data; + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + result = _ref[_i]; + if (result.selected) { + _results.push(result.selected = false); + } else { + _results.push(void 0); + } + } + return _results; + }; + + AbstractChosen.prototype.results_toggle = function() { + if (this.results_showing) { + return this.results_hide(); + } else { + return this.results_show(); + } + }; + + AbstractChosen.prototype.results_search = function(evt) { + if (this.results_showing) { + return this.winnow_results(); + } else { + return this.results_show(); + } + }; + + AbstractChosen.prototype.winnow_results = function() { + var escapedSearchText, option, regex, regexAnchor, results, results_group, searchText, startpos, text, zregex, _i, _len, _ref; + this.no_results_clear(); + results = 0; + searchText = this.get_search_text(); + escapedSearchText = searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"); + regexAnchor = this.search_contains ? "" : "^"; + regex = new RegExp(regexAnchor + escapedSearchText, 'i'); + zregex = new RegExp(escapedSearchText, 'i'); + _ref = this.results_data; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + option = _ref[_i]; + option.search_match = false; + results_group = null; + if (this.include_option_in_results(option)) { + if (option.group) { + option.group_match = false; + option.active_options = 0; + } + if ((option.group_array_index != null) && this.results_data[option.group_array_index]) { + results_group = this.results_data[option.group_array_index]; + if (results_group.active_options === 0 && results_group.search_match) { + results += 1; + } + results_group.active_options += 1; + } + if (!(option.group && !this.group_search)) { + option.search_text = option.group ? option.label : option.html; + option.search_match = this.search_string_match(option.search_text, regex); + if (option.search_match && !option.group) { + results += 1; + } + if (option.search_match) { + if (searchText.length) { + startpos = option.search_text.search(zregex); + text = option.search_text.substr(0, startpos + searchText.length) + '' + option.search_text.substr(startpos + searchText.length); + option.search_text = text.substr(0, startpos) + '' + text.substr(startpos); + } + if (results_group != null) { + results_group.group_match = true; + } + } else if ((option.group_array_index != null) && this.results_data[option.group_array_index].search_match) { + option.search_match = true; + } + } + } + } + this.result_clear_highlight(); + if (results < 1 && searchText.length) { + this.update_results_content(""); + return this.no_results(searchText); + } else { + this.update_results_content(this.results_option_build()); + return this.winnow_results_set_highlight(); + } + }; + + AbstractChosen.prototype.search_string_match = function(search_string, regex) { + var part, parts, _i, _len; + if (regex.test(search_string)) { + return true; + } else if (this.enable_split_word_search && (search_string.indexOf(" ") >= 0 || search_string.indexOf("[") === 0)) { + parts = search_string.replace(/\[|\]/g, "").split(" "); + if (parts.length) { + for (_i = 0, _len = parts.length; _i < _len; _i++) { + part = parts[_i]; + if (regex.test(part)) { + return true; + } + } + } + } + }; + + AbstractChosen.prototype.choices_count = function() { + var option, _i, _len, _ref; + if (this.selected_option_count != null) { + return this.selected_option_count; + } + this.selected_option_count = 0; + _ref = this.form_field.options; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + option = _ref[_i]; + if (option.selected) { + this.selected_option_count += 1; + } + } + return this.selected_option_count; + }; + + AbstractChosen.prototype.choices_click = function(evt) { + evt.preventDefault(); + if (!(this.results_showing || this.is_disabled)) { + return this.results_show(); + } + }; + + AbstractChosen.prototype.keyup_checker = function(evt) { + var stroke, _ref; + stroke = (_ref = evt.which) != null ? _ref : evt.keyCode; + this.search_field_scale(); + switch (stroke) { + case 8: + if (this.is_multiple && this.backstroke_length < 1 && this.choices_count() > 0) { + return this.keydown_backstroke(); + } else if (!this.pending_backstroke) { + this.result_clear_highlight(); + return this.results_search(); + } + break; + case 13: + evt.preventDefault(); + if( this.result_highlight ){ + if (this.results_showing) { + return this.result_select(evt); + } + }else{ + if( jQuery(this.form_field).hasClass('sa_cbl_add_location') ) { + var element = this; + var form_field = jQuery(element.form_field); + var entered = jQuery(evt.target).val(); + if ( entered.indexOf( "|" ) > 0 ) { + var splitted = entered.split("|"); + var len = 0 - splitted.length; + var joined = splitted.join("'); + form_field.trigger('chosen:updated'); + jQuery.each(element.search_results.find('li.active-result').slice(len), function(index, value){ + element.result_highlight = jQuery(this); + element.result_select(evt) + }); + } else { + form_field.append(''); + form_field.trigger('chosen:updated'); + element.result_highlight = element.search_results.find('li.active-result').last(); + element.result_select(evt); + } + } + } + break; + case 27: + if (this.results_showing) { + this.results_hide(); + } + return true; + case 9: + case 38: + case 40: + case 16: + case 91: + case 17: + break; + default: + return this.results_search(); + } + }; + + AbstractChosen.prototype.clipboard_event_checker = function(evt) { + var _this = this; + return setTimeout((function() { + return _this.results_search(); + }), 50); + }; + + AbstractChosen.prototype.container_width = function() { + if (this.options.width != null) { + return this.options.width; + } else { + return "" + this.form_field.offsetWidth + "px"; + } + }; + + AbstractChosen.prototype.include_option_in_results = function(option) { + if (this.is_multiple && (!this.display_selected_options && option.selected)) { + return false; + } + if (!this.display_disabled_options && option.disabled) { + return false; + } + if (option.empty) { + return false; + } + return true; + }; + + AbstractChosen.prototype.search_results_touchstart = function(evt) { + this.touch_started = true; + return this.search_results_mouseover(evt); + }; + + AbstractChosen.prototype.search_results_touchmove = function(evt) { + this.touch_started = false; + return this.search_results_mouseout(evt); + }; + + AbstractChosen.prototype.search_results_touchend = function(evt) { + if (this.touch_started) { + return this.search_results_mouseup(evt); + } + }; + + AbstractChosen.prototype.outerHTML = function(element) { + var tmp; + if (element.outerHTML) { + return element.outerHTML; + } + tmp = document.createElement("div"); + tmp.appendChild(element); + return tmp.innerHTML; + }; + + AbstractChosen.browser_is_supported = function() { + if (window.navigator.appName === "Microsoft Internet Explorer") { + return document.documentMode >= 8; + } + if (/iP(od|hone)/i.test(window.navigator.userAgent)) { + return false; + } + if (/Android/i.test(window.navigator.userAgent)) { + if (/Mobile/i.test(window.navigator.userAgent)) { + return false; + } + } + return true; + }; + + AbstractChosen.default_multiple_text = "Select Some Options"; + + AbstractChosen.default_single_text = "Select an Option"; + + AbstractChosen.default_no_result_text = "No results match"; + + return AbstractChosen; + + })(); + + $ = jQuery; + + $.fn.extend({ + chosen: function(options) { + if (!AbstractChosen.browser_is_supported()) { + return this; + } + return this.each(function(input_field) { + var $this, chosen; + $this = $(this); + chosen = $this.data('chosen'); + if (options === 'destroy' && chosen) { + chosen.destroy(); + } else if (!chosen) { + $this.data('chosen', new Chosen(this, options)); + } + }); + } + }); + + Chosen = (function(_super) { + __extends(Chosen, _super); + + function Chosen() { + _ref = Chosen.__super__.constructor.apply(this, arguments); + return _ref; + } + + Chosen.prototype.setup = function() { + this.form_field_jq = $(this.form_field); + this.current_selectedIndex = this.form_field.selectedIndex; + return this.is_rtl = this.form_field_jq.hasClass("chosen-rtl"); + }; + + Chosen.prototype.set_up_html = function() { + var container_classes, container_props; + container_classes = ["chosen-container"]; + container_classes.push("chosen-container-" + (this.is_multiple ? "multi" : "single")); + if (this.inherit_select_classes && this.form_field.className) { + container_classes.push(this.form_field.className); + } + if (this.is_rtl) { + container_classes.push("chosen-rtl"); + } + container_props = { + 'class': container_classes.join(' '), + 'style': "width: " + (this.container_width()) + ";", + 'title': this.form_field.title + }; + if (this.form_field.id.length) { + container_props.id = this.form_field.id.replace(/[^\w]/g, '_') + "_chosen"; + } + this.container = $("
", container_props); + if (this.is_multiple) { + this.container.html('
    '); + } else { + this.container.html('' + this.default_text + '
      '); + } + this.form_field_jq.hide().after(this.container); + this.dropdown = this.container.find('div.chosen-drop').first(); + this.search_field = this.container.find('input').first(); + this.search_results = this.container.find('ul.chosen-results').first(); + this.search_field_scale(); + this.search_no_results = this.container.find('li.no-results').first(); + if (this.is_multiple) { + this.search_choices = this.container.find('ul.chosen-choices').first(); + this.search_container = this.container.find('li.search-field').first(); + } else { + this.search_container = this.container.find('div.chosen-search').first(); + this.selected_item = this.container.find('.chosen-single').first(); + } + this.results_build(); + this.set_tab_index(); + this.set_label_behavior(); + return this.form_field_jq.trigger("chosen:ready", { + chosen: this + }); + }; + + Chosen.prototype.register_observers = function() { + var _this = this; + this.container.bind('mousedown.chosen', function(evt) { + _this.container_mousedown(evt); + }); + this.container.bind('mouseup.chosen', function(evt) { + _this.container_mouseup(evt); + }); + this.container.bind('mouseenter.chosen', function(evt) { + _this.mouse_enter(evt); + }); + this.container.bind('mouseleave.chosen', function(evt) { + _this.mouse_leave(evt); + }); + this.search_results.bind('mouseup.chosen', function(evt) { + _this.search_results_mouseup(evt); + }); + this.search_results.bind('mouseover.chosen', function(evt) { + _this.search_results_mouseover(evt); + }); + this.search_results.bind('mouseout.chosen', function(evt) { + _this.search_results_mouseout(evt); + }); + this.search_results.bind('mousewheel.chosen DOMMouseScroll.chosen', function(evt) { + _this.search_results_mousewheel(evt); + }); + this.search_results.bind('touchstart.chosen', function(evt) { + _this.search_results_touchstart(evt); + }); + this.search_results.bind('touchmove.chosen', function(evt) { + _this.search_results_touchmove(evt); + }); + this.search_results.bind('touchend.chosen', function(evt) { + _this.search_results_touchend(evt); + }); + this.form_field_jq.bind("chosen:updated.chosen", function(evt) { + _this.results_update_field(evt); + }); + this.form_field_jq.bind("chosen:activate.chosen", function(evt) { + _this.activate_field(evt); + }); + this.form_field_jq.bind("chosen:open.chosen", function(evt) { + _this.container_mousedown(evt); + }); + this.form_field_jq.bind("chosen:close.chosen", function(evt) { + _this.input_blur(evt); + }); + this.search_field.bind('blur.chosen', function(evt) { + _this.input_blur(evt); + }); + this.search_field.bind('keyup.chosen', function(evt) { + _this.keyup_checker(evt); + }); + this.search_field.bind('keydown.chosen', function(evt) { + _this.keydown_checker(evt); + }); + this.search_field.bind('focus.chosen', function(evt) { + _this.input_focus(evt); + }); + this.search_field.bind('cut.chosen', function(evt) { + _this.clipboard_event_checker(evt); + }); + this.search_field.bind('paste.chosen', function(evt) { + _this.clipboard_event_checker(evt); + }); + if (this.is_multiple) { + return this.search_choices.bind('click.chosen', function(evt) { + _this.choices_click(evt); + }); + } else { + return this.container.bind('click.chosen', function(evt) { + evt.preventDefault(); + }); + } + }; + + Chosen.prototype.destroy = function() { + $(this.container[0].ownerDocument).unbind("click.chosen", this.click_test_action); + if (this.search_field[0].tabIndex) { + this.form_field_jq[0].tabIndex = this.search_field[0].tabIndex; + } + this.container.remove(); + this.form_field_jq.removeData('chosen'); + return this.form_field_jq.show(); + }; + + Chosen.prototype.search_field_disabled = function() { + this.is_disabled = this.form_field_jq[0].disabled; + if (this.is_disabled) { + this.container.addClass('chosen-disabled'); + this.search_field[0].disabled = true; + if (!this.is_multiple) { + this.selected_item.unbind("focus.chosen", this.activate_action); + } + return this.close_field(); + } else { + this.container.removeClass('chosen-disabled'); + this.search_field[0].disabled = false; + if (!this.is_multiple) { + return this.selected_item.bind("focus.chosen", this.activate_action); + } + } + }; + + Chosen.prototype.container_mousedown = function(evt) { + if (!this.is_disabled) { + if (evt && evt.type === "mousedown" && !this.results_showing) { + evt.preventDefault(); + } + if (!((evt != null) && ($(evt.target)).hasClass("search-choice-close"))) { + if (!this.active_field) { + if (this.is_multiple) { + this.search_field.val(""); + } + $(this.container[0].ownerDocument).bind('click.chosen', this.click_test_action); + this.results_show(); + } else if (!this.is_multiple && evt && (($(evt.target)[0] === this.selected_item[0]) || $(evt.target).parents("a.chosen-single").length)) { + evt.preventDefault(); + this.results_toggle(); + } + return this.activate_field(); + } + } + }; + + Chosen.prototype.container_mouseup = function(evt) { + if (evt.target.nodeName === "ABBR" && !this.is_disabled) { + return this.results_reset(evt); + } + }; + + Chosen.prototype.search_results_mousewheel = function(evt) { + var delta; + if (evt.originalEvent) { + delta = -evt.originalEvent.wheelDelta || evt.originalEvent.detail; + } + if (delta != null) { + evt.preventDefault(); + if (evt.type === 'DOMMouseScroll') { + delta = delta * 40; + } + return this.search_results.scrollTop(delta + this.search_results.scrollTop()); + } + }; + + Chosen.prototype.blur_test = function(evt) { + if (!this.active_field && this.container.hasClass("chosen-container-active")) { + return this.close_field(); + } + }; + + Chosen.prototype.close_field = function() { + $(this.container[0].ownerDocument).unbind("click.chosen", this.click_test_action); + this.active_field = false; + this.results_hide(); + this.container.removeClass("chosen-container-active"); + this.clear_backstroke(); + this.show_search_field_default(); + return this.search_field_scale(); + }; + + Chosen.prototype.activate_field = function() { + this.container.addClass("chosen-container-active"); + this.active_field = true; + this.search_field.val(this.search_field.val()); + return this.search_field.focus(); + }; + + Chosen.prototype.test_active_click = function(evt) { + var active_container; + active_container = $(evt.target).closest('.chosen-container'); + if (active_container.length && this.container[0] === active_container[0]) { + return this.active_field = true; + } else { + return this.close_field(); + } + }; + + Chosen.prototype.results_build = function() { + this.parsing = true; + this.selected_option_count = null; + this.results_data = SelectParser.select_to_array(this.form_field); + if (this.is_multiple) { + this.search_choices.find("li.search-choice").remove(); + } else if (!this.is_multiple) { + this.single_set_selected_text(); + if (this.disable_search || this.form_field.options.length <= this.disable_search_threshold) { + this.search_field[0].readOnly = true; + this.container.addClass("chosen-container-single-nosearch"); + } else { + this.search_field[0].readOnly = false; + this.container.removeClass("chosen-container-single-nosearch"); + } + } + this.update_results_content(this.results_option_build({ + first: true + })); + this.search_field_disabled(); + this.show_search_field_default(); + this.search_field_scale(); + return this.parsing = false; + }; + + Chosen.prototype.result_do_highlight = function(el) { + var high_bottom, high_top, maxHeight, visible_bottom, visible_top; + if (el.length) { + this.result_clear_highlight(); + this.result_highlight = el; + this.result_highlight.addClass("highlighted"); + maxHeight = parseInt(this.search_results.css("maxHeight"), 10); + visible_top = this.search_results.scrollTop(); + visible_bottom = maxHeight + visible_top; + high_top = this.result_highlight.position().top + this.search_results.scrollTop(); + high_bottom = high_top + this.result_highlight.outerHeight(); + if (high_bottom >= visible_bottom) { + return this.search_results.scrollTop((high_bottom - maxHeight) > 0 ? high_bottom - maxHeight : 0); + } else if (high_top < visible_top) { + return this.search_results.scrollTop(high_top); + } + } + }; + + Chosen.prototype.result_clear_highlight = function() { + if (this.result_highlight) { + this.result_highlight.removeClass("highlighted"); + } + return this.result_highlight = null; + }; + + Chosen.prototype.results_show = function() { + if (this.is_multiple && this.max_selected_options <= this.choices_count()) { + this.form_field_jq.trigger("chosen:maxselected", { + chosen: this + }); + return false; + } + this.container.addClass("chosen-with-drop"); + this.results_showing = true; + this.search_field.focus(); + this.search_field.val(this.search_field.val()); + this.winnow_results(); + return this.form_field_jq.trigger("chosen:showing_dropdown", { + chosen: this + }); + }; + + Chosen.prototype.update_results_content = function(content) { + return this.search_results.html(content); + }; + + Chosen.prototype.results_hide = function() { + if (this.results_showing) { + this.result_clear_highlight(); + this.container.removeClass("chosen-with-drop"); + this.form_field_jq.trigger("chosen:hiding_dropdown", { + chosen: this + }); + } + return this.results_showing = false; + }; + + Chosen.prototype.set_tab_index = function(el) { + var ti; + if (this.form_field.tabIndex) { + ti = this.form_field.tabIndex; + this.form_field.tabIndex = -1; + return this.search_field[0].tabIndex = ti; + } + }; + + Chosen.prototype.set_label_behavior = function() { + var _this = this; + this.form_field_label = this.form_field_jq.parents("label"); + if (!this.form_field_label.length && this.form_field.id.length) { + this.form_field_label = $("label[for='" + this.form_field.id + "']"); + } + if (this.form_field_label.length > 0) { + return this.form_field_label.bind('click.chosen', function(evt) { + if (_this.is_multiple) { + return _this.container_mousedown(evt); + } else { + return _this.activate_field(); + } + }); + } + }; + + Chosen.prototype.show_search_field_default = function() { + if (this.is_multiple && this.choices_count() < 1 && !this.active_field) { + this.search_field.val(this.default_text); + return this.search_field.addClass("default"); + } else { + this.search_field.val(""); + return this.search_field.removeClass("default"); + } + }; + + Chosen.prototype.search_results_mouseup = function(evt) { + var target; + target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first(); + if (target.length) { + this.result_highlight = target; + this.result_select(evt); + return this.search_field.focus(); + } + }; + + Chosen.prototype.search_results_mouseover = function(evt) { + var target; + target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first(); + if (target) { + return this.result_do_highlight(target); + } + }; + + Chosen.prototype.search_results_mouseout = function(evt) { + if ($(evt.target).hasClass("active-result" || $(evt.target).parents('.active-result').first())) { + return this.result_clear_highlight(); + } + }; + + Chosen.prototype.choice_build = function(item) { + var choice, close_link, + _this = this; + choice = $('
    • ', { + "class": "search-choice" + }).html("" + item.html + ""); + if (item.disabled) { + choice.addClass('search-choice-disabled'); + } else { + close_link = $('', { + "class": 'search-choice-close', + 'data-option-array-index': item.array_index + }); + close_link.bind('click.chosen', function(evt) { + return _this.choice_destroy_link_click(evt); + }); + choice.append(close_link); + } + return this.search_container.before(choice); + }; + + Chosen.prototype.choice_destroy_link_click = function(evt) { + evt.preventDefault(); + evt.stopPropagation(); + if (!this.is_disabled) { + return this.choice_destroy($(evt.target)); + } + }; + + Chosen.prototype.choice_destroy = function(link) { + if (this.result_deselect(link[0].getAttribute("data-option-array-index"))) { + this.show_search_field_default(); + if (this.is_multiple && this.choices_count() > 0 && this.search_field.val().length < 1) { + this.results_hide(); + } + link.parents('li').first().remove(); + return this.search_field_scale(); + } + }; + + Chosen.prototype.results_reset = function() { + this.reset_single_select_options(); + this.form_field.options[0].selected = true; + this.single_set_selected_text(); + this.show_search_field_default(); + this.results_reset_cleanup(); + this.form_field_jq.trigger("change"); + if (this.active_field) { + return this.results_hide(); + } + }; + + Chosen.prototype.results_reset_cleanup = function() { + this.current_selectedIndex = this.form_field.selectedIndex; + return this.selected_item.find("abbr").remove(); + }; + + Chosen.prototype.result_select = function(evt) { + var high, item; + if (this.result_highlight) { + high = this.result_highlight; + this.result_clear_highlight(); + if (this.is_multiple && this.max_selected_options <= this.choices_count()) { + this.form_field_jq.trigger("chosen:maxselected", { + chosen: this + }); + return false; + } + if (this.is_multiple) { + high.removeClass("active-result"); + } else { + this.reset_single_select_options(); + } + item = this.results_data[high[0].getAttribute("data-option-array-index")]; + item.selected = true; + this.form_field.options[item.options_index].selected = true; + this.selected_option_count = null; + if (this.is_multiple) { + this.choice_build(item); + } else { + this.single_set_selected_text(item.text); + } + if (!((evt.metaKey || evt.ctrlKey) && this.is_multiple)) { + this.results_hide(); + } + this.search_field.val(""); + if (this.is_multiple || this.form_field.selectedIndex !== this.current_selectedIndex) { + this.form_field_jq.trigger("change", { + 'selected': this.form_field.options[item.options_index].value + }); + } + this.current_selectedIndex = this.form_field.selectedIndex; + return this.search_field_scale(); + } + }; + + Chosen.prototype.single_set_selected_text = function(text) { + if (text == null) { + text = this.default_text; + } + if (text === this.default_text) { + this.selected_item.addClass("chosen-default"); + } else { + this.single_deselect_control_build(); + this.selected_item.removeClass("chosen-default"); + } + return this.selected_item.find("span").text(text); + }; + + Chosen.prototype.result_deselect = function(pos) { + var result_data; + result_data = this.results_data[pos]; + if (!this.form_field.options[result_data.options_index].disabled) { + result_data.selected = false; + this.form_field.options[result_data.options_index].selected = false; + this.selected_option_count = null; + this.result_clear_highlight(); + if (this.results_showing) { + this.winnow_results(); + } + this.form_field_jq.trigger("change", { + deselected: this.form_field.options[result_data.options_index].value + }); + this.search_field_scale(); + return true; + } else { + return false; + } + }; + + Chosen.prototype.single_deselect_control_build = function() { + if (!this.allow_single_deselect) { + return; + } + if (!this.selected_item.find("abbr").length) { + this.selected_item.find("span").first().after(""); + } + return this.selected_item.addClass("chosen-single-with-deselect"); + }; + + Chosen.prototype.get_search_text = function() { + if (this.search_field.val() === this.default_text) { + return ""; + } else { + return $('
      ').text($.trim(this.search_field.val())).html(); + } + }; + + Chosen.prototype.winnow_results_set_highlight = function() { + var do_high, selected_results; + selected_results = !this.is_multiple ? this.search_results.find(".result-selected.active-result") : []; + do_high = selected_results.length ? selected_results.first() : this.search_results.find(".active-result").first(); + if (do_high != null) { + return this.result_do_highlight(do_high); + } + }; + + Chosen.prototype.no_results = function(terms) { + var no_results_html; + no_results_html = $('
    • ' + this.results_none_found + ' ""
    • '); + no_results_html.find("span").first().html(terms); + this.search_results.append(no_results_html); + return this.form_field_jq.trigger("chosen:no_results", { + chosen: this + }); + }; + + Chosen.prototype.no_results_clear = function() { + return this.search_results.find(".no-results").remove(); + }; + + Chosen.prototype.keydown_arrow = function() { + var next_sib; + if (this.results_showing && this.result_highlight) { + next_sib = this.result_highlight.nextAll("li.active-result").first(); + if (next_sib) { + return this.result_do_highlight(next_sib); + } + } else { + return this.results_show(); + } + }; + + Chosen.prototype.keyup_arrow = function() { + var prev_sibs; + if (!this.results_showing && !this.is_multiple) { + return this.results_show(); + } else if (this.result_highlight) { + prev_sibs = this.result_highlight.prevAll("li.active-result"); + if (prev_sibs.length) { + return this.result_do_highlight(prev_sibs.first()); + } else { + if (this.choices_count() > 0) { + this.results_hide(); + } + return this.result_clear_highlight(); + } + } + }; + + Chosen.prototype.keydown_backstroke = function() { + var next_available_destroy; + if (this.pending_backstroke) { + this.choice_destroy(this.pending_backstroke.find("a").first()); + return this.clear_backstroke(); + } else { + next_available_destroy = this.search_container.siblings("li.search-choice").last(); + if (next_available_destroy.length && !next_available_destroy.hasClass("search-choice-disabled")) { + this.pending_backstroke = next_available_destroy; + if (this.single_backstroke_delete) { + return this.keydown_backstroke(); + } else { + return this.pending_backstroke.addClass("search-choice-focus"); + } + } + } + }; + + Chosen.prototype.clear_backstroke = function() { + if (this.pending_backstroke) { + this.pending_backstroke.removeClass("search-choice-focus"); + } + return this.pending_backstroke = null; + }; + + Chosen.prototype.keydown_checker = function(evt) { + var stroke, _ref1; + stroke = (_ref1 = evt.which) != null ? _ref1 : evt.keyCode; + this.search_field_scale(); + if (stroke !== 8 && this.pending_backstroke) { + this.clear_backstroke(); + } + switch (stroke) { + case 8: + this.backstroke_length = this.search_field.val().length; + break; + case 9: + if (this.results_showing && !this.is_multiple) { + this.result_select(evt); + } + this.mouse_on_container = false; + break; + case 13: + evt.preventDefault(); + break; + case 38: + evt.preventDefault(); + this.keyup_arrow(); + break; + case 40: + evt.preventDefault(); + this.keydown_arrow(); + break; + } + }; + + Chosen.prototype.search_field_scale = function() { + var div, f_width, h, style, style_block, styles, w, _i, _len; + if (this.is_multiple) { + h = 0; + w = 0; + style_block = "position:absolute; left: -1000px; top: -1000px; display:none;"; + styles = ['font-size', 'font-style', 'font-weight', 'font-family', 'line-height', 'text-transform', 'letter-spacing']; + for (_i = 0, _len = styles.length; _i < _len; _i++) { + style = styles[_i]; + style_block += style + ":" + this.search_field.css(style) + ";"; + } + div = $('
      ', { + 'style': style_block + }); + div.text(this.search_field.val()); + $('body').append(div); + w = div.width() + 25; + div.remove(); + f_width = this.container.outerWidth(); + if (w > f_width - 10) { + w = f_width - 10; + } + return this.search_field.css({ + 'width': w + 'px' + }); + } + }; + + return Chosen; + + })(AbstractChosen); + +}).call(this); diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/assets/js/chosen.jquery.min.js b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/js/chosen.jquery.min.js new file mode 100644 index 00000000..4ef6c6d9 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/js/chosen.jquery.min.js @@ -0,0 +1,2 @@ +/* phpcs:ignoreFile */ +(function(){var t,e,s,i,r,o={}.hasOwnProperty,n=function(t,e){function s(){this.constructor=t}for(var i in e)o.call(e,i)&&(t[i]=e[i]);return s.prototype=e.prototype,t.prototype=new s,t.__super__=e.prototype,t};i=function(){function t(){this.options_index=0,this.parsed=[]}return t.prototype.add_node=function(t){return"OPTGROUP"===t.nodeName.toUpperCase()?this.add_group(t):this.add_option(t)},t.prototype.add_group=function(t){var e,s,i,r,o,n;for(e=this.parsed.length,this.parsed.push({array_index:e,group:!0,label:this.escapeExpression(t.label),children:0,disabled:t.disabled}),o=t.childNodes,n=[],i=0,r=o.length;i\"\'\`]/.test(t)?(e={"<":"<",">":">",'"':""","'":"'","`":"`"},s=/&(?!\w+;)|[\<\>\"\'\`]/g,t.replace(s,function(t){return e[t]||"&"})):t},t}(),i.select_to_array=function(t){var e,s,r,o,n;for(s=new i,n=t.childNodes,r=0,o=n.length;r0?(e=document.createElement("li"),e.className="group-result",e.innerHTML=t.search_text,this.outerHTML(e)):""},t.prototype.results_update_field=function(){if(this.set_default_text(),this.is_multiple||this.results_reset_cleanup(),this.result_clear_highlight(),this.results_build(),this.results_showing)return this.winnow_results()},t.prototype.reset_single_select_options=function(){var t,e,s,i,r;for(i=this.results_data,r=[],e=0,s=i.length;e"+e.search_text.substr(h+n.length),e.search_text=l.substr(0,h)+""+l.substr(h)),null!=o&&(o.group_match=!0)):null!=e.group_array_index&&this.results_data[e.group_array_index].search_match&&(e.search_match=!0)));return this.result_clear_highlight(),r<1&&n.length?(this.update_results_content(""),this.no_results(n)):(this.update_results_content(this.results_option_build()),this.winnow_results_set_highlight())},t.prototype.search_string_match=function(t,e){var s,i,r,o;if(e.test(t))return!0;if(this.enable_split_word_search&&(t.indexOf(" ")>=0||0===t.indexOf("["))&&(i=t.replace(/\[|\]/g,"").split(" "),i.length))for(r=0,o=i.length;r0)return this.keydown_backstroke();if(!this.pending_backstroke)return this.result_clear_highlight(),this.results_search();break;case 13:if(t.preventDefault(),this.result_highlight){if(this.results_showing)return this.result_select(t)}else if(jQuery(this.form_field).hasClass("sa_cbl_add_location")){var i=this,r=jQuery(i.form_field),o=jQuery(t.target).val();if(o.indexOf("|")>0){var n=o.split("|"),h=0-n.length,l=n.join(""),r.trigger("chosen:updated"),jQuery.each(i.search_results.find("li.active-result").slice(h),function(e,s){i.result_highlight=jQuery(this),i.result_select(t)})}else r.append(""),r.trigger("chosen:updated"),i.result_highlight=i.search_results.find("li.active-result").last(),i.result_select(t)}break;case 27:return this.results_showing&&this.results_hide(),!0;case 9:case 38:case 40:case 16:case 91:case 17:break;default:return this.results_search()}},t.prototype.clipboard_event_checker=function(t){var e=this;return setTimeout(function(){return e.results_search()},50)},t.prototype.container_width=function(){return null!=this.options.width?this.options.width:""+this.form_field.offsetWidth+"px"},t.prototype.include_option_in_results=function(t){return!(this.is_multiple&&!this.display_selected_options&&t.selected)&&(!(!this.display_disabled_options&&t.disabled)&&!t.empty)},t.prototype.search_results_touchstart=function(t){return this.touch_started=!0,this.search_results_mouseover(t)},t.prototype.search_results_touchmove=function(t){return this.touch_started=!1,this.search_results_mouseout(t)},t.prototype.search_results_touchend=function(t){if(this.touch_started)return this.search_results_mouseup(t)},t.prototype.outerHTML=function(t){var e;return t.outerHTML?t.outerHTML:(e=document.createElement("div"),e.appendChild(t),e.innerHTML)},t.browser_is_supported=function(){return"Microsoft Internet Explorer"===window.navigator.appName?document.documentMode>=8:!/iP(od|hone)/i.test(window.navigator.userAgent)&&(!/Android/i.test(window.navigator.userAgent)||!/Mobile/i.test(window.navigator.userAgent))},t.default_multiple_text="Select Some Options",t.default_single_text="Select an Option",t.default_no_result_text="No results match",t}(),t=jQuery,t.fn.extend({chosen:function(i){return e.browser_is_supported()?this.each(function(e){var r,o;r=t(this),o=r.data("chosen"),"destroy"===i&&o?o.destroy():o||r.data("chosen",new s(this,i))}):this}}),s=function(e){function s(){return r=s.__super__.constructor.apply(this,arguments)}return n(s,e),s.prototype.setup=function(){return this.form_field_jq=t(this.form_field),this.current_selectedIndex=this.form_field.selectedIndex,this.is_rtl=this.form_field_jq.hasClass("chosen-rtl")},s.prototype.set_up_html=function(){var e,s;return e=["chosen-container"],e.push("chosen-container-"+(this.is_multiple?"multi":"single")),this.inherit_select_classes&&this.form_field.className&&e.push(this.form_field.className),this.is_rtl&&e.push("chosen-rtl"),s={class:e.join(" "),style:"width: "+this.container_width()+";",title:this.form_field.title},this.form_field.id.length&&(s.id=this.form_field.id.replace(/[^\w]/g,"_")+"_chosen"),this.container=t("
      ",s),this.is_multiple?this.container.html('
        '):this.container.html('
        '+this.default_text+'
          '),this.form_field_jq.hide().after(this.container),this.dropdown=this.container.find("div.chosen-drop").first(),this.search_field=this.container.find("input").first(),this.search_results=this.container.find("ul.chosen-results").first(),this.search_field_scale(),this.search_no_results=this.container.find("li.no-results").first(),this.is_multiple?(this.search_choices=this.container.find("ul.chosen-choices").first(),this.search_container=this.container.find("li.search-field").first()):(this.search_container=this.container.find("div.chosen-search").first(),this.selected_item=this.container.find(".chosen-single").first()),this.results_build(),this.set_tab_index(),this.set_label_behavior(),this.form_field_jq.trigger("chosen:ready",{chosen:this})},s.prototype.register_observers=function(){var t=this;return this.container.bind("mousedown.chosen",function(e){t.container_mousedown(e)}),this.container.bind("mouseup.chosen",function(e){t.container_mouseup(e)}),this.container.bind("mouseenter.chosen",function(e){t.mouse_enter(e)}),this.container.bind("mouseleave.chosen",function(e){t.mouse_leave(e)}),this.search_results.bind("mouseup.chosen",function(e){t.search_results_mouseup(e)}),this.search_results.bind("mouseover.chosen",function(e){t.search_results_mouseover(e)}),this.search_results.bind("mouseout.chosen",function(e){t.search_results_mouseout(e)}),this.search_results.bind("mousewheel.chosen DOMMouseScroll.chosen",function(e){t.search_results_mousewheel(e)}),this.search_results.bind("touchstart.chosen",function(e){t.search_results_touchstart(e)}),this.search_results.bind("touchmove.chosen",function(e){t.search_results_touchmove(e)}),this.search_results.bind("touchend.chosen",function(e){t.search_results_touchend(e)}),this.form_field_jq.bind("chosen:updated.chosen",function(e){t.results_update_field(e)}),this.form_field_jq.bind("chosen:activate.chosen",function(e){t.activate_field(e)}),this.form_field_jq.bind("chosen:open.chosen",function(e){t.container_mousedown(e)}),this.form_field_jq.bind("chosen:close.chosen",function(e){t.input_blur(e)}),this.search_field.bind("blur.chosen",function(e){t.input_blur(e)}),this.search_field.bind("keyup.chosen",function(e){t.keyup_checker(e)}),this.search_field.bind("keydown.chosen",function(e){t.keydown_checker(e)}),this.search_field.bind("focus.chosen",function(e){t.input_focus(e)}),this.search_field.bind("cut.chosen",function(e){t.clipboard_event_checker(e)}),this.search_field.bind("paste.chosen",function(e){t.clipboard_event_checker(e)}),this.is_multiple?this.search_choices.bind("click.chosen",function(e){t.choices_click(e)}):this.container.bind("click.chosen",function(t){t.preventDefault()})},s.prototype.destroy=function(){return t(this.container[0].ownerDocument).unbind("click.chosen",this.click_test_action),this.search_field[0].tabIndex&&(this.form_field_jq[0].tabIndex=this.search_field[0].tabIndex),this.container.remove(),this.form_field_jq.removeData("chosen"),this.form_field_jq.show()},s.prototype.search_field_disabled=function(){return this.is_disabled=this.form_field_jq[0].disabled,this.is_disabled?(this.container.addClass("chosen-disabled"),this.search_field[0].disabled=!0,this.is_multiple||this.selected_item.unbind("focus.chosen",this.activate_action),this.close_field()):(this.container.removeClass("chosen-disabled"),this.search_field[0].disabled=!1,this.is_multiple?void 0:this.selected_item.bind("focus.chosen",this.activate_action))},s.prototype.container_mousedown=function(e){if(!this.is_disabled&&(e&&"mousedown"===e.type&&!this.results_showing&&e.preventDefault(),null==e||!t(e.target).hasClass("search-choice-close")))return this.active_field?this.is_multiple||!e||t(e.target)[0]!==this.selected_item[0]&&!t(e.target).parents("a.chosen-single").length||(e.preventDefault(),this.results_toggle()):(this.is_multiple&&this.search_field.val(""),t(this.container[0].ownerDocument).bind("click.chosen",this.click_test_action),this.results_show()),this.activate_field()},s.prototype.container_mouseup=function(t){if("ABBR"===t.target.nodeName&&!this.is_disabled)return this.results_reset(t)},s.prototype.search_results_mousewheel=function(t){var e;if(t.originalEvent&&(e=-t.originalEvent.wheelDelta||t.originalEvent.detail),null!=e)return t.preventDefault(),"DOMMouseScroll"===t.type&&(e*=40),this.search_results.scrollTop(e+this.search_results.scrollTop())},s.prototype.blur_test=function(t){if(!this.active_field&&this.container.hasClass("chosen-container-active"))return this.close_field()},s.prototype.close_field=function(){return t(this.container[0].ownerDocument).unbind("click.chosen",this.click_test_action),this.active_field=!1,this.results_hide(),this.container.removeClass("chosen-container-active"),this.clear_backstroke(),this.show_search_field_default(),this.search_field_scale()},s.prototype.activate_field=function(){return this.container.addClass("chosen-container-active"),this.active_field=!0,this.search_field.val(this.search_field.val()),this.search_field.focus()},s.prototype.test_active_click=function(e){var s;return s=t(e.target).closest(".chosen-container"),s.length&&this.container[0]===s[0]?this.active_field=!0:this.close_field()},s.prototype.results_build=function(){return this.parsing=!0,this.selected_option_count=null,this.results_data=i.select_to_array(this.form_field),this.is_multiple?this.search_choices.find("li.search-choice").remove():this.is_multiple||(this.single_set_selected_text(),this.disable_search||this.form_field.options.length<=this.disable_search_threshold?(this.search_field[0].readOnly=!0,this.container.addClass("chosen-container-single-nosearch")):(this.search_field[0].readOnly=!1,this.container.removeClass("chosen-container-single-nosearch"))),this.update_results_content(this.results_option_build({first:!0})),this.search_field_disabled(),this.show_search_field_default(),this.search_field_scale(),this.parsing=!1},s.prototype.result_do_highlight=function(t){var e,s,i,r,o;if(t.length){if(this.result_clear_highlight(),this.result_highlight=t,this.result_highlight.addClass("highlighted"),i=parseInt(this.search_results.css("maxHeight"),10),o=this.search_results.scrollTop(),r=i+o,s=this.result_highlight.position().top+this.search_results.scrollTop(),e=s+this.result_highlight.outerHeight(),e>=r)return this.search_results.scrollTop(e-i>0?e-i:0);if(s0)return this.form_field_label.bind("click.chosen",function(t){return e.is_multiple?e.container_mousedown(t):e.activate_field()})},s.prototype.show_search_field_default=function(){return this.is_multiple&&this.choices_count()<1&&!this.active_field?(this.search_field.val(this.default_text),this.search_field.addClass("default")):(this.search_field.val(""),this.search_field.removeClass("default"))},s.prototype.search_results_mouseup=function(e){var s;if(s=t(e.target).hasClass("active-result")?t(e.target):t(e.target).parents(".active-result").first(),s.length)return this.result_highlight=s,this.result_select(e),this.search_field.focus()},s.prototype.search_results_mouseover=function(e){var s;if(s=t(e.target).hasClass("active-result")?t(e.target):t(e.target).parents(".active-result").first())return this.result_do_highlight(s)},s.prototype.search_results_mouseout=function(e){if(t(e.target).hasClass("active-result")||t(e.target).parents(".active-result").first())return this.result_clear_highlight()},s.prototype.choice_build=function(e){var s,i,r=this;return s=t("
        • ",{class:"search-choice"}).html(""+e.html+""),e.disabled?s.addClass("search-choice-disabled"):(i=t("",{class:"search-choice-close","data-option-array-index":e.array_index}),i.bind("click.chosen",function(t){return r.choice_destroy_link_click(t)}),s.append(i)),this.search_container.before(s)},s.prototype.choice_destroy_link_click=function(e){if(e.preventDefault(),e.stopPropagation(),!this.is_disabled)return this.choice_destroy(t(e.target))},s.prototype.choice_destroy=function(t){if(this.result_deselect(t[0].getAttribute("data-option-array-index")))return this.show_search_field_default(),this.is_multiple&&this.choices_count()>0&&this.search_field.val().length<1&&this.results_hide(),t.parents("li").first().remove(),this.search_field_scale()},s.prototype.results_reset=function(){if(this.reset_single_select_options(),this.form_field.options[0].selected=!0,this.single_set_selected_text(),this.show_search_field_default(),this.results_reset_cleanup(),this.form_field_jq.trigger("change"),this.active_field)return this.results_hide()},s.prototype.results_reset_cleanup=function(){return this.current_selectedIndex=this.form_field.selectedIndex,this.selected_item.find("abbr").remove()},s.prototype.result_select=function(t){var e,s;if(this.result_highlight)return e=this.result_highlight,this.result_clear_highlight(),this.is_multiple&&this.max_selected_options<=this.choices_count()?(this.form_field_jq.trigger("chosen:maxselected",{chosen:this}),!1):(this.is_multiple?e.removeClass("active-result"):this.reset_single_select_options(),s=this.results_data[e[0].getAttribute("data-option-array-index")],s.selected=!0,this.form_field.options[s.options_index].selected=!0,this.selected_option_count=null,this.is_multiple?this.choice_build(s):this.single_set_selected_text(s.text),(t.metaKey||t.ctrlKey)&&this.is_multiple||this.results_hide(),this.search_field.val(""),(this.is_multiple||this.form_field.selectedIndex!==this.current_selectedIndex)&&this.form_field_jq.trigger("change",{selected:this.form_field.options[s.options_index].value}),this.current_selectedIndex=this.form_field.selectedIndex,this.search_field_scale())},s.prototype.single_set_selected_text=function(t){return null==t&&(t=this.default_text),t===this.default_text?this.selected_item.addClass("chosen-default"):(this.single_deselect_control_build(),this.selected_item.removeClass("chosen-default")),this.selected_item.find("span").text(t)},s.prototype.result_deselect=function(t){var e;return e=this.results_data[t],!this.form_field.options[e.options_index].disabled&&(e.selected=!1,this.form_field.options[e.options_index].selected=!1,this.selected_option_count=null,this.result_clear_highlight(),this.results_showing&&this.winnow_results(),this.form_field_jq.trigger("change",{deselected:this.form_field.options[e.options_index].value}),this.search_field_scale(),!0)},s.prototype.single_deselect_control_build=function(){if(this.allow_single_deselect)return this.selected_item.find("abbr").length||this.selected_item.find("span").first().after(''),this.selected_item.addClass("chosen-single-with-deselect")},s.prototype.get_search_text=function(){return this.search_field.val()===this.default_text?"":t("
          ").text(t.trim(this.search_field.val())).html()},s.prototype.winnow_results_set_highlight=function(){var t,e;if(e=this.is_multiple?[]:this.search_results.find(".result-selected.active-result"),t=e.length?e.first():this.search_results.find(".active-result").first(),null!=t)return this.result_do_highlight(t)},s.prototype.no_results=function(e){var s;return s=t('
        • '+this.results_none_found+' ""
        • '),s.find("span").first().html(e),this.search_results.append(s),this.form_field_jq.trigger("chosen:no_results",{chosen:this})},s.prototype.no_results_clear=function(){return this.search_results.find(".no-results").remove()},s.prototype.keydown_arrow=function(){var t;return this.results_showing&&this.result_highlight?(t=this.result_highlight.nextAll("li.active-result").first())?this.result_do_highlight(t):void 0:this.results_show()},s.prototype.keyup_arrow=function(){var t;return this.results_showing||this.is_multiple?this.result_highlight?(t=this.result_highlight.prevAll("li.active-result"),t.length?this.result_do_highlight(t.first()):(this.choices_count()>0&&this.results_hide(),this.result_clear_highlight())):void 0:this.results_show()},s.prototype.keydown_backstroke=function(){var t;return this.pending_backstroke?(this.choice_destroy(this.pending_backstroke.find("a").first()),this.clear_backstroke()):(t=this.search_container.siblings("li.search-choice").last(),t.length&&!t.hasClass("search-choice-disabled")?(this.pending_backstroke=t,this.single_backstroke_delete?this.keydown_backstroke():this.pending_backstroke.addClass("search-choice-focus")):void 0)},s.prototype.clear_backstroke=function(){return this.pending_backstroke&&this.pending_backstroke.removeClass("search-choice-focus"),this.pending_backstroke=null},s.prototype.keydown_checker=function(t){var e,s;switch(e=null!=(s=t.which)?s:t.keyCode,this.search_field_scale(),8!==e&&this.pending_backstroke&&this.clear_backstroke(),e){case 8:this.backstroke_length=this.search_field.val().length;break;case 9:this.results_showing&&!this.is_multiple&&this.result_select(t),this.mouse_on_container=!1;break;case 13:t.preventDefault();break;case 38:t.preventDefault(),this.keyup_arrow();break;case 40:t.preventDefault(),this.keydown_arrow()}},s.prototype.search_field_scale=function(){var e,s,i,r,o,n,h,l,c;if(this.is_multiple){for(i=0,h=0,o="position:absolute; left: -1000px; top: -1000px; display:none;",n=["font-size","font-style","font-weight","font-family","line-height","text-transform","letter-spacing"],l=0,c=n.length;l",{style:o}),e.text(this.search_field.val()),t("body").append(e),h=e.width()+25,e.remove(),s=this.container.outerWidth(),h>s-10&&(h=s-10),this.search_field.css({width:h+"px"})}},s}(e)}).call(this); \ No newline at end of file diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/assets/js/jquery-ui-timepicker-addon.js b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/js/jquery-ui-timepicker-addon.js new file mode 100644 index 00000000..7d13bade --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/assets/js/jquery-ui-timepicker-addon.js @@ -0,0 +1,2355 @@ +// phpcs:ignoreFile +/*! jQuery Timepicker Addon - v1.6.3 - 2016-04-20 +* http://trentrichardson.com/examples/timepicker +* Copyright (c) 2016 Trent Richardson; Licensed MIT */ +(function (factory) { + if (typeof define === 'function' && define.amd) { + define( ['jquery', 'jquery-ui'], factory ); + } else { + factory( jQuery ); + } +}(function ($) { + + /* + * Lets not redefine timepicker, Prevent "Uncaught RangeError: Maximum call stack size exceeded" + */ + $.ui.timepicker = $.ui.timepicker || {}; + if ($.ui.timepicker.version) { + return; + } + + /* + * Extend jQueryUI, get it started with our version number + */ + $.extend( + $.ui, { + timepicker: { + version: "1.6.3" + } + } + ); + + /* + * Timepicker manager. + * Use the singleton instance of this class, $.timepicker, to interact with the time picker. + * Settings for (groups of) time pickers are maintained in an instance object, + * allowing multiple different settings on the same page. + */ + var Timepicker = function () { + this.regional = []; // Available regional settings, indexed by language code + this.regional[''] = { // Default regional settings + currentText: 'Now', + closeText: 'Done', + amNames: ['AM', 'A'], + pmNames: ['PM', 'P'], + timeFormat: 'HH:mm', + timeSuffix: '', + timeOnlyTitle: 'Choose Time', + timeText: 'Time', + hourText: 'Hour', + minuteText: 'Minute', + secondText: 'Second', + millisecText: 'Millisecond', + microsecText: 'Microsecond', + timezoneText: 'Time Zone', + isRTL: false + }; + this._defaults = { // Global defaults for all the datetime picker instances + showButtonPanel: true, + timeOnly: false, + timeOnlyShowDate: false, + showHour: null, + showMinute: null, + showSecond: null, + showMillisec: null, + showMicrosec: null, + showTimezone: null, + showTime: true, + stepHour: 1, + stepMinute: 1, + stepSecond: 1, + stepMillisec: 1, + stepMicrosec: 1, + hour: 0, + minute: 0, + second: 0, + millisec: 0, + microsec: 0, + timezone: null, + hourMin: 0, + minuteMin: 0, + secondMin: 0, + millisecMin: 0, + microsecMin: 0, + hourMax: 23, + minuteMax: 59, + secondMax: 59, + millisecMax: 999, + microsecMax: 999, + minDateTime: null, + maxDateTime: null, + maxTime: null, + minTime: null, + onSelect: null, + hourGrid: 0, + minuteGrid: 0, + secondGrid: 0, + millisecGrid: 0, + microsecGrid: 0, + alwaysSetTime: true, + separator: ' ', + altFieldTimeOnly: true, + altTimeFormat: null, + altSeparator: null, + altTimeSuffix: null, + altRedirectFocus: true, + pickerTimeFormat: null, + pickerTimeSuffix: null, + showTimepicker: true, + timezoneList: null, + addSliderAccess: false, + sliderAccessArgs: null, + controlType: 'slider', + oneLine: false, + defaultValue: null, + parse: 'strict', + afterInject: null + }; + $.extend( this._defaults, this.regional[''] ); + }; + + $.extend( + Timepicker.prototype, { + $input: null, + $altInput: null, + $timeObj: null, + inst: null, + hour_slider: null, + minute_slider: null, + second_slider: null, + millisec_slider: null, + microsec_slider: null, + timezone_select: null, + maxTime: null, + minTime: null, + hour: 0, + minute: 0, + second: 0, + millisec: 0, + microsec: 0, + timezone: null, + hourMinOriginal: null, + minuteMinOriginal: null, + secondMinOriginal: null, + millisecMinOriginal: null, + microsecMinOriginal: null, + hourMaxOriginal: null, + minuteMaxOriginal: null, + secondMaxOriginal: null, + millisecMaxOriginal: null, + microsecMaxOriginal: null, + ampm: '', + formattedDate: '', + formattedTime: '', + formattedDateTime: '', + timezoneList: null, + units: ['hour', 'minute', 'second', 'millisec', 'microsec'], + support: {}, + control: null, + + /* + * Override the default settings for all instances of the time picker. + * @param {Object} settings object - the new settings to use as defaults (anonymous object) + * @return {Object} the manager object + */ + setDefaults: function (settings) { + extendRemove( this._defaults, settings || {} ); + return this; + }, + + /* + * Create a new Timepicker instance + */ + _newInst: function ($input, opts) { + var tp_inst = new Timepicker(), + inlineSettings = {}, + fns = {}, + overrides, i; + + for (var attrName in this._defaults) { + if (this._defaults.hasOwnProperty( attrName )) { + var attrValue = $input.attr( 'time:' + attrName ); + if (attrValue) { + try { + inlineSettings[attrName] = eval( attrValue ); + } catch (err) { + inlineSettings[attrName] = attrValue; + } + } + } + } + + overrides = { + beforeShow: function (input, dp_inst) { + if ($.isFunction( tp_inst._defaults.evnts.beforeShow )) { + return tp_inst._defaults.evnts.beforeShow.call( $input[0], input, dp_inst, tp_inst ); + } + }, + onChangeMonthYear: function (year, month, dp_inst) { + // Update the time as well : this prevents the time from disappearing from the $input field. + // tp_inst._updateDateTime(dp_inst); + if ($.isFunction( tp_inst._defaults.evnts.onChangeMonthYear )) { + tp_inst._defaults.evnts.onChangeMonthYear.call( $input[0], year, month, dp_inst, tp_inst ); + } + }, + onClose: function (dateText, dp_inst) { + if (tp_inst.timeDefined === true && $input.val() !== '') { + tp_inst._updateDateTime( dp_inst ); + } + if ($.isFunction( tp_inst._defaults.evnts.onClose )) { + tp_inst._defaults.evnts.onClose.call( $input[0], dateText, dp_inst, tp_inst ); + } + } + }; + for (i in overrides) { + if (overrides.hasOwnProperty( i )) { + fns[i] = opts[i] || this._defaults[i] || null; + } + } + + tp_inst._defaults = $.extend( + {}, this._defaults, inlineSettings, opts, overrides, { + evnts: fns, + timepicker: tp_inst // add timepicker as a property of datepicker: $.datepicker._get(dp_inst, 'timepicker'); + } + ); + tp_inst.amNames = $.map( + tp_inst._defaults.amNames, function (val) { + return val.toUpperCase(); + } + ); + tp_inst.pmNames = $.map( + tp_inst._defaults.pmNames, function (val) { + return val.toUpperCase(); + } + ); + + // detect which units are supported + tp_inst.support = detectSupport( + tp_inst._defaults.timeFormat + + (tp_inst._defaults.pickerTimeFormat ? tp_inst._defaults.pickerTimeFormat : '') + + (tp_inst._defaults.altTimeFormat ? tp_inst._defaults.altTimeFormat : '') + ); + + // controlType is string - key to our this._controls + if (typeof(tp_inst._defaults.controlType) === 'string') { + if (tp_inst._defaults.controlType === 'slider' && typeof($.ui.slider) === 'undefined') { + tp_inst._defaults.controlType = 'select'; + } + tp_inst.control = tp_inst._controls[tp_inst._defaults.controlType]; + } + // controlType is an object and must implement create, options, value methods + else { + tp_inst.control = tp_inst._defaults.controlType; + } + + // prep the timezone options + var timezoneList = [-720, -660, -600, -570, -540, -480, -420, -360, -300, -270, -240, -210, -180, -120, -60, + 0, 60, 120, 180, 210, 240, 270, 300, 330, 345, 360, 390, 420, 480, 525, 540, 570, 600, 630, 660, 690, 720, 765, 780, 840]; + if (tp_inst._defaults.timezoneList !== null) { + timezoneList = tp_inst._defaults.timezoneList; + } + var tzl = timezoneList.length, tzi = 0, tzv = null; + if (tzl > 0 && typeof timezoneList[0] !== 'object') { + for (; tzi < tzl; tzi++) { + tzv = timezoneList[tzi]; + timezoneList[tzi] = { value: tzv, label: $.timepicker.timezoneOffsetString( tzv, tp_inst.support.iso8601 ) }; + } + } + tp_inst._defaults.timezoneList = timezoneList; + + // set the default units + tp_inst.timezone = tp_inst._defaults.timezone !== null ? $.timepicker.timezoneOffsetNumber( tp_inst._defaults.timezone ) : + ((new Date()).getTimezoneOffset() * -1); + tp_inst.hour = tp_inst._defaults.hour < tp_inst._defaults.hourMin ? tp_inst._defaults.hourMin : + tp_inst._defaults.hour > tp_inst._defaults.hourMax ? tp_inst._defaults.hourMax : tp_inst._defaults.hour; + tp_inst.minute = tp_inst._defaults.minute < tp_inst._defaults.minuteMin ? tp_inst._defaults.minuteMin : + tp_inst._defaults.minute > tp_inst._defaults.minuteMax ? tp_inst._defaults.minuteMax : tp_inst._defaults.minute; + tp_inst.second = tp_inst._defaults.second < tp_inst._defaults.secondMin ? tp_inst._defaults.secondMin : + tp_inst._defaults.second > tp_inst._defaults.secondMax ? tp_inst._defaults.secondMax : tp_inst._defaults.second; + tp_inst.millisec = tp_inst._defaults.millisec < tp_inst._defaults.millisecMin ? tp_inst._defaults.millisecMin : + tp_inst._defaults.millisec > tp_inst._defaults.millisecMax ? tp_inst._defaults.millisecMax : tp_inst._defaults.millisec; + tp_inst.microsec = tp_inst._defaults.microsec < tp_inst._defaults.microsecMin ? tp_inst._defaults.microsecMin : + tp_inst._defaults.microsec > tp_inst._defaults.microsecMax ? tp_inst._defaults.microsecMax : tp_inst._defaults.microsec; + tp_inst.ampm = ''; + tp_inst.$input = $input; + + if (tp_inst._defaults.altField) { + tp_inst.$altInput = $( tp_inst._defaults.altField ); + if (tp_inst._defaults.altRedirectFocus === true) { + tp_inst.$altInput.css( + { + cursor: 'pointer' + } + ).focus( + function () { + $input.trigger( "focus" ); + } + ); + } + } + + if (tp_inst._defaults.minDate === 0 || tp_inst._defaults.minDateTime === 0) { + tp_inst._defaults.minDate = new Date(); + } + if (tp_inst._defaults.maxDate === 0 || tp_inst._defaults.maxDateTime === 0) { + tp_inst._defaults.maxDate = new Date(); + } + + // datepicker needs minDate/maxDate, timepicker needs minDateTime/maxDateTime.. + if (tp_inst._defaults.minDate !== undefined && tp_inst._defaults.minDate instanceof Date) { + tp_inst._defaults.minDateTime = new Date( tp_inst._defaults.minDate.getTime() ); + } + if (tp_inst._defaults.minDateTime !== undefined && tp_inst._defaults.minDateTime instanceof Date) { + tp_inst._defaults.minDate = new Date( tp_inst._defaults.minDateTime.getTime() ); + } + if (tp_inst._defaults.maxDate !== undefined && tp_inst._defaults.maxDate instanceof Date) { + tp_inst._defaults.maxDateTime = new Date( tp_inst._defaults.maxDate.getTime() ); + } + if (tp_inst._defaults.maxDateTime !== undefined && tp_inst._defaults.maxDateTime instanceof Date) { + tp_inst._defaults.maxDate = new Date( tp_inst._defaults.maxDateTime.getTime() ); + } + tp_inst.$input.bind( + 'focus', function () { + tp_inst._onFocus(); + } + ); + + return tp_inst; + }, + + /* + * add our sliders to the calendar + */ + _addTimePicker: function (dp_inst) { + var currDT = $.trim( (this.$altInput && this._defaults.altFieldTimeOnly) ? this.$input.val() + ' ' + this.$altInput.val() : this.$input.val() ); + + this.timeDefined = this._parseTime( currDT ); + this._limitMinMaxDateTime( dp_inst, false ); + this._injectTimePicker(); + this._afterInject(); + }, + + /* + * parse the time string from input value or _setTime + */ + _parseTime: function (timeString, withDate) { + if ( ! this.inst) { + this.inst = $.datepicker._getInst( this.$input[0] ); + } + + if (withDate || ! this._defaults.timeOnly) { + var dp_dateFormat = $.datepicker._get( this.inst, 'dateFormat' ); + try { + var parseRes = parseDateTimeInternal( dp_dateFormat, this._defaults.timeFormat, timeString, $.datepicker._getFormatConfig( this.inst ), this._defaults ); + if ( ! parseRes.timeObj) { + return false; + } + $.extend( this, parseRes.timeObj ); + } catch (err) { + $.timepicker.log( + "Error parsing the date/time string: " + err + + "\ndate/time string = " + timeString + + "\ntimeFormat = " + this._defaults.timeFormat + + "\ndateFormat = " + dp_dateFormat + ); + return false; + } + return true; + } else { + var timeObj = $.datepicker.parseTime( this._defaults.timeFormat, timeString, this._defaults ); + if ( ! timeObj) { + return false; + } + $.extend( this, timeObj ); + return true; + } + }, + + /* + * Handle callback option after injecting timepicker + */ + _afterInject: function() { + var o = this.inst.settings; + if ($.isFunction( o.afterInject )) { + o.afterInject.call( this ); + } + }, + + /* + * generate and inject html for timepicker into ui datepicker + */ + _injectTimePicker: function () { + var $dp = this.inst.dpDiv, + o = this.inst.settings, + tp_inst = this, + litem = '', + uitem = '', + show = null, + max = {}, + gridSize = {}, + size = null, + i = 0, + l = 0; + + // Prevent displaying twice + if ($dp.find( "div.ui-timepicker-div" ).length === 0 && o.showTimepicker) { + var noDisplay = ' ui_tpicker_unit_hide', + html = '
          ' + '
          ' + o.timeText + '
          ' + + '
          '; + + // Create the markup + for (i = 0, l = this.units.length; i < l; i++) { + litem = this.units[i]; + uitem = litem.substr( 0, 1 ).toUpperCase() + litem.substr( 1 ); + show = o['show' + uitem] !== null ? o['show' + uitem] : this.support[litem]; + + // Added by Peter Medeiros: + // - Figure out what the hour/minute/second max should be based on the step values. + // - Example: if stepMinute is 15, then minMax is 45. + max[litem] = parseInt( (o[litem + 'Max'] - ((o[litem + 'Max'] - o[litem + 'Min']) % o['step' + uitem])), 10 ); + gridSize[litem] = 0; + + html += '
          ' + o[litem + 'Text'] + '
          ' + + '
          '; + + if (show && o[litem + 'Grid'] > 0) { + html += '
          '; + + if (litem === 'hour') { + for (var h = o[litem + 'Min']; h <= max[litem]; h += parseInt( o[litem + 'Grid'], 10 )) { + gridSize[litem]++; + var tmph = $.datepicker.formatTime( this.support.ampm ? 'hht' : 'HH', {hour : h}, o ); + html += ''; + } + } else { + for (var m = o[litem + 'Min']; m <= max[litem]; m += parseInt( o[litem + 'Grid'], 10 )) { + gridSize[litem]++; + html += ''; + } + } + + html += '
          ' + tmph + '' + ((m < 10) ? '0' : '') + m + '
          '; + } + html += '
          '; + } + + // Timezone + var showTz = o.showTimezone !== null ? o.showTimezone : this.support.timezone; + html += '
          ' + o.timezoneText + '
          '; + html += '
          '; + + // Create the elements from string + html += '
          '; + var $tp = $( html ); + + // if we only want time picker... + if (o.timeOnly === true) { + $tp.prepend( '
          ' + '
          ' + o.timeOnlyTitle + '
          ' + '
          ' ); + $dp.find( '.ui-datepicker-header, .ui-datepicker-calendar' ).hide(); + } + + // add sliders, adjust grids, add events + for (i = 0, l = tp_inst.units.length; i < l; i++) { + litem = tp_inst.units[i]; + uitem = litem.substr( 0, 1 ).toUpperCase() + litem.substr( 1 ); + show = o['show' + uitem] !== null ? o['show' + uitem] : this.support[litem]; + + // add the slider + tp_inst[litem + '_slider'] = tp_inst.control.create( tp_inst, $tp.find( '.ui_tpicker_' + litem + '_slider' ), litem, tp_inst[litem], o[litem + 'Min'], max[litem], o['step' + uitem] ); + + // adjust the grid and add click event + if (show && o[litem + 'Grid'] > 0) { + size = 100 * gridSize[litem] * o[litem + 'Grid'] / (max[litem] - o[litem + 'Min']); + $tp.find( '.ui_tpicker_' + litem + ' table' ).css( + { + width: size + "%", + marginLeft: o.isRTL ? '0' : ((size / (-2 * gridSize[litem])) + "%"), + marginRight: o.isRTL ? ((size / (-2 * gridSize[litem])) + "%") : '0', + borderCollapse: 'collapse' + } + ).find( "td" ).click( + function (e) { + var $t = $( this ), + h = $t.html(), + n = parseInt( h.replace( /[^0-9]/g ), 10 ), + ap = h.replace( /[^apm]/ig ), + f = $t.data( 'for' ); // loses scope, so we use data-for + + if (f === 'hour') { + if (ap.indexOf( 'p' ) !== -1 && n < 12) { + n += 12; + } else { + if (ap.indexOf( 'a' ) !== -1 && n === 12) { + n = 0; + } + } + } + + tp_inst.control.value( tp_inst, tp_inst[f + '_slider'], litem, n ); + + tp_inst._onTimeChange(); + tp_inst._onSelectHandler(); + } + ).css( + { + cursor: 'pointer', + width: (100 / gridSize[litem]) + '%', + textAlign: 'center', + overflow: 'hidden' + } + ); + } // end if grid > 0 + } // end for loop + + // Add timezone options + this.timezone_select = $tp.find( '.ui_tpicker_timezone' ).append( '' ).find( "select" ); + $.fn.append.apply( + this.timezone_select, + $.map( + o.timezoneList, function (val, idx) { + return $( "
          ' . __( 'Copy', 'woocommerce-smart-coupons' ) . ''; + + $actions['share-link'] = '' . __( 'Get shareable link', 'woocommerce-smart-coupons' ) . ''; + + if ( function_exists( 'duplicate_post_plugin_activation' ) ) { + return $actions; + } else { + $actions['duplicate'] = '' . __( 'Duplicate', 'woocommerce-smart-coupons' ) . ''; + } + + return $actions; + } + + /** + * Function to insert post meta values for duplicate coupon + * + * @param int $id ID of parent coupon. + * @param int $new_id ID of duplicated coupon. + */ + public function woocommerce_duplicate_coupon_post_meta( $id, $new_id ) { + global $wpdb; + + $meta_keys = array( 'expiry_date', 'usage_count', '_used_by', 'date_expires' ); + + $how_many = count( $meta_keys ); + $placeholders = array_fill( 0, $how_many, '%s' ); + + $post_meta_infos = $wpdb->get_results( $wpdb->prepare( "SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id=%d AND meta_key NOT IN ( " . implode( ',', $placeholders ) . ' )', array_merge( array( $id ), $meta_keys ) ) ); // phpcs:ignore + + if ( 0 !== count( $post_meta_infos ) ) { + $sql_query = "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) "; + foreach ( $post_meta_infos as $meta_info ) { + $meta_key = $meta_info->meta_key; + $meta_value = $meta_info->meta_value; + $sql_query_sel[] = $wpdb->prepare( 'SELECT %d, %s, %s', $new_id, $meta_key, $meta_value ); + } + $sql_query .= implode( ' UNION ALL ', $sql_query_sel ); + $wpdb->query( $sql_query ); // phpcs:ignore + } + } + + /** + * Function to duplicate post taxonomies for the duplicate coupon + * + * @param int $id ID of parent coupon. + * @param int $new_id ID of duplicated coupon. + * @param string $post_type Post type being duplicated. + */ + public function woocommerce_duplicate_coupon_post_taxonomies( $id, $new_id, $post_type ) { + $taxonomies = get_object_taxonomies( $post_type ); + + foreach ( $taxonomies as $taxonomy ) { + $post_terms = wp_get_object_terms( $id, $taxonomy ); + $post_terms_count = count( $post_terms ); + + for ( $i = 0; $i < $post_terms_count; $i++ ) { + wp_set_object_terms( $new_id, $post_terms[ $i ]->slug, $taxonomy, true ); + } + } + } + + /** + * Function to create duplicate coupon and copy all properties of the coupon to duplicate coupon + * + * @param WP_Post $post Post object. + * @param int $parent Post parent ID. + * @param string $post_status Post status. + * @return int $new_post_id + */ + public function woocommerce_create_duplicate_from_coupon( $post, $parent = 0, $post_status = '' ) { + global $wpdb; + + $new_post_author = wp_get_current_user(); + $new_post_date = current_time( 'mysql' ); + $new_post_date_gmt = get_gmt_from_date( $new_post_date ); + + if ( $parent > 0 ) { + $post_parent = $parent; + $post_status = $post_status ? $post_status : 'publish'; + $suffix = ''; + } else { + $post_parent = $post->post_parent; + $post_status = $post_status ? $post_status : 'draft'; + $suffix = __( '(Copy)', 'woocommerce-smart-coupons' ); + } + + $new_post_type = $post->post_type; + $post_content = str_replace( "'", "''", $post->post_content ); + $post_content_filtered = str_replace( "'", "''", $post->post_content_filtered ); + $post_excerpt = str_replace( "'", "''", $post->post_excerpt ); + $post_title = strtolower( str_replace( "'", "''", $post->post_title ) . $suffix ); + $post_name = str_replace( "'", "''", $post->post_name ); + $comment_status = str_replace( "'", "''", $post->comment_status ); + $ping_status = str_replace( "'", "''", $post->ping_status ); + + $wpdb->insert( + $wpdb->posts, + array( + 'post_author' => $new_post_author->ID, + 'post_date' => $new_post_date, + 'post_date_gmt' => $new_post_date_gmt, + 'post_content' => $post_content, + 'post_content_filtered' => $post_content_filtered, + 'post_title' => $post_title, + 'post_excerpt' => $post_excerpt, + 'post_status' => $post_status, + 'post_type' => $new_post_type, + 'comment_status' => $comment_status, + 'ping_status' => $ping_status, + 'post_password' => $post->post_password, + 'to_ping' => $post->to_ping, + 'pinged' => $post->pinged, + 'post_modified' => $new_post_date, + 'post_modified_gmt' => $new_post_date_gmt, + 'post_parent' => 0, // No need to link it with any other coupon. + 'menu_order' => $post->menu_order, + 'post_mime_type' => $post->post_mime_type, + ) + ); // WPCS: db call ok. + + $new_post_id = $wpdb->insert_id; + + $this->woocommerce_duplicate_coupon_post_taxonomies( $post->ID, $new_post_id, $post->post_type ); + + $this->woocommerce_duplicate_coupon_post_meta( $post->ID, $new_post_id ); + + return $new_post_id; + } + + /** + * Function to return post id of the duplicate coupon to be created + * + * @param int $id ID of the coupon to duplicate. + * @return object $post Duplicated post object. + */ + public function woocommerce_get_coupon_to_duplicate( $id ) { + global $wpdb; + $post = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE ID=%d", $id ) ); // WPCS: cache ok, db call ok. + if ( isset( $post->post_type ) && 'revision' === $post->post_type ) { + $id = $post->post_parent; + $post = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE ID=%d", $id ) ); // WPCS: cache ok, db call ok. + } + return $post[0]; + } + + /** + * Function to validate condition and create duplicate coupon + */ + public function woocommerce_duplicate_coupon() { + if ( empty( $_REQUEST['post'] ) || ( isset( $_REQUEST['action'] ) && 'duplicate_post_save_as_new_page' === $_REQUEST['action'] ) ) { // phpcs:ignore + wp_die( esc_html__( 'No coupon to duplicate has been supplied!', 'woocommerce-smart-coupons' ) ); + } + + // Get the original page. + $id = absint( $_REQUEST['post'] ); // WPCS: input var ok. + + check_admin_referer( 'woocommerce-duplicate-coupon_' . $id ); + + $post = $this->woocommerce_get_coupon_to_duplicate( $id ); + + if ( isset( $post ) && null !== $post ) { + $new_id = $this->woocommerce_create_duplicate_from_coupon( $post ); + + // If you have written a plugin which uses non-WP database tables to save + // information about a page you can hook this action to dupe that data. + do_action( 'woocommerce_duplicate_coupon', $new_id, $post ); + + // Redirect to the edit screen for the new draft page. + wp_safe_redirect( admin_url( 'post.php?action=edit&post=' . $new_id ) ); + exit; + } else { + /* translators: %d: Post ID */ + wp_die( sprintf( esc_html__( 'Coupon creation failed, could not find original coupon: %d', 'woocommerce-smart-coupons' ), esc_html( $id ) ) ); + } + } + + /** + * Function to call function to create duplicate coupon + */ + public function woocommerce_duplicate_coupon_action() { + $coupon_id = ( ! empty( $_REQUEST['post'] ) ) ? absint( $_REQUEST['post'] ) : 0; + + check_admin_referer( 'woocommerce-duplicate-coupon_' . $coupon_id ); + + $action = ( ! empty( $_REQUEST['action'] ) ) ? wc_clean( wp_unslash( $_REQUEST['action'] ) ) : ''; // phpcs:ignore + + if ( 'duplicate_coupon' !== $action ) { + return; + } + + if ( $this->is_wc_gte_30() ) { + $coupon = new WC_Coupon( $coupon_id ); + + if ( false === $coupon ) { + /* translators: %s: coupon id */ + wp_die( sprintf( esc_html__( 'Coupon creation failed, could not find original coupon: %s', 'woocommerce-smart-coupons' ), esc_html( $coupon_id ) ) ); + } + + $duplicate = $this->coupon_duplicate( $coupon ); + + // Hook rename to match other woocommerce_coupon_* hooks, and to move away from depending on a response from the wp_posts table. + do_action( 'wc_sc_duplicate_coupon', $duplicate, $coupon ); + + // Redirect to the edit screen for the new draft page. + wp_safe_redirect( admin_url( 'post.php?action=edit&post=' . $duplicate->get_id() ) ); + exit; + } else { + $this->woocommerce_duplicate_coupon(); + } + } + + /** + * Duplicate coupon + * + * @param WC_Coupon $coupon The coupon object to duplicate. + * @return WC_Coupon $duplicate The duplicated coupon. + */ + public function coupon_duplicate( $coupon = null ) { + /** + * Filter to allow us to exclude meta keys from coupon duplication.. + * + * @param array $exclude_meta The keys to exclude from the duplicate. + * @param array $existing_meta_keys The meta keys that the coupon already has. + * @since 7.2.0 + */ + $meta_to_exclude = array_filter( + apply_filters( + 'wc_sc_duplicate_coupon_exclude_meta', + array(), + array_map( + function ( $meta ) { + return $meta->key; + }, + $coupon->get_meta_data() + ) + ) + ); + + $duplicate = clone $coupon; + $duplicate->set_id( 0 ); + /* translators: %s contains the code of the original coupon. */ + $duplicate->set_code( sprintf( '%s-copy', $duplicate->get_code() ) ); + $duplicate->set_date_created( null ); + $duplicate->set_usage_count( 0 ); + $duplicate->set_used_by( array() ); + $duplicate->set_date_expires( null ); + + if ( $this->is_wc_greater_than( '6.1.2' ) && $this->is_callable( $duplicate, 'set_status' ) ) { + $duplicate->set_status( 'draft' ); + } + + foreach ( $meta_to_exclude as $meta_key ) { + $duplicate->delete_meta_data( $meta_key ); + } + + /** + * This action can be used to modify the object further before it is created - it will be passed by reference. + * + * @since 3.0 + */ + do_action( 'wc_sc_coupon_duplicate_before_save', $duplicate, $coupon ); + + // Save parent coupon. + $duplicate_id = $duplicate->save(); + + $duplicate = new WC_Coupon( $duplicate ); + + $this->woocommerce_duplicate_coupon_post_taxonomies( $coupon->get_id(), $duplicate_id, 'shop_coupon' ); + + if ( $this->is_wc_greater_than( '6.1.2' ) && $this->is_callable( $duplicate, 'get_status' ) ) { + $coupon_status = $duplicate->get_status(); + } else { + $coupon_status = get_post_status( $duplicate_id ); + } + + if ( ! empty( $duplicate_id ) && 'draft' !== $coupon_status ) { + $args = array( + 'ID' => $duplicate_id, + 'post_status' => 'draft', + ); + wp_update_post( $args ); // Because $coupon->set_status( 'draft' ) not working. + } + + return new WC_Coupon( $duplicate_id ); + } + + /** + * Function to copy and share coupon via jQuery. + */ + public function add_post_row_script() { + $screen = get_current_screen(); + if ( 'edit-shop_coupon' === $screen->id ) { + ?> + + '' . esc_html__( 'Settings', 'woocommerce-smart-coupons' ) . '', + 'faqs' => '' . esc_html__( 'FAQ\'s', 'woocommerce-smart-coupons' ) . '', + 'docs' => '' . __( 'Docs', 'woocommerce-smart-coupons' ) . '', + 'support' => '' . __( 'Support', 'woocommerce-smart-coupons' ) . '', + 'review' => '' . __( 'Review', 'woocommerce-smart-coupons' ) . '', + ); + + return array_merge( $action_links, $links ); + } + + /** + * Handle Smart Coupons review notice action + */ + public function wc_sc_review_notice_action() { + + check_ajax_referer( 'wc-sc-review-notice-action', 'security' ); + + $post_do = ( ! empty( $_POST['do'] ) ) ? wc_clean( wp_unslash( $_POST['do'] ) ) : ''; // phpcs:ignore + + $option = strtotime( '+1 month' ); + if ( 'remove' === $post_do ) { + $option = 'no'; + } + + update_option( 'wc_sc_is_show_review_notice', $option, 'no' ); + + wp_send_json( array( 'success' => 'yes' ) ); + + } + + /** + * Handle Smart Coupons version 4.0.0 notice action + */ + public function wc_sc_40_notice_action() { + + check_ajax_referer( 'wc-sc-40-notice-action', 'security' ); + + update_option( 'wc_sc_is_show_40_notice', 'no', 'no' ); + + wp_send_json( array( 'success' => 'yes' ) ); + + } + + /** + * Show plugin review notice + */ + public function show_plugin_notice() { + + global $pagenow, $post; + + $valid_post_types = array( 'shop_coupon', 'shop_order', 'product' ); + $valid_pagenow = array( 'edit.php', 'post.php', 'plugins.php' ); + $is_show_review_notice = get_option( 'wc_sc_is_show_review_notice' ); + $is_coupon_enabled = get_option( 'woocommerce_enable_coupons' ); + $get_post_type = ( ! empty( $post->ID ) ) ? $this->get_post_type( $post->ID ) : ''; + $get_page = ( ! empty( $_GET['page'] ) ) ? wc_clean( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore + $get_tab = ( ! empty( $_GET['tab'] ) ) ? wc_clean( wp_unslash( $_GET['tab'] ) ) : ''; // phpcs:ignore + $design = get_option( 'wc_sc_setting_coupon_design', 'basic' ); + + $is_page = ( in_array( $pagenow, $valid_pagenow, true ) || in_array( $get_post_type, $valid_post_types, true ) || ( 'admin.php' === $pagenow && ( 'wc-smart-coupons' === $get_page || 'wc-smart-coupons' === $get_tab ) ) ); + + if ( $is_page && 'yes' !== $is_coupon_enabled ) { + ?> +
          +

          + ' . esc_html__( 'Important', 'woocommerce-smart-coupons' ) . ': ' . esc_html__( 'Setting "Enable the use of coupon codes" is disabled.', 'woocommerce-smart-coupons' ) . ' ' . sprintf( + '%s', + esc_url( + add_query_arg( + array( + 'page' => 'wc-settings', + 'tab' => 'general', + ), + admin_url( 'admin.php' ) + ) + ), + esc_html__( 'Enable', 'woocommerce-smart-coupons' ) + ) . ' ' . esc_html__( 'it to use', 'woocommerce-smart-coupons' ) . ' ' . esc_html__( 'WooCommerce Smart Coupons', 'woocommerce-smart-coupons' ) . ' ' . esc_html__( 'features.', 'woocommerce-smart-coupons' ); + ?> +

          +
          + = absint( $is_show_review_notice ) ) { + if ( ! wp_script_is( 'jquery' ) ) { + wp_enqueue_script( 'jquery' ); + } + ?> + + +
          +
          +
          + +
          +

          + ' . esc_html__( 'WooCommerce Smart Coupons', 'woocommerce-smart-coupons' ) . ' ' . esc_html__( 'so far?', 'woocommerce-smart-coupons' ) . '
          ' . esc_html__( 'Please consider', 'woocommerce-smart-coupons' ) . ' ' . esc_html__( 'leaving a review', 'woocommerce-smart-coupons' ) . ' ' . esc_html__( '! If things aren\'t going quite as expected, we\'re happy to help -- please reach out to', 'woocommerce-smart-coupons' ) . ' ' . esc_html__( 'our support team', 'woocommerce-smart-coupons' ) . '.'; ?> +

          +
          + +
          +

          + ' . esc_html__( 'WooCommerce Smart Coupons', 'woocommerce-smart-coupons' ) . '', + '' . esc_html__( + 'Smart Coupons settings', + 'woocommerce-smart-coupons' + ) . '' + ); + ?> +

          +
          + ID ) ) ? $this->get_post_type( $post->ID ) : ''; + $get_page = ( ! empty( $_GET['page'] ) ) ? wc_clean( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore + $get_tab = ( ! empty( $_GET['tab'] ) ) ? wc_clean( wp_unslash( $_GET['tab'] ) ) : ''; // phpcs:ignore + $sc_pages = array( 'wc-smart-coupons', 'sc-about', 'sc-faqs' ); + + if ( in_array( $get_page, $sc_pages, true ) || 'shop_coupon' === $get_post_type || 'wc-smart-coupons' === $get_tab ) { + ?> + + 5-star rating here' ) ); + } + } + + return $sc_rating_text; + + } + + /** + * Function to 'Connect your store' notice on Smart Coupons pages in admin + * + * @param string $sc_text Text in footer (right). + * @return string $sc_text + */ + public function wc_sc_update_footer_text( $sc_text ) { + + global $post, $pagenow; + + if ( ! empty( $pagenow ) ) { + $get_post_type = ( ! empty( $post->ID ) ) ? $this->get_post_type( $post->ID ) : ''; + $get_page = ( ! empty( $_GET['page'] ) ) ? wc_clean( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore + $get_tab = ( ! empty( $_GET['tab'] ) ) ? wc_clean( wp_unslash( $_GET['tab'] ) ) : ''; // phpcs:ignore + $sc_pages = array( 'wc-smart-coupons', 'sc-about', 'sc-faqs' ); + + if ( in_array( $get_page, $sc_pages, true ) || 'shop_coupon' === $get_post_type || 'wc-smart-coupons' === $get_tab ) { + /* translators: %s: link to submit idea for Smart Coupons on WooCommerce idea board */ + $sc_text = sprintf( __( 'Have a feature request? Submit it %s.', 'woocommerce-smart-coupons' ), '' . __( 'here', 'woocommerce-smart-coupons' ) . '' ); + } + } + + return $sc_text; + + } + + /** + * Function to 'Connect your store' notice on Smart Coupons pages in admin + * + * @param array $screen_ids List of existing screen ids. + * @return array $screen_ids + */ + public function add_wc_connect_store_notice_on_sc_pages( $screen_ids ) { + + array_push( $screen_ids, 'woocommerce_page_wc-smart-coupons' ); + + return $screen_ids; + } + + /** + * Function to render admin notice + * + * @param string $type Notice type. + * @param string $title Notice title. + * @param string $message Notice message. + * @param string $action Notice actions. + * @param bool $dismissible Notice dismissible. + * @return void. + */ + public function show_notice( $type = 'info', $title = '', $message = '', $action = '', $dismissible = false ) { + $css_classes = array( + 'notice', + 'notice-' . $type, + ); + if ( true === $dismissible ) { + $css_classes[] = 'is-dismissible'; + } + ?> +
          + %s

          ', esc_html( $title ) ); + } + if ( ! empty( $message ) ) { + printf( '

          %s

          ', esc_html( $message ) ); + } + if ( ! empty( $action ) ) { + printf( '

          %s

          ', wp_kses_post( $action ) ); + } + ?> +
          + get_status( '4.28.0' ); + if ( 'pending' === $update_status ) { + // Notice for pending update. + $this->db_update_pending_notice(); + } elseif ( 'processing' === $update_status ) { + // Notice for processing update. + $this->db_update_processing_notice(); + } elseif ( 'completed' === $update_status ) { + // Notice for completed update. + $this->db_update_completed_notice(); + $wcsc_db->set_status( '4.28.0', 'done' ); + } + } + + /** + * Function to show pending database update notice + */ + public function db_update_pending_notice() { + global $woocommerce_smart_coupon; + + $plugin_version = $woocommerce_smart_coupon->get_smart_coupons_version(); + /* translators: %s: Plugin name */ + $title = sprintf( __( '%s database update required', 'woocommerce-smart-coupons' ), 'WooCommerce Smart Coupons' ); + $message = __( 'The database update process runs in the background and may take a little while, so please be patient.', 'woocommerce-smart-coupons' ); + $update_url = wp_nonce_url( + add_query_arg( + array( + 'page' => 'wc-settings', + 'tab' => 'wc-smart-coupons', + 'wc_sc_update' => '4.28.0', + ), + admin_url( 'admin.php' ) + ), + 'wc_sc_db_process', + 'wc_sc_db_update_nonce' + ); + $action_button = sprintf( '%2$s', esc_url( $update_url ), __( 'Update database', 'woocommerce-smart-coupons' ) ); + + $this->show_notice( 'warning', $title, $message, $action_button ); + } + + /** + * Function to show database update processing notice. + */ + public function db_update_processing_notice() { + if ( 'woocommerce_page_wc-status' === $this->get_current_screen_id() && isset( $_GET['tab'] ) && 'action-scheduler' === wc_clean( wp_unslash( $_GET['tab'] ) ) ) { // phpcs:ignore + return; + } + + $actions_url = add_query_arg( + array( + 'page' => 'wc-status', + 'tab' => 'action-scheduler', + 's' => 'move_applied_coupon_options_to_transient', + 'status' => 'pending', + ), + admin_url( 'admin.php' ) + ); + $cron_disabled = defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON; + /* translators: %s: Plugin name */ + $message = sprintf( __( '%s is updating the database in the background. The database update process may take a little while, so please be patient.', 'woocommerce-smart-coupons' ), 'WooCommerce Smart Coupons' ); + if ( true === $cron_disabled ) { + $message .= '
          ' . __( 'Note: WP CRON has been disabled on your install which may prevent this update from completing.', 'woocommerce-smart-coupons' ); + } + $action_button = sprintf( '%2$s', esc_url( $actions_url ), __( 'View status', 'woocommerce-smart-coupons' ) ); + $this->show_notice( 'info', '', $message, $action_button ); + } + + /** + * Function to show database update completed notice. + */ + public function db_update_completed_notice() { + /* translators: %s: Plugin name */ + $message = sprintf( __( '%s database update completed. Thank you for updating to the latest version!', 'woocommerce-smart-coupons' ), 'WooCommerce Smart Coupons' ); + $this->show_notice( 'success', '', $message, '', true ); + } + + /** + * Function to get current screen id. + * + * @return string. + */ + public function get_current_screen_id() { + $screen = get_current_screen(); + return $screen ? $screen->id : ''; + } + + } + +} + +WC_SC_Admin_Notifications::get_instance(); diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-admin-pages.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-admin-pages.php new file mode 100644 index 00000000..ba9fb542 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-admin-pages.php @@ -0,0 +1,1659 @@ + + + registered['jquery-ui-core']->ver ) ? $wp_scripts->registered['jquery-ui-core']->ver : '1.9.2'; + + $locale = localeconv(); + $decimal = isset( $locale['decimal_point'] ) ? $locale['decimal_point'] : '.'; + + wp_enqueue_style( 'woocommerce_admin_menu_styles', WC()->plugin_url() . '/assets/css/menu.css', array(), WC()->version ); + wp_enqueue_style( 'woocommerce_admin_styles', WC()->plugin_url() . '/assets/css/admin.css', array(), WC()->version ); + if ( ! wp_style_is( 'jquery-ui-style', 'registered' ) ) { + wp_register_style( 'jquery-ui-style', WC()->plugin_url() . '/assets/css/jquery-ui/jquery-ui' . $suffix . '.css', array(), WC()->version ); + } + if ( ! wp_style_is( 'jquery-ui-style' ) ) { + wp_enqueue_style( 'jquery-ui-style' ); + } + + $woocommerce_admin_params = array( + /* translators: Decimal point */ + 'i18n_decimal_error' => sprintf( __( 'Please enter in decimal (%s) format without thousand separators.', 'woocommerce-smart-coupons' ), $decimal ), + /* translators: Decimal point */ + 'i18n_mon_decimal_error' => sprintf( __( 'Please enter in monetary decimal (%s) format without thousand separators and currency symbols.', 'woocommerce-smart-coupons' ), wc_get_price_decimal_separator() ), + 'i18n_country_iso_error' => __( 'Please enter in country code with two capital letters.', 'woocommerce-smart-coupons' ), + 'i18_sale_less_than_regular_error' => __( 'Please enter in a value less than the regular price.', 'woocommerce-smart-coupons' ), + 'decimal_point' => $decimal, + 'mon_decimal_point' => wc_get_price_decimal_separator(), + 'strings' => array( + 'import_products' => __( 'Import', 'woocommerce-smart-coupons' ), + 'export_products' => __( 'Export', 'woocommerce-smart-coupons' ), + ), + 'urls' => array( + 'import_products' => esc_url_raw( admin_url( 'edit.php?post_type=product&page=product_importer' ) ), + 'export_products' => esc_url_raw( admin_url( 'edit.php?post_type=product&page=product_exporter' ) ), + ), + ); + + $woocommerce_admin_meta_boxes_params = array( + 'remove_item_notice' => __( 'Are you sure you want to remove the selected items? If you have previously reduced this item\'s stock, or this order was submitted by a customer, you will need to manually restore the item\'s stock.', 'woocommerce-smart-coupons' ), + 'i18n_select_items' => __( 'Please select some items.', 'woocommerce-smart-coupons' ), + 'i18n_do_refund' => __( 'Are you sure you wish to process this refund? This action cannot be undone.', 'woocommerce-smart-coupons' ), + 'i18n_delete_refund' => __( 'Are you sure you wish to delete this refund? This action cannot be undone.', 'woocommerce-smart-coupons' ), + 'i18n_delete_tax' => __( 'Are you sure you wish to delete this tax column? This action cannot be undone.', 'woocommerce-smart-coupons' ), + 'remove_item_meta' => __( 'Remove this item meta?', 'woocommerce-smart-coupons' ), + 'remove_attribute' => __( 'Remove this attribute?', 'woocommerce-smart-coupons' ), + 'name_label' => __( 'Name', 'woocommerce-smart-coupons' ), + 'remove_label' => __( 'Remove', 'woocommerce-smart-coupons' ), + 'click_to_toggle' => __( 'Click to toggle', 'woocommerce-smart-coupons' ), + 'values_label' => __( 'Value(s)', 'woocommerce-smart-coupons' ), + 'text_attribute_tip' => __( 'Enter some text, or some attributes by pipe (|) separating values.', 'woocommerce-smart-coupons' ), + 'visible_label' => __( 'Visible on the product page', 'woocommerce-smart-coupons' ), + 'used_for_variations_label' => __( 'Used for variations', 'woocommerce-smart-coupons' ), + 'new_attribute_prompt' => __( 'Enter a name for the new attribute term:', 'woocommerce-smart-coupons' ), + 'calc_totals' => __( 'Calculate totals based on order items, discounts, and shipping?', 'woocommerce-smart-coupons' ), + 'calc_line_taxes' => __( 'Calculate line taxes? This will calculate taxes based on the customers country. If no billing/shipping is set it will use the store base country.', 'woocommerce-smart-coupons' ), + 'copy_billing' => __( 'Copy billing information to shipping information? This will remove any currently entered shipping information.', 'woocommerce-smart-coupons' ), + 'load_billing' => __( 'Load the customer\'s billing information? This will remove any currently entered billing information.', 'woocommerce-smart-coupons' ), + 'load_shipping' => __( 'Load the customer\'s shipping information? This will remove any currently entered shipping information.', 'woocommerce-smart-coupons' ), + 'featured_label' => __( 'Featured', 'woocommerce-smart-coupons' ), + 'prices_include_tax' => esc_attr( get_option( 'woocommerce_prices_include_tax' ) ), + 'round_at_subtotal' => esc_attr( get_option( 'woocommerce_tax_round_at_subtotal' ) ), + 'no_customer_selected' => __( 'No customer selected', 'woocommerce-smart-coupons' ), + 'plugin_url' => WC()->plugin_url(), + 'ajax_url' => admin_url( 'admin-ajax.php' ), + 'order_item_nonce' => wp_create_nonce( 'order-item' ), + 'add_attribute_nonce' => wp_create_nonce( 'add-attribute' ), + 'save_attributes_nonce' => wp_create_nonce( 'save-attributes' ), + 'calc_totals_nonce' => wp_create_nonce( 'calc-totals' ), + 'get_customer_details_nonce' => wp_create_nonce( 'get-customer-details' ), + 'search_products_nonce' => wp_create_nonce( 'search-products' ), + 'grant_access_nonce' => wp_create_nonce( 'grant-access' ), + 'revoke_access_nonce' => wp_create_nonce( 'revoke-access' ), + 'add_order_note_nonce' => wp_create_nonce( 'add-order-note' ), + 'delete_order_note_nonce' => wp_create_nonce( 'delete-order-note' ), + 'calendar_image' => WC()->plugin_url() . '/assets/images/calendar.png', + 'post_id' => '', + 'base_country' => WC()->countries->get_base_country(), + 'currency_format_num_decimals' => wc_get_price_decimals(), + 'currency_format_symbol' => get_woocommerce_currency_symbol(), + 'currency_format_decimal_sep' => esc_attr( wc_get_price_decimal_separator() ), + 'currency_format_thousand_sep' => esc_attr( wc_get_price_thousand_separator() ), + 'currency_format' => esc_attr( str_replace( array( '%1$s', '%2$s' ), array( '%s', '%v' ), get_woocommerce_price_format() ) ), // For accounting JS. + 'rounding_precision' => WC_ROUNDING_PRECISION, + 'tax_rounding_mode' => WC_TAX_ROUNDING_MODE, + 'product_types' => array_map( + 'sanitize_title', + get_terms( + 'product_type', + array( + 'hide_empty' => false, + 'fields' => 'names', + ) + ) + ), + 'i18n_download_permission_fail' => __( 'Could not grant access - the user may already have permission for this file or billing email is not set. Ensure the billing email is set, and the order has been saved.', 'woocommerce-smart-coupons' ), + 'i18n_permission_revoke' => __( 'Are you sure you want to revoke access to this download?', 'woocommerce-smart-coupons' ), + 'i18n_tax_rate_already_exists' => __( 'You cannot add the same tax rate twice!', 'woocommerce-smart-coupons' ), + 'i18n_product_type_alert' => __( 'Your product has variations! Before changing the product type, it is a good idea to delete the variations to avoid errors in the stock reports.', 'woocommerce-smart-coupons' ), + ); + + if ( ! wp_script_is( 'wc-admin-coupon-meta-boxes' ) ) { + wp_enqueue_script( 'wc-admin-coupon-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-coupon' . $suffix . '.js', array( 'woocommerce_admin', 'wc-enhanced-select', 'wc-admin-meta-boxes' ), WC()->version, false ); + } + wp_localize_script( + 'wc-admin-coupon-meta-boxes', + 'woocommerce_admin_meta_boxes_coupon', + array( + 'generate_button_text' => esc_html__( 'Generate coupon code', 'woocommerce-smart-coupons' ), + 'characters' => apply_filters( 'woocommerce_coupon_code_generator_characters', 'ABCDEFGHJKMNPQRSTUVWXYZ23456789' ), + 'char_length' => apply_filters( 'woocommerce_coupon_code_generator_character_length', 8 ), + 'prefix' => apply_filters( 'woocommerce_coupon_code_generator_prefix', '' ), + 'suffix' => apply_filters( 'woocommerce_coupon_code_generator_suffix', '' ), + ) + ); + wp_localize_script( 'wc-admin-meta-boxes', 'woocommerce_admin_meta_boxes', $woocommerce_admin_meta_boxes_params ); + + if ( ! wp_script_is( 'woocommerce_admin' ) ) { + wp_enqueue_script( 'woocommerce_admin', WC()->plugin_url() . '/assets/js/admin/woocommerce_admin' . $suffix . '.js', array( 'jquery', 'jquery-blockui', 'jquery-ui-sortable', 'jquery-ui-widget', 'jquery-ui-core', 'jquery-tiptip' ), WC()->version, false ); + } + wp_localize_script( 'woocommerce_admin', 'woocommerce_admin', $woocommerce_admin_params ); + + } + + /** + * Function to show import message + */ + public function woocommerce_show_import_message() { + global $pagenow, $typenow; + + $get_show_import_message = ( ! empty( $_GET['show_import_message'] ) ) ? wc_clean( wp_unslash( $_GET['show_import_message'] ) ) : ''; // phpcs:ignore + $get_imported = ( ! empty( $_GET['imported'] ) ) ? wc_clean( wp_unslash( $_GET['imported'] ) ) : 0; // phpcs:ignore + $get_skipped = ( ! empty( $_GET['skipped'] ) ) ? wc_clean( wp_unslash( $_GET['skipped'] ) ) : 0; // phpcs:ignore + + if ( empty( $get_show_import_message ) ) { + return; + } + + if ( 'true' === $get_show_import_message ) { + if ( 'edit.php' === $pagenow && 'shop_coupon' === $typenow ) { + + $imported = $get_imported; + $skipped = $get_skipped; + + echo '

          ' . esc_html__( 'Import complete - imported', 'woocommerce-smart-coupons' ) . ' ' . esc_html( $imported ) . ', ' . esc_html__( 'skipped', 'woocommerce-smart-coupons' ) . ' ' . esc_html( $skipped ) . '

          '; + } + } + } + + /** + * Function to include script in admin footer + */ + public function smart_coupons_script_in_footer() { + + global $pagenow; + if ( empty( $pagenow ) ) { + return; + } + + $get_page = ( ! empty( $_GET['page'] ) ) ? wc_clean( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore + $post_type = ( ! empty( $_GET['post_type'] ) ) ? wc_clean( wp_unslash( $_GET['post_type'] ) ) : ''; // phpcs:ignore + + if ( in_array( $get_page, array( 'wc-smart-coupons', 'sc-about', 'sc-faqs' ), true ) || 'shop_coupon' === $post_type ) { + ?> + + coupons to your store via a csv file.', 'woocommerce-smart-coupons' ), array( $this, 'coupon_importer' ) ); + } + + if ( 'sent_gift_certificate' === $get_action && 'wc-smart-coupons' === $get_page ) { + $email = $post_smart_coupon_email; + $amount = $post_smart_coupon_amount; + $message = $post_smart_coupon_message; + $this->send_gift_certificate( $email, $amount, $message ); + } + } + + /** + * Function to process & send gift certificate + * + * @param string $email Comma separated email address. + * @param float $amount Coupon amount. + * @param string $message Optional. + */ + public function send_gift_certificate( $email, $amount, $message = '' ) { + + $emails = explode( ',', $email ); + $location = add_query_arg( + array( + 'page' => 'wc-smart-coupons', + 'tab' => 'send-smart-coupons', + ), + admin_url( 'admin.php' ) + ); + $validation_error = ''; + + // Check for valid amount. + if ( ! $amount || ! is_numeric( $amount ) ) { + $validation_error = 'amount_error'; + } + + if ( empty( $validation_error ) ) { + foreach ( $emails as $email ) { + $email = sanitize_email( $email ); + // Check for valid email address. + if ( ( ! $email || ! is_email( $email ) ) ) { + $validation_error = 'email_error'; + break; + } + } + } + + // Proceed to bulk generate if there isn't any validation error. + if ( empty( $validation_error ) ) { + + // Set required $_POST data for bulk generate. + $_POST['no_of_coupons_to_generate'] = count( $emails ); + $_POST['discount_type'] = 'smart_coupon'; + $_POST['smart_coupons_generate_action'] = 'send_store_credit'; + + // includes. + require 'class-wc-sc-coupon-import.php'; + require 'class-wc-sc-coupon-parser.php'; + + $coupon_importer = WC_SC_Coupon_Import::get_instance(); + $action_processed = $coupon_importer->process_bulk_generate_action(); + + if ( false === $action_processed ) { + $location = add_query_arg( + array( + 'process_error' => 'yes', + ), + $location + ); + } + } elseif ( 'amount_error' === $validation_error ) { + $location = add_query_arg( + array( + 'amount_error' => 'yes', + ), + $location + ); + } elseif ( 'email_error' === $validation_error ) { + $location = add_query_arg( + array( + 'email_error' => 'yes', + ), + $location + ); + } + + if ( ! empty( $location ) ) { + wp_safe_redirect( $location ); + exit; + } + } + + /** + * Function to perform importing of coupon from csv file + */ + public function coupon_importer() { + + if ( defined( 'WP_LOAD_IMPORTERS' ) ) { + wp_safe_redirect( + add_query_arg( + array( + 'page' => 'wc-smart-coupons', + 'tab' => 'import-smart-coupons', + ), + admin_url( 'admin.php' ) + ) + ); + exit; + } + + // Load Importer API. + require_once ABSPATH . 'wp-admin/includes/import.php'; + + if ( ! class_exists( 'WP_Importer' ) ) { + + $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php'; + + if ( file_exists( $class_wp_importer ) ) { + require $class_wp_importer; + } + } + + // includes. + require 'class-wc-sc-coupon-import.php'; + require 'class-wc-sc-coupon-parser.php'; + + $wc_csv_coupon_import = new WC_SC_Coupon_Import(); + + $wc_csv_coupon_import->dispatch(); + + } + + /** + * Function to add submenu page for Coupon CSV Import + */ + public function woocommerce_coupon_admin_menu() { + if ( $this->is_wc_gte_44() ) { + add_submenu_page( 'woocommerce-marketing', __( 'Smart Coupon', 'woocommerce-smart-coupons' ), __( 'Smart Coupon', 'woocommerce-smart-coupons' ), 'manage_woocommerce', 'wc-smart-coupons', array( $this, 'admin_page' ) ); + } else { + add_submenu_page( 'woocommerce', __( 'Smart Coupon', 'woocommerce-smart-coupons' ), __( 'Smart Coupon', 'woocommerce-smart-coupons' ), 'manage_woocommerce', 'wc-smart-coupons', array( $this, 'admin_page' ) ); + } + } + + /** + * Function to remove submenu link for Smart Coupons + */ + public function woocommerce_coupon_admin_head() { + if ( $this->is_wc_gte_44() ) { + remove_submenu_page( 'woocommerce-marketing', 'wc-smart-coupons' ); + } else { + remove_submenu_page( 'woocommerce', 'wc-smart-coupons' ); + } + } + + /** + * Function to show content on the Coupon CSV Importer page + */ + public function admin_page() { + global $store_credit_label; + + $tab = ( ! empty( $_GET['tab'] ) ? ( $_GET['tab'] == 'send-smart-coupons' ? 'send-smart-coupons' : 'import-smart-coupons' ) : 'generate_bulk_coupons' ); // phpcs:ignore + + ?> + +
          +

          + + +

          +
          + +
          + admin_send_certificate(); + break; + case 'import-smart-coupons': + $this->admin_import_page(); + break; + default: + $this->admin_generate_bulk_coupons_and_export(); + break; + } + ?> + +
          + dispatch(); + + } + + /** + * Send Gift Certificate page content + */ + public function admin_send_certificate() { + global $store_credit_label; + + $get_sent = ( ! empty( $_GET['sent'] ) ) ? wc_clean( wp_unslash( $_GET['sent'] ) ) : ''; // phpcs:ignore + $get_email_error = ( ! empty( $_GET['email_error'] ) ) ? wc_clean( wp_unslash( $_GET['email_error'] ) ) : ''; // phpcs:ignore + $get_amount_error = ( ! empty( $_GET['amount_error'] ) ) ? wc_clean( wp_unslash( $_GET['amount_error'] ) ) : ''; // phpcs:ignore + $get_process_error = ( ! empty( $_GET['process_error'] ) ) ? wc_clean( wp_unslash( $_GET['process_error'] ) ) : ''; // phpcs:ignore + + if ( 'yes' === $get_sent ) { + /* translators: %s: singular name for store credit */ + $ack_message = ! empty( $store_credit_label['singular'] ) ? sprintf( esc_html__( '%s sent successfully.', 'woocommerce-smart-coupons' ), esc_html( ucfirst( $store_credit_label['singular'] ) ) ) : esc_html__( 'Store Credit / Gift Certificate sent successfully.', 'woocommerce-smart-coupons' ); + echo '

          ' . esc_html( $ack_message ) . '

          '; + } elseif ( 'yes' === $get_process_error ) { + /* translators: %s: singular name for store credit */ + $error_message = ! empty( $store_credit_label['singular'] ) ? sprintf( esc_html__( 'There has been an error in sending %s.', 'woocommerce-smart-coupons' ), esc_html( ucfirst( $store_credit_label['singular'] ) ) ) : esc_html__( 'There has been an error in sending Store Credit / Gift Certificate.', 'woocommerce-smart-coupons' ); + $error_message = $error_message . ' ' . esc_html__( 'Please try again later.', 'woocommerce-smart-coupons' ); + echo '

          ' . esc_html( $error_message ) . '

          '; + } + + if ( ! wp_script_is( 'jquery' ) ) { + wp_enqueue_script( 'jquery' ); + } + + $message = ''; + $editor_args = array( + 'textarea_name' => 'smart_coupon_message', + 'textarea_rows' => 10, + 'editor_class' => 'wp-editor-message', + 'media_buttons' => true, + 'tinymce' => true, + ); + $editor_id = 'edit_smart_coupon_message'; + + ?> + + + get_preview_email_js( $editor_id ); + ?> +

          + 'wc-smart-coupons', + 'tab' => 'import-smart-coupons', + 'step' => '2', + ), + admin_url( 'admin.php' ) + ); + ?> +

          + +
          + +
          + + + + + + + + + + + + + + + + + + + + + + + +
          + + + + +

          ' . esc_html__( 'Invalid email address.', 'woocommerce-smart-coupons' ) . '

          '; + } + ?> + +
          + + + ' . esc_html( get_woocommerce_currency_symbol() ) . '', '  ' ); // phpcs:ignore + ?> + +

          ' . esc_html__( 'Invalid amount.', 'woocommerce-smart-coupons' ) . '

          '; + } + ?> +
          + + + + +
          + + + +
          + +

          + + get_sample_coupon_code(); + if ( ! empty( $coupon_code ) ) { + ?> + + +

          +
          +
          + get_preview_email_html( $coupon_code ); + } + } + + /** + * Function to get sample coupon code + */ + public function get_sample_coupon_code() { + global $wpdb; + $coupon_code = wp_cache_get( 'wc_sc_any_coupon_code', 'woocommerce_smart_coupons' ); + if ( false === $coupon_code ) { + $coupon_code = $wpdb->get_var( // phpcs:ignore + $wpdb->prepare( + "SELECT post_title + FROM $wpdb->posts AS p + LEFT JOIN $wpdb->postmeta AS pm + ON (p.ID = pm.post_id) + WHERE post_type = %s + AND ( pm.meta_key = %s AND pm.meta_value = %s ) + LIMIT 1", + 'shop_coupon', + 'discount_type', + 'smart_coupon' + ) + ); + wp_cache_set( 'wc_sc_any_coupon_code', $coupon_code, 'woocommerce_smart_coupons' ); + $this->maybe_add_cache_key( 'wc_sc_any_coupon_code' ); + } + if ( empty( $coupon_code ) ) { + $args = array( + 'return' => 'code', + 'discount_type' => 'smart_coupon', + 'amount' => 1.99, + 'description' => __( 'This is a sample coupon', 'woocommerce_smart_coupons' ), + 'date_expires' => $this->strtotime( '+20 years' ), + 'email_restrictions' => array( get_option( 'admin_email' ) ), + ); + $coupon_code = $this->generate_coupon( $args ); + $coupon = new WC_Coupon( $coupon_code ); + $coupon_id = $this->is_callable( $coupon, 'get_id' ) ? $coupon->get_id() : 0; + if ( ! empty( $coupon_id ) ) { + $args = array( + 'ID' => $coupon_id, + 'post_status' => 'auto-draft', + ); + wp_update_post( $args ); // Because $coupon->set_status( 'auto-draft' ) not working. + } + } + return $coupon_code; + } + + /** + * Function to get preview html for Coupon Emails + * + * @param string $coupon_code Coupon code. + */ + public function get_preview_email_html( $coupon_code = '' ) { + ?> + + generate_unique_code() ); + $reference_post_id = ( $this->is_callable( $coupon, 'save' ) ) ? $coupon->save() : 0; + if ( ! empty( $reference_post_id ) ) { + $args = array( + 'ID' => $reference_post_id, + 'post_status' => 'auto-draft', + ); + wp_update_post( $args ); // Because $coupon->set_status( 'draft' ) not working. + update_option( 'empty_reference_smart_coupons', $reference_post_id, 'no' ); + } + } else { + $reference_post_id = $empty_reference_coupon; + } + + $post = get_post( $reference_post_id ); // phpcs:ignore + + if ( empty( $post ) ) { + $coupon = new WC_Coupon( $this->generate_unique_code() ); + $reference_post_id = ( $this->is_callable( $coupon, 'save' ) ) ? $coupon->save() : 0; + if ( ! empty( $reference_post_id ) ) { + $args = array( + 'ID' => $reference_post_id, + 'post_status' => 'auto-draft', + ); + wp_update_post( $args ); // Because $coupon->set_status( 'auto-draft' ) not working. + update_option( 'empty_reference_smart_coupons', $reference_post_id, 'no' ); + } + $post = get_post( $reference_post_id ); // phpcs:ignore + } + + if ( ! class_exists( 'WC_Meta_Box_Coupon_Data' ) ) { + require_once WC()->plugin_path() . '/includes/admin/meta-boxes/class-wc-meta-box-coupon-data.php'; + } + if ( ! class_exists( 'WC_Admin_Post_Types' ) ) { + require_once WC()->plugin_path() . '/includes/admin/class-wc-admin-post-types.php'; + } + $admin_post_types = new WC_Admin_Post_Types(); + + $is_post_generate_and_import = ( isset( $_POST['generate_and_import'] ) ) ? true : false; // phpcs:ignore + $post_smart_coupons_generate_action = ( ! empty( $_POST['smart_coupons_generate_action'] ) ) ? wc_clean( wp_unslash( $_POST['smart_coupons_generate_action'] ) ) : ''; // phpcs:ignore + + $message = ''; + $editor_args = array( + 'textarea_name' => 'smart_coupon_message', + 'textarea_rows' => 7, + 'editor_class' => 'wp-editor-message', + 'media_buttons' => true, + 'tinymce' => true, + ); + $editor_id = 'edit_smart_coupon_message'; + ?> + + +
          +

          +
          + +

          + + + 'wc-smart-coupons', + 'tab' => 'import-smart-coupons', + 'step' => '2', + ), + admin_url( 'admin.php' ) + ); + ?> +
          + +
          +
          +

          +
          +
          +
          + +

          + + +

          + +

          + +   + +

          + +

          + +   + + 'wc-smart-coupons', + 'tab' => 'import-smart-coupons', + ), + admin_url( 'admin.php' ) + ); + ?> + + ' . esc_html__( 'import', 'woocommerce-smart-coupons' ) . ' ' . esc_html__( 'later', 'woocommerce-smart-coupons' ) . ')'; + ?> + +

          + +

          + +   + + + +
          + +

          +
          +
          +
          +
          + + get_preview_email_js( $editor_id ); + ?> +
          +

          + + ', '' ); + ?> + +

          +
          + ID ) && $this->is_hpos_order( $post->ID ) ) { + $post_or_order = wc_get_order( $post->ID ); + } else { + $post_or_order = $post; + } + $admin_post_types->edit_form_after_title( $post_or_order ); + ?> +
          +
          +
          +
          +
          +

          + + + +

          +
          + +
          +
          +
          +
          +
          +

          +
          +
          +
          + +
          + + 'sc_coupon_category' ); + $tax_name = esc_attr( $args['taxonomy'] ); + $taxonomy = get_taxonomy( $args['taxonomy'] ); + ?> +
          + + + + +
          +
            + ID, + array( + 'taxonomy' => $tax_name, + 'popular_cats' => $popular_ids, + ) + ); + ?> +
          +
          +
          +
          +
          +
          +
          +
          + +
          + +

          + +
          +
          +
          + + + query_vars['s'] ) ) { + return; + } + if ( 'shop_coupon' !== $wp->query_vars['post_type'] ) { + return; + } + + $e = substr( $wp->query_vars['s'], 0, 5 ); + + if ( 'email:' === strtolower( substr( $wp->query_vars['s'], 0, 6 ) ) ) { + + $email = trim( substr( $wp->query_vars['s'], 6 ) ); + + if ( ! $email ) { + return; + } + + $post_ids = wp_cache_get( 'wc_sc_get_coupon_ids_by_email_' . sanitize_key( $email ), 'woocommerce_smart_coupons' ); + + if ( false === $post_ids ) { + $post_ids = $wpdb->get_col( + $wpdb->prepare( + "SELECT pm.post_id + FROM {$wpdb->postmeta} AS pm + LEFT JOIN {$wpdb->posts} AS p + ON (p.ID = pm.post_id AND p.post_type = 'shop_coupon') + WHERE pm.meta_key = 'customer_email' + AND pm.meta_value LIKE %s", + '%' . $wpdb->esc_like( $email ) . '%' + ) + ); // WPCS: db call ok. + wp_cache_set( 'wc_sc_get_coupon_ids_by_email_' . sanitize_key( $email ), $post_ids, 'woocommerce_smart_coupons' ); + $this->maybe_add_cache_key( 'wc_sc_get_coupon_ids_by_email_' . sanitize_key( $email ) ); + } + + if ( empty( $post_ids ) ) { + return; + } + + unset( $wp->query_vars['s'] ); + + $wp->query_vars['post__in'] = $post_ids; + + $wp->query_vars['email'] = $email; + } + + } + + /** + * Function to show label of the search result on coupon + * + * @param mixed $query Query. + * @return mixed $query + */ + public function filter_coupons_using_meta_label( $query ) { + global $pagenow, $typenow, $wp; + + if ( 'edit.php' !== $pagenow ) { + return $query; + } + if ( 'shop_coupon' !== $typenow ) { + return $query; + } + + $s = get_query_var( 's' ); + if ( ! empty( $s ) ) { + return $query; + } + + $email = get_query_var( 'email' ); + + if ( ! empty( $email ) ) { + + $post_type = get_post_type_object( $wp->query_vars['post_type'] ); + /* translators: 1: Singular name for post type 2: Email */ + return sprintf( __( '[%1$s restricted with email: %2$s]', 'woocommerce-smart-coupons' ), $post_type->labels->name, $email ); + } + + return $query; + } + + /** + * WooCommerce Navigation Is Connected Page + * + * @param boolean $is_connected_page Is connected page. + * @param string $current_page The current page. + * @return boolean + */ + public function woocommerce_navigation_is_connected_page( $is_connected_page = false, $current_page = '' ) { + $get_page = ( ! empty( $_GET['page'] ) ) ? wc_clean( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore + if ( empty( $is_connected_page ) && 'wc-smart-coupons' === $get_page ) { + return true; + } + return $is_connected_page; + } + + /** + * WooCommerce Navigation Is Connected Page + * + * @param boolean $breadcrumbs The breadcrumbs. + * @param string $current_page The current page. + * @return boolean + */ + public function woocommerce_navigation_breadcrumbs( $breadcrumbs = array(), $current_page = '' ) { + global $store_credit_label; + $get_page = ( ! empty( $_GET['page'] ) ) ? wc_clean( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore + if ( 'wc-smart-coupons' === $get_page ) { + $breadcrumbs = $this->get_default_breadcrumbs(); + $get_tab = ( ! empty( $_GET['tab'] ) ) ? wc_clean( wp_unslash( $_GET['tab'] ) ) : ''; // phpcs:ignore + switch ( $get_tab ) { + case 'import-smart-coupons': + $breadcrumbs[] = __( 'Import Coupons', 'woocommerce-smart-coupons' ); + break; + case 'send-smart-coupons': + /* translators: Store Credit label */ + $breadcrumbs[] = sprintf( __( 'Send %s', 'woocommerce-smart-coupons' ), ( ( ! empty( $store_credit_label['singular'] ) ) ? ucwords( $store_credit_label['singular'] ) : __( 'Store Credit', 'woocommerce-smart-coupons' ) ) ); + break; + default: + $breadcrumbs[] = __( 'Bulk Generate', 'woocommerce-smart-coupons' ); + break; + } + } + return $breadcrumbs; + } + + /** + * Default breadcrums + * + * @return array + */ + public function get_default_breadcrumbs() { + $breadcrumbs = array(); + $breadcrumbs[] = array( + 'admin.php?page=wc-admin', + __( 'WooCommerce', 'woocommerce-smart-coupons' ), + ); + if ( $this->is_wc_gte_44() ) { // To make sure that the WooCommerce is 4.4 or greater. + $breadcrumbs[] = array( + 'admin.php?page=wc-admin&path=/marketing', + __( 'Marketing', 'woocommerce-smart-coupons' ), + ); + } + $breadcrumbs[] = array( + 'edit.php?post_type=shop_coupon', + __( 'Coupons', 'woocommerce-smart-coupons' ), + ); + return $breadcrumbs; + } + + /** + * Function to add a column to display original amount for store credit to coupons list + * + * @param array $columns The columns. + * @return array + */ + public function add_original_amount_column( $columns = array() ) { + if ( ! array_key_exists( 'wc_sc_original_amount', $columns ) ) { + $columns['wc_sc_original_amount'] = __( 'Original amount', 'woocommerce-smart-coupons' ); + } + return $columns; + } + + /** + * Function to add value to the column to display original amount + * + * @param string $column The column id. + * @param integer $post_id The post id. + */ + public function add_original_amount_column_value( $column = '', $post_id = 0 ) { + if ( 'wc_sc_original_amount' === $column ) { + $column_value = $this->get_post_meta( $post_id, $column, true ); + if ( ! empty( $column_value ) ) { + echo esc_html( $column_value ); + } else { + echo esc_html( '' ); + } + } + } + + } + +} + +WC_SC_Admin_Pages::get_instance(); diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-admin-welcome.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-admin-welcome.php new file mode 100644 index 00000000..5f56dc4a --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-admin-welcome.php @@ -0,0 +1,504 @@ +is_wc_gte_44() ) ? 'woocommerce-marketing' : 'woocommerce'; + + switch ( $get_page ) { + case 'sc-about': + add_submenu_page( $parent_slug, $welcome_page_title, $welcome_page_name, 'manage_options', 'sc-about', array( $this, 'about_screen' ) ); + break; + case 'sc-faqs': + add_submenu_page( $parent_slug, $welcome_page_title, $welcome_page_name, 'manage_options', 'sc-faqs', array( $this, 'faqs_screen' ) ); + break; + } + } + + /** + * Add styles just for this page, and remove dashboard page links. + */ + public function admin_head() { + $parent_slug = ( $this->is_wc_gte_44() ) ? 'woocommerce-marketing' : 'woocommerce'; + + remove_submenu_page( $parent_slug, 'sc-about' ); + remove_submenu_page( $parent_slug, 'sc-faqs' ); + + $get_page = ( ! empty( $_GET['page'] ) ) ? wc_clean( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore + + if ( ! empty( $get_page ) && ( 'sc-faqs' === $get_page || 'sc-about' === $get_page ) ) { + ?> + + +

          + +

          + +
          +
          + +
          + +
          +

          + 'wc-settings', + 'tab' => 'wc-smart-coupons', + ), + admin_url( 'admin.php' ) + ); + ?> + + +

          +
          +
          + + + + + + +
          + + intro(); ?> + +
          +
          +
          +

          +

          + + +

          +
          +
          +

          +
            +
          • +
          • +
          • +
          • +
          +

          + +

          +
          +
          +

          +

          + ' . esc_html__( 'WooCommerce Subscriptions', 'woocommerce-smart-coupons' ) . '' ); + ?> +

          +
          +
          +

          +
          +
          +

          +

          + ' . esc_html__( 'any amount', 'woocommerce-smart-coupons' ) . '', '' . esc_html__( 'variable but fixed amount', 'woocommerce-smart-coupons' ) . '.' ); + ?> +

          +
          +
          +

          +

          + ' . esc_html__( 'See how', 'woocommerce-smart-coupons' ) . '.'; ?> +

          +
          +
          +

          +

          + ' . esc_html__( 'See how', 'woocommerce-smart-coupons' ) . '.'; ?> +

          +
          +
          +
          +
          +

          +

          + ' . esc_html__( 'See how', 'woocommerce-smart-coupons' ) . '.'; ?> +

          +
          +
          +

          +

          + +

          +
          +
          +

          +

          + +

          +
          +
          +
          +
          + + + + +
          + + intro(); ?> + +

          + + esc_html__( 'When trying to add coupon/Smart Coupon, I get "Invalid post type" message.', 'woocommerce-smart-coupons' ), + 'ans' => esc_html__( 'Make sure use of coupon is enabled in your store. You can find this setting', 'woocommerce-smart-coupons' ) . ' ' . __( 'here', 'woocommerce-smart-coupons' ) . '.', + ), + array( + 'que' => esc_html__( 'Smart Coupon\'s fields are broken?', 'woocommerce-smart-coupons' ), + 'ans' => esc_html__( 'Make sure you are using the ', 'woocommerce-smart-coupons' ) . '' . __( 'latest version of Smart Coupons', 'woocommerce-smart-coupons' ) . '' . esc_html__( '. If still the issue persist, temporarily de-activate all plugins except WooCommerce & Smart Coupons. Re-check the issue, if the issue still persists, contact us (from the link at the end of this page). If the issue goes away, re-activate other plugins one-by-one & re-checking the fields, to find out which plugin is conflicting.', 'woocommerce-smart-coupons' ), + ), + array( + 'que' => esc_html__( 'How to translate texts from Smart Coupons?', 'woocommerce-smart-coupons' ), + 'ans' => esc_html__( 'Simplest method is by installing', 'woocommerce-smart-coupons' ) . ' ' . esc_html__( 'Loco Translate', 'woocommerce-smart-coupons' ) . ' ' . esc_html__( 'plugin and then following steps listed ', 'woocommerce-smart-coupons' ) . ' ' . __( 'here', 'woocommerce-smart-coupons' ) . '.', + ), + array( + 'que' => esc_html__( 'How to change texts of the emails sent from Smart Coupons?', 'woocommerce-smart-coupons' ), + 'ans' => esc_html__( 'You can do this by overriding the email template.', 'woocommerce-smart-coupons' ) . ' ' . esc_html__( 'How to override email template', 'woocommerce-smart-coupons' ) . '.', + ), + array( + 'que' => esc_html__( 'Can coupon code have any spaces in the name? / My Store Credit/Gift Certificate is not working (not generating new coupon code).', 'woocommerce-smart-coupons' ), + 'ans' => esc_html__( 'No. Coupon code should not have any spaces in the name, Eg, Coupon code should be “gift-certificate” & not “gift certificate”.', 'woocommerce-smart-coupons' ), + ), + array( + 'que' => esc_html__( 'What\'s the URL to a coupon, so it\'s automatically inserted when visiting?', 'woocommerce-smart-coupons' ), + /* translators: Documentation link for 'How to Apply Single or Multiple Coupons on Click of a Link' */ + 'ans' => esc_html__( 'URL of coupon should be like this:', 'woocommerce-smart-coupons' ) . ' https://www.mysite.com/?coupon-code=discount5&sc-page=shop ' . esc_html__( '. Replace www.mysite.com with your own site URL and replace discount5 with the your coupon code.', 'woocommerce-smart-coupons' ) . ' ' . sprintf( esc_html__( 'For more details you can refer to this article: %s', 'woocommerce-smart-coupons' ), '' . esc_html__( 'How to Apply Single or Multiple Coupons on Click of a Link', 'woocommerce-smart-coupons' ) . '' ), + ), + array( + 'que' => esc_html__( 'Do not want to tie store credit to be used by only one customer? / Can a customer send a gift certificate to themselves to pass on to someone else?', 'woocommerce-smart-coupons' ), + 'ans' => esc_html__( 'Edit the main coupon which is entered in "Coupons" field of the product edit page, then go to "Usage Restrictions" > "Disable Email Restriction" and disable this setting and save the coupon.', 'woocommerce-smart-coupons' ), + ), + array( + 'que' => esc_html__( 'Getting \'Page Not Found Error\' when accessing Coupons tab from My Account Page?', 'woocommerce-smart-coupons' ), + 'ans' => esc_html__( 'Go to WordPress -> Settings -> Permalinks and click on Save Settings once.', 'woocommerce-smart-coupons' ), + ), + array( + 'que' => esc_html__( 'Is there any reference file for creating an import file for coupons?', 'woocommerce-smart-coupons' ), + /* translators: 1. File name 2. File download link */ + 'ans' => sprintf( esc_html__( 'There is one file which is located inside the plugin. You can download the %1$s file from %2$s.', 'woocommerce-smart-coupons' ), 'sample.csv', '' . esc_html__( 'here', 'woocommerce-smart-coupons' ) . '' ) . ' ' . esc_html__( 'If you want to import coupon through file, the file should be like', 'woocommerce-smart-coupons' ) . ' sample.csv', + ), + array( + 'que' => esc_html__( 'Available coupons are not visible on Cart, Checkout & My Account page?', 'woocommerce-smart-coupons' ), + 'ans' => esc_html__( 'Smart Coupons uses hooks of Cart, Checkout & My Account page to display available coupons. If your theme is not using those hooks in cart, checkout & my-account template, coupons will not be displayed.', 'woocommerce-smart-coupons' ), + ), + array( + 'que' => esc_html__( 'How can I resend gift card coupon bought by customers?', 'woocommerce-smart-coupons' ), + 'ans' => esc_html__( 'You can resend them from order admin edit page.', 'woocommerce-smart-coupons' ) . ' ' . __( 'See how', 'woocommerce-smart-coupons' ) . '.', + ), + array( + 'que' => esc_html__( 'Uncheck "Auto-generate" option in Store Credit is not saving? Is it always checked?', 'woocommerce-smart-coupons' ), + 'ans' => esc_html__( 'Store Credit\'s default behavior is auto-generate because, when using a store credit, it\'s balance keeps reducing. Therefore it should be uniquely created for every user automatically.', 'woocommerce-smart-coupons' ), + ), + array( + 'que' => esc_html__( 'Smart Coupons is not sending emails.', 'woocommerce-smart-coupons' ), + 'ans' => esc_html__( 'Smart Coupons sends email only after order completion. So make sure that order complete email is enabled and sending. If enabled, then make sure all settings of coupons, products are in place. Also check by switching your theme.', 'woocommerce-smart-coupons' ), + ), + array( + 'que' => esc_html__( '"Store Credit Receiver detail" form not appearing on checkout page?', 'woocommerce-smart-coupons' ), + 'ans' => esc_html__( 'This form is displayed using a hook which is available in My Account template. Make sure your theme\'s my-account template contains all hooks required for that template. Update your theme if it is not updated.', 'woocommerce-smart-coupons' ), + ), + array( + 'que' => esc_html__( 'Does Smart Coupons allow printing of coupon as Gift Card?', 'woocommerce-smart-coupons' ), + /* translators: Documentation link for 'How to Print Coupons' */ + 'ans' => sprintf( esc_html__( 'Yes, Smart Coupons does provide a feature for printing coupons. For more details, check this article: %s', 'woocommerce-smart-coupons' ), '' . esc_html__( 'How to Print Coupons', 'woocommerce-smart-coupons' ) . '' ), + ), + array( + 'que' => esc_html__( 'Is it possible to have a coupon for each variation of the variable product?', 'woocommerce-smart-coupons' ), + 'ans' => esc_html__( 'From version 4.11.0, you can add/link coupons to product variations as well. This feature is not available in a version lower than 4.11.0.', 'woocommerce-smart-coupons' ), + ), + array( + 'que' => esc_html__( 'Is Smart Coupons compatible with WooCommerce Subscriptions?', 'woocommerce-smart-coupons' ), + 'ans' => esc_html__( 'Yes, Smart Coupons does work with WooCommerce Subscriptions.', 'woocommerce-smart-coupons' ), + ), + array( + 'que' => esc_html__( 'Which features of Smart Coupons work with Subscriptions?', 'woocommerce-smart-coupons' ), + 'ans' => esc_html__( 'Give away a discount or credit on signing up a subscription, give away recurring discount or credits, apply credit during sign up, automatic payment for renewals from credit (Note: When using PayPal Standard Gateway, store credit can be applied only during sign up. Automatic payment for renewals by credit will not work for PayPal Standard Gateway).', 'woocommerce-smart-coupons' ), + ), + array( + 'que' => esc_html__( 'How does automatic payment by store credit work with Subscriptions?', 'woocommerce-smart-coupons' ), + 'ans' => esc_html__( 'Customers can apply store credit on a subscription during purchase of subscription. If the same store credit has sufficient balance, it\'ll keep applying it to renewals till the remainder in store credit is higher than renewal price. Customers will be able to apply store credit only during signup. They will not get an option to apply store credit in renewals. But if the store credit will not have sufficient balance to pay for the renewals, then the order will go into pending mode. Now when the customer will go to pay for this renewal order, they\'ll get an option to apply store credit again. To activate the subscription again, the customer will have to pay for the renewals. When the customer is paying for the renewals from their account, then in that process they can use the same store credit which didn\'t have the sufficient balance, again & pay for the remaining amount.', 'woocommerce-smart-coupons' ), + ), + array( + 'que' => esc_html__( 'Is it possible to partially pay for a subscription with store credit and the remainder by another method?', 'woocommerce-smart-coupons' ), + 'ans' => esc_html__( 'No, this is possible only in those cases where subscription amount is more than store credit\'s balance. If store credit\'s balance is more than subscription\'s total then your bank account or credit card will not be charged.', 'woocommerce-smart-coupons' ), + ), + array( + 'que' => esc_html__( 'Is Smart Coupons WPML compatible?', 'woocommerce-smart-coupons' ), + 'ans' => esc_html__( 'Not yet, but this is being worked on. You will find this in later versions.', 'woocommerce-smart-coupons' ), + ), + array( + 'que' => esc_html__( 'I\'m using WPML & WPML provides support for multi-currency, but Smart Coupons only changes currency symbol & the price value remains same. Can Smart Coupons change the currency symbol and the price value associated with it?', 'woocommerce-smart-coupons' ), + /* translators: Link for the plugin 'Aelia Currency Switcher for WooCommerce' */ + 'ans' => sprintf( esc_html__( 'Currently, Smart Coupons is compatible with %s. But it is not compatible with any other multi-currency plugin or with WPML.', 'woocommerce-smart-coupons' ), '' . esc_html__( 'Aelia Currency Switcher for WooCommerce', 'woocommerce-smart-coupons' ) . '' ), + ), + ); + + $faqs = array_chunk( $faqs, 2 ); + $right_faq_numbering = 1; + $left_faq_numbering = 0; + echo '
          '; + foreach ( $faqs as $fqs ) { + echo '
          '; + foreach ( $fqs as $index => $faq ) { + echo ''; + echo '

          ' . ( ( 1 === absint( $index ) ) ? $right_faq_numbering : ( $left_faq_numbering + 1 ) ) . '. ' . $faq['que'] . '

          '; // phpcs:ignore + echo '

          ' . $faq['ans'] . '

          '; // phpcs:ignore + echo '
          '; + $right_faq_numbering++; + $left_faq_numbering++; + } + echo '
          '; + } + echo '
          '; + ?> + +
          +

          + ' . esc_html__( 'submit a ticket', 'woocommerce-smart-coupons' ) . '' ); // phpcs:ignore + ?> +

          +
          +
          + $post_types, + 'post_status' => 'publish', + 'posts_per_page' => -1, + 's' => $term, + 'fields' => 'all', + ); + + $posts = wp_cache_get( 'wc_sc_search_coupon_by_code_' . sanitize_title( $term ), 'woocommerce_smart_coupons' ); + + if ( false === $posts ) { + $posts = $wpdb->get_results( // phpcs:ignore + $wpdb->prepare( + "SELECT * FROM {$wpdb->prefix}posts + WHERE post_type = %s + AND post_title LIKE %s + AND post_status = %s", + 'shop_coupon', + $wpdb->esc_like( $term ) . '%', + 'publish' + ) + ); + wp_cache_set( 'wc_sc_search_coupon_by_code_' . sanitize_title( $term ), $posts, 'woocommerce_smart_coupons' ); + $this->maybe_add_cache_key( 'wc_sc_search_coupon_by_code_' . sanitize_title( $term ) ); + } + + $found_products = array(); + + $all_discount_types = wc_get_coupon_types(); + + if ( $posts && ! is_scalar( $posts ) ) { + foreach ( $posts as $post ) { + + $discount_type = ( ! empty( $post->ID ) ) ? $this->get_post_meta( $post->ID, 'discount_type', true ) : 'fixed_cart'; + + if ( ! empty( $all_discount_types[ $discount_type ] ) ) { + $discount_type = ' (' . __( 'Type', 'woocommerce-smart-coupons' ) . ': ' . $all_discount_types[ $discount_type ] . ')'; + $found_products[ $post->post_title ] = $post->post_title . $discount_type; + } + } + } + + wp_send_json( $found_products ); + + } + + /** + * Function to search storewide coupons + * + * @param string $x Search term. + * @param array $post_types Post types. + */ + public function sc_json_search_storewide_coupons( $x = '', $post_types = array( 'shop_coupon' ) ) { + global $wpdb; + + check_ajax_referer( 'search-coupons', 'security' ); + + $term = (string) wc_clean( wp_unslash( $_GET['term'] ) ); // phpcs:ignore + + if ( empty( $term ) ) { + die(); + } + + $found_coupons = array(); + $coupon_posts = array(); + + $posts = wp_cache_get( 'wc_sc_search_storewide_coupon_by_code_' . sanitize_title( $term ), 'woocommerce_smart_coupons' ); + + if ( false === $posts ) { + $posts = $wpdb->get_results( // phpcs:ignore + $wpdb->prepare( + "SELECT p.ID, + p.post_title, + pm.meta_key, + pm.meta_value + FROM {$wpdb->posts} AS p + JOIN {$wpdb->postmeta} AS pm + ON (p.ID = pm.post_id AND pm.meta_key IN (%s,%s,%s,%s,%s,%s)) + WHERE p.post_type = %s + AND p.post_title LIKE %s + AND p.post_status = %s", + 'discount_type', + 'coupon_amount', + 'date_expires', + 'auto_generate_coupon', + 'customer_email', + 'wc_sc_expiry_time', + 'shop_coupon', + $wpdb->esc_like( $term ) . '%', + 'publish' + ), + ARRAY_A + ); + wp_cache_set( 'wc_sc_search_storewide_coupon_by_code_' . sanitize_title( $term ), $posts, 'woocommerce_smart_coupons' ); + $this->maybe_add_cache_key( 'wc_sc_search_storewide_coupon_by_code_' . sanitize_title( $term ) ); + } + + if ( ! empty( $posts ) ) { + foreach ( $posts as $post ) { + $post_id = ( ! empty( $post['ID'] ) ) ? absint( $post['ID'] ) : 0; + $post_title = ( ! empty( $post['post_title'] ) ) ? $post['post_title'] : ''; + if ( empty( $post_id ) || empty( $post_title ) ) { + continue; + } + if ( empty( $coupon_posts[ $post_id ] ) || ! is_array( $coupon_posts[ $post_id ] ) ) { + $coupon_posts[ $post_id ] = array(); + } + $coupon_posts[ $post_id ]['post_id'] = $post_id; + $coupon_posts[ $post_id ]['post_title'] = $post_title; + switch ( $post['meta_key'] ) { + case 'discount_type': + case 'coupon_amount': + case 'date_expires': + case 'auto_generate_coupon': + case 'wc_sc_expiry_time': + $coupon_posts[ $post_id ][ $post['meta_key'] ] = $post['meta_value']; // phpcs:ignore + break; + case 'customer_email': + $coupon_posts[ $post_id ][ $post['meta_key'] ] = maybe_unserialize( $post['meta_value'] ); // phpcs:ignore + break; + } + } + } + + $all_discount_types = wc_get_coupon_types(); + + if ( ! empty( $coupon_posts ) ) { + foreach ( $coupon_posts as $post_id => $coupon_post ) { + $discount_type = ( ! empty( $coupon_post['discount_type'] ) ) ? $coupon_post['discount_type'] : ''; + $coupon_amount = ( ! empty( $coupon_post['coupon_amount'] ) ) ? $coupon_post['coupon_amount'] : 0; + $date_expires = ( ! empty( $coupon_post['date_expires'] ) ) ? absint( $coupon_post['date_expires'] ) : 0; + $wc_sc_expiry_time = ( ! empty( $coupon_post['wc_sc_expiry_time'] ) ) ? absint( $coupon_post['wc_sc_expiry_time'] ) : 0; + $auto_generate_coupon = ( ! empty( $coupon_post['auto_generate_coupon'] ) ) ? $coupon_post['auto_generate_coupon'] : ''; + $customer_email = ( ! empty( $coupon_post['customer_email'] ) ) ? $coupon_post['customer_email'] : array(); + + if ( empty( $discount_type ) || 'smart_coupon' === $discount_type ) { + continue; + } + if ( empty( $coupon_amount ) ) { + continue; + } + if ( ! empty( $date_expires ) ) { + $date_expires += $wc_sc_expiry_time; + if ( time() >= $date_expires ) { + continue; + } + } + if ( 'yes' === $auto_generate_coupon ) { + continue; + } + if ( ! empty( $customer_email ) ) { + continue; + } + + if ( ! empty( $all_discount_types[ $discount_type ] ) ) { + /* translators: 1. The coupon code, 2. The discount type */ + $found_coupons[ $coupon_post['post_title'] ] = sprintf( __( '%1$s (Type: %2$s)', 'woocommerce-smart-coupons' ), $coupon_post['post_title'], $all_discount_types[ $discount_type ] ); + } + } + + $found_coupons = apply_filters( + 'wc_sc_json_search_storewide_coupons', + $found_coupons, + array( + 'source' => $this, + 'search_text' => $term, + 'posts' => $posts, + 'coupon_posts' => $coupon_posts, + ) + ); + } + + wp_send_json( $found_coupons ); + + } + + /** + * JSON Search coupon via ajax + * + * @param string $x Search text. + * @param array $post_types Post types. + */ + public function smart_coupons_json_search( $x = '', $post_types = array( 'shop_coupon' ) ) { + global $wpdb, $store_credit_label; + + check_ajax_referer( 'search-coupons', 'security' ); + + $term = (string) wc_clean( wp_unslash( $_GET['term'] ) ); // phpcs:ignore + + if ( empty( $term ) ) { + die(); + } + + $posts = wp_cache_get( 'wc_sc_shortcode_search_coupon_by_code_' . sanitize_title( $term ), 'woocommerce_smart_coupons' ); + + if ( false === $posts ) { + $posts = $wpdb->get_results( // phpcs:ignore + $wpdb->prepare( + "SELECT * + FROM {$wpdb->prefix}posts + WHERE post_type = %s + AND post_title LIKE %s + AND post_status = %s", + 'shop_coupon', + $wpdb->esc_like( $term ) . '%', + 'publish' + ) + ); + wp_cache_set( 'wc_sc_shortcode_search_coupon_by_code_' . sanitize_title( $term ), $posts, 'woocommerce_smart_coupons' ); + $this->maybe_add_cache_key( 'wc_sc_shortcode_search_coupon_by_code_' . sanitize_title( $term ) ); + } + + $found_products = array(); + + $all_discount_types = wc_get_coupon_types(); + + if ( $posts ) { + + foreach ( $posts as $post ) { + + $discount_type = ( ! empty( $post->ID ) ) ? $this->get_post_meta( $post->ID, 'discount_type', true ) : 'fixed_cart'; + if ( ! empty( $all_discount_types[ $discount_type ] ) ) { + + $coupon = new WC_Coupon( $post->post_title ); + + if ( $this->is_wc_gte_30() ) { + $discount_type = $coupon->get_discount_type(); + } else { + $discount_type = ( ! empty( $coupon->discount_type ) ) ? $coupon->discount_type : ''; + } + + $coupon_amount = $this->get_amount( $coupon ); + + switch ( $discount_type ) { + + case 'smart_coupon': + $coupon_type = ! empty( $store_credit_label['singular'] ) ? ucwords( $store_credit_label['singular'] ) : __( 'Store Credit', 'woocommerce-smart-coupons' ); + $coupon_amount = wc_price( $coupon_amount ); + break; + + case 'fixed_cart': + $coupon_type = __( 'Cart Discount', 'woocommerce-smart-coupons' ); + $coupon_amount = wc_price( $coupon_amount ); + break; + + case 'fixed_product': + $coupon_type = __( 'Product Discount', 'woocommerce-smart-coupons' ); + $coupon_amount = wc_price( $coupon_amount ); + break; + + case 'percent_product': + $coupon_type = __( 'Product Discount', 'woocommerce-smart-coupons' ); + $coupon_amount = $coupon_amount . '%'; + break; + + case 'percent': + $coupon_type = ( $this->is_wc_gte_30() ) ? __( 'Discount', 'woocommerce-smart-coupons' ) : __( 'Cart Discount', 'woocommerce-smart-coupons' ); + $coupon_amount = $coupon_amount . '%'; + $max_discount = $this->get_post_meta( $post->ID, 'wc_sc_max_discount', true ); + if ( ! empty( $max_discount ) && is_numeric( $max_discount ) ) { + /* translators: %s: Maximum coupon discount amount */ + $coupon_type .= ' ' . sprintf( __( 'upto %s', 'woocommerce-smart-coupons' ), wc_price( $max_discount ) ); + } + break; + + default: + $default_coupon_type = ( ! empty( $all_discount_types[ $discount_type ] ) ) ? $all_discount_types[ $discount_type ] : ucwords( str_replace( array( '_', '-' ), ' ', $discount_type ) ); + $coupon_type = apply_filters( 'wc_sc_coupon_type', $default_coupon_type, $coupon, $all_discount_types ); + $coupon_amount = apply_filters( 'wc_sc_coupon_amount', $coupon_amount, $coupon ); + break; + + } + + $discount_type = ' ( ' . $coupon_amount . ' ' . $coupon_type . ' )'; + $discount_type = wp_strip_all_tags( $discount_type ); + + $found_products[ $post->post_title ] = $post->post_title . ' ' . $discount_type; + } + } + } + + if ( ! empty( $found_products ) ) { + echo wp_json_encode( $found_products ); + } + + die(); + } + + /** + * Function to Hide Notice Delete After Usage + */ + public function hide_notice_delete_after_usage() { + + check_ajax_referer( 'hide-smart-coupons-notice', 'security' ); + + $current_user_id = get_current_user_id(); + update_user_meta( $current_user_id, 'hide_delete_credit_after_usage_notice', 'yes' ); + + wp_send_json( array( 'message' => 'success' ) ); + + } + + } + +} + +WC_SC_Ajax::get_instance(); diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-apply-before-tax.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-apply-before-tax.php new file mode 100644 index 00000000..4b122996 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-apply-before-tax.php @@ -0,0 +1,633 @@ +is_callable( $order, 'get_id' ) ) ? $order->get_id() : 0; + + $post_post_type = ( ! empty( $_POST['post_type'] ) ) ? wc_clean( wp_unslash( $_POST['post_type'] ) ) : ''; // phpcs:ignore + $post_action = ( ! empty( $_POST['action'] ) ) ? wc_clean( wp_unslash( $_POST['action'] ) ) : ''; // phpcs:ignore + + $post_type = ( ! empty( $order_id ) && $this->is_hpos() ) ? $this->get_post_type( $order_id ) : $post_post_type; + + if ( $order instanceof WC_Order && ( in_array( $post_action, $order_actions, true ) || ( 'shop_order' === $post_type && in_array( $post_action, array( 'edit_order', 'editpost' ), true ) ) ) ) { + if ( ! is_object( $order ) || ! is_callable( array( $order, 'get_id' ) ) ) { + return; + } + if ( empty( $order_id ) ) { + return; + } + $coupons = $order->get_items( 'coupon' ); + $order_items = $order->get_items( 'line_item' ); + + if ( empty( $order_items ) && empty( $coupons ) ) { + return; + } + + foreach ( $coupons as $item_id => $item ) { + + $coupon_code = ( is_object( $item ) && is_callable( array( $item, 'get_name' ) ) ) ? $item->get_name() : $item['name']; + + if ( empty( $coupon_code ) ) { + continue; + } + + $coupon = new WC_Coupon( $coupon_code ); + $discount_type = $coupon->get_discount_type(); + + if ( 'smart_coupon' === $discount_type ) { + $sc_include_tax = $this->is_store_credit_include_tax(); + $smart_coupons_contribution = $this->get_post_meta( $order_id, 'smart_coupons_contribution', true, true ); + $smart_coupons_contribution = ( ! empty( $smart_coupons_contribution ) ) ? $smart_coupons_contribution : array(); + + $discount_amount = ( is_object( $item ) && is_callable( array( $item, 'get_discount' ) ) ) ? $item->get_discount() : $this->get_order_item_meta( $item_id, 'discount_amount', true, true ); + $discount_amount_tax = ( is_object( $item ) && is_callable( array( $item, 'get_discount_tax' ) ) ) ? $item->get_discount_tax() : $this->get_order_item_meta( $item_id, 'discount_amount_tax', true, true ); + + if ( is_array( $smart_coupons_contribution ) && count( $smart_coupons_contribution ) > 0 && array_key_exists( $coupon_code, $smart_coupons_contribution ) ) { + // If store credit discount is inclusive of tax then remove discount given tax from Smart Coupons' contribution. + if ( 'yes' === $sc_include_tax && ! empty( $discount_amount_tax ) ) { + $new_discount = $smart_coupons_contribution[ $coupon_code ] - $discount_amount_tax; + } else { + $new_discount = $smart_coupons_contribution[ $coupon_code ]; + } + if ( is_object( $item ) && is_callable( array( $item, 'set_discount' ) ) ) { + $item->set_discount( $new_discount ); + } else { + $item['discount_amount'] = $new_discount; + } + } elseif ( ! empty( $discount_amount ) ) { + if ( is_object( $item ) && is_callable( array( $item, 'set_discount' ) ) ) { + $item->set_discount( $discount_amount ); + } else { + $item['discount_amount'] = $discount_amount; + } + // If discount includes tax then Smart Coupons contribution is sum of discount on product price and discount on tax. + if ( 'yes' === $sc_include_tax && ! empty( $discount_amount_tax ) ) { + $smart_coupons_contribution[ $coupon_code ] = $discount_amount + $discount_amount_tax; + } else { + $smart_coupons_contribution[ $coupon_code ] = $discount_amount; + } + $this->update_post_meta( $order_id, 'smart_coupons_contribution', $smart_coupons_contribution, true ); + } else { + $coupon_amount = $this->get_amount( $coupon, true, $order ); + $coupon_product_ids = $coupon->get_product_ids(); + $coupon_category_ids = $coupon->get_product_categories(); + + $subtotal = 0; + $items_to_apply_credit = array(); + + if ( count( $coupon_product_ids ) > 0 || count( $coupon_category_ids ) > 0 ) { + foreach ( $order_items as $order_item_id => $order_item ) { + + $product_category_ids = wc_get_product_cat_ids( $order_item['product_id'] ); + + if ( count( $coupon_product_ids ) > 0 && count( $coupon_category_ids ) > 0 ) { + if ( ( in_array( $order_item['product_id'], $coupon_product_ids, true ) || in_array( $order_item['variation_id'], $coupon_product_ids, true ) ) && count( array_intersect( $product_category_ids, $coupon_category_ids ) ) > 0 ) { + $items_to_apply_credit[] = $order_item_id; + } + } else { + if ( in_array( $order_item['product_id'], $coupon_product_ids, true ) || in_array( $order_item['variation_id'], $coupon_product_ids, true ) || count( array_intersect( $product_category_ids, $coupon_category_ids ) ) > 0 ) { + $items_to_apply_credit[] = $order_item_id; + } + } + } + } else { + $items_to_apply_credit = array_keys( $order_items ); + } + + $subtotal = array_sum( array_map( array( $this, 'sc_get_order_subtotal' ), $items_to_apply_credit ) ); + + if ( $subtotal <= 0 ) { + continue; + } + + $store_credit_used = 0; + + foreach ( $items_to_apply_credit as $order_item_id ) { + $order_item = $order_items[ $order_item_id ]; + $discounting_amount = $order_item->get_total(); + // If discount include tax then add item tax to discounting amount to allow discount calculation on tax also. + if ( 'yes' === $sc_include_tax ) { + $item_tax = ( is_callable( array( $order, 'get_line_tax' ) ) ) ? $order->get_line_tax( $order_item ) : 0; + $discounting_amount += $item_tax; + } + $quantity = $order_item->get_quantity(); + $discount = $this->sc_get_discounted_price( $discounting_amount, $quantity, $subtotal, $coupon_amount ); + $discount *= $quantity; + $order_item->set_total( $discounting_amount - $discount ); + + $store_credit_used += $discount; + } + + if ( is_object( $item ) && is_callable( array( $item, 'set_discount' ) ) ) { + $item->set_discount( $store_credit_used ); + } else { + $item['discount_amount'] = $store_credit_used; + } + + $smart_coupons_contribution[ $coupon_code ] = $store_credit_used; + + $this->update_post_meta( $order_id, 'smart_coupons_contribution', $smart_coupons_contribution, true ); + } + + $order->sc_total_credit_used = $smart_coupons_contribution; + } + } + } + } + + /** + * Function to calculate subtotal of items in order which is necessary for applying store credit before tax calculation + * + * @param int $order_item_id Item ID. + * @return float $subtotal + */ + private function sc_get_order_subtotal( $order_item_id ) { + $order_item = WC_Order_Factory::get_order_item( $order_item_id ); + $subtotal = $order_item->get_total(); + + $prices_include_tax = wc_prices_include_tax(); + // Get global setting for whether store credit discount is inclusive of tax or not. + $sc_include_tax = get_option( 'woocommerce_smart_coupon_include_tax', 'no' ); + + // If prices are inclusive of tax and discount amount is also inclusive of tax then add item tax in subtotal to handle discount calculation correctly. + if ( true === $prices_include_tax && 'yes' === $sc_include_tax ) { + $subtotal += $order_item->get_total_tax(); + } + + return $subtotal; + } + + /** + * Function to update_discount_total for an order + * + * @param WC_Order $order Order object. + * @param float $total_credit_used Total store credit used. + */ + public function update_discount_total( $order = '', $total_credit_used = 0 ) { + if ( $order instanceof WC_Order ) { + $discount_total = $order->get_discount_total(); + $sc_credit_used = min( $discount_total, $total_credit_used ); + $order->set_discount_total( $discount_total - $sc_credit_used ); + } + } + + + /** + * Function to set discount total for a new order + * + * @param WC_Order $order Order object. + */ + public function cart_set_discount_total( $order ) { + if ( isset( WC()->cart->smart_coupon_credit_used ) && is_array( WC()->cart->smart_coupon_credit_used ) && count( WC()->cart->smart_coupon_credit_used ) > 0 ) { + $total_credit_used = array_sum( WC()->cart->smart_coupon_credit_used ); + $this->update_discount_total( $order, $total_credit_used ); + } + } + + /** + * Function to apply store credit before tax calculation for cart items + */ + public function cart_calculate_discount_amount() { + $cart = ( isset( WC()->cart ) ) ? WC()->cart : ''; + + if ( $cart instanceof WC_Cart ) { + $cart_contents = WC()->cart->get_cart(); + $coupons = $cart->get_coupons(); + + if ( ! empty( $coupons ) ) { + $items_to_apply_credit = array(); + + foreach ( $coupons as $coupon_code => $coupon ) { + $discount_type = $coupon->get_discount_type(); + + if ( 'smart_coupon' === $discount_type ) { + $coupon_product_ids = $coupon->get_product_ids(); + $coupon_category_ids = $coupon->get_product_categories(); + + if ( count( $coupon_product_ids ) > 0 || count( $coupon_category_ids ) > 0 ) { + + foreach ( $cart_contents as $cart_item_key => $cart_item ) { + $product_category_ids = wc_get_product_cat_ids( $cart_item['product_id'] ); + + if ( count( $coupon_product_ids ) > 0 && count( $coupon_category_ids ) > 0 ) { + if ( ( in_array( $cart_item['product_id'], $coupon_product_ids, true ) || in_array( $cart_item['variation_id'], $coupon_product_ids, true ) ) && count( array_intersect( $product_category_ids, $coupon_category_ids ) ) > 0 ) { + $items_to_apply_credit[ $coupon_code ][] = $cart_item_key; + } + } else { + if ( in_array( $cart_item['product_id'], $coupon_product_ids, true ) || in_array( $cart_item['variation_id'], $coupon_product_ids, true ) || count( array_intersect( $product_category_ids, $coupon_category_ids ) ) > 0 ) { + $items_to_apply_credit[ $coupon_code ][] = $cart_item_key; + } + } + } + } else { + $items_to_apply_credit[ $coupon_code ] = array_keys( $cart_contents ); + } + } + } + + if ( ! empty( $items_to_apply_credit ) ) { + WC()->cart->sc_items_to_apply_credit = $items_to_apply_credit; + } + } + } + + } + + /** + * Get discount amount for a cart item. + * + * @param float $discount Amount this coupon has discounted. + * @param float $discounting_amount Amount the coupon is being applied to. + * @param array|null $cart_item Cart item being discounted if applicable. + * @param bool $single True if discounting a single qty item, false if its the line. + * @param WC_Coupon $coupon Coupon object. + * @return float $discount + */ + public function cart_return_discount_amount( $discount, $discounting_amount, $cart_item, $single, $coupon ) { + + if ( ! is_object( $coupon ) || ! is_a( $coupon, 'WC_Coupon' ) ) { + return $discount; + } + + $discount_type = is_callable( array( $coupon, 'get_discount_type' ) ) ? $coupon->get_discount_type() : ''; + if ( 'smart_coupon' !== $discount_type ) { + return $discount; + } + + $coupon_code = is_callable( array( $coupon, 'get_code' ) ) ? $coupon->get_code() : ''; + + if ( is_object( $cart_item ) && is_a( $cart_item, 'WC_Order_Item_Product' ) ) { + return $this->calculate_discount_amount_for_rest_api( $discount, $discounting_amount, $cart_item, $single, $coupon ); + } + + $coupon_amount = $this->get_amount( $coupon, true ); + + $product = isset( $cart_item['data'] ) ? $cart_item['data'] : array(); + $quantity = $cart_item['quantity']; + + // Compatibility for WC version < 3.2.0. + if ( ! isset( $cart_item['key'] ) ) { + $product_id = ( ! empty( $cart_item['variation_id'] ) ) ? $cart_item['variation_id'] : $cart_item['product_id']; + + foreach ( WC()->cart->cart_contents as $key => $cart_data ) { + $cart_data_product_id = ( ! empty( $cart_data['variation_id'] ) ) ? $cart_data['variation_id'] : $cart_data['product_id']; + + if ( $product_id === $cart_data_product_id ) { + $cart_item['key'] = $key; + } + } + } + + $prices_include_tax = ( 'incl' === get_option( 'woocommerce_tax_display_cart' ) ) ? true : false; + if ( true === $prices_include_tax ) { + $sc_include_tax = get_option( 'woocommerce_smart_coupon_include_tax', 'no' ); + if ( 'no' === $sc_include_tax ) { + $discounting_amount = $cart_item['line_subtotal'] / $quantity; + } + } + + $items_to_apply_credit = isset( WC()->cart->sc_items_to_apply_credit ) ? WC()->cart->sc_items_to_apply_credit : array(); + + if ( ! empty( $items_to_apply_credit ) && is_array( $items_to_apply_credit ) && array_key_exists( $coupon_code, $items_to_apply_credit ) && in_array( $cart_item['key'], $items_to_apply_credit[ $coupon_code ], true ) ) { + + $credit_left = isset( $this->sc_credit_left[ $coupon_code ] ) ? $this->sc_credit_left[ $coupon_code ] : $coupon_amount; + $total_discounting_amount = $discounting_amount * $quantity; + if ( isset( $this->remaining_total_to_apply_credit[ $cart_item['key'] ] ) ) { + $total_discounting_amount = wc_remove_number_precision( $this->remaining_total_to_apply_credit[ $cart_item['key'] ] ); + } + $applied_discount = min( $total_discounting_amount, $credit_left ); + + $this->sc_credit_left[ $coupon_code ] = ( $total_discounting_amount < $credit_left ) ? $credit_left - $total_discounting_amount : 0; + + $discount = $applied_discount / $quantity; + } + + return $discount; + } + + /** + * Calculate discount amount for REST API and Order created via backend. + * + * @param float $discount Amount this coupon has discounted. + * @param float $discounting_amount Amount the coupon is being applied to. + * @param WC_Order_Item_Product $cart_item Object. + * @param bool $single True if discounting a single qty item, false if its the line. + * @param WC_Coupon $coupon Object. + * @return float|int|mixed + */ + public function calculate_discount_amount_for_rest_api( $discount = 0, $discounting_amount = 0, $cart_item = object, $single = false, $coupon = object ) { + + if ( ! is_object( $coupon ) || ! is_a( $coupon, 'WC_Coupon' ) ) { + return $discount; + } + + if ( ! is_object( $cart_item ) || ! is_a( $cart_item, 'WC_Order_Item_Product' ) ) { + return $discount; + } + + $quantity = ( is_callable( array( $cart_item, 'get_quantity' ) ) ) ? $cart_item->get_quantity() : 1; + $item_id = ( is_callable( array( $cart_item, 'get_id' ) ) ) ? $cart_item->get_id() : 0; + $product_subtotal = ( is_callable( array( $cart_item, 'get_subtotal' ) ) ) ? $cart_item->get_subtotal() : 0; + $order = ( is_callable( array( $cart_item, 'get_order' ) ) ) ? $cart_item->get_order() : null; + $coupon_code = ( is_callable( array( $coupon, 'get_code' ) ) ) ? $coupon->get_code() : ''; + $discount_type = ( is_callable( array( $coupon, 'get_discount_type' ) ) ) ? $coupon->get_discount_type() : ''; + + if ( 'smart_coupon' !== $discount_type ) { + return $discount; + } + $smart_coupons_contribution = ( is_callable( array( $order, 'get_meta' ) ) ) ? $order->get_meta( 'smart_coupons_contribution' ) : array(); + + if ( isset( $this->sc_api_credit_left[ $coupon_code ]['items'] ) && ! empty( $this->sc_api_credit_left[ $coupon_code ]['items'][ $item_id ] ) ) { + return $this->sc_api_credit_left[ $coupon_code ]['items'][ $item_id ]; + } + + $coupon_amount = is_array( $smart_coupons_contribution ) && isset( $smart_coupons_contribution[ $coupon_code ] ) ? $smart_coupons_contribution[ $coupon_code ] : (float) $this->get_amount( $coupon, true, $order ); + // isset is required here to confirm that store credit was used but now it is empty. + if ( $coupon_amount < 1 || ( isset( $this->sc_api_credit_left[ $coupon_code ]['credit_left'] ) && empty( $this->sc_api_credit_left[ $coupon_code ]['credit_left'] ) ) ) { + return $discount; + } + + $prices_include_tax = ( 'yes' === get_option( 'woocommerce_prices_include_tax' ) ) ? true : false; + if ( true === $prices_include_tax ) { + $sc_include_tax = get_option( 'woocommerce_smart_coupon_include_tax', 'no' ); + if ( 'no' === $sc_include_tax ) { + $discounting_amount = $product_subtotal / $quantity; + } + } + + $credit_left = ( ! empty( $this->sc_api_credit_left ) && isset( $this->sc_api_credit_left[ $coupon_code ]['credit_left'] ) ) ? $this->sc_api_credit_left[ $coupon_code ]['credit_left'] : $coupon_amount; + + if ( $credit_left > 0 ) { + $total_credit_already_applied_current_item = is_array( $this->sc_api_credit_left ) && count( $this->sc_api_credit_left ) > 0 ? (float) array_sum( wp_list_pluck( array_column( array_values( $this->sc_api_credit_left ), 'items' ), $item_id ) ) : 0; + if ( $single ) { + $discount = min( $quantity * ( $discounting_amount - $total_credit_already_applied_current_item ), $credit_left ); + } else { + $discount = min( ( $discounting_amount - ( $total_credit_already_applied_current_item * $quantity ) ), $credit_left ); + } + + $credit_left -= $discount; + $this->sc_api_credit_left[ $coupon_code ]['credit_left'] = $credit_left; + $discount = (float) $discount / $quantity; + } + + // Note*: We always store discount credit inside sc_api_credit_left as discounting_amount not line total. + $this->sc_api_credit_left[ $coupon_code ]['items'][ $item_id ] = $discount; + return $single ? $discount : $discount * $quantity; + + } + + + /** + * Discount details for store credit + * + * @param array $discounts The discount details. + * @param WC_Coupon $coupon The coupon object. + * @return array + */ + public function store_credit_discounts_array( $discounts = array(), $coupon = null ) { + $cart = ( isset( WC()->cart ) ) ? WC()->cart : ''; + if ( $cart instanceof WC_Cart ) { + $cart_contents = ( is_object( WC()->cart ) && is_callable( array( WC()->cart, 'get_cart' ) ) ) ? WC()->cart->get_cart() : array(); + if ( ! empty( $cart_contents ) ) { + $discount_type = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_discount_type' ) ) ) ? $coupon->get_discount_type() : ''; + if ( 'smart_coupon' === $discount_type ) { + $prices_include_tax = ( 'incl' === get_option( 'woocommerce_tax_display_cart' ) ) ? true : false; + if ( true === $prices_include_tax ) { + $sc_include_tax = get_option( 'woocommerce_smart_coupon_include_tax', 'no' ); + if ( 'no' === $sc_include_tax ) { + if ( ! empty( $discounts ) ) { + foreach ( $discounts as $item_key => $discount ) { + $line_subtotal = wc_round_discount( wc_add_number_precision( $cart_contents[ $item_key ]['line_subtotal'] ), 0 ); + $line_subtotal = ( isset( $this->remaining_total_to_apply_credit[ $item_key ] ) ) ? min( $this->remaining_total_to_apply_credit[ $item_key ], $line_subtotal ) : $line_subtotal; + $discount = min( $discount, $line_subtotal ); + $discounts [ $item_key ] = $discount; + $this->remaining_total_to_apply_credit[ $item_key ] = $line_subtotal - $discount; + } + } + } + } + } + } + } + return $discounts; + } + + /** + * Set smart coupon credit used + */ + public function cart_set_total_credit_used() { + + $coupon_discount_totals = ( is_callable( array( 'WC_Cart', 'get_coupon_discount_totals' ) ) ) ? WC()->cart->get_coupon_discount_totals() : WC()->cart->coupon_discount_amounts; + $coupon_discount_tax_totals = ( is_callable( array( 'WC_Cart', 'get_coupon_discount_tax_totals' ) ) ) ? WC()->cart->get_coupon_discount_tax_totals() : WC()->cart->coupon_discount_tax_amounts; + $sc_total_credit_used = array(); + + if ( ! empty( $coupon_discount_totals ) && is_array( $coupon_discount_totals ) && count( $coupon_discount_totals ) > 0 ) { + foreach ( $coupon_discount_totals as $coupon_code => $total ) { + $coupon = new WC_Coupon( $coupon_code ); + $discount_type = $coupon->get_discount_type(); + + if ( 'smart_coupon' === $discount_type ) { + $sc_total_credit_used[ $coupon_code ] = $total; + + if ( ! empty( $coupon_discount_tax_totals[ $coupon_code ] ) ) { + $sc_include_tax = $this->is_store_credit_include_tax(); + if ( 'yes' === $sc_include_tax ) { + $sc_total_credit_used[ $coupon_code ] += $coupon_discount_tax_totals[ $coupon_code ]; + } else { + $prices_include_tax = ( 'incl' === get_option( 'woocommerce_tax_display_cart' ) ) ? true : false; + if ( true === $prices_include_tax ) { + $apply_before_tax = get_option( 'woocommerce_smart_coupon_apply_before_tax', 'no' ); + if ( 'yes' === $apply_before_tax ) { + $_sc_include_tax = get_option( 'woocommerce_smart_coupon_include_tax', 'no' ); + if ( 'no' === $_sc_include_tax ) { + $sc_total_credit_used[ $coupon_code ] += $coupon_discount_tax_totals[ $coupon_code ]; + } + } + } + } + } + } + } + } + + if ( ! empty( $sc_total_credit_used ) ) { + WC()->cart->smart_coupon_credit_used = $sc_total_credit_used; + } + } + + /** + * Function to calculate discount amount for an item + * + * @param float $discounting_amount Amount the coupon is being applied to. + * @param int $quantity Item quantity. + * @param float $subtotal Cart/Order subtotal. + * @param float $coupon_amount Coupon amount. + * @return float $discount + */ + public function sc_get_discounted_price( $discounting_amount = 0, $quantity = 1, $subtotal = 0, $coupon_amount = 0 ) { + $discount = 0; + $discounting_amount = $discounting_amount / $quantity; + $discount_percent = ( $discounting_amount * $quantity ) / $subtotal; + + $discount = ( $coupon_amount * $discount_percent ) / $quantity; + $discount = min( $discount, $discounting_amount ); + + return $discount; + } + + /** + * Function to add cart item key for MNM child items. + * This was need because MNM child items didn't had cart item key inside $cart_item_data array and the + * function WC_SC_Apply_Before_Tax::cart_return_discount_amount() uses cart item key to set discount amount. + * + * @param array $cart_item_data Cart item data. + * @param string $cart_item_key Cart item key. + * @return float $cart_item_data + */ + public function sc_mnm_compat( $cart_item_data, $cart_item_key ) { + if ( ! empty( $cart_item_data['mnm_container'] ) ) { + $cart_item_data['key'] = $cart_item_key; + } + + return $cart_item_data; + } + + /** + * Reset credit left to the defaults. + */ + public function cart_reset_credit_left() { + $this->sc_credit_left = array(); + $this->sc_api_credit_left = array(); + $this->remaining_total_to_apply_credit = array(); + } + + /** + * Function to override smart coupon sequence order defauly by woocommerce. + * + * @param number $sort order sequence number. + * @param object $coupon object of Coupon. + * @return number $sort + */ + public function change_default_sort_order( $sort = 0, $coupon = null ) { + + if ( is_admin() || ! $coupon instanceof WC_Coupon || is_null( $coupon ) || ! is_callable( array( $coupon, 'get_discount_type' ) ) || ( is_callable( array( $coupon, 'get_discount_type' ) ) && $coupon->get_discount_type() !== 'smart_coupon' ) ) { + return $sort; + } + // Allow plugins to override the default order. + return apply_filters( 'wc_sc_coupon_sort_order', 4, $coupon ); + } + } +} + +WC_SC_Apply_Before_Tax::get_instance(); diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-auto-apply-coupon.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-auto-apply-coupon.php new file mode 100644 index 00000000..0ddb2f1f --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-auto-apply-coupon.php @@ -0,0 +1,751 @@ + + +
          + sc_get_option( 'wc_sc_allow_auto_apply', 'yes' ); + if ( 'yes' === $is_allow_auto_apply ) { + woocommerce_wp_checkbox( + array( + 'id' => 'wc_sc_auto_apply_coupon', + 'label' => __( 'Auto apply?', 'woocommerce-smart-coupons' ), + 'description' => __( 'When checked, this coupon will be applied automatically, if it is valid. If enabled in more than 5 coupons, only 5 coupons will be applied automatically, rest will be ignored.', 'woocommerce-smart-coupons' ), + ) + ); + } + ?> +
          + is_callable( $coupon, 'update_meta_data' ) && $this->is_callable( $coupon, 'save' ); + + // Get list of ids of coupons to auto apply. + $auto_apply_coupon_ids = get_option( 'wc_sc_auto_apply_coupon_ids', array() ); + $auto_apply_coupon_ids = ( empty( $auto_apply_coupon_ids ) || ! is_array( $auto_apply_coupon_ids ) ) ? array() : $auto_apply_coupon_ids; + $auto_apply_coupon_ids = array_map( 'absint', $auto_apply_coupon_ids ); + $post_id = absint( $post_id ); + if ( isset( $_POST['wc_sc_auto_apply_coupon'] ) && isset( $_POST['discount_type'] ) && 'smart_coupon' !== wc_clean( wp_unslash( $_POST['discount_type'] ) ) ) { // phpcs:ignore + $auto_apply_coupon = wc_clean( wp_unslash( $_POST['wc_sc_auto_apply_coupon'] ) ); // phpcs:ignore + if ( true === $is_callable_coupon_update_meta ) { + $coupon->update_meta_data( 'wc_sc_auto_apply_coupon', $auto_apply_coupon ); + $coupon->save(); + } else { + $this->update_post_meta( $post_id, 'wc_sc_auto_apply_coupon', $auto_apply_coupon ); + } + // Add coupon id to auto apply coupon list if haven't added already. + if ( is_array( $auto_apply_coupon_ids ) && ! in_array( $post_id, $auto_apply_coupon_ids, true ) ) { + $auto_apply_coupon_ids[] = $post_id; + } + } else { + if ( true === $is_callable_coupon_update_meta ) { + $coupon->update_meta_data( 'wc_sc_auto_apply_coupon', 'no' ); + $coupon->save(); + } else { + $this->update_post_meta( $post_id, 'wc_sc_auto_apply_coupon', 'no' ); + } + // Remove coupon id from auto apply coupon list if auto apply is disabled. + if ( is_array( $auto_apply_coupon_ids ) && in_array( $post_id, $auto_apply_coupon_ids, true ) ) { + $auto_apply_coupon_ids = array_diff( $auto_apply_coupon_ids, array( $post_id ) ); + } + } + update_option( 'wc_sc_auto_apply_coupon_ids', $auto_apply_coupon_ids, 'no' ); + } + + /** + * Add meta in export headers + * + * @param array $headers Existing headers. + * @return array + */ + public function export_headers( $headers = array() ) { + + $headers['wc_sc_auto_apply_coupon'] = __( 'Auto apply?', 'woocommerce-smart-coupons' ); + + return $headers; + } + + /** + * Post meta defaults for auto apply coupon meta + * + * @param array $defaults Existing postmeta defaults. + * @return array $defaults Modified postmeta defaults + */ + public function postmeta_defaults( $defaults = array() ) { + + $defaults['wc_sc_auto_apply_coupon'] = ''; + + return $defaults; + } + + /** + * Add auto apply coupon's meta with value in coupon meta + * + * @param array $data The row data. + * @param array $post The POST values. + * @return array $data Modified row data + */ + public function generate_coupon_meta( $data = array(), $post = array() ) { + + if ( isset( $post['discount_type'] ) && 'smart_coupon' !== $post['discount_type'] ) { + $data['wc_sc_auto_apply_coupon'] = ( isset( $post['wc_sc_auto_apply_coupon'] ) ) ? $post['wc_sc_auto_apply_coupon'] : ''; + } + + return $data; + } + + /** + * Process coupon meta value for import + * + * @param mixed $meta_value The meta value. + * @param array $args Additional Arguments. + * @return mixed $meta_value + */ + public function process_coupon_meta_value_for_import( $meta_value = null, $args = array() ) { + + $discount_type = isset( $args['discount_type'] ) ? $args['discount_type'] : ''; + if ( 'smart_coupon' !== $discount_type && ! empty( $args['meta_key'] ) && 'wc_sc_auto_apply_coupon' === $args['meta_key'] ) { + $auto_apply_coupon = $meta_value; + if ( 'yes' === $auto_apply_coupon ) { + $auto_apply_coupon_ids = get_option( 'wc_sc_auto_apply_coupon_ids', array() ); + $auto_apply_coupon_ids = ( empty( $auto_apply_coupon_ids ) || ! is_array( $auto_apply_coupon_ids ) ) ? array() : $auto_apply_coupon_ids; + $auto_apply_coupon_ids = array_map( 'absint', $auto_apply_coupon_ids ); + $coupon_id = ( isset( $args['post']['post_id'] ) ) ? absint( $args['post']['post_id'] ) : 0; + if ( ! empty( $coupon_id ) && ! in_array( $coupon_id, $auto_apply_coupon_ids, true ) ) { + $auto_apply_coupon_ids[] = $coupon_id; + update_option( 'wc_sc_auto_apply_coupon_ids', $auto_apply_coupon_ids, 'no' ); + } + } + } + + return $meta_value; + } + + /** + * Make meta data of auto apply coupon meta protected + * + * @param bool $protected Is protected. + * @param string $meta_key The meta key. + * @param string $meta_type The meta type. + * @return bool $protected + */ + public function make_action_meta_protected( $protected = false, $meta_key = '', $meta_type = '' ) { + + if ( 'wc_sc_auto_apply_coupon' === $meta_key ) { + return true; + } + + return $protected; + } + + /** + * Get auto applied coupons + * + * @since 4.27.0 + * @return array + */ + public function get_auto_applied_coupons() { + $coupons = ( is_object( WC()->session ) && is_callable( array( WC()->session, 'get' ) ) ) ? WC()->session->get( 'wc_sc_auto_applied_coupons' ) : array(); + $coupons = ( ! empty( $coupons ) && is_array( $coupons ) ) ? array_filter( array_unique( $coupons ) ) : array(); + return apply_filters( 'wc_sc_' . __FUNCTION__, $coupons, array( 'source' => $this ) ); + } + + /** + * Add auto applied coupon to WC session + * + * @since 4.27.0 + * @param string $coupon_code Coupon Code. + */ + public function set_auto_applied_coupon( $coupon_code = '' ) { + if ( ! empty( $coupon_code ) ) { + $coupons = $this->get_auto_applied_coupons(); + // Check if auto applied coupons are not empty. + if ( ! empty( $coupons ) && is_array( $coupons ) ) { + $coupons[] = $coupon_code; + } else { + $coupons = array( $coupon_code ); + } + if ( is_object( WC()->session ) && is_callable( array( WC()->session, 'set' ) ) ) { + WC()->session->set( 'wc_sc_auto_applied_coupons', $coupons ); + } + } + } + + /** + * Remove an auto applied coupon from WC session + * + * @since 4.31.0 + * @param string $coupon_code Coupon Code. + */ + public function unset_auto_applied_coupon( $coupon_code = '' ) { + if ( ! empty( $coupon_code ) ) { + $update = false; + $coupons = $this->get_auto_applied_coupons(); + // Check if auto applied coupons are not empty. + if ( ! empty( $coupons ) && in_array( $coupon_code, $coupons, true ) ) { + $coupons = array_diff( $coupons, array( $coupon_code ) ); + $update = true; + } + if ( true === $update && is_object( WC()->session ) && is_callable( array( WC()->session, 'set' ) ) ) { + $coupons = array_values( array_filter( $coupons ) ); + WC()->session->set( 'wc_sc_auto_applied_coupons', $coupons ); + } + } + } + + /** + * Reset cart session data. + * + * @since 4.27.0 + */ + public function reset_auto_applied_coupons_session() { + if ( is_object( WC()->session ) && is_callable( array( WC()->session, 'set' ) ) ) { + WC()->session->set( 'wc_sc_auto_applied_coupons', null ); + } + } + + /** + * Runs after a coupon is removed + * + * @since 4.31.0 + * @param string $coupon_code The coupon code. + * @return void + */ + public function wc_sc_removed_coupon( $coupon_code = '' ) { + $backtrace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ); // phpcs:ignore + $is_automatic = true; + if ( ! empty( $backtrace ) ) { + foreach ( $backtrace as $trace ) { + if ( + isset( $trace['file'] ) && + ( + false !== strpos( $trace['file'], 'StoreApi/Routes/V1/CartRemoveCoupon.php' ) || + ( ! empty( $trace['function'] ) && 'remove_coupon' === $trace['function'] && ! empty( $trace['class'] ) && 'WC_AJAX' === $trace['class'] ) + ) + ) { + if ( false !== strpos( $trace['file'], 'StoreApi/Routes/V1/CartRemoveCoupon.php' ) ) { + // Call auto_apply_coupons() if removal is from StoreApi/Routes/V1/CartRemoveCoupon.php. + $this->auto_apply_coupons(); + return; // Exit function after calling auto_apply_coupons(). + } + + // Coupon was removed by the user. + $is_automatic = false; + break; // Exit loop once the user removal is identified. + } + } + } + if ( $is_automatic ) { + $this->unset_auto_applied_coupon( $coupon_code ); + } + } + + /** + * Check if auto apply coupon allowed in the cart + * + * @since 4.27.0 + * @return bool. + */ + public function is_allow_auto_apply_coupons() { + $auto_applied_coupons = $this->get_auto_applied_coupons(); + $auto_applied_coupons_count = ! empty( $auto_applied_coupons ) && is_array( $auto_applied_coupons ) ? count( $auto_applied_coupons ) : 0; + $max_auto_apply_coupons_limit = apply_filters( 'wc_sc_max_auto_apply_coupons_limit', get_option( 'wc_sc_max_auto_apply_coupons_limit', 5 ), array( 'source' => $this ) ); + + return apply_filters( + 'wc_sc_' . __FUNCTION__, + $auto_applied_coupons_count < $max_auto_apply_coupons_limit, + array( + 'source' => $this, + 'auto_applied_coupons' => $auto_applied_coupons, + ) + ); + } + + /** + * Check if the auto apply removable + * + * @since 4.27.0 + * @param string $coupon_code Coupon Code. + * @return bool. + */ + public function is_auto_apply_coupon_removable( $coupon_code = '' ) { + + return apply_filters( + 'wc_sc_' . __FUNCTION__, + get_option( 'wc_sc_auto_apply_coupon_removable', 'yes' ), + array( + 'source' => $this, + 'coupon_code' => $coupon_code, + ) + ); + } + + /** + * Check if the coupon is applied through auto apply + * + * @since 4.27.0 + * @param string $coupon_code Coupon Code. + * @return bool. + */ + public function is_coupon_applied_by_auto_apply( $coupon_code = '' ) { + if ( ! empty( $coupon_code ) ) { + $applied_coupons = $this->get_auto_applied_coupons(); + if ( ! empty( $applied_coupons ) && is_array( $applied_coupons ) && in_array( $coupon_code, $applied_coupons, true ) ) { + return true; + } + } + return false; + } + + /** + * Check if coupon is applicable for auto apply + * + * @since 4.26.0 + * @param WC_Coupon $coupon WooCommerce coupon object. + * @return bool + */ + public function is_coupon_valid_for_auto_apply( $coupon = null ) { + + $valid = false; + if ( is_object( $coupon ) && $coupon instanceof WC_Coupon ) { + + if ( $this->is_wc_gte_30() ) { + $coupon_code = is_callable( array( $coupon, 'get_code' ) ) ? $coupon->get_code() : ''; + $discount_type = is_callable( array( $coupon, 'get_discount_type' ) ) ? $coupon->get_discount_type() : ''; + $is_auto_generate_coupon = is_callable( array( $coupon, 'get_meta' ) ) ? $coupon->get_meta( 'auto_generate_coupon' ) : 'no'; + $is_disable_email_restrict = is_callable( array( $coupon, 'get_meta' ) ) ? $coupon->get_meta( 'sc_disable_email_restriction' ) : 'no'; + } else { + $coupon_id = ( ! empty( $coupon->id ) ) ? $coupon->id : 0; + $coupon_code = ( ! empty( $coupon->code ) ) ? $coupon->code : ''; + $discount_type = get_post_meta( $coupon_id, 'discount_type', true ); + $is_auto_generate_coupon = get_post_meta( $coupon_id, 'auto_generate_coupon', true ); + $is_disable_email_restrict = get_post_meta( $coupon_id, 'sc_disable_email_restriction', true ); + } + + $is_removable = $this->is_auto_apply_coupon_removable( $coupon_code ); + $is_auto_applied = $this->is_coupon_applied_by_auto_apply( $coupon_code ); + + /** + * Validate coupon for auto apply if + * + * Discount type is not smart_coupon. + * Auto generate is not enabled. + * Coupon should not be auto applied OR auto applied coupon should not be removable. + * Coupon code is valid. + */ + $valid = 'smart_coupon' !== $discount_type + && 'yes' !== $is_auto_generate_coupon + && ( ! $is_auto_applied || 'yes' !== $is_removable ) + && $this->is_valid( $coupon ); + } + + return apply_filters( + 'wc_sc_' . __FUNCTION__, + $valid, + array( + 'coupon_obj' => $coupon, + 'source' => $this, + ) + ); + } + + /** + * Function to apply coupons automatically. + * + * TODO: IF we need another variable for removed coupons; + * There will be 2 session variables: wc_sc_auto_applied_coupons and wc_sc_removed_auto_applied_coupons. + * Whenever a coupon will be auto-applied, it'll be stored in wc_sc_auto_applied_coupons. + * Whenever a coupon will be removed, it'll be moved from wc_sc_auto_applied_coupons to wc_sc_removed_auto_applied_coupons. + * And before applying an auto-apply coupon, it'll be made sure that the coupon doesn't exist in wc_sc_removed_auto_applied_coupons + * And sum of counts of both session variable will be considered before auto applying coupons. It will be made sure that the sum of counts in not exceeding option `wc_sc_max_auto_apply_coupons_limit` + * Reference: issues/234#note_27085 + */ + public function auto_apply_coupons() { + $cart = ( is_object( WC() ) && isset( WC()->cart ) ) ? WC()->cart : null; + if ( is_object( $cart ) && is_callable( array( $cart, 'is_empty' ) ) && ! $cart->is_empty() && $this->is_allow_auto_apply_coupons() ) { + global $wpdb; + $user_role = ''; + $email = ''; + if ( ! is_admin() ) { + $current_user = wp_get_current_user(); + if ( ! empty( $current_user->ID ) ) { + $max_user_roles_limit = apply_filters( 'wc_sc_max_user_roles_limit', 5 ); + $user_roles = ( ! empty( $current_user->roles ) ) ? $current_user->roles : array(); + if ( count( $user_roles ) > $max_user_roles_limit ) { + $user_roles = array_slice( $user_roles, 0, $max_user_roles_limit ); + } + $email = get_user_meta( $current_user->ID, 'billing_email', true ); + $email = ( ! empty( $email ) ) ? $email : $current_user->user_email; + } + } + $query = $wpdb->prepare( + "SELECT DISTINCT p.ID + FROM {$wpdb->posts} AS p + JOIN {$wpdb->postmeta} AS pm1 + ON (p.ID = pm1.post_id + AND p.post_type = %s + AND p.post_status = %s + AND pm1.meta_key = %s + AND pm1.meta_value = %s) + JOIN {$wpdb->postmeta} AS pm2 + ON (p.ID = pm2.post_id + AND pm2.meta_key IN ('wc_sc_user_role_ids', 'customer_email') + AND (pm2.meta_value = '' + OR pm2.meta_value = 'a:0:{}'", + 'shop_coupon', + 'publish', + 'wc_sc_auto_apply_coupon', + 'yes' + ); + if ( ! empty( $user_roles ) ) { + foreach ( $user_roles as $user_role ) { + $query .= $wpdb->prepare( + ' OR pm2.meta_value LIKE %s', + '%' . $wpdb->esc_like( $user_role ) . '%' + ); + } + } + if ( ! empty( $email ) ) { + $query .= $wpdb->prepare( + ' OR pm2.meta_value LIKE %s', + '%' . $wpdb->esc_like( $email ) . '%' + ); + } + $query .= '))'; + $auto_apply_coupon_ids = $wpdb->get_col( $query ); // phpcs:ignore + $auto_apply_coupon_ids = ( empty( $auto_apply_coupon_ids ) || ! is_array( $auto_apply_coupon_ids ) ) ? array() : $auto_apply_coupon_ids; + $auto_apply_coupon_ids = array_filter( array_map( 'absint', $auto_apply_coupon_ids ) ); + if ( ! empty( $auto_apply_coupon_ids ) && is_array( $auto_apply_coupon_ids ) ) { + $valid_coupon_counter = 0; + $max_auto_apply_coupons_limit = apply_filters( 'wc_sc_max_auto_apply_coupons_limit', get_option( 'wc_sc_max_auto_apply_coupons_limit', 5 ), array( 'source' => $this ) ); + $current_filter = current_filter(); + do_action( + 'wc_sc_before_auto_apply_coupons', + array( + 'source' => $this, + 'current_filter' => $current_filter, + ) + ); + foreach ( $auto_apply_coupon_ids as $apply_coupon_id ) { + // Process only five coupons. + if ( absint( $max_auto_apply_coupons_limit ) === $valid_coupon_counter ) { + break; + } + $coupon = new WC_Coupon( absint( $apply_coupon_id ) ); + if ( $this->is_wc_gte_30() ) { + $coupon_id = ( ! empty( $coupon ) && is_callable( array( $coupon, 'get_id' ) ) ) ? $coupon->get_id() : 0; + $coupon_code = ( ! empty( $coupon ) && is_callable( array( $coupon, 'get_code' ) ) ) ? $coupon->get_code() : ''; + } else { + $coupon_id = ( ! empty( $coupon->id ) ) ? $coupon->id : 0; + $coupon_code = ( ! empty( $coupon->code ) ) ? $coupon->code : ''; + } + + // If coupon has payment method restriction and already store wc_sc_auto_applied_coupons. + $payment_method_ids = $this->get_post_meta( $coupon_id, 'wc_sc_payment_method_ids', true ); + if ( ( is_array( $payment_method_ids ) && count( $payment_method_ids ) > 0 ) && $this->is_coupon_applied_by_auto_apply( $coupon_code ) ) { + $this->unset_auto_applied_coupon( $coupon_code ); + } + + // Check if it is a valid coupon object. + if ( $apply_coupon_id === $coupon_id && ! empty( $coupon_code ) && $this->is_coupon_valid_for_auto_apply( $coupon ) ) { + $cart_total = ( $this->is_wc_greater_than( '3.1.2' ) ) ? $cart->get_cart_contents_total() : $cart->cart_contents_total; + $is_auto_apply = apply_filters( + 'wc_sc_is_auto_apply', + ( $cart_total > 0 ), + array( + 'source' => $this, + 'cart_obj' => $cart, + 'coupon_obj' => $coupon, + 'cart_total' => $cart_total, + ) + ); + // Check if cart still requires a coupon discount and does not have coupon already applied. + if ( true === $is_auto_apply && ! $cart->has_discount( $coupon_code ) ) { + $cart->add_discount( $coupon_code ); + $cart->calculate_shipping(); + $cart->calculate_totals(); + $this->set_auto_applied_coupon( $coupon_code ); + } + $valid_coupon_counter++; + } // End if to check valid coupon. + } + } + } + } + + /** + * Function to apply coupons for cart and checkout block. + * + * @param bool $pre_render Is protected. + * @param array $parsed_block The meta key. + * @param array $parent_block The meta type. + * @return bool + */ + public function auto_apply_coupons_to_cart_checkout_block( $pre_render = null, $parsed_block = array(), $parent_block = null ) { + if ( isset( $parsed_block['blockName'] ) && in_array( $parsed_block['blockName'], array( 'woocommerce/cart', 'woocommerce/checkout' ), true ) ) { + $this->auto_apply_coupons(); + } + return $pre_render; + } + + /** + * Function to Automatically Apply Coupons on Cart Update. + * + * @param string $cart_item_key contains the id of the cart item. This may be empty if the cart item does not exist any more. + * @param int $quantity contains the quantity of the item. + * @param WC_Cart $cart Cart class. + */ + public function auto_apply_coupons_on_cart_update( $cart_item_key, $quantity, $cart ) { + if ( WC()->is_rest_api_request() ) { + $this->auto_apply_coupons(); + } + } + + /** + * Automatically apply coupons during the WooCommerce checkout order review update process. + * This function checks for changes in the shipping method and updates the chosen shipping method in the session. + * Then, it automatically applies any eligible coupons. + */ + public function wc_checkout_update_order_review_auto_apply_coupons() { + check_ajax_referer( 'update-order-review', 'security' ); + + // Get the posted shipping methods from the form data, if available. + $posted_shipping_methods = isset( $_POST['shipping_method'] ) ? wc_clean( wp_unslash( $_POST['shipping_method'] ) ) : array(); // phpcs:ignore + + if ( ! empty( $posted_shipping_methods ) ) { + // Retrieve the current chosen shipping methods from the session. + $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' ); + + if ( is_array( $posted_shipping_methods ) ) { + // Update the chosen shipping methods with the posted values. + foreach ( $posted_shipping_methods as $i => $value ) { + if ( ! is_string( $value ) ) { + continue; + } + $chosen_shipping_methods[ $i ] = $value; + } + } + + // Save the updated chosen shipping methods back to the session. + WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods ); + } + + // Automatically apply any eligible coupons. + $this->auto_apply_coupons(); + } + + /** + * Remove coupons that result in zero discount. + * + * This method loops through all applied coupons in the cart and checks if they are + * not present in the coupon discount totals. If a coupon is found to have a zero + * discount (i.e., it is not in the coupon discount totals), it is removed from the + * applied coupons list and the auto-applied coupon logic is handled. + * + * @param WC_Cart $cart The WooCommerce cart object. + */ + public function remove_coupon_if_zero( $cart ) { + // Get all applied coupons. + $applied_coupons = $cart->get_applied_coupons(); + + if ( ! empty( $applied_coupons ) ) { + foreach ( $applied_coupons as $coupon_code ) { + // Check if the coupon is not in the coupon discount totals (indicating a zero discount). + if ( ! array_key_exists( $coupon_code, $cart->get_coupon_discount_totals() ) ) { + // Remove the coupon from the applied coupons array. + $updated_coupons = array_diff( $applied_coupons, array( $coupon_code ) ); + $cart->set_applied_coupons( $updated_coupons ); + + // Unset the auto-applied coupon from session. + $this->unset_auto_applied_coupon( $coupon_code ); + } + } + } + } + + /** + * Automatically apply coupons to the cart when the shipping method is changed. + * This method checks if the request is an AJAX request to update the shipping method, + * and if so, it calls the auto_apply_coupons method to apply any eligible coupons. + */ + public function auto_apply_coupons_to_cart_on_shipping_change() { + if ( is_ajax() ) { + // Check if the request is an AJAX request to update the shipping method. + check_ajax_referer( 'update-shipping-method', 'security' ); + $this->auto_apply_coupons(); + } + } + + /** + * Handle auto apply related hooks + */ + public function handle_auto_apply_hooks() { + $is_allow_auto_apply = $this->sc_get_option( 'wc_sc_allow_auto_apply', 'yes' ); + if ( 'yes' === $is_allow_auto_apply ) { + // Action to auto apply coupons. + add_action( 'woocommerce_cart_is_empty', array( $this, 'auto_apply_coupons' ) ); + add_action( 'woocommerce_shortcode_before_product_cat_loop', array( $this, 'auto_apply_coupons' ) ); + add_action( 'woocommerce_before_shop_loop', array( $this, 'auto_apply_coupons' ) ); + add_action( 'woocommerce_before_single_product', array( $this, 'auto_apply_coupons' ) ); + add_action( 'woocommerce_before_cart', array( $this, 'auto_apply_coupons' ) ); + add_action( 'woocommerce_before_checkout_form', array( $this, 'auto_apply_coupons' ) ); + add_action( 'woocommerce_account_content', array( $this, 'auto_apply_coupons' ) ); + add_action( 'woocommerce_checkout_update_order_review', array( $this, 'wc_checkout_update_order_review_auto_apply_coupons' ) ); + add_action( 'woocommerce_cart_emptied', array( $this, 'reset_auto_applied_coupons_session' ) ); + add_action( 'woocommerce_removed_coupon', array( $this, 'blocks_removed_coupon' ), 20 ); + add_action( 'woocommerce_removed_coupon', array( $this, 'wc_sc_removed_coupon' ), 99 ); + + add_filter( 'pre_render_block', array( $this, 'auto_apply_coupons_to_cart_checkout_block' ), 10, 3 ); + + add_action( 'woocommerce_cart_item_set_quantity', array( $this, 'auto_apply_coupons_on_cart_update' ), 10, 4 ); + + add_action( 'woocommerce_before_cart_totals', array( $this, 'auto_apply_coupons_to_cart_on_shipping_change' ) ); + } + } + + /** + * Recheck coupon removed from auto-apply + * + * @param string $code The coupon code. + */ + public function blocks_removed_coupon( $code = '' ) { + if ( empty( $code ) ) { + return; + } + if ( function_exists( 'WC' ) && isset( WC()->cart ) && is_a( WC()->cart, 'WC_Cart' ) ) { + $coupon = new WC_Coupon( $code ); + $is_removable = $this->is_auto_apply_coupon_removable( $code ); + $is_auto_applied = $this->is_coupon_applied_by_auto_apply( $code ); + if ( true === $is_auto_applied && 'yes' !== $is_removable && $this->is_callable( WC()->cart, 'add_discount' ) ) { + WC()->cart->add_discount( $code ); + } + } + } + } + +} + +WC_SC_Auto_Apply_Coupon::get_instance(); diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-background-coupon-importer.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-background-coupon-importer.php new file mode 100644 index 00000000..e72d5c07 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-background-coupon-importer.php @@ -0,0 +1,1269 @@ +plugin_data = WC_Smart_Coupons::get_smart_coupons_plugin_data(); + + // Uses unique prefix per blog so each blog has separate queue. + $this->prefix = 'wp_' . get_current_blog_id(); + $this->identifier = 'wc_sc_coupon_importer'; + + add_action( 'admin_notices', array( $this, 'coupon_background_notice' ) ); + add_action( 'admin_footer', array( $this, 'styles_and_scripts' ) ); + add_action( 'wp_ajax_wc_sc_coupon_background_progress', array( $this, 'ajax_coupon_background_progress' ) ); + add_action( 'wp_ajax_wc_sc_stop_coupon_background_process', array( $this, 'ajax_stop_coupon_background_process' ) ); + add_action( 'wp_ajax_wc_sc_download_csv', array( $this, 'ajax_download_csv' ) ); + add_action( 'woo_sc_generate_coupon_csv', array( $this, 'woo_sc_generate_coupon_csv' ) ); + add_action( 'woo_sc_import_coupons_from_csv', array( $this, 'woo_sc_import_coupons_from_csv' ) ); + add_action( 'woocommerce_smart_coupons_send_combined_coupon_email', array( $this, 'send_scheduled_combined_email' ) ); + add_action( 'action_scheduler_failed_action', array( $this, 'restart_failed_action' ) ); + + add_filter( 'heartbeat_send', array( $this, 'check_coupon_background_progress' ), 10, 2 ); + add_filter( 'cron_schedules', array( $this, 'modify_action_scheduler_default_interval' ), 1000 ); // phpcs:ignore + + } + + /** + * Get single instance of WC_SC_Background_Coupon_Importer + * + * @return WC_SC_Background_Coupon_Importer Singleton object of WC_SC_Background_Coupon_Importer + */ + public static function get_instance() { + // Check if instance is already exists. + if ( is_null( self::$instance ) ) { + self::$instance = new self(); + } + + return self::$instance; + } + + /** + * Handle call to functions which is not available in this class + * + * @param string $function_name The function name. + * @param array $arguments Array of arguments passed while calling $function_name. + * @return result of function call + */ + public function __call( $function_name, $arguments = array() ) { + + global $woocommerce_smart_coupon; + + if ( ! is_callable( array( $woocommerce_smart_coupon, $function_name ) ) ) { + return; + } + + if ( ! empty( $arguments ) ) { + return call_user_func_array( array( $woocommerce_smart_coupon, $function_name ), $arguments ); + } else { + return call_user_func( array( $woocommerce_smart_coupon, $function_name ) ); + } + + } + + /** + * Get Identifier + * + * @return string The Identifier + */ + public function get_identifier() { + return $this->identifier; + } + + /** + * Memory exceeded + * + * Ensures the batch process never exceeds 90% + * of the maximum WordPress memory. + * + * @return bool + */ + protected function memory_exceeded() { + $memory_limit = $this->get_memory_limit() * 0.9; // 90% of max memory + $current_memory = memory_get_usage( true ); + + if ( $current_memory >= $memory_limit ) { + return true; + } + + return false; + } + + /** + * Get memory limit. + * + * @return int + */ + protected function get_memory_limit() { + if ( function_exists( 'ini_get' ) ) { + $memory_limit = ini_get( 'memory_limit' ); + } else { + // Sensible default. + $memory_limit = '128M'; + } + + if ( ! $memory_limit || -1 === intval( $memory_limit ) ) { + // Unlimited, set to 32GB. + $memory_limit = '32G'; + } + + return wp_convert_hr_to_bytes( $memory_limit ); + } + + /** + * Time exceeded. + * + * Ensures the batch never exceeds a sensible time limit. + * A timeout limit of 30s is common on shared hosting. + * + * @param string $start_time start timestamp. + * @return bool + */ + protected function time_exceeded( $start_time = '' ) { + + if ( ! empty( $start_time ) ) { + $this->start_time = $start_time; + } + + $finish = $this->start_time + apply_filters( $this->identifier . '_default_time_limit', 20 ); // 20 seconds + $return = false; + + if ( time() >= $finish ) { + $return = true; + } + + return apply_filters( $this->identifier . '_time_exceeded', $return ); + } + + /** + * Get list of scheduled actions of this plugin + * + * Note: wc_sc_send_scheduled_coupon_email is not included because it's not used in bulk generate/import process + * + * @return array + */ + public function get_scheduled_action_hooks() { + $hooks = array( + 'woo_sc_generate_coupon_csv', + 'woo_sc_import_coupons_from_csv', + 'woocommerce_smart_coupons_send_combined_coupon_email', + ); + return $hooks; + } + + /** + * Get scheduled actions by this plugin + * + * @return array + */ + public function get_scheduled_actions() { + + $found_actions = array(); + + if ( ! function_exists( 'as_get_scheduled_actions' ) ) { + return $found_actions; + } + + $hooks = $this->get_scheduled_action_hooks(); + + if ( ! empty( $hooks ) ) { + foreach ( $hooks as $hook ) { + $args = array( + 'hook' => $hook, + ); + $found = as_get_scheduled_actions( $args, ARRAY_A ); + if ( ! empty( $found ) ) { + $found_actions[ $hook ] = $found; + } + } + } + + return $found_actions; + + } + + /** + * Stop all scheduled actions by this plugin + */ + public function stop_scheduled_actions() { + if ( function_exists( 'as_unschedule_action' ) ) { + $hooks = $this->get_scheduled_action_hooks(); + if ( ! empty( $hooks ) ) { + foreach ( $hooks as $hook ) { + as_unschedule_action( $hook ); + } + } + } + $this->clean_scheduled_action_data(); + } + + /** + * Clean scheduled action data + */ + public function clean_scheduled_action_data() { + delete_option( 'woo_sc_generate_coupon_posted_data' ); + delete_option( 'start_time_woo_sc' ); + delete_option( 'current_time_woo_sc' ); + delete_option( 'all_tasks_count_woo_sc' ); + delete_option( 'remaining_tasks_count_woo_sc' ); + delete_option( 'skipped_tasks_count_woo_sc' ); + delete_option( 'bulk_coupon_action_woo_sc' ); + } + + /** + * Display notice if a background process is already running + */ + public function coupon_background_notice() { + global $pagenow, $post, $store_credit_label; + + if ( ! is_admin() ) { + return; + } + + $page = ( ! empty( $_GET['page'] ) ) ? wc_clean( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore + $tab = ( ! empty( $_GET['tab'] ) ? ( 'send-smart-coupons' === $_GET['tab'] ? 'send-smart-coupons' : 'import-smart-coupons' ) : 'generate_bulk_coupons' ); // phpcs:ignore + + if ( ( ! empty( $post->post_type ) && 'shop_coupon' !== $post->post_type ) || ! in_array( $tab, array( 'generate_bulk_coupons', 'import-smart-coupons', 'send-smart-coupons' ), true ) ) { + return; + } + + if ( ! wp_script_is( 'jquery' ) ) { + wp_enqueue_script( 'jquery' ); + } + if ( ! wp_script_is( 'heartbeat' ) ) { + wp_enqueue_script( 'heartbeat' ); + } + + $upload_dir = wp_get_upload_dir(); + $upload_path = $upload_dir['basedir'] . '/woocommerce_uploads'; + + if ( 'wc-smart-coupons' === $page && 'generate_bulk_coupons' === $tab && ! empty( $upload_dir['error'] ) ) { + if ( ! wp_script_is( 'jquery-tiptip', 'registered' ) ) { + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; + wp_register_script( 'jquery-tiptip', WC()->plugin_url() . '/assets/js/jquery-tiptip/jquery.tipTip' . $suffix . '.js', array( 'jquery' ), WC()->version, true ); + } + + if ( ! wp_script_is( 'jquery-tiptip' ) ) { + wp_enqueue_script( 'jquery-tiptip' ); + } + ?> +
          +

          +   + + ' . esc_html__( 'Important', 'woocommerce-smart-coupons' ) . '', '' . esc_html( $upload_path ) . '' ); ?> +

          +
          + + is_process_running() ) { + $bulk_action = get_option( 'bulk_coupon_action_woo_sc' ); + + switch ( $bulk_action ) { + + case 'import_email': + case 'import': + $bulk_text = __( 'imported', 'woocommerce-smart-coupons' ); + $bulk_process = __( 'import', 'woocommerce-smart-coupons' ); + break; + + case 'generate_email': + case 'send_store_credit': + $bulk_text = __( 'generated & sent', 'woocommerce-smart-coupons' ); + $bulk_process = __( 'generate', 'woocommerce-smart-coupons' ); + break; + case 'generate': + default: + $bulk_text = __( 'generated', 'woocommerce-smart-coupons' ); + $bulk_process = __( 'generate', 'woocommerce-smart-coupons' ); + break; + + } + $scheduled_actions = $this->get_scheduled_actions(); + ?> +
          + clean_scheduled_action_data(); + ?> +

          + ' . esc_html( $this->plugin_data['Name'] ) . ' ' . esc_html__( 'Error', 'woocommerce-smart-coupons' ) . '', esc_html( $bulk_process ) ); + ?> +

          + +

          + ' . esc_html__( 'Important', 'woocommerce-smart-coupons' ) . ': ' . sprintf( esc_html__( '%s are being', 'woocommerce-smart-coupons' ), esc_html( $coupon_text ) ); + echo ' ' . esc_html( $bulk_text ) . ' '; + echo esc_html__( 'in the background. You will be notified when it is completed.', 'woocommerce-smart-coupons' ) . ' '; + ?> + +

          +

          + +

          + +
          + + +
          +

          + :  + +

          + +

          + ' . esc_html__( 'here', 'woocommerce-smart-coupons' ) . '.'; + ?> +

          + +
          + + + calculate_coupon_background_progress(); + + if ( isset( $progress['percent_completion'] ) ) { + $response['percent_completion'] = $progress['percent_completion']; + if ( floatval( 100 ) === floatval( $progress['percent_completion'] ) ) { + $this->stop_scheduled_actions(); + } + } + + $coupon_posted_data = get_option( 'woo_sc_generate_coupon_posted_data', false ); + + if ( $coupon_posted_data ) { + + $coupon_action = $coupon_posted_data['smart_coupons_generate_action']; + $response['coupon_action'] = $coupon_action; + $action_stage = $coupon_posted_data['action_stage']; + $response['action_stage'] = $action_stage; + $action_data = get_option( 'woo_sc_action_data', false ); + $response['action_data'] = $action_data; + + } + + wp_send_json( $response ); + } + + /** + * Stop coupoon background process via AJAX + */ + public function ajax_stop_coupon_background_process() { + + check_ajax_referer( 'wc-sc-stop-coupon-background-process', 'security' ); + + $this->stop_scheduled_actions(); + + wp_send_json_success(); + } + + /** + * Get coupon background progress via ajax + */ + public function ajax_download_csv() { + + check_ajax_referer( 'wc_sc_download_csv', 'download_nonce' ); + + $woo_sc_action_data = get_option( 'woo_sc_action_data', false ); + + if ( $woo_sc_action_data ) { + WP_Filesystem(); + + global $wp_filesystem; + + $file_path = $woo_sc_action_data['data']['generated_file_path']; + $csv_file_path = ''; + $file_name = basename( $file_path ); + $dirname = dirname( $file_path ); + $mime_type = 'text/x-csv'; + $upload_dir = wp_get_upload_dir(); + $upload_dir_path = $upload_dir['basedir'] . '/woocommerce_uploads'; + + if ( class_exists( 'ZipArchive' ) ) { + $zip = new ZipArchive(); + $zip_name = $file_name . '.zip'; + $zip_path = $dirname . '/' . $zip_name; + $mime_type = 'application/zip'; + if ( $zip->open( $zip_path, ZIPARCHIVE::CREATE ) ) { + $zip->addFile( $file_path, $file_name ); + $zip->close(); + $file_name = $zip_name; + $csv_file_path = $file_path; + $file_path = $zip_path; + } else { + echo esc_html__( 'Failed to create export file.', 'woocommerce-smart-coupons' ); + exit(); + } + } + if ( file_exists( $file_path ) && is_readable( $file_path ) ) { + + nocache_headers(); + header( 'X-Robots-Tag: noindex, nofollow', true ); + header( 'Content-Type: ' . $mime_type . '; charset=UTF-8' ); + header( 'Content-Description: File Transfer' ); + header( 'Content-Transfer-Encoding: binary' ); + header( 'Content-Disposition: attachment; filename="' . sanitize_file_name( $file_name ) . '";' ); + readfile( $file_path ); // phpcs:ignore + if ( ! empty( $upload_dir_path ) && false !== strpos( $file_path, $upload_dir_path ) ) { + unlink( $file_path ); // phpcs:ignore + } + } else { + echo esc_html__( 'Failed to create export file.', 'woocommerce-smart-coupons' ); + exit(); + } + + if ( file_exists( $csv_file_path ) ) { + if ( ! empty( $upload_dir_path ) && false !== strpos( $csv_file_path, $upload_dir_path ) ) { + unlink( $csv_file_path ); // phpcs:ignore + } + } + + delete_option( 'woo_sc_action_data' ); + delete_option( 'skipped_tasks_count_woo_sc' ); + delete_option( 'wc_sc_background_coupon_process_result' ); + exit(); + + } + } + + /** + * Push coupon background progress in heartbeat response + * + * @param array $response The response. + * @param string $screen_id The screen id. + * @return array $response + */ + public function check_coupon_background_progress( $response = array(), $screen_id = '' ) { + + if ( 'yes' === $this->is_process_running() ) { + $progress = $this->calculate_coupon_background_progress(); + + if ( ! empty( $progress['percent_completion'] ) ) { + $response['percent_completion'] = $progress['percent_completion']; + } + + $coupon_posted_data = get_option( 'woo_sc_generate_coupon_posted_data', false ); + + if ( $coupon_posted_data ) { + + $coupon_action = $coupon_posted_data['smart_coupons_generate_action']; + $response['coupon_action'] = $coupon_action; + $action_stage = $coupon_posted_data['action_stage']; + $response['action_stage'] = $action_stage; + + } + + $action_data = get_option( 'woo_sc_action_data', false ); + + $response['action_data'] = $action_data; + } + + return $response; + } + + /** + * Checks if background process is running + * + * @return string $is_process_running + */ + public function is_process_running() { + + // Return process status if it has already been saved. + if ( ! empty( $this->is_process_running ) ) { + return $this->is_process_running; + } + + $bulk_action = get_option( 'bulk_coupon_action_woo_sc', false ); + $this->is_process_running = ( ! empty( $bulk_action ) ) ? 'yes' : 'no'; + + return $this->is_process_running; + } + + /** + * Function to send combined emails when receiver is the same. + * + * @param array $action_args Action arguments. + */ + public function send_scheduled_combined_email( $action_args = array() ) { + + $posted_data = get_option( 'woo_sc_generate_coupon_posted_data', true ); + + if ( true === $posted_data ) { + return; + } + + if ( empty( $action_args['receiver_email'] ) || empty( $action_args['coupon_ids'] ) || ! is_array( $action_args['coupon_ids'] ) ) { + return; + } + + $receiver_email = $action_args['receiver_email']; + $coupon_ids = $action_args['coupon_ids']; + $receiver_details = array(); + $message = ''; + + if ( ! empty( $posted_data ) && is_array( $posted_data ) ) { + $message = ( ! empty( $posted_data['smart_coupon_message'] ) ) ? $posted_data['smart_coupon_message'] : ''; + } + + foreach ( $coupon_ids as $coupon_id ) { + $coupon = new WC_Coupon( $coupon_id ); + if ( is_a( $coupon, 'WC_Coupon' ) ) { + if ( $this->is_wc_gte_30() ) { + $coupon_code = $coupon->get_code(); + } else { + $coupon_code = ( ! empty( $coupon->code ) ) ? $coupon->code : ''; + } + $receiver_details[] = array( + 'code' => $coupon_code, + 'message' => $message, + ); + } + } + + if ( ! empty( $receiver_details ) ) { + $this->send_combined_coupon_email( $receiver_email, $receiver_details ); + } + } + + /** + * Calculate progress of background coupon process + * + * @return array $progress + */ + public function calculate_coupon_background_progress() { + $progress = array(); + + $start_time = get_option( 'start_time_woo_sc', false ); + $current_time = get_option( 'current_time_woo_sc', false ); + $all_tasks_count = get_option( 'all_tasks_count_woo_sc', false ); + $remaining_tasks_count = get_option( 'remaining_tasks_count_woo_sc', false ); + + $percent_completion = floatval( 0 ); + if ( false !== $all_tasks_count && false !== $remaining_tasks_count ) { + $percent_completion = ( ( intval( $all_tasks_count ) - intval( $remaining_tasks_count ) ) * 100 ) / intval( $all_tasks_count ); + $progress['percent_completion'] = floatval( $percent_completion ); + } + + if ( $percent_completion > 0 && false !== $start_time && false !== $current_time ) { + $time_taken_in_seconds = $current_time - $start_time; + $time_remaining_in_seconds = ( $time_taken_in_seconds / $percent_completion ) * ( 100 - $percent_completion ); + $progress['remaining_seconds'] = ceil( $time_remaining_in_seconds ); + } + + return $progress; + } + + /** + * Generate Coupons' CSV from saved coupon's data + */ + public function woo_sc_generate_coupon_csv() { + + $posted_data = get_option( 'woo_sc_generate_coupon_posted_data', true ); + + if ( true === $posted_data ) { + return; + } + + $no_of_coupons_to_generate = absint( $posted_data['no_of_coupons_to_generate'] ); + + $woocommerce_smart_coupon = WC_Smart_Coupons::get_instance(); + + $coupon_column_headers = $this->get_coupon_column_headers(); + $coupon_posts_headers = $coupon_column_headers['posts_headers']; + $coupon_postmeta_headers = $coupon_column_headers['postmeta_headers']; + $coupon_term_headers = $coupon_column_headers['term_headers']; + + $column_headers = array_merge( $coupon_posts_headers, $coupon_postmeta_headers, $coupon_term_headers ); + + $batch_start_time = time(); + $start_time = get_option( 'start_time_woo_sc', false ); + if ( false === $start_time ) { + update_option( 'start_time_woo_sc', $batch_start_time, 'no' ); + } + + $all_tasks_count = get_option( 'all_tasks_count_woo_sc', false ); + + if ( false === $all_tasks_count ) { + update_option( 'all_tasks_count_woo_sc', $posted_data['total_coupons_to_generate'], 'no' ); + } + + if ( isset( $posted_data['export_file'] ) && is_array( $posted_data['export_file'] ) ) { + $export_file = $posted_data['export_file']; + $csv_folder = $export_file['wp_upload_dir']; + $filename = str_replace( array( '\'', '"', ',', ';', '<', '>', '/', ':' ), '', $export_file['file_name'] ); + $csvfilename = $csv_folder . $filename; + $csv_file_handler = fopen( $csvfilename, 'a' ); // phpcs:ignore + $smart_coupon_email = array(); + $customer_emails = $posted_data['customer_email'] = empty( $posted_data['customer_email'] ) ? $posted_data['smart_coupon_email'] : $posted_data['customer_email'];// phpcs:ignore + if ( ! empty( $customer_emails ) ) { + $smart_coupon_email = explode( ',', $customer_emails ); + } + // Proceed only if file has opened in append mode. + if ( false !== $csv_file_handler ) { + for ( $no_of_coupons_created = 1; $no_of_coupons_created <= $no_of_coupons_to_generate; $no_of_coupons_created++ ) { + $posted_data['no_of_coupons_to_generate'] = 1; + $coupon_data = $woocommerce_smart_coupon->generate_coupons_code( $posted_data, '', '' ); + + $file_data = $woocommerce_smart_coupon->get_coupon_csv_data( $column_headers, $coupon_data ); // phpcs:ignore + if ( $file_data ) { + + fwrite( $csv_file_handler, $file_data ); // phpcs:ignore + $no_of_remaining_coupons = $no_of_coupons_to_generate - $no_of_coupons_created; + + update_option( 'current_time_woo_sc', time(), 'no' ); + update_option( 'remaining_tasks_count_woo_sc', $no_of_remaining_coupons, 'no' ); + + if ( ! empty( $posted_data['customer_email'] ) && count( $smart_coupon_email ) > 1 ) { + $posted_data['customer_email'] = ''; + if ( ! empty( $customer_emails ) ) { + $sc_emails = explode( ',', $customer_emails ); + array_shift( $sc_emails ); // Remove first email so that it does not included in next run. + $customer_emails = $posted_data['customer_email'] = ! empty( $sc_emails ) ? implode( ',', $sc_emails ) : '';// phpcs:ignore + } + } + + // If csv generation is complete. + if ( 0 === $no_of_remaining_coupons ) { + // If user opted for add_to_store option then create another scheduler to generate actual coupons. + if ( in_array( $posted_data['smart_coupons_generate_action'], array( 'add_to_store', 'woo_sc_is_email_imported_coupons', 'send_store_credit' ), true ) ) { + + delete_option( 'start_time_woo_sc' ); + delete_option( 'current_time_woo_sc' ); + + $posted_data['no_of_coupons_to_generate'] = $posted_data['total_coupons_to_generate']; + $posted_data['action_stage'] = 1; + update_option( 'woo_sc_generate_coupon_posted_data', $posted_data, 'no' ); + + do_action( 'woo_sc_import_coupons_from_csv' ); + } else { + + $bulk_coupon_action = get_option( 'bulk_coupon_action_woo_sc' ); + $all_tasks_count = get_option( 'all_tasks_count_woo_sc' ); + $remaining_tasks_count = get_option( 'remaining_tasks_count_woo_sc' ); + $skipped_tasks_count = get_option( 'skipped_tasks_count_woo_sc' ); + $success_count = $all_tasks_count - $remaining_tasks_count; + + $coupon_background_process_result = array( + 'action' => $bulk_coupon_action, + 'successful' => $success_count - $skipped_tasks_count, + 'skipped' => $skipped_tasks_count, + ); + + delete_option( 'bulk_coupon_action_woo_sc' ); + update_option( 'wc_sc_background_coupon_process_result', $coupon_background_process_result, 'no' ); + + $action_data = array( + 'name' => 'download_csv', + 'data' => array( + 'generated_file_path' => $csvfilename, + ), + ); + update_option( 'woo_sc_action_data', $action_data, 'no' ); + } + } elseif ( $this->time_exceeded( $batch_start_time ) || $this->memory_exceeded() ) { + $posted_data['no_of_coupons_to_generate'] = $no_of_remaining_coupons; + update_option( 'woo_sc_generate_coupon_posted_data', $posted_data, 'no' ); + if ( function_exists( 'as_schedule_single_action' ) ) { + as_schedule_single_action( time(), 'woo_sc_generate_coupon_csv' ); + } + break; + } + } + } + fclose( $csv_file_handler ); // phpcs:ignore + } + } + + } + + /** + * Generate Coupons from generated/imported csv file + */ + public function woo_sc_import_coupons_from_csv() { + + $posted_data = get_option( 'woo_sc_generate_coupon_posted_data', true ); + + if ( true === $posted_data ) { + return; + } + + $is_send_email = $this->is_email_template_enabled(); + $combine_emails = $this->is_email_template_enabled( 'combine' ); + $is_email_imported_coupons = get_option( 'woo_sc_is_email_imported_coupons' ); + $no_of_coupons_to_generate = $posted_data['no_of_coupons_to_generate']; + + require 'class-wc-sc-coupon-import.php'; + require 'class-wc-sc-coupon-parser.php'; + + $wc_csv_coupon_import = new WC_SC_Coupon_Import(); + $wc_csv_coupon_import->parser = new WC_SC_Coupon_Parser( 'shop_coupon' ); + $woocommerce_smart_coupon = WC_Smart_Coupons::get_instance(); + + $upload_dir = wp_get_upload_dir(); + $upload_dir_path = $upload_dir['basedir'] . '/woocommerce_uploads'; + + if ( isset( $posted_data['export_file'] ) && is_array( $posted_data['export_file'] ) ) { + + $export_file = $posted_data['export_file']; + $csv_folder = $export_file['wp_upload_dir']; + $filename = str_replace( array( '\'', '"', ',', ';', '<', '>', '/', ':' ), '', $export_file['file_name'] ); + $csvfilename = $csv_folder . $filename; + $file_position = isset( $posted_data['file_position'] ) && is_numeric( $posted_data['file_position'] ) ? $posted_data['file_position'] : 0; + + // Set locale. + $encoding = $this->mb_detect_encoding( $csvfilename, 'UTF-8, ISO-8859-1', true ); + if ( $encoding ) { + setlocale( LC_ALL, 'en_US.' . $encoding ); + } + if ( ! $this->is_php_gte( '8.0.0' ) ) { + ini_set( 'auto_detect_line_endings', true ); // phpcs:ignore + } + $csv_file_handler = fopen( $csvfilename, 'r' ); // phpcs:ignore + if ( false !== $csv_file_handler ) { + $csv_header = fgetcsv( $csv_file_handler, 0 ); + $counter = 0; + + $batch_start_time = time(); + $start_time = get_option( 'start_time_woo_sc', false ); + if ( false === $start_time ) { + update_option( 'start_time_woo_sc', $batch_start_time, 'no' ); + } + + $reading_completed = false; + $no_of_remaining_coupons = -1; + $combined_receiver_details = array(); + for ( $no_of_coupons_created = 1; $no_of_coupons_created <= $no_of_coupons_to_generate; $no_of_coupons_created++ ) { + + $result = $wc_csv_coupon_import->parser->parse_data_by_row( $csv_file_handler, $csv_header, $file_position, $encoding ); + $file_position = $result['file_position']; + $parsed_csv_data = $result['parsed_csv_data']; + $reading_completed = $result['reading_completed']; + if ( ! $reading_completed ) { + $coupon = $wc_csv_coupon_import->parser->parse_coupon( $parsed_csv_data ); + $coupon_parsed_data = array( + 'filter' => array( + 'class' => 'WC_SC_Coupon_Import', + 'function' => 'process_coupon', + ), + 'args' => array( $coupon ), + ); + + $coupon_id = $this->create_coupon( $coupon_parsed_data ); + + if ( ! empty( $parsed_csv_data['customer_email'] ) && 'yes' === $is_send_email && 'yes' === $combine_emails && 'yes' === $is_email_imported_coupons ) { + $receiver_emails = explode( ',', $parsed_csv_data['customer_email'] ); + foreach ( $receiver_emails as $receiver_email ) { + if ( ! isset( $combined_receiver_details[ $receiver_email ] ) || ! is_array( $combined_receiver_details[ $receiver_email ] ) ) { + $combined_receiver_details[ $receiver_email ] = array(); + } + $combined_receiver_details[ $receiver_email ][] = array( + 'code' => $parsed_csv_data['post_title'], + ); + } + } + $counter++; + } + + $no_of_remaining_coupons = $no_of_coupons_to_generate - $no_of_coupons_created; + update_option( 'current_time_woo_sc', time(), 'no' ); + update_option( 'remaining_tasks_count_woo_sc', $no_of_remaining_coupons, 'no' ); + + if ( 0 === $no_of_remaining_coupons ) { + + $bulk_coupon_action = get_option( 'bulk_coupon_action_woo_sc' ); + $all_tasks_count = get_option( 'all_tasks_count_woo_sc' ); + $remaining_tasks_count = get_option( 'remaining_tasks_count_woo_sc' ); + $skipped_tasks_count = get_option( 'skipped_tasks_count_woo_sc' ); + $success_count = $all_tasks_count - $remaining_tasks_count; + + $coupon_background_process_result = array( + 'action' => $bulk_coupon_action, + 'successful' => $success_count - $skipped_tasks_count, + 'skipped' => $skipped_tasks_count, + ); + + fclose( $csv_file_handler ); // phpcs:ignore + if ( ! empty( $upload_dir_path ) && false !== strpos( $csvfilename, $upload_dir_path ) ) { + unlink( $csvfilename ); // phpcs:ignore + } + update_option( 'woo_sc_is_email_imported_coupons', 'no', 'no' ); + delete_option( 'bulk_coupon_action_woo_sc' ); + + update_option( 'wc_sc_background_coupon_process_result', $coupon_background_process_result, 'no' ); + break; + } + $posted_data['no_of_coupons_to_generate'] = $no_of_remaining_coupons; + if ( $this->time_exceeded( $batch_start_time ) || $this->memory_exceeded() ) { + fclose( $csv_file_handler ); // phpcs:ignore + $posted_data['file_position'] = $file_position; + update_option( 'woo_sc_generate_coupon_posted_data', $posted_data, 'no' ); + if ( function_exists( 'as_schedule_single_action' ) ) { + as_schedule_single_action( time(), 'woo_sc_import_coupons_from_csv' ); + } + break; + } + } + if ( ! empty( $combined_receiver_details ) && is_array( $combined_receiver_details ) ) { + + foreach ( $combined_receiver_details as $receiver_email => $coupon_codes ) { + $coupon_ids = array(); + foreach ( $coupon_codes as $coupon_data ) { + $coupon_code = $coupon_data['code']; + $coupon = new WC_Coupon( $coupon_code ); + if ( is_a( $coupon, 'WC_Coupon' ) ) { + if ( $this->is_wc_gte_30() ) { + $coupon_id = $coupon->get_id(); + } else { + $coupon_id = ( ! empty( $coupon->id ) ) ? $coupon->id : 0; + } + $coupon_ids[] = $coupon_id; + } + } + if ( ! empty( $receiver_email ) && ! empty( $coupon_ids ) ) { + $action_args = array( + 'args' => array( + 'receiver_email' => $receiver_email, + 'coupon_ids' => $coupon_ids, + ), + ); + if ( function_exists( 'as_schedule_single_action' ) ) { + as_schedule_single_action( time(), 'woocommerce_smart_coupons_send_combined_coupon_email', $action_args ); + } + } + } + } + } + } + } + + /** + * Create coupon from parsed coupon data + * + * @param array $parsed_data parsed coupon data. + */ + public function create_coupon( $parsed_data ) { + + $coupon_id = 0; + if ( isset( $parsed_data['filter'], $parsed_data['args'] ) ) { + try { + if ( empty( $this->global_coupons_new ) && ! is_array( $this->global_coupons_new ) ) { + $this->global_coupons_new = array(); + } + if ( ! class_exists( $parsed_data['filter']['class'] ) ) { + include_once 'class-' . strtolower( str_replace( '_', '-', $parsed_data['filter']['class'] ) ) . '.php'; + } + $object = $parsed_data['filter']['class']::get_instance(); + $coupon_id = call_user_func_array( array( $object, $parsed_data['filter']['function'] ), $parsed_data['args'] ); + } catch ( Exception $e ) { + if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { + error_log( 'Error: ' . $e->getMessage() . ' ' . __FILE__ . ' ' . __LINE__ ); // phpcs:ignore + } + } + } + return $coupon_id; + } + + /** + * Restart scheduler after one minute if it fails + * + * @param array $action_id id of failed action. + */ + public function restart_failed_action( $action_id = 0 ) { + + if ( empty( $action_id ) || ! class_exists( 'ActionScheduler' ) || ! is_callable( array( 'ActionScheduler', 'store' ) ) || ! function_exists( 'as_schedule_single_action' ) ) { + return; + } + + $action = ActionScheduler::store()->fetch_action( $action_id ); + $action_hook = $action->get_hook(); + + $hooks = $this->get_scheduled_action_hooks(); + if ( in_array( $action_hook, $hooks, true ) ) { + $posted_data = get_option( 'woo_sc_generate_coupon_posted_data', true ); + if ( true === $posted_data ) { + return; + } + } + + if ( in_array( $action_hook, array( 'woo_sc_generate_coupon_csv', 'woo_sc_import_coupons_from_csv' ), true ) ) { + as_schedule_single_action( time() + MINUTE_IN_SECONDS, $action_hook ); + } elseif ( in_array( $action_hook, array( 'wc_sc_send_scheduled_coupon_email', 'woocommerce_smart_coupons_send_combined_coupon_email' ), true ) ) { + $action_args = $action->get_args(); + as_schedule_single_action( time() + MINUTE_IN_SECONDS, $action_hook, $action_args ); + } + } + + /** + * Function to modify action scheduler's default interval between two consecutive scheduler when smart coupon process running + * + * @param array $schedules schedules with interval and display. + * @return array $schedules + */ + public function modify_action_scheduler_default_interval( $schedules = array() ) { + + if ( 'yes' === $this->is_process_running() ) { + + $schedules['every_minute'] = array( + 'interval' => 5, + 'display' => __( 'Every 5 Seconds', 'woocommerce-smart-coupons' ), + ); + } + + return $schedules; + + } + + } + +} + +WC_SC_Background_Coupon_Importer::get_instance(); diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-background-upgrade.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-background-upgrade.php new file mode 100644 index 00000000..ed69f174 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-background-upgrade.php @@ -0,0 +1,433 @@ +action = 'wc_db_upgrade'; + add_action( 'plugins_loaded', array( $this, 'init' ) ); + add_action( 'init', array( $this, 'process_handler' ) ); + add_action( 'init', array( $this, 'clear_all_process' ) ); + add_action( 'action_scheduler_failed_action', array( $this, 'restart_failed_action' ) ); + } + + /** + * Init + */ + public function init() { + global $woocommerce_smart_coupon; + // Get list of db updates. + $updates = $this->get_updates(); + if ( ! empty( $updates ) ) { + foreach ( $updates as $update ) { + // Break if version is empty. + if ( empty( $update['version'] ) ) { + break; + } + + $version = $update['version']; + $update_status = $this->get_status( $version ); + if ( version_compare( $woocommerce_smart_coupon->get_smart_coupons_version(), $version, '>=' ) && ( false === $update_status ) ) { + // Set db update status to pending. + $this->set_status( $version, 'pending' ); + } + $handler = isset( $update['cron_handler'] ) ? $update['cron_handler'] : ''; + $this->register_scheduler( $handler ); + } + } + } + + /** + * Process handler + */ + public function process_handler() { + if ( ! isset( $_GET['wc_sc_update'] ) || ! isset( $_GET['wc_sc_db_update_nonce'] ) ) { + return; + } + + if ( ! wp_verify_nonce( wc_clean( wp_unslash( $_GET['wc_sc_db_update_nonce'] ) ), 'wc_sc_db_process' ) ) { // phpcs:ignore + return; + } + + $this->handle_all( wc_clean( wp_unslash( $_GET['wc_sc_update'] ) ) ); // phpcs:ignore + } + + /** + * Get list of db updates. + */ + public function get_updates() { + return array( + array( + 'version' => '4.28.0', // Minimum plugin version to do the action. + 'get_row_handler' => array( __CLASS__, 'get_applied_coupon_profile_options' ), // get data. + 'cron_handler' => 'wcsc_move_applied_coupon_options_to_transient', // define cron handler which should be in this class. + ), + ); + } + + /** + * Register action schedulers for db update. + * + * @param string $handler Handler name. + */ + public function register_scheduler( $handler = '' ) { + if ( ! empty( $handler ) && is_callable( array( $this, $handler ) ) ) { + add_action( $handler, array( $this, $handler ) ); + } + } + + /** + * Handle all updates. + * + * @param string $current_version Plugin version. + */ + protected function handle_all( $current_version = '0' ) { + if ( empty( $current_version ) ) { + return; + } + do_action( 'wc_sc_start_background_update', $current_version ); + $updates = $this->get_updates(); + if ( is_array( $updates ) && ! empty( $updates ) ) { + foreach ( $updates as $update ) { + // Compare version for db updates. + if ( ! empty( $update['version'] ) && version_compare( $current_version, $update['version'], '>=' ) ) { + $cron_handler = isset( $update['cron_handler'] ) ? $update['cron_handler'] : ''; + if ( ! empty( $cron_handler ) && is_callable( array( $this, $cron_handler ) ) ) { + $row_handler = isset( $update['get_row_handler'] ) ? $update['get_row_handler'] : ''; + $this->process( $update['version'], $cron_handler, $row_handler ); + } + } + } + } + } + + /** + * Handle the process. + * + * @param string $version Version number. + * @param string $cron_handler Cron handler action name. + * @param string $row_handler Fetch data handler name. + */ + private function process( $version = '', $cron_handler = '', $row_handler = '' ) { + $rows = ! empty( $row_handler ) && is_callable( $row_handler ) ? call_user_func( $row_handler ) : ''; + if ( ! empty( $rows ) && is_array( $rows ) ) { + // Start the process if the status is pending. + if ( 'pending' === $this->get_status( $version ) ) { + if ( function_exists( 'as_enqueue_async_action' ) ) { + $this->set_status( $version, 'processing' ); + as_enqueue_async_action( $cron_handler ); + } + } + } else { + // Set status to `completed` if the data is empty. + $this->set_status( $version, 'completed' ); + } + } + + /** + * Clear all update process. + */ + public function clear_all_process() { + $updates = $this->get_updates(); + foreach ( $updates as $update ) { + $version = isset( $update['version'] ) ? $update['version'] : ''; + $row_handler = isset( $update['get_row_handler'] ) ? $update['get_row_handler'] : ''; + $status = $this->get_status( $version ); + if ( false === $status || 'done' === $status ) { + return; + } + $rows = ! empty( $row_handler ) && is_callable( $row_handler ) ? call_user_func( $row_handler ) : ''; + if ( 'processing' === $status && empty( $rows ) ) { + do_action( 'wc_sc_background_update_completed', $version ); + $this->set_status( $version, 'completed' ); + } + } + } + + /** + * Callback Method for move options to transient. + * + * @return void + */ + public function wcsc_move_applied_coupon_options_to_transient() { + $options = $this->get_applied_coupon_profile_options(); + // Check if coupons are not empty. + if ( ! empty( $options ) && is_array( $options ) ) { + + $start_time = time(); + $loop = 1; + foreach ( $options as $option ) { + // disable auto apply. + $this->move_option_to_transient( $option ); + + if ( $this->loop_exceeded( $loop ) || $this->time_exceeded( $start_time ) || $this->memory_exceeded() ) { + // Update auto apply coupon id list. + if ( function_exists( 'as_enqueue_async_action' ) ) { + as_enqueue_async_action( __FUNCTION__ ); + } + break; + } + $loop++; + } + } + } + + /** + * Restart scheduler after one minute if it fails + * + * @param array $action_id id of failed action. + */ + public function restart_failed_action( $action_id = 0 ) { + + if ( empty( $action_id ) || ! class_exists( 'ActionScheduler' ) || ! is_callable( array( 'ActionScheduler', 'store' ) ) || ! function_exists( 'as_enqueue_async_action' ) ) { + return; + } + + $action = ActionScheduler::store()->fetch_action( $action_id ); + $action_hook = $action->get_hook(); + + $updates = $this->get_updates(); + if ( ! empty( $updates ) ) { + foreach ( $updates as $update ) { + if ( ! empty( $update['version'] ) && ! empty( $update['cron_handler'] ) ) { + if ( $action_hook === $update['cron_handler'] ) { + $this->set_status( $update['version'], 'processing' ); + as_enqueue_async_action( $update['cron_handler'] ); + } + } + } + } + } + + /** + * Method to update the status of db upgrade. + * + * @param string $version wcsc db version. + * @param string $status status. + * + * @return bool. + */ + public function set_status( $version = '', $status = '' ) { + if ( ! empty( $version ) && ! empty( $status ) ) { + $db_status = get_option( 'sc_wc_db_update_status', array() ); + $db_status[ $version ] = $status; + return update_option( 'sc_wc_db_update_status', $db_status, 'no' ); + } + return false; + } + + /** + * Method to get the status of db upgrade. + * + * @param string $version wcsc db version. + * + * @return bool. + */ + public function get_status( $version = '' ) { + if ( ! empty( $version ) ) { + $db_status = get_option( 'sc_wc_db_update_status', array() ); + return ( ! empty( $db_status ) && isset( $db_status[ $version ] ) ) ? $db_status[ $version ] : false; + } + return false; + } + + /** + * Loop exceeded + * + * Ensures the batch process never exceeds to handle the given limit of row. + * + * @param int $loop Number of loop done. + * @return bool + */ + public function loop_exceeded( $loop = 0 ) { + return $loop > apply_filters( $this->action . '_default_row_limit', $this->row_limit ); + } + + /** + * Memory exceeded + * + * Ensures the batch process never exceeds 90% + * of the maximum WordPress memory. + * + * @return bool + */ + protected function memory_exceeded() { + $memory_limit = $this->get_memory_limit() * 0.9; // 90% of max memory + $current_memory = memory_get_usage( true ); + + if ( $current_memory >= $memory_limit ) { + return true; + } + + return false; + } + + /** + * Get memory limit. + * + * @return int + */ + protected function get_memory_limit() { + if ( function_exists( 'ini_get' ) ) { + $memory_limit = ini_get( 'memory_limit' ); + } else { + // Sensible default. + $memory_limit = '128M'; + } + + if ( ! $memory_limit || -1 === intval( $memory_limit ) ) { + // Unlimited, set to 32GB. + $memory_limit = '32G'; + } + + return wp_convert_hr_to_bytes( $memory_limit ); + } + + /** + * Time exceeded. + * + * Ensures the batch never exceeds a sensible time limit. + * A timeout limit of 30s is common on shared hosting. + * + * @param string $start_time start timestamp. + * @return bool + */ + protected function time_exceeded( $start_time = '' ) { + + $finish = $start_time + apply_filters( $this->action . '_default_time_limit', 20 ); // 20 seconds + $return = false; + + if ( time() >= $finish ) { + $return = true; + } + + return apply_filters( $this->action . '_time_exceeded', $return ); + } + + /** + * Get `applied_coupon_profile` options names and values + * + * @return array + */ + public function get_applied_coupon_profile_options() { + global $wpdb; + $option_name = 'sc_applied_coupon_profile_%'; + $options = $wpdb->get_results( // @codingStandardsIgnoreLine + $wpdb->prepare( + "SELECT option_name, option_value + FROM $wpdb->options + WHERE option_name LIKE %s", + $option_name + ), + ARRAY_A + ); + return $options; + } + + /** + * Method to transfer single options to transient. + * + * @param array $option Array of option name and value. + * @return void + */ + protected function move_option_to_transient( $option = array() ) { + if ( isset( $option['option_name'] ) && isset( $option['option_value'] ) ) { + + // Add new transient with option name. + $move = set_transient( + $option['option_name'], + maybe_unserialize( $option['option_value'] ), + apply_filters( 'wc_sc_applied_coupon_by_url_expire_time', MONTH_IN_SECONDS ) + ); + + if ( true === $move ) { + // Delete the option if option is successfully moved. + delete_option( $option['option_name'] ); + } + } + } + + } // End class +} // End class exists check + +WC_SC_Background_Upgrade::get_instance(); diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupon-actions.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupon-actions.php new file mode 100644 index 00000000..a28b8c99 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupon-actions.php @@ -0,0 +1,865 @@ + 'shop_coupon', + 'title' => $coupon_code, + 'post_status' => 'publish', + 'numberposts' => 1, + ) + ); + $coupon = current( $coupons ); + $coupon_id = ( ! empty( $coupon->ID ) ) ? $coupon->ID : 0; + $coupon = new WC_Coupon( $coupon_id ); + + if ( ! is_wp_error( $coupon ) ) { + + if ( $this->is_wc_gte_30() ) { + $actions = $coupon->get_meta( 'wc_sc_add_product_details' ); + } else { + $coupon_id = ( ! empty( $coupon->id ) ) ? $coupon->id : 0; + $actions = get_post_meta( $coupon_id, 'wc_sc_add_product_details', true ); + } + + return apply_filters( 'wc_sc_coupon_actions', $actions, array( 'coupon_code' => $coupon_code ) ); + + } + + return array(); + + } + + /** + * Modify cart item data + * + * @param array $cart_item_data The cart item data. + * @param integer $product_id The product id. + * @param integer $variation_id The variation id. + * @param integer $quantity The quantity of product. + * @return array $cart_item_data + */ + public function modify_cart_item_data( $cart_item_data = array(), $product_id = 0, $variation_id = 0, $quantity = 0 ) { + + if ( empty( $cart_item_data ) || empty( $product_id ) || empty( $quantity ) ) { + return $cart_item_data; + } + + if ( ! empty( $cart_item_data['wc_sc_product_source'] ) ) { + $coupon_code = $cart_item_data['wc_sc_product_source']; + $coupon_actions = $this->get_coupon_actions( $coupon_code ); + if ( ! empty( $coupon_actions ) && ! is_scalar( $coupon_actions ) ) { + foreach ( $coupon_actions as $product_data ) { + if ( ! empty( $product_data['product_id'] ) && in_array( absint( $product_data['product_id'] ), array_map( 'absint', array( $product_id, $variation_id ) ), true ) ) { + $discount_amount = ( '' !== $product_data['discount_amount'] ) ? $product_data['discount_amount'] : ''; + if ( '' !== $discount_amount ) { + if ( ! empty( $variation_id ) ) { + $product = wc_get_product( $variation_id ); + } else { + $product = wc_get_product( $product_id ); + } + $product_price = $product->get_price(); + $regular_price = $product->get_regular_price(); + $discount_type = ( ! empty( $product_data['discount_type'] ) ) ? $product_data['discount_type'] : 'percent'; + switch ( $discount_type ) { + case 'flat': + $discount = $this->convert_price( $discount_amount ); + break; + + case 'percent': + $discount = ( $product_price * $discount_amount ) / 100; + break; + } + $discount = wc_cart_round_discount( min( $product_price, $discount ), 2 ); + $discounted_price = $product_price - $discount; + $cart_item_data['data']->set_price( $discounted_price ); + $cart_item_data['data']->set_regular_price( $regular_price ); + $cart_item_data['data']->set_sale_price( $discounted_price ); + } + break; + } + } + } + } + + return $cart_item_data; + } + + /** + * Modify cart item in WC_Cart::add_to_cart() + * + * @param array $cart_item_data The cart item data as passed by filter 'woocommerce_add_cart_item'. + * @param string $cart_item_key The cart item key. + * @return array $cart_item_data + */ + public function modify_cart_item_data_in_add_to_cart( $cart_item_data = array(), $cart_item_key = '' ) { + if ( ! empty( $cart_item_data['wc_sc_product_source'] ) ) { + $cart_item_data = $this->modify_cart_item_data( $cart_item_data, $cart_item_data['product_id'], $cart_item_data['variation_id'], $cart_item_data['quantity'] ); + } + + return $cart_item_data; + } + + /** + * Modify cart item in session + * + * @param array $session_data The session data. + * @param array $values The cart item. + * @param string $key The cart item key. + * @return array $session_data + */ + public function modify_cart_item_in_session( $session_data = array(), $values = array(), $key = '' ) { + + if ( ! empty( $values['wc_sc_product_source'] ) ) { + $session_data['wc_sc_product_source'] = $values['wc_sc_product_source']; + $qty = ( ! empty( $session_data['quantity'] ) ) ? absint( $session_data['quantity'] ) : ( ( ! empty( $values['quantity'] ) ) ? absint( $values['quantity'] ) : 1 ); + $session_data = $this->modify_cart_item_data( $session_data, $session_data['product_id'], $session_data['variation_id'], $qty ); + } + + return $session_data; + } + + /** + * Modify cart item quantity + * + * @param string $product_quantity The product quantity. + * @param string $cart_item_key The cart item key. + * @param array $cart_item The cart item. + * @return string $product_quantity + */ + public function modify_cart_item_quantity( $product_quantity = '', $cart_item_key = '', $cart_item = array() ) { + + if ( ! empty( $cart_item['wc_sc_product_source'] ) ) { + $product_quantity = sprintf( '%s ', $cart_item['quantity'], $cart_item_key, $cart_item['quantity'] ); + } + + return $product_quantity; + } + + /** + * Modify cart item price + * + * @param string $product_price The product price. + * @param array $cart_item The cart item. + * @param string $cart_item_key The cart item key. + * @return string $product_price + */ + public function modify_cart_item_price( $product_price = '', $cart_item = array(), $cart_item_key = '' ) { + + if ( ( is_array( $cart_item ) && isset( $cart_item['wc_sc_product_source'] ) ) || ( is_object( $cart_item ) && is_callable( array( $cart_item, 'get_meta' ) ) && $cart_item->get_meta( '_wc_sc_product_source' ) ) ) { + if ( wc_price( 0 ) === $product_price ) { + $product_price = apply_filters( + 'wc_sc_price_zero_text', + $product_price, + array( + 'cart_item' => $cart_item, + 'cart_item_key' => $cart_item_key, + ) + ); + } + } + + return $product_price; + } + + /** + * Remove products added by the coupon from validation + * + * Since the filter 'woocommerce_coupon_get_items_to_validate' is added in WooCommerce 3.4.0, this function will work only in WC 3.4.0+ + * Otherwise, the products added by coupon might get double discounts applied + * + * @param array $items The cart/order items. + * @param WC_Discounts $discounts The discounts object. + * @return mixed $items + */ + public function remove_products_from_validation( $items = array(), $discounts = null ) { + + if ( ! empty( $items ) && ! is_scalar( $items ) ) { + foreach ( $items as $index => $item ) { + $coupon_code = ''; + if ( is_array( $item->object ) && isset( $item->object['wc_sc_product_source'] ) ) { + $coupon_code = $item->object['wc_sc_product_source']; + } elseif ( is_a( $item->object, 'WC_Order_Item' ) && is_callable( array( $item->object, 'get_meta' ) ) && $item->object->get_meta( '_wc_sc_product_source' ) ) { + $coupon_code = $item->object->get_meta( '_wc_sc_product_source' ); + } + if ( ! empty( $coupon_code ) ) { + $item_product_id = ( is_a( $item->product, 'WC_Product' ) && is_callable( array( $item->product, 'get_id' ) ) ) ? $item->product->get_id() : 0; + $coupon_actions = $this->get_coupon_actions( $coupon_code ); + if ( ! empty( $coupon_actions ) && ! is_scalar( $coupon_actions ) ) { + foreach ( $coupon_actions as $product_data ) { + if ( ! empty( $product_data['product_id'] ) && absint( $product_data['product_id'] ) === absint( $item_product_id ) ) { + $discount_amount = ( '' !== $product_data['discount_amount'] ) ? $product_data['discount_amount'] : ''; + if ( '' !== $discount_amount ) { + unset( $items[ $index ] ); + } + } + } + } + } + } + } + + return $items; + + } + + /** + * Apply coupons actions + * + * @param string $coupon_code The coupon code. + * @param WC_Order $order WooCommerce order instance. + */ + public function coupon_action( $coupon_code = '', $order = null ) { + + if ( empty( $coupon_code ) ) { + return; + } + + if ( $coupon_code instanceof WC_Coupon && is_callable( array( $coupon_code, 'get_code' ) ) ) { + $coupon_code = $coupon_code->get_code(); + } + + $coupon_actions = $this->get_coupon_actions( $coupon_code ); + + if ( ! empty( $coupon_actions ) && ! is_scalar( $coupon_actions ) ) { + $product_names = array(); + foreach ( $coupon_actions as $coupon_action ) { + if ( empty( $coupon_action['product_id'] ) ) { + continue; + } + + $id = absint( $coupon_action['product_id'] ); + + $product = wc_get_product( $id ); + + $product_data = $this->get_product_data( $product ); + + $product_id = ( ! empty( $product_data['product_id'] ) ) ? absint( $product_data['product_id'] ) : 0; + $variation_id = ( ! empty( $product_data['variation_id'] ) ) ? absint( $product_data['variation_id'] ) : 0; + $variation = array(); + + if ( ! empty( $variation_id ) ) { + $variation = $product->get_variation_attributes(); + } + + $quantity = absint( $coupon_action['quantity'] ); + + $cart_item_data = array( + 'wc_sc_product_source' => $coupon_code, + ); + + if ( $order instanceof WC_Abstract_Order ) { + $product_exists = false; + $order_items = $order->get_items(); + foreach ( $order_items as $order_item ) { + if ( absint( $order_item->get_product_id() ) === $product_id ) { + $product_exists = true; // Exit if the product is already in the order. + break; + } + } + if ( ! $product_exists ) { + // Add a line item to the order. + $item = new WC_Order_Item_Product(); + $discount_amount = ( '' !== $product_data['discount_amount'] ) ? $coupon_action['discount_amount'] : ''; + $discount_type = ( ! empty( $coupon_action['discount_type'] ) ) ? $coupon_action['discount_type'] : 'percent'; + switch ( $discount_type ) { + case 'flat': + $discount = $this->convert_price( $discount_amount ); + break; + + case 'percent': + $discount = ( $product->get_price() * $discount_amount ) / 100; + break; + } + // Calculated the discounted amount. + $discounted_price = ( $product->get_price() - $discount ) * $quantity; + + $item->set_props( + array( + 'name' => $product->get_name(), + 'product_id' => $product_id, // ID of the product to add. + 'quantity' => $quantity, // Quantity of the product. + 'variation_id' => $variation_id, // ID of the product variation (if applicable). + ) + ); + $item->set_subtotal( $discounted_price ); + $item->add_meta_data( '_wc_sc_product_source', $coupon_code ); + $item->set_order_id( $order->get_id() ); + + // Add the item to the order. + $order->add_item( $item ); + } + } else { + $cart_item_key = WC()->cart->add_to_cart( $product_id, $quantity, $variation_id, $variation, $cart_item_data ); + + if ( ! empty( $cart_item_key ) ) { + if ( $this->is_wc_gte_30() ) { + $product_names[] = ( is_object( $product ) && is_callable( array( $product, 'get_name' ) ) ) ? $product->get_name() : ''; + } else { + $product_names[] = ( is_object( $product ) && is_callable( array( $product, 'get_title' ) ) ) ? $product->get_title() : ''; + } + } + } + } + + if ( ! ( $order instanceof WC_Abstract_Order ) && ! empty( $product_names ) ) { + /* translators: 1. Product title */ + wc_add_notice( sprintf( __( '%s has been added to your cart!', 'woocommerce-smart-coupons' ), implode( ', ', $product_names ) ) ); + } + } + + } + + /** + * Remove products from cart if the coupon, which added the product, is removed + * + * @param string $coupon_code The coupon code. + */ + public function remove_product_from_cart( $coupon_code = '' ) { + + if ( is_admin() ) { + return; + } + + if ( ! empty( $coupon_code ) ) { + foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { + if ( isset( $cart_item['wc_sc_product_source'] ) && $cart_item['wc_sc_product_source'] === $coupon_code ) { + // Action 'woocommerce_before_calculate_totals' is hooked by WooCommerce Subscription while removing coupons in local WooCommerce Cart variable in which we don't need to remove added cart item. + if ( ! doing_action( 'woocommerce_before_calculate_totals' ) ) { + WC()->cart->set_quantity( $cart_item_key, 0 ); + } + } + } + } + + } + + /** + * Remove products added by coupon actions when the coupon is removed from the order. + */ + public function remove_product_from_order() { + $action = ( ! empty( $_POST['action'] ) ) ? wc_clean( wp_unslash( $_POST['action'] ) ) : ''; // phpcs:ignore + $coupon_code = ( ! empty( $_POST['coupon'] ) ) ? wc_clean( wp_unslash( $_POST['coupon'] ) ) : ''; // phpcs:ignore + $order_id = ( ! empty( $_POST['order_id'] ) ) ? wc_clean( wp_unslash( $_POST['order_id'] ) ) : 0; // phpcs:ignore + + if ( 'woocommerce_remove_order_coupon' !== $action || empty( $order_id ) || empty( $coupon_code ) ) { + return; + } + + $order = wc_get_order( $order_id ); + + if ( ! $order instanceof WC_Order ) { + return; + } + + foreach ( $order->get_items() as $item_id => $item ) { + if ( $item->get_meta( '_wc_sc_product_source', true ) === $coupon_code ) { + $order->remove_item( $item_id ); + } + } + + $order->calculate_totals(); // Recalculate totals. + $order->save(); // Save the order. + } + + /** + * Review cart items + */ + public function review_cart_items() { + $cart = ( is_object( WC() ) && isset( WC()->cart ) ) ? WC()->cart : null; + $applied_coupons = isset( $cart->applied_coupons ) ? (array) $cart->applied_coupons : array(); + + $products = array(); + if ( $cart instanceof WC_Cart && is_callable( array( $cart, 'get_cart' ) ) ) { + foreach ( $cart->get_cart() as $cart_item_key => $cart_item ) { + if ( ! empty( $cart_item['wc_sc_product_source'] ) && ! in_array( $cart_item['wc_sc_product_source'], $applied_coupons, true ) ) { + $cart->set_quantity( $cart_item_key, 0 ); + $coupon_code = $cart_item['wc_sc_product_source']; + if ( empty( $products[ $coupon_code ] ) || ! is_array( $products[ $coupon_code ] ) ) { + $products[ $coupon_code ] = array(); + } + $products[ $coupon_code ][] = ( is_object( $cart_item['data'] ) && is_callable( array( $cart_item['data'], 'get_name' ) ) ) ? $cart_item['data']->get_name() : ''; + $products[ $coupon_code ] = array_filter( $products[ $coupon_code ] ); + } + } + } + + if ( ! empty( $products ) && ! is_scalar( $products ) ) { + foreach ( $products as $coupon_code => $product_names ) { + /* translators: 1. Product/s 2. Product names 3. is/are 4. Coupons code */ + wc_add_notice( sprintf( __( '%1$s %2$s %3$s removed because coupon %4$s is removed.', 'woocommerce-smart-coupons' ), _n( 'Product', 'Products', count( $products[ $coupon_code ] ), 'woocommerce-smart-coupons' ), '' . implode( ', ', $products[ $coupon_code ] ) . '', _n( 'is', 'are', count( $products[ $coupon_code ] ), 'woocommerce-smart-coupons' ), '' . $coupon_code . '' ), 'error' ); + } + } + + } + + /** + * Add product source in order item meta + * + * @param mixed $item The item. + * @param string $cart_item_key The cart item key. + * @param array $values The cart item. + * @param WC_Order $order The order. + */ + public function add_product_source_in_order_item_meta( $item = null, $cart_item_key = '', $values = array(), $order = null ) { + + if ( isset( $values['wc_sc_product_source'] ) ) { + $item->add_meta_data( '_wc_sc_product_source', $values['wc_sc_product_source'], true ); + } + + } + + /** + * Get product data + * + * @param mixed $product The product object. + * @return array + */ + public function get_product_data( $product = null ) { + + if ( empty( $product ) ) { + return array(); + } + + if ( $this->is_wc_gte_30() ) { + $product_id = ( is_object( $product ) && is_callable( array( $product, 'get_id' ) ) ) ? $product->get_id() : 0; + } else { + $product_id = ( ! empty( $product->id ) ) ? $product->id : 0; + } + + $product_type = ( is_object( $product ) && is_callable( array( $product, 'get_type' ) ) ) ? $product->get_type() : ''; + + if ( 'variation' === $product_type ) { + $variation_id = $product_id; + if ( $this->is_wc_gte_30() ) { + $parent_id = ( is_object( $product ) && is_callable( array( $product, 'get_parent_id' ) ) ) ? $product->get_parent_id() : 0; + $variation_data = wc_get_product_variation_attributes( $variation_id ); + } else { + $parent_id = ( is_object( $product ) && is_callable( array( $product, 'get_parent' ) ) ) ? $product->get_parent() : 0; + $variation_data = ( ! empty( $product->variation_data ) ) ? $product->variation_data : array(); + } + $product_id = $parent_id; + } else { + $variation_id = 0; + $variation_data = array(); + } + + $product_data = array( + 'product_id' => $product_id, + 'variation_id' => $variation_id, + 'variation_data' => $variation_data, + ); + + return apply_filters( 'wc_sc_product_data', $product_data, array( 'product_obj' => $product ) ); + + } + + /** + * Add action's meta in export headers + * + * @param array $headers Existing headers. + * @return array + */ + public function export_headers( $headers = array() ) { + + $action_headers = array( + 'wc_sc_add_product_details' => __( 'Add product details', 'woocommerce-smart-coupons' ), + ); + + return array_merge( $headers, $action_headers ); + + } + + /** + * Function to handle coupon meta data during export of existing coupons + * + * @param mixed $meta_value The meta value. + * @param array $args Additional arguments. + * @return string Processed meta value + */ + public function export_coupon_meta_data( $meta_value = '', $args = array() ) { + + $index = ( ! empty( $args['index'] ) ) ? $args['index'] : -1; + $meta_keys = ( ! empty( $args['meta_keys'] ) ) ? $args['meta_keys'] : array(); + $meta_values = ( ! empty( $args['meta_values'] ) ) ? $args['meta_values'] : array(); + + if ( $index >= 0 && ! empty( $meta_keys[ $index ] ) && 'wc_sc_add_product_details' === $meta_keys[ $index ] ) { + + if ( ! empty( $meta_value ) && is_array( $meta_value ) ) { + $product_details = array(); + foreach ( $meta_value as $value ) { + $product_details[] = implode( ',', $value ); + } + $meta_value = implode( '|', $product_details ); + } + } + + return $meta_value; + + } + + /** + * Post meta defaults for action's meta + * + * @param array $defaults Existing postmeta defaults. + * @return array + */ + public function postmeta_defaults( $defaults = array() ) { + + $actions_defaults = array( + 'wc_sc_add_product_details' => '', + ); + + return array_merge( $defaults, $actions_defaults ); + } + + /** + * Add action's meta with value in coupon meta + * + * @param array $data The row data. + * @param array $post The POST values. + * @return array Modified data + */ + public function generate_coupon_meta( $data = array(), $post = array() ) { + + if ( isset( $post['wc_sc_add_product_ids'] ) ) { + if ( $this->is_wc_gte_30() ) { + $product_ids = wc_clean( wp_unslash( $post['wc_sc_add_product_ids'] ) ); // phpcs:ignore + } else { + $product_ids = array_filter( array_map( 'trim', explode( ',', sanitize_text_field( wp_unslash( $post['wc_sc_add_product_ids'] ) ) ) ) ); // phpcs:ignore + } + $add_product_details = array(); + if ( ! empty( $product_ids ) && ! is_scalar( $product_ids ) ) { + $quantity = ( isset( $post['wc_sc_add_product_qty'] ) ) ? wc_clean( wp_unslash( $post['wc_sc_add_product_qty'] ) ) : 1; + $discount_amount = ( isset( $post['wc_sc_product_discount_amount'] ) ) ? wc_clean( wp_unslash( $post['wc_sc_product_discount_amount'] ) ) : ''; + $discount_type = ( isset( $post['wc_sc_product_discount_type'] ) ) ? wc_clean( wp_unslash( $post['wc_sc_product_discount_type'] ) ) : ''; + foreach ( $product_ids as $id ) { + $product_data = array(); + $product_data['product_id'] = $id; + $product_data['quantity'] = $quantity; + $product_data['discount_amount'] = $discount_amount; + $product_data['discount_type'] = $discount_type; + $add_product_details[] = implode( ',', $product_data ); + } + } + $data['wc_sc_add_product_details'] = implode( '|', $add_product_details ); + } + + return $data; + } + + /** + * Make meta data of SC actions, protected + * + * @param bool $protected Is protected. + * @param string $meta_key The meta key. + * @param string $meta_type The meta type. + * @return bool $protected + */ + public function make_action_meta_protected( $protected, $meta_key, $meta_type ) { + $sc_meta = array( + 'wc_sc_add_product_details', + ); + if ( in_array( $meta_key, $sc_meta, true ) ) { + return true; + } + return $protected; + } + + /** + * Function to copy coupon action meta in newly generated coupon + * + * @param array $args The arguments. + */ + public function copy_coupon_action_meta( $args = array() ) { + + $new_coupon_id = ( ! empty( $args['new_coupon_id'] ) ) ? absint( $args['new_coupon_id'] ) : 0; + $coupon = ( ! empty( $args['ref_coupon'] ) ) ? $args['ref_coupon'] : false; + + if ( empty( $new_coupon_id ) || empty( $coupon ) ) { + return; + } + + $add_product_details = array(); + if ( $this->is_wc_gte_30() ) { + $add_product_details = $coupon->get_meta( 'wc_sc_add_product_details' ); + } else { + $old_coupon_id = ( ! empty( $coupon->id ) ) ? $coupon->id : 0; + $add_product_details = get_post_meta( $old_coupon_id, 'wc_sc_add_product_details', true ); + } + $this->update_post_meta( $new_coupon_id, 'wc_sc_add_product_details', $add_product_details ); + + } + + /** + * Function to validate whether to show the coupon or not + * + * @param boolean $is_show Show or not. + * @param array $args Additional arguments. + * @return boolean + */ + public function show_coupon_with_actions( $is_show = false, $args = array() ) { + + $coupon = ( ! empty( $args['coupon'] ) ) ? $args['coupon'] : null; + + if ( empty( $coupon ) ) { + return $is_show; + } + + if ( $this->is_wc_gte_30() ) { + $coupon_code = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_code' ) ) ) ? $coupon->get_code() : ''; + } else { + $coupon_code = ( ! empty( $coupon->code ) ) ? $coupon->code : ''; + } + + $coupon_actions = $this->get_coupon_actions( $coupon_code ); + + if ( ! empty( $coupon_actions ) ) { + return true; + } + + return $is_show; + + } + + /** + * Allow auto-generate of coupon with coupon action + * + * @param boolean $is_auto_generate Whether to auto-generate or not. + * @param array $args Additional parameters. + * @return boolean $is_auto_generate + */ + public function auto_generate_coupon_with_actions( $is_auto_generate = false, $args = array() ) { + + $coupon = ( ! empty( $args['coupon_obj'] ) && $args['coupon_obj'] instanceof WC_Coupon ) ? $args['coupon_obj'] : false; + $coupon_id = ( ! empty( $args['coupon_id'] ) ) ? $args['coupon_id'] : false; + + if ( ! empty( $coupon ) && ! empty( $coupon_id ) ) { + if ( $this->is_wc_gte_30() ) { + $coupon_code = $coupon->get_code(); + } else { + $coupon_code = ( ! empty( $coupon->code ) ) ? $coupon->code : ''; + } + if ( ! empty( $coupon_code ) ) { + $actions = ( $this->is_callable( $coupon, 'get_meta' ) ) ? $coupon->get_meta( 'wc_sc_add_product_details' ) : get_post_meta( $coupon_id, 'wc_sc_add_product_details', true ); + $coupon_actions = apply_filters( + 'wc_sc_coupon_actions', + $actions, + array( + 'coupon_code' => $coupon_code, + 'source' => $this, + ) + ); + if ( ! empty( $coupon_actions ) ) { + return true; + } + } + } + + return $is_auto_generate; + } + + /** + * Validate coupon having actions but without an amount + * + * @param boolean $is_valid_coupon_amount Whether the amount is validate or not. + * @param array $args Additional parameters. + * @return boolean + */ + public function validate_coupon_amount( $is_valid_coupon_amount = true, $args = array() ) { + + if ( ! $is_valid_coupon_amount ) { + $coupon_amount = ( ! empty( $args['coupon_amount'] ) ) ? $args['coupon_amount'] : 0; + $discount_type = ( ! empty( $args['discount_type'] ) ) ? $args['discount_type'] : ''; + $coupon_code = ( ! empty( $args['coupon_code'] ) ) ? $args['coupon_code'] : ''; + + $coupon_actions = ( ! empty( $coupon_code ) ) ? $this->get_coupon_actions( $coupon_code ) : array(); + + if ( 'smart_coupon' === $discount_type && $coupon_amount <= 0 && ! empty( $coupon_actions ) ) { + return true; + } + } + + return $is_valid_coupon_amount; + } + + /** + * Handle coupon actions when the cart is empty + * + * @param boolean $is_hold Whether to hold the coupon in cookie. + * @param array $args Additional arguments. + * @return boolean + */ + public function maybe_run_coupon_actions( $is_hold = true, $args = array() ) { + $cart = ( is_object( WC() ) && isset( WC()->cart ) ) ? WC()->cart : null; + if ( empty( $cart ) || WC()->cart->is_empty() ) { + $coupons_data = ( ! empty( $args['coupons_data'] ) ) ? $args['coupons_data'] : array(); + if ( ! empty( $coupons_data ) && ! is_scalar( $coupons_data ) ) { + foreach ( $coupons_data as $coupon_data ) { + $coupon_code = ( ! empty( $coupon_data['coupon-code'] ) ) ? $coupon_data['coupon-code'] : ''; + if ( ! empty( $coupon_code ) ) { + $coupon = new WC_Coupon( $coupon_code ); + $coupon_actions = $this->get_coupon_actions( $coupon_code ); + $coupon_products = ( ! empty( $coupon_actions ) ) ? wp_list_pluck( $coupon_actions, 'product_id' ) : array(); + if ( ! empty( $coupon_products ) ) { + if ( $this->is_valid( $coupon ) && ! WC()->cart->has_discount( $coupon_code ) ) { + WC()->cart->add_discount( trim( $coupon_code ) ); + $is_hold = false; + } + } + } + } + } + } + return $is_hold; + } + + /** + * Stop product update option for action tab products. + * + * @param string $cart_item_key contains the id of the cart item. + * @param int $quantity Current quantity of the item. + * @param int $old_quantity Old quantity of the item. + * @param WC_Cart $cart Cart object. + * @return void + */ + public function stop_cart_item_quantity_update( $cart_item_key = '', $quantity = 1, $old_quantity = 1, $cart = object ) { + + if ( empty( $cart_item_key ) || ! is_object( $cart ) || ! is_a( $cart, 'WC_Cart' ) ) { + return; + } + + $cart_data = is_callable( array( $cart, 'get_cart' ) ) ? $cart->get_cart() : array(); + $cart_item = ( ! empty( $cart_data[ $cart_item_key ] ) ) ? $cart_data[ $cart_item_key ] : array(); + + if ( empty( $cart_item ) ) { + return; + } + + $applied_coupons = is_callable( array( $cart, 'get_applied_coupons' ) ) ? $cart->get_applied_coupons() : array(); + + if ( ! empty( $cart_item['wc_sc_product_source'] ) && in_array( $cart_item['wc_sc_product_source'], $applied_coupons, true ) ) { + $cart->cart_contents[ $cart_item_key ]['quantity'] = $old_quantity; + } + + } + + } + +} + +WC_SC_Coupon_Actions::get_instance(); diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupon-categories.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupon-categories.php new file mode 100644 index 00000000..051c175b --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupon-categories.php @@ -0,0 +1,253 @@ + __( 'Coupon categories', 'woocommerce-smart-coupons' ), + 'singular_name' => __( 'Category', 'woocommerce-smart-coupons' ), + 'menu_name' => _x( 'Categories', 'Admin menu name', 'woocommerce-smart-coupons' ), + 'search_items' => __( 'Search coupon categories', 'woocommerce-smart-coupons' ), + 'all_items' => __( 'All coupon categories', 'woocommerce-smart-coupons' ), + 'parent_item' => __( 'Parent coupon category', 'woocommerce-smart-coupons' ), + 'parent_item_colon' => __( 'Parent coupon category:', 'woocommerce-smart-coupons' ), + 'edit_item' => __( 'Edit coupon category', 'woocommerce-smart-coupons' ), + 'update_item' => __( 'Update coupon category', 'woocommerce-smart-coupons' ), + 'add_new_item' => __( 'Add new coupon category', 'woocommerce-smart-coupons' ), + 'new_item_name' => __( 'New coupon category name', 'woocommerce-smart-coupons' ), + 'not_found' => __( 'No coupon categories found', 'woocommerce-smart-coupons' ), + ); + register_taxonomy( + 'sc_coupon_category', // Taxonomy name. + array( 'shop_coupon' ), // object for which the taxonomy is created. + array( + 'labels' => $labels, + 'description' => __( 'Manage coupon categories', 'woocommerce-smart-coupons' ), + 'public' => true, + 'hierarchical' => true, + 'show_ui' => true, + 'show_in_menu' => false, + 'show_in_rest' => true, + 'show_admin_column' => true, + 'rewrite' => array( 'slug' => 'sc_coupon_category' ), + 'query_var' => true, + ) + ); + register_taxonomy_for_object_type( 'sc_coupon_category', 'shop_coupon' ); + } + + /** + * Function to render coupon category column on coupons dashboard. + * + * @param int $post_id The coupon ID. + * @param WC_Coupon $coupon The coupon object. + */ + public function render_coupon_category_column( $post_id = 0, $coupon = null ) { + $terms = get_the_terms( $post_id, 'sc_coupon_category' ); + if ( ! empty( $terms ) ) { + foreach ( $terms as $term ) { + $content[] = '' . esc_html( $term->name ) . ''; + } + echo join( ', ', $content ); // phpcs:ignore + } else { + echo ''; + } + } + + /** + * Function to set woocommerce menu active + * + * @param string $parent_file file reference for menu. + */ + public function wc_sc_make_menu_active( $parent_file ) { + global $current_screen; + + $taxonomy = $current_screen->taxonomy; + if ( 'sc_coupon_category' === $taxonomy ) { + if ( $this->is_wc_gte_44() ) { + $parent_file = 'woocommerce-marketing'; + } else { + $parent_file = 'woocommerce'; + } + } + + return $parent_file; + } + + /** + * Function to add custom script in admin footer. + */ + public function add_footer_script() { + global $pagenow, $post; + $get_post_type = ( ! empty( $post->ID ) ) ? $this->get_post_type( $post->ID ) : ( ( ! empty( $_GET['post_type'] ) ) ? wc_clean( wp_unslash( $_GET['post_type'] ) ) : '' ); // phpcs:ignore + if ( 'shop_coupon' === $get_post_type ) { + if ( 'post.php' === $pagenow || 'post-new.php' === $pagenow ) { + $manage_category_string = __( 'Manage coupon categories', 'woocommerce-smart-coupons' ); + ?> + + 'ID' ) + array_slice( $columns, 1, count( $columns ) - 1, true ); + } + return $columns; + } + + /** + * Function for add content to ID column of coupon category taxonomy page. + * + * @param string $content - column content. + * @param string $column_name - column_name. + * @param string $term_id - id. + * @return string + */ + public function wc_sc_coupon_category_id_column_content( $content = '', $column_name = '', $term_id = 0 ) { + return $term_id; + } + + /** + * Function for change ID column to sortable. + * + * @param array $columns - Existing columns. + * @return array + */ + public function wc_sc_define_sortable_id_columns( $columns = array() ) { + $columns['id'] = 'id'; + return $columns; + } + + /** + * Define which columns to show on this screen. + * + * @param array $columns Existing columns. + * @return array + */ + public function define_columns( $columns = array() ) { + + if ( ! is_array( $columns ) || empty( $columns ) ) { + $columns = array(); + } + + $columns['wc_sc_coupon_category'] = __( 'Coupon categories', 'woocommerce-smart-coupons' ); + + return $columns; + } + + /** + * Render individual columns. + * + * @param string $column Column ID to render. + * @param int $post_id Post ID being shown. + */ + public function render_columns( $column = '', $post_id = 0 ) { + + if ( empty( $post_id ) || empty( $column ) || 'wc_sc_coupon_category' !== $column ) { + return; + } + + $coupon = new WC_Coupon( $post_id ); + + $this->render_coupon_category_column( $post_id, $coupon ); + + } + + + } + +} + +WC_SC_Coupon_Categories::get_instance(); diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupon-columns.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupon-columns.php new file mode 100644 index 00000000..19ac76c4 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupon-columns.php @@ -0,0 +1,200 @@ +list_table_type . '_posts_columns', array( $this, 'define_columns' ), 11 ); + add_action( 'manage_' . $this->list_table_type . '_posts_custom_column', array( $this, 'render_columns' ), 10, 2 ); + } + + /** + * Get single instance of WC_SC_Coupon_Columns + * + * @return WC_SC_Coupon_Columns Singleton object of WC_SC_Coupon_Columns + */ + public static function get_instance() { + // Check if instance is already exists. + if ( is_null( self::$instance ) ) { + self::$instance = new self(); + } + + return self::$instance; + } + + /** + * Handle call to functions which is not available in this class + * + * @param string $function_name The function name. + * @param array $arguments Array of arguments passed while calling $function_name. + * @return result of function call + */ + public function __call( $function_name, $arguments = array() ) { + + global $woocommerce_smart_coupon; + + if ( ! is_callable( array( $woocommerce_smart_coupon, $function_name ) ) ) { + return; + } + + if ( ! empty( $arguments ) ) { + return call_user_func_array( array( $woocommerce_smart_coupon, $function_name ), $arguments ); + } else { + return call_user_func( array( $woocommerce_smart_coupon, $function_name ) ); + } + + } + + /** + * Pre-fetch any data for the row each column has access to it. + * + * @param int $post_id Post ID being shown. + */ + protected function prepare_row_data( $post_id = 0 ) { + + if ( empty( $post_id ) ) { + return; + } + + $coupon_id = 0; + if ( ! empty( $this->object ) ) { + $coupon = $this->object; + if ( $this->is_wc_gte_30() ) { + $coupon_id = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_id' ) ) ) ? $coupon->get_id() : 0; + } else { + $coupon_id = ( ! empty( $coupon->id ) ) ? $coupon->id : 0; + } + } + + if ( empty( $this->object ) || $coupon_id !== $post_id ) { + $this->object = new WC_Coupon( $post_id ); + } + } + + /** + * Define which columns to show on this screen. + * + * @param array $columns Existing columns. + * @return array + */ + public function define_columns( $columns = array() ) { + + if ( ! is_array( $columns ) || empty( $columns ) ) { + $columns = array(); + } + + $columns['wc_sc_view_orders'] = __( 'Used in orders', 'woocommerce-smart-coupons' ); + + return $columns; + } + + /** + * Render individual columns. + * + * @param string $column Column ID to render. + * @param int $post_id Post ID being shown. + */ + public function render_columns( $column = '', $post_id = 0 ) { + + $this->prepare_row_data( $post_id ); + + if ( ! $this->object ) { + return; + } + + if ( ! empty( $column ) ) { + switch ( $column ) { + case 'wc_sc_view_orders': + $this->render_view_orders_column( $post_id, $this->object ); + break; + } + } + + } + + /** + * Render column: View orders. + * + * @param integer $coupon_id The coupon id. + * @param WC_Coupon $coupon The coupon object. + */ + public function render_view_orders_column( $coupon_id = 0, $coupon = null ) { + + if ( $this->is_wc_gte_30() ) { + $usage_count = ( ! empty( $coupon ) && is_callable( array( $coupon, 'get_usage_count' ) ) ) ? $coupon->get_usage_count() : 0; + } else { + $usage_count = ( ! empty( $coupon->usage_count ) ) ? $coupon->usage_count : 0; + } + + $column_content = ''; + if ( ! empty( $usage_count ) ) { + if ( $this->is_wc_gte_30() ) { + $coupon_code = ( ! empty( $coupon ) && is_callable( array( $coupon, 'get_code' ) ) ) ? $coupon->get_code() : ''; + } else { + $coupon_code = ( ! empty( $coupon->code ) ) ? $coupon->code : ''; + } + $coupon_usage_url = add_query_arg( + array( + 's' => $coupon_code, + 'post_status' => 'all', + 'post_type' => 'shop_order', + ), + admin_url( 'edit.php' ) + ); + $column_content = sprintf( '', esc_url( $coupon_usage_url ) ); + } else { + $column_content = '–'; + } + + $column_content = apply_filters( 'wc_sc_view_orders_column_content', $column_content, array( 'coupon' => $coupon ) ); + echo wp_kses_post( $column_content ); + + } + + } + +} + +WC_SC_Coupon_Columns::get_instance(); diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupon-fields.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupon-fields.php new file mode 100644 index 00000000..1e2bfe22 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupon-fields.php @@ -0,0 +1,1464 @@ +post_title ) ) { + return; + } + + $shop_page_id = get_option( 'woocommerce_shop_page_id', 0 ); + + if ( ! empty( $shop_page_id ) ) { + $shop_page_id = 'shop'; + } else { + $home_url = home_url(); + $shop_page_id = ( function_exists( 'wpcom_vip_url_to_postid' ) ) ? wpcom_vip_url_to_postid( $home_url ) : url_to_postid( $home_url ); // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.url_to_postid_url_to_postid + } + + if ( empty( $shop_page_id ) ) { + $shop_page_id = 'cart'; + } + + $coupon_share_url = add_query_arg( + array( + 'coupon-code' => $post->post_title, + 'sc-page' => $shop_page_id, + ), + home_url( '/' ) + ); + + ?> +

          + +


          + + ID ) ) ? $post->ID : 0; + } + $coupon = ( ! empty( $coupon_id ) ) ? new WC_Coupon( $coupon_id ) : null; + } + + $is_callable_coupon_get_meta = $this->is_callable( $coupon, 'get_meta' ); + + ?> + +
          + is_wc_gte_32() ) { + woocommerce_wp_hidden_input( + array( + 'id' => 'wc_sc_expiry_time', + ) + ); + + woocommerce_wp_text_input( + array( + 'id' => 'wc_sc_expiry_time_picker', + 'label' => __( 'Coupon expiry time', 'woocommerce-smart-coupons' ), + 'placeholder' => esc_attr__( 'HH:MM', 'woocommerce-smart-coupons' ), + 'description' => __( 'Time after which coupon will be expired. This will work in conjunction with Coupon expiry date.', 'woocommerce-smart-coupons' ), + 'type' => 'text', + 'desc_tip' => true, + 'custom_attributes' => array( + 'autocomplete' => 'off', + ), + ) + ); + } + + // Max discount field for percentage type coupon. + woocommerce_wp_text_input( + array( + 'id' => 'wc_sc_max_discount', + 'label' => __( 'Max discount', 'woocommerce-smart-coupons' ), + 'placeholder' => esc_attr__( 'Unlimited discount', 'woocommerce-smart-coupons' ), + 'description' => __( 'The maximum discount this coupon can give on a cart.', 'woocommerce-smart-coupons' ), + 'type' => 'number', + 'desc_tip' => true, + 'custom_attributes' => array( + 'step' => 'any', + 'min' => 0, + ), + ) + ); + + woocommerce_wp_checkbox( + array( + 'id' => 'sc_restrict_to_new_user', + 'label' => __( 'For new user only?', 'woocommerce-smart-coupons' ), + 'description' => __( 'When checked, this coupon will be valid for the user\'s first order on the store.', 'woocommerce-smart-coupons' ), + ) + ); + + if ( true === $is_callable_coupon_get_meta ) { + $sc_coupon_validity = $coupon->get_meta( 'sc_coupon_validity' ); + $validity_suffix = $coupon->get_meta( 'validity_suffix' ); + } else { + $sc_coupon_validity = get_post_meta( $post->ID, 'sc_coupon_validity', true ); + $validity_suffix = get_post_meta( $post->ID, 'validity_suffix', true ); + } + + ?> +

          + +   + + +

          + 'is_pick_price_of_product', + 'label' => __( 'Coupon value same as product\'s price?', 'woocommerce-smart-coupons' ), + 'description' => __( 'When checked, generated coupon\'s value will be same as product\'s price', 'woocommerce-smart-coupons' ), + ) + ); + woocommerce_wp_checkbox( + array( + 'id' => 'auto_generate_coupon', + 'label' => __( 'Auto generate new coupons with each item', 'woocommerce-smart-coupons' ), + 'description' => __( 'Generate exact copy of this coupon with unique coupon code for each purchased product (needs this coupon to be linked with that product)', 'woocommerce-smart-coupons' ), + ) + ); + } + + echo '
          '; + + ?> +

          + get_meta( 'coupon_title_prefix' ); + $coupon_title_suffix = $coupon->get_meta( 'coupon_title_suffix' ); + } elseif ( ! empty( $post->ID ) ) { + $coupon_title_prefix = get_post_meta( $post->ID, 'coupon_title_prefix', true ); + $coupon_title_suffix = get_post_meta( $post->ID, 'coupon_title_suffix', true ); + } + ?> + +   + coupon_code  + + +

          + '; + + if ( ! $is_page_bulk_generate ) { + + echo '
          '; + // for disabling e-mail restriction. + woocommerce_wp_checkbox( + array( + 'id' => 'sc_is_visible_storewide', + 'label' => __( 'Show on cart, checkout', 'woocommerce-smart-coupons' ) . '
          ' . __( 'and my account?', 'woocommerce-smart-coupons' ), + 'description' => __( 'When checked, this coupon will be visible on cart/checkout page for everyone', 'woocommerce-smart-coupons' ), + ) + ); + + echo '
          '; + + } + ?> +
          + +
          + $this, + 'coupon_id' => $coupon_id, + 'coupon_obj' => $coupon, + ) + ); + + $generated_from_order_id = ( is_object( $coupon ) && $this->is_callable( $coupon, 'get_meta' ) ) ? $coupon->get_meta( 'generated_from_order_id' ) : $this->get_post_meta( $coupon_id, 'generated_from_order_id', true ); + + if ( empty( $generated_from_order_id ) ) { + woocommerce_wp_checkbox( + array( + 'id' => 'sc_disable_email_restriction', + 'label' => __( 'Disable email restriction?', 'woocommerce-smart-coupons' ), + 'description' => __( 'Do not restrict auto-generated coupons to buyer/receiver email, anyone with coupon code can use it', 'woocommerce-smart-coupons' ), + ) + ); + } + + ?> +
          + is_callable( $coupon, 'get_meta' ) ) ? $coupon->get_discount_type() : get_post_meta( $post_id, 'discount_type', true ); + + if ( true === $this->is_callable( $coupon, 'update_meta_data' ) ) { + + if ( isset( $_POST['sc_restrict_to_new_user'] ) ) { // phpcs:ignore + $coupon->update_meta_data( 'sc_restrict_to_new_user', $post_sc_restrict_to_new_user ); + } else { + $coupon->update_meta_data( 'sc_restrict_to_new_user', 'no' ); + } + + if ( isset( $_POST['auto_generate_coupon'] ) ) { // phpcs:ignore + $coupon->update_meta_data( 'auto_generate_coupon', $post_auto_generate_coupon ); + } else { + if ( 'smart_coupon' === $type ) { + $coupon->update_meta_data( 'auto_generate_coupon', 'yes' ); + } else { + $coupon->update_meta_data( 'auto_generate_coupon', 'no' ); + } + } + + if ( isset( $_POST['usage_limit_per_user'] ) ) { // phpcs:ignore + $coupon->set_usage_limit_per_user( $post_usage_limit_per_user ); + } + + if ( isset( $_POST['limit_usage_to_x_items'] ) ) { // phpcs:ignore + $coupon->set_limit_usage_to_x_items( $post_limit_usage_to_x_items ); + } + + if ( 'smart_coupon' === $type ) { + $coupon->update_meta_data( 'apply_before_tax', 'no' ); + } + + if ( isset( $_POST['coupon_title_prefix'] ) ) { // phpcs:ignore + $coupon->update_meta_data( 'coupon_title_prefix', $post_coupon_title_prefix ); + } + + if ( isset( $_POST['coupon_title_suffix'] ) ) { // phpcs:ignore + $coupon->update_meta_data( 'coupon_title_suffix', $post_coupon_title_suffix ); + } + + if ( isset( $_POST['sc_coupon_validity'] ) ) { // phpcs:ignore + $coupon->update_meta_data( 'sc_coupon_validity', $post_sc_coupon_validity ); + $coupon->update_meta_data( 'validity_suffix', $post_validity_suffix ); + } + + if ( isset( $_POST['sc_is_visible_storewide'] ) ) { // phpcs:ignore + $coupon->update_meta_data( 'sc_is_visible_storewide', $post_sc_is_visible_storewide ); + } else { + $coupon->update_meta_data( 'sc_is_visible_storewide', 'no' ); + } + + if ( isset( $_POST['sc_disable_email_restriction'] ) ) { // phpcs:ignore + $coupon->update_meta_data( 'sc_disable_email_restriction', $post_sc_disable_email_restriction ); + } else { + $coupon->update_meta_data( 'sc_disable_email_restriction', 'no' ); + } + + if ( isset( $_POST['is_pick_price_of_product'] ) ) { // phpcs:ignore + $coupon->update_meta_data( 'is_pick_price_of_product', $post_is_pick_price_of_product ); + } else { + $coupon->update_meta_data( 'is_pick_price_of_product', 'no' ); + } + + if ( isset( $_POST['wc_sc_add_product_ids'] ) ) { // phpcs:ignore + if ( $this->is_wc_gte_30() ) { + $product_ids = $post_wc_sc_add_product_ids; + } else { + $product_ids = array_filter( array_map( 'trim', explode( ',', $post_wc_sc_add_product_ids ) ) ); + } + $add_product_details = array(); + if ( ! empty( $product_ids ) ) { + $quantity = $post_wc_sc_add_product_qty; + $discount_amount = $post_wc_sc_product_discount_amount; + $discount_type = $post_wc_sc_product_discount_type; + foreach ( $product_ids as $id ) { + $data = array(); + $data['product_id'] = $id; + $data['quantity'] = $quantity; + $data['discount_amount'] = $discount_amount; + $data['discount_type'] = $discount_type; + $add_product_details[] = $data; + } + } + $coupon->update_meta_data( 'wc_sc_add_product_details', $add_product_details ); + } else { + $coupon->update_meta_data( 'wc_sc_add_product_details', array() ); + } + + if ( isset( $_POST['wc_sc_max_discount'] ) ) { // phpcs:ignore + $max_discount = wc_clean( wp_unslash( $_POST['wc_sc_max_discount'] ) ); // phpcs:ignore + $coupon->update_meta_data( 'wc_sc_max_discount', $max_discount ); + } + + if ( isset( $_POST['wc_sc_expiry_time'] ) ) { // phpcs:ignore + $expiry_time = wc_clean( wp_unslash( $_POST['wc_sc_expiry_time'] ) ); // phpcs:ignore + $coupon->update_meta_data( 'wc_sc_expiry_time', $expiry_time ); + } + + if ( ! empty( $post_discount_type ) && 'smart_coupon' === $post_discount_type && ! empty( $post_original_post_status ) && 'auto-draft' === $post_original_post_status && ! empty( $post_coupon_amount ) ) { + $coupon->update_meta_data( 'wc_sc_original_amount', $post_coupon_amount ); + } + } else { + + if ( isset( $_POST['sc_restrict_to_new_user'] ) ) { // phpcs:ignore + update_post_meta( $post_id, 'sc_restrict_to_new_user', $post_sc_restrict_to_new_user ); + } else { + update_post_meta( $post_id, 'sc_restrict_to_new_user', 'no' ); + } + + if ( isset( $_POST['auto_generate_coupon'] ) ) { // phpcs:ignore + update_post_meta( $post_id, 'auto_generate_coupon', $post_auto_generate_coupon ); + } else { + if ( 'smart_coupon' === $type ) { + update_post_meta( $post_id, 'auto_generate_coupon', 'yes' ); + } else { + update_post_meta( $post_id, 'auto_generate_coupon', 'no' ); + } + } + + if ( isset( $_POST['usage_limit_per_user'] ) ) { // phpcs:ignore + update_post_meta( $post_id, 'usage_limit_per_user', $post_usage_limit_per_user ); + } + + if ( isset( $_POST['limit_usage_to_x_items'] ) ) { // phpcs:ignore + update_post_meta( $post_id, 'limit_usage_to_x_items', $post_limit_usage_to_x_items ); + } + + if ( 'smart_coupon' === $type ) { + update_post_meta( $post_id, 'apply_before_tax', 'no' ); + } + + if ( isset( $_POST['coupon_title_prefix'] ) ) { // phpcs:ignore + update_post_meta( $post_id, 'coupon_title_prefix', $post_coupon_title_prefix ); + } + + if ( isset( $_POST['coupon_title_suffix'] ) ) { // phpcs:ignore + update_post_meta( $post_id, 'coupon_title_suffix', $post_coupon_title_suffix ); + } + + if ( isset( $_POST['sc_coupon_validity'] ) ) { // phpcs:ignore + update_post_meta( $post_id, 'sc_coupon_validity', $post_sc_coupon_validity ); + update_post_meta( $post_id, 'validity_suffix', $post_validity_suffix ); + } + + if ( isset( $_POST['sc_is_visible_storewide'] ) ) { // phpcs:ignore + update_post_meta( $post_id, 'sc_is_visible_storewide', $post_sc_is_visible_storewide ); + } else { + update_post_meta( $post_id, 'sc_is_visible_storewide', 'no' ); + } + + if ( isset( $_POST['sc_disable_email_restriction'] ) ) { // phpcs:ignore + update_post_meta( $post_id, 'sc_disable_email_restriction', $post_sc_disable_email_restriction ); + } else { + update_post_meta( $post_id, 'sc_disable_email_restriction', 'no' ); + } + + if ( isset( $_POST['is_pick_price_of_product'] ) ) { // phpcs:ignore + update_post_meta( $post_id, 'is_pick_price_of_product', $post_is_pick_price_of_product ); + } else { + update_post_meta( $post_id, 'is_pick_price_of_product', 'no' ); + } + + if ( isset( $_POST['wc_sc_add_product_ids'] ) ) { // phpcs:ignore + if ( $this->is_wc_gte_30() ) { + $product_ids = $post_wc_sc_add_product_ids; + } else { + $product_ids = array_filter( array_map( 'trim', explode( ',', $post_wc_sc_add_product_ids ) ) ); + } + $add_product_details = array(); + if ( ! empty( $product_ids ) ) { + $quantity = $post_wc_sc_add_product_qty; + $discount_amount = $post_wc_sc_product_discount_amount; + $discount_type = $post_wc_sc_product_discount_type; + foreach ( $product_ids as $id ) { + $data = array(); + $data['product_id'] = $id; + $data['quantity'] = $quantity; + $data['discount_amount'] = $discount_amount; + $data['discount_type'] = $discount_type; + $add_product_details[] = $data; + } + } + update_post_meta( $post_id, 'wc_sc_add_product_details', $add_product_details ); + } else { + update_post_meta( $post_id, 'wc_sc_add_product_details', array() ); + } + + if ( isset( $_POST['wc_sc_max_discount'] ) ) { // phpcs:ignore + $max_discount = wc_clean( wp_unslash( $_POST['wc_sc_max_discount'] ) ); // phpcs:ignore + update_post_meta( $post_id, 'wc_sc_max_discount', $max_discount ); + } + + if ( isset( $_POST['wc_sc_expiry_time'] ) ) { // phpcs:ignore + $expiry_time = wc_clean( wp_unslash( $_POST['wc_sc_expiry_time'] ) ); // phpcs:ignore + update_post_meta( $post_id, 'wc_sc_expiry_time', $expiry_time ); + } + + if ( ! empty( $post_discount_type ) && 'smart_coupon' === $post_discount_type && ! empty( $post_original_post_status ) && 'auto-draft' === $post_original_post_status && ! empty( $post_coupon_amount ) ) { + update_post_meta( $post_id, 'wc_sc_original_amount', $post_coupon_amount ); + } + } + + if ( $this->is_callable( $coupon, 'save' ) ) { + $coupon->save(); + } + + } + + /** + * Function to process smart coupon meta for legacy api + * + * @param int $coupon_id The coupon id. + * @param array $data request body. + */ + public function woocommerce_legacy_api_process_smart_coupon_meta( $coupon_id = 0, $data = null ) { + if ( empty( $coupon_id ) ) { + return; + } + $coupon = new WC_Coupon( $coupon_id ); + if ( ! $coupon instanceof WC_Coupon ) { + return; + } + if ( ! empty( $data ) && ! is_array( $data ) ) { + return; + } + + $post_sc_restrict_to_new_user = ( isset( $data['sc_restrict_to_new_user'] ) ) ? wc_clean( wp_unslash( $data['sc_restrict_to_new_user'] ) ) : 'no'; // phpcs:ignore + $post_auto_generate_coupon = ( isset( $data['auto_generate_coupon'] ) ) ? wc_clean( wp_unslash( $data['auto_generate_coupon'] ) ) : 'no'; // phpcs:ignore + $post_usage_limit_per_user = ( isset( $data['usage_limit_per_user'] ) ) ? wc_clean( wp_unslash( $data['usage_limit_per_user'] ) ) : ''; // phpcs:ignore + $post_limit_usage_to_x_items = ( isset( $data['limit_usage_to_x_items'] ) ) ? wc_clean( wp_unslash( $data['limit_usage_to_x_items'] ) ) : ''; // phpcs:ignore + $post_coupon_title_prefix = ( isset( $data['coupon_title_prefix'] ) ) ? wc_clean( wp_unslash( $data['coupon_title_prefix'] ) ) : ''; // phpcs:ignore + $post_coupon_title_suffix = ( isset( $data['coupon_title_suffix'] ) ) ? wc_clean( wp_unslash( $data['coupon_title_suffix'] ) ) : ''; // phpcs:ignore + $post_sc_coupon_validity = ( isset( $data['sc_coupon_validity'] ) ) ? wc_clean( wp_unslash( $data['sc_coupon_validity'] ) ) : ''; // phpcs:ignore + $post_validity_suffix = ( isset( $data['validity_suffix'] ) ) ? wc_clean( wp_unslash( $data['validity_suffix'] ) ) : 'days'; // phpcs:ignore + $post_sc_is_visible_storewide = ( isset( $data['sc_is_visible_storewide'] ) ) ? wc_clean( wp_unslash( $data['sc_is_visible_storewide'] ) ) : 'no'; // phpcs:ignore + $post_sc_disable_email_restriction = ( isset( $data['sc_disable_email_restriction'] ) ) ? wc_clean( wp_unslash( $data['sc_disable_email_restriction'] ) ) : 'no'; // phpcs:ignore + $post_is_pick_price_of_product = ( isset( $data['is_pick_price_of_product'] ) ) ? wc_clean( wp_unslash( $data['is_pick_price_of_product'] ) ) : 'no'; // phpcs:ignore + $post_wc_sc_add_product_ids = ( isset( $data['wc_sc_add_product_ids'] ) ) ? wc_clean( wp_unslash( $data['wc_sc_add_product_ids'] ) ) : array(); // phpcs:ignore + $post_wc_sc_add_product_qty = ( isset( $data['wc_sc_add_product_qty'] ) ) ? wc_clean( wp_unslash( $data['wc_sc_add_product_qty'] ) ) : 1; // phpcs:ignore + $post_wc_sc_product_discount_amount = ( isset( $data['wc_sc_product_discount_amount'] ) ) ? wc_clean( wp_unslash( $data['wc_sc_product_discount_amount'] ) ) : ''; // phpcs:ignore + $post_wc_sc_product_discount_type = ( isset( $data['wc_sc_product_discount_type'] ) ) ? wc_clean( wp_unslash( $data['wc_sc_product_discount_type'] ) ) : 'percent'; // phpcs:ignore + $post_original_post_status = ( isset( $data['original_post_status'] ) ) ? wc_clean( wp_unslash( $data['original_post_status'] ) ) : ''; // phpcs:ignore + $post_coupon_amount = ( isset( $data['amount'] ) ) ? wc_clean( wp_unslash( $data['amount'] ) ) : 0; + $post_discount_type = ( $this->is_callable( $coupon, 'get_discount_type' ) ) ? $coupon->get_discount_type() : get_post_meta( $coupon_id, 'discount_type', true ); + + if ( true === $this->is_callable( $coupon, 'update_meta_data' ) ) { + if ( isset( $data['sc_restrict_to_new_user'] ) ) { // phpcs:ignore + $coupon->update_meta_data( 'sc_restrict_to_new_user', $post_sc_restrict_to_new_user ); + } else { + $coupon->update_meta_data( 'sc_restrict_to_new_user', 'no' ); + } + + if ( isset( $data['auto_generate_coupon'] ) ) { // phpcs:ignore + $coupon->update_meta_data( 'auto_generate_coupon', $post_auto_generate_coupon ); + } + + if ( isset( $data['usage_limit_per_user'] ) ) { // phpcs:ignore + $coupon->set_usage_limit_per_user( $post_usage_limit_per_user ); + } + + if ( isset( $data['limit_usage_to_x_items'] ) ) { // phpcs:ignore + $coupon->set_limit_usage_to_x_items( $post_limit_usage_to_x_items ); + } + + if ( 'smart_coupon' === $post_discount_type ) { + $coupon->update_meta_data( 'apply_before_tax', 'no' ); + } + + if ( isset( $data['coupon_title_prefix'] ) ) { // phpcs:ignore + $coupon->update_meta_data( 'coupon_title_prefix', $post_coupon_title_prefix ); + } + + if ( isset( $data['coupon_title_suffix'] ) ) { // phpcs:ignore + $coupon->update_meta_data( 'coupon_title_suffix', $post_coupon_title_suffix ); + } + + if ( isset( $data['sc_coupon_validity'] ) ) { // phpcs:ignore + $coupon->update_meta_data( 'sc_coupon_validity', $post_sc_coupon_validity ); + $coupon->update_meta_data( 'validity_suffix', $post_validity_suffix ); + } + + if ( isset( $data['sc_is_visible_storewide'] ) ) { // phpcs:ignore + $coupon->update_meta_data( 'sc_is_visible_storewide', $post_sc_is_visible_storewide ); + } else { + $coupon->update_meta_data( 'sc_is_visible_storewide', 'no' ); + } + + if ( isset( $data['sc_disable_email_restriction'] ) ) { // phpcs:ignore + $coupon->update_meta_data( 'sc_disable_email_restriction', $post_sc_disable_email_restriction ); + } else { + $coupon->update_meta_data( 'sc_disable_email_restriction', 'no' ); + } + + if ( isset( $data['is_pick_price_of_product'] ) ) { // phpcs:ignore + $coupon->update_meta_data( 'is_pick_price_of_product', $post_is_pick_price_of_product ); + } else { + $coupon->update_meta_data( 'is_pick_price_of_product', 'no' ); + } + + if ( isset( $data['wc_sc_add_product_ids'] ) ) { // phpcs:ignore + if ( $this->is_wc_gte_30() ) { + $product_ids = $post_wc_sc_add_product_ids; + } else { + $product_ids = array_filter( array_map( 'trim', explode( ',', $post_wc_sc_add_product_ids ) ) ); + } + $add_product_details = array(); + if ( ! empty( $product_ids ) ) { + $quantity = $post_wc_sc_add_product_qty; + $discount_amount = $post_wc_sc_product_discount_amount; + $discount_type = $post_wc_sc_product_discount_type; + foreach ( $product_ids as $id ) { + $data = array(); + $data['product_id'] = $id; + $data['quantity'] = $quantity; + $data['discount_amount'] = $discount_amount; + $data['discount_type'] = $discount_type; + $add_product_details[] = $data; + } + } + $coupon->update_meta_data( 'wc_sc_add_product_details', $add_product_details ); + } else { + $coupon->update_meta_data( 'wc_sc_add_product_details', array() ); + } + + if ( isset( $data['wc_sc_max_discount'] ) ) { // phpcs:ignore + $max_discount = wc_clean( wp_unslash( $data['wc_sc_max_discount'] ) ); // phpcs:ignore + $coupon->update_meta_data( 'wc_sc_max_discount', $max_discount ); + } + + if ( isset( $data['wc_sc_expiry_time'] ) ) { // phpcs:ignore + $expiry_time = wc_clean( wp_unslash( $data['wc_sc_expiry_time'] ) ); // phpcs:ignore + $coupon->update_meta_data( 'wc_sc_expiry_time', $expiry_time ); + } + + if ( ! empty( $post_discount_type ) && 'smart_coupon' === $post_discount_type && ! empty( $post_coupon_amount ) ) { + $coupon->update_meta_data( 'wc_sc_original_amount', $post_coupon_amount ); + } + + if ( $this->is_callable( $coupon, 'save' ) ) { + $coupon->save(); + } + } + } + + /** + * Add a tab in coupon data metabox + * + * @param array $tabs Existing tabs. + * @return array $tabs With additional tab + */ + public function smart_coupons_data_tabs( $tabs = array() ) { + + $tabs['wc_sc_actions'] = array( + 'label' => __( 'Actions', 'woocommerce-smart-coupons' ), + 'target' => 'wc_smart_coupons_actions', + 'class' => '', + ); + + return $tabs; + } + + /** + * Panel for Smart Coupons additional data fields + * + * @param integer $coupon_id The coupon id. + * @param WC_Coupon $coupon The coupon object. + */ + public function smart_coupons_data_panels( $coupon_id = 0, $coupon = null ) { + + $add_product_details = ( ! empty( $coupon_id ) ) ? $this->get_post_meta( $coupon_id, 'wc_sc_add_product_details', true ) : array(); + $add_product_qty = ( isset( $add_product_details[0]['quantity'] ) ) ? $add_product_details[0]['quantity'] : 1; + $discount_amount = ( isset( $add_product_details[0]['discount_amount'] ) && '' !== $add_product_details[0]['discount_amount'] ) ? $add_product_details[0]['discount_amount'] : ''; + $discount_type = ( ! empty( $add_product_details[0]['discount_type'] ) ) ? $add_product_details[0]['discount_type'] : 'percent'; + + $is_js_started = did_action( 'wc_sc_enhanced_select_script_start' ); + if ( 0 === $is_js_started ) { + do_action( 'wc_sc_enhanced_select_script_start' ); + } + ?> +
          +
          +

          +

          + + + is_wc_gte_30() ) { ?> + + + get_formatted_name() ); + } + } + } + ?> + + +

          +

          + + + +

          +

          + + + + +

          +
          + +
          + plugin_url() ) . '/assets/'; + + // Register scripts. + if ( ! wp_script_is( 'woocommerce_admin', 'registered' ) ) { + wp_register_script( 'woocommerce_admin', WC()->plugin_url() . '/assets/js/admin/woocommerce_admin' . $suffix . '.js', array( 'jquery', 'jquery-blockui', 'jquery-ui-sortable', 'jquery-ui-widget', 'jquery-ui-core', 'jquery-tiptip' ), WC()->version, false ); + } + + if ( $this->is_wc_gte_32() ) { + wp_register_script( 'wc-sc-select2', WC()->plugin_url() . '/assets/js/selectWoo/selectWoo.full' . $suffix . '.js', array( 'jquery' ), WC()->version, false ); + } else { + wp_register_script( 'wc-sc-select2', WC()->plugin_url() . '/assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WC()->version, false ); + } + + if ( ! wp_script_is( 'wc-enhanced-select', 'registered' ) ) { + wp_register_script( 'wc-enhanced-select', WC()->plugin_url() . '/assets/js/admin/wc-enhanced-select' . $suffix . '.js', array( 'jquery', 'wc-sc-select2' ), WC()->version, false ); + } + $wc_sc_select_params = array( + 'i18n_matches_1' => _x( 'One result is available, press enter to select it.', 'enhanced select', 'woocommerce-smart-coupons' ), + 'i18n_matches_n' => _x( '%qty% results are available, use up and down arrow keys to navigate.', 'enhanced select', 'woocommerce-smart-coupons' ), + 'i18n_no_matches' => _x( 'No matches found', 'enhanced select', 'woocommerce-smart-coupons' ), + 'i18n_ajax_error' => _x( 'Searching…', 'enhanced select', 'woocommerce-smart-coupons' ), + 'i18n_input_too_short_1' => _x( 'Please enter 1 or more characters', 'enhanced select', 'woocommerce-smart-coupons' ), + 'i18n_input_too_short_n' => _x( 'Please enter %qty% or more characters', 'enhanced select', 'woocommerce-smart-coupons' ), + 'i18n_input_too_long_1' => _x( 'Please delete 1 character', 'enhanced select', 'woocommerce-smart-coupons' ), + 'i18n_input_too_long_n' => _x( 'Please delete %qty% characters', 'enhanced select', 'woocommerce-smart-coupons' ), + 'i18n_selection_too_long_1' => _x( 'You can only select 1 item', 'enhanced select', 'woocommerce-smart-coupons' ), + 'i18n_selection_too_long_n' => _x( 'You can only select %qty% items', 'enhanced select', 'woocommerce-smart-coupons' ), + 'i18n_load_more' => _x( 'Loading more results…', 'enhanced select', 'woocommerce-smart-coupons' ), + 'i18n_searching' => _x( 'Searching…', 'enhanced select', 'woocommerce-smart-coupons' ), + 'ajax_url' => admin_url( 'admin-ajax.php' ), + 'search_products_nonce' => wp_create_nonce( 'search-products' ), + 'search_customers_nonce' => wp_create_nonce( 'search-customers' ), + ); + + $params = array( + 'strings' => array( + 'import_products' => '', + 'export_products' => '', + ), + 'urls' => array( + 'import_products' => '', + 'export_products' => '', + ), + ); + + wp_localize_script( 'woocommerce_admin', 'woocommerce_admin', $params ); + wp_localize_script( 'wc-sc-select2', 'wc_enhanced_select_params', $wc_sc_select_params ); + + wp_enqueue_script( 'woocommerce_admin' ); + wp_enqueue_style( 'woocommerce_admin_styles', WC()->plugin_url() . '/assets/css/admin.css', array(), WC()->version ); + + wp_enqueue_script( 'wc-sc-select2' ); + wp_enqueue_script( 'wc-enhanced-select' ); + wp_enqueue_style( 'wc-sc-select2', $assets_path . 'css/select2.css', array(), WC()->version ); + + } + + /** + * Enhanced select script end + */ + public function enhanced_select_script_end() { + ?> + + 'false', + 'message' => __( 'Could not locate WooCommerce', 'woocommerce-smart-coupons' ), + ) + ); + } + include_once dirname( WC_PLUGIN_FILE ) . '/includes/class-wc-ajax.php'; + } + + $term = (string) urldecode( sanitize_text_field( wp_unslash( $_GET['term'] ) ) ); // phpcs:ignore + + WC_AJAX::json_search_products( $term, true ); + + } + + /** + * Remove variation parent from search result + * + * @param array $products Array of product ids with product name. + * @return array $products Array of product ids with product name after removing variation parent + */ + public function exclude_variation_parent( $products = null ) { + + $backtrace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ); // phpcs:ignore + + if ( 'wc_sc_json_search_products_and_variations' === $backtrace[5]['function'] ) { + if ( ! empty( $products ) ) { + $product_ids = array_keys( $products ); + $parent_ids = array_map( 'wp_get_post_parent_id', $product_ids ); + $parent_ids = array_filter( array_unique( $parent_ids ) ); + foreach ( $parent_ids as $parent ) { + unset( $products[ $parent ] ); + } + } + } + + return $products; + + } + + /** + * Function to add new discount type 'smart_coupon' + * + * @param array $discount_types Existing discount types. + * @return array $discount_types Including smart coupon discount type. + */ + public function add_smart_coupon_discount_type( $discount_types ) { + global $store_credit_label; + + $discount_types['smart_coupon'] = ! empty( $store_credit_label['singular'] ) ? ucfirst( $store_credit_label['singular'] ) : __( 'Store Credit / Gift Certificate', 'woocommerce-smart-coupons' ); + + return $discount_types; + } + + /** + * Function to enqueue required styles and scripts for Smart Coupons' custom fields + */ + public function enqueue_styles_scripts() { + global $post; + + if ( ! empty( $post->post_type ) && 'shop_coupon' === $post->post_type && ! empty( $post->ID ) ) { + + $coupon = ( ! empty( $post->ID ) ) ? new WC_Coupon( $post->ID ) : null; + $is_callable_coupon_get_meta = $this->is_callable( $coupon, 'get_meta' ); + + // Compatibility between expiry_date & date_expires meta field. + if ( $this->is_wc_gte_30() ) { + $date_expires = ( true === $is_callable_coupon_get_meta ) ? $coupon->get_date_expires() : intval( get_post_meta( $post->ID, 'date_expires', true ) ); + $expiry_date = get_post_meta( $post->ID, 'expiry_date', true ); + + if ( is_object( $date_expires ) && is_a( $date_expires, 'WC_DateTime' ) && $this->is_callable( $date_expires, 'getTimestamp' ) ) { + $date_expires = $date_expires->getTimestamp(); + } + + if ( ! empty( $expiry_date ) && empty( $date_expires ) ) { + $date_expires = $this->wc_string_to_datetime_to_timestamp( $expiry_date ); + $date_expires = $this->get_date_expires_value( $date_expires ); + $this->update_post_meta( $post->ID, 'date_expires', $date_expires ); + delete_post_meta( $post->ID, 'expiry_date' ); // No need to run CRUD function as this meta_key no longer exists. + $js = "jQuery('input#expiry_date').val('" . $expiry_date . "');"; + wc_enqueue_js( $js ); + } + } + + if ( is_callable( 'WC_Smart_Coupons::get_smart_coupons_plugin_data' ) ) { + $plugin_data = WC_Smart_Coupons::get_smart_coupons_plugin_data(); + $version = $plugin_data['Version']; + } else { + $version = ''; + } + + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; + + if ( ! wp_style_is( 'jquery-ui-style', 'registered' ) ) { + wp_register_style( 'jquery-ui-style', WC()->plugin_url() . '/assets/css/jquery-ui/jquery-ui' . $suffix . '.css', array(), WC()->version ); + } + + if ( ! wp_style_is( 'jquery-ui-timepicker', 'registered' ) ) { + wp_register_style( 'jquery-ui-timepicker', untrailingslashit( plugins_url( '/', WC_SC_PLUGIN_FILE ) ) . '/assets/css/jquery-ui-timepicker-addon' . $suffix . '.css', array( 'jquery-ui-style' ), $version ); + } + + if ( ! wp_style_is( 'jquery-ui-timepicker' ) ) { + wp_enqueue_style( 'jquery-ui-timepicker' ); + } + + if ( ! wp_script_is( 'jquery-ui-timepicker', 'registered' ) ) { + wp_register_script( 'jquery-ui-timepicker', untrailingslashit( plugins_url( '/', WC_SC_PLUGIN_FILE ) ) . '/assets/js/jquery-ui-timepicker-addon' . $suffix . '.js', array( 'jquery', 'jquery-ui-datepicker', 'jquery-ui-slider', 'wp-i18n' ), $version, true ); + } + + if ( ! wp_script_is( 'jquery-ui-timepicker' ) ) { + wp_enqueue_script( 'jquery-ui-timepicker' ); + } + + $screen = get_current_screen(); + if ( 'shop_coupon' === $screen->id ) { + ?> + + import_page = 'wc-sc-coupons'; + add_filter( 'upload_dir', array( $this, 'upload_dir' ) ); + ob_start(); + } + + /** + * Get single instance of WC_SC_Coupon_Import + * + * @return WC_SC_Coupon_Import Singleton object of WC_SC_Coupon_Import + */ + public static function get_instance() { + // Check if instance is already exists. + if ( is_null( self::$instance ) ) { + self::$instance = new self(); + } + + return self::$instance; + } + + /** + * Handle call to functions which is not available in this class + * + * @param string $function_name The function name. + * @param array $arguments Array of arguments passed while calling $function_name. + * @return result of function call + */ + public function __call( $function_name, $arguments = array() ) { + + global $woocommerce_smart_coupon; + + if ( ! is_callable( array( $woocommerce_smart_coupon, $function_name ) ) ) { + return; + } + + if ( ! empty( $arguments ) ) { + return call_user_func_array( array( $woocommerce_smart_coupon, $function_name ), $arguments ); + } else { + return call_user_func( array( $woocommerce_smart_coupon, $function_name ) ); + } + + } + + /** + * Registered callback function for the WordPress Importer + * + * Manages the three separate stages of the CSV import process + */ + public function dispatch() { + global $woocommerce_smart_coupon; + $step = ( empty( $_GET['step'] ) ) ? 0 : absint( wc_clean( wp_unslash( $_GET['step'] ) ) ); // phpcs:ignore + + switch ( $step ) { + case 0: + $this->greet(); + break; + case 1: + check_admin_referer( 'import-upload' ); + if ( $this->handle_upload() ) { + $this->import_options(); + } + break; + case 2: + $action_processed = $this->process_bulk_generate_action(); + $url = admin_url( 'edit.php?post_type=shop_coupon' ); + + ob_clean(); + wp_safe_redirect( $url ); + exit; + } + } + + /** + * Process bulk generation action + * + * @return bool $action_processed Is action processed + */ + public function process_bulk_generate_action() { + global $woocommerce_smart_coupon; + + check_admin_referer( 'import-woocommerce-coupon' ); + + $schedule_action = ''; + $permission_error = false; + $action_processed = false; + + $post_smart_coupons_generate_action = ( isset( $_POST['smart_coupons_generate_action'] ) ) ? wc_clean( wp_unslash( $_POST['smart_coupons_generate_action'] ) ) : ''; // phpcs:ignore + $post_generate_and_import = ( isset( $_POST['generate_and_import'] ) ) ? wc_clean( wp_unslash( $_POST['generate_and_import'] ) ) : ''; // phpcs:ignore + + if ( empty( $post_smart_coupons_generate_action ) && empty( $post_generate_and_import ) ) { + + $this->id = ( ! empty( $_POST['import_id'] ) ) ? absint( wc_clean( wp_unslash( $_POST['import_id'] ) ) ) : 0; // phpcs:ignore + $this->file_url = ( ! empty( $_POST['import_url'] ) ) ? wc_clean( wp_unslash( $_POST['import_url'] ) ) : ''; // phpcs:ignore + + if ( $this->id ) { + $file = get_attached_file( $this->id ); + } else { + $file = ( ! empty( $this->file_url ) ) ? ABSPATH . $this->file_url : ''; + } + + $upload_dir = wp_get_upload_dir(); + $csv_file_data['file_name'] = basename( $file ); + $csv_file_data['wp_upload_dir'] = $upload_dir['basedir'] . '/woocommerce_uploads/'; + + $_POST['export_file'] = $csv_file_data; + + if ( ! isset( $_POST['no_of_coupons_to_generate'] ) ) { + if ( ! $this->is_php_gte( '8.0.0' ) ) { + ini_set( 'auto_detect_line_endings', true ); // phpcs:ignore + } + $fp = file( $file ); + if ( is_array( $fp ) && ! empty( $fp ) ) { + $_POST['no_of_coupons_to_generate'] = count( $fp ) - 1; + } else { + $permission_error = true; + } + } + + $total_coupons_to_generate = sanitize_text_field( wp_unslash( $_POST['no_of_coupons_to_generate'] ) ); + $_POST['total_coupons_to_generate'] = $total_coupons_to_generate; + + $_POST['action_stage'] = 0; + $_POST['smart_coupons_generate_action'] = 'import_from_csv'; + + update_option( 'woo_sc_generate_coupon_posted_data', $_POST, 'no' ); + + update_option( 'start_time_woo_sc', time(), 'no' ); + update_option( 'current_time_woo_sc', time(), 'no' ); + update_option( 'all_tasks_count_woo_sc', sanitize_text_field( wp_unslash( $_POST['no_of_coupons_to_generate'] ) ), 'no' ); + update_option( 'remaining_tasks_count_woo_sc', sanitize_text_field( wp_unslash( $_POST['no_of_coupons_to_generate'] ) ), 'no' ); + + as_unschedule_action( 'woo_sc_generate_coupon_csv' ); + as_unschedule_action( 'woo_sc_import_coupons_from_csv' ); + + $schedule_action = 'woo_sc_import_coupons_from_csv'; + } else { + + // If we are exporting coupons then create export file and save its path in options table. + $coupon_column_headers = $this->get_coupon_column_headers(); + $coupon_posts_headers = $coupon_column_headers['posts_headers']; + $coupon_postmeta_headers = $coupon_column_headers['postmeta_headers']; + $coupon_term_headers = $coupon_column_headers['term_headers']; + $column_headers = array_merge( $coupon_posts_headers, $coupon_postmeta_headers, $coupon_term_headers ); + $export_file = $woocommerce_smart_coupon->export_coupon_csv( $column_headers, array() ); // phpcs:ignore + + if ( is_array( $export_file ) && ! isset( $export_file['error'] ) ) { + + // Create CSV file. + $csv_folder = $export_file['wp_upload_dir']; + $filename = str_replace( array( '\'', '"', ',', ';', '<', '>', '/', ':' ), '', $export_file['file_name'] ); + $csvfilename = $csv_folder . $filename; + $fp = fopen( $csvfilename, 'w' ); // phpcs:ignore + if ( false !== $fp ) { + fwrite( $fp , $export_file['file_content'] ); // phpcs:ignore + fclose( $fp ); // phpcs:ignore + $_POST['export_file'] = $export_file; + + $total_coupons_to_generate = sanitize_text_field( wp_unslash( $_POST['no_of_coupons_to_generate'] ) ); + $_POST['total_coupons_to_generate'] = $total_coupons_to_generate; + + $_POST['action_stage'] = 0; + + update_option( 'woo_sc_generate_coupon_posted_data', $_POST, 'no' ); + update_option( 'start_time_woo_sc', time(), 'no' ); + update_option( 'current_time_woo_sc', time(), 'no' ); + update_option( 'all_tasks_count_woo_sc', sanitize_text_field( wp_unslash( $_POST['no_of_coupons_to_generate'] ) ), 'no' ); + update_option( 'remaining_tasks_count_woo_sc', sanitize_text_field( wp_unslash( $_POST['no_of_coupons_to_generate'] ) ), 'no' ); + + as_unschedule_action( 'woo_sc_generate_coupon_csv' ); + as_unschedule_action( 'woo_sc_import_coupons_from_csv' ); + delete_option( 'woo_sc_action_data' ); + + $schedule_action = 'woo_sc_generate_coupon_csv'; + } else { + $permission_error = true; + } + } else { + $permission_error = true; + } + } + + // Proceed only if there is not any file permission error. + if ( true !== $permission_error ) { + if ( ( ! empty( $post_smart_coupons_generate_action ) && ( 'woo_sc_is_email_imported_coupons' === $post_smart_coupons_generate_action || 'send_store_credit' === $post_smart_coupons_generate_action ) ) || ( isset( $_POST['woo_sc_is_email_imported_coupons'] ) ) ) { + update_option( 'woo_sc_is_email_imported_coupons', 'yes', 'no' ); + } + if ( isset( $_POST['wc_sc_update_existing_coupons'] ) ) { + update_option( 'wc_sc_update_existing_coupons', 'yes', 'no' ); + } + + $generate_action = ( isset( $_POST['smart_coupons_generate_action'] ) ) ? wc_clean( wp_unslash( $_POST['smart_coupons_generate_action'] ) ) : ''; // phpcs:ignore + $is_import_email = get_option( 'woo_sc_is_email_imported_coupons' ); + + if ( 'yes' === $is_import_email && ( isset( $_POST['import_id'] ) || isset( $_POST['import_url'] ) ) ) { // phpcs:ignore + $bulk_action = 'import_email'; + } elseif ( isset( $_POST['import_id'] ) || isset( $_POST['import_url'] ) ) { // phpcs:ignore + $bulk_action = 'import'; + } elseif ( 'woo_sc_is_email_imported_coupons' === $generate_action ) { + $bulk_action = 'generate_email'; + } elseif ( 'send_store_credit' === $generate_action ) { + $bulk_action = 'send_store_credit'; + } else { + $bulk_action = 'generate'; + } + + update_option( 'bulk_coupon_action_woo_sc', $bulk_action, 'no' ); + + if ( ! empty( $schedule_action ) ) { + do_action( $schedule_action ); + $action_processed = true; + } + } + + return $action_processed; + } + + /** + * Create new posts based on import information + * + * @param array $post The post. + * @return int $global_coupon_id The imported coupon id + */ + public function process_coupon( $post ) { + global $woocommerce_smart_coupon; + + $global_coupon_id = ''; // for handling global coupons. + + // Get parent. + $post_parent = absint( $post['post_parent'] ); + + if ( ! empty( $post_parent ) ) { + // if we already know the parent, map it to the new local ID. + if ( isset( $this->processed_posts[ $post_parent ] ) ) { + $post_parent = $this->processed_posts[ $post_parent ]; + // otherwise record the parent for later. + } else { + $this->post_orphans[ intval( $post['post_id'] ) ] = $post_parent; + $post_parent = 0; + } + } + + // Generate coupon code if post_title is empty. + $post_title = ( ! empty( $post['post_title'] ) ) ? $post['post_title'] : $woocommerce_smart_coupon->generate_unique_code(); + + $postdata = array( + 'import_id' => $post['post_id'], + 'post_author' => ( ! empty( $post['post_author'] ) ) ? absint( $post['post_author'] ) : get_current_user_id(), + 'post_date' => ( ! empty( $post['post_date'] ) ) ? gmdate( 'Y-m-d H:i:s', $this->strtotime( $post['post_date'] ) ) : gmdate( 'Y-m-d H:i:s', time() ), + 'post_date_gmt' => ( ! empty( $post['post_date_gmt'] ) ) ? gmdate( 'Y-m-d H:i:s', $this->strtotime( $post['post_date_gmt'] ) ) : ( ( ! empty( $post['post_date'] ) ) ? gmdate( 'Y-m-d H:i:s', ( $this->strtotime( $post['post_date'] ) - $this->wc_timezone_offset() ) ) : gmdate( 'Y-m-d H:i:s', time() ) ), + 'post_content' => $post['post_content'], + 'post_excerpt' => $post['post_excerpt'], + 'post_title' => $post_title, + 'post_name' => ( ! empty( $post['post_name'] ) ) ? $post['post_name'] : ( ! empty( $post['post_title'] ) ? sanitize_title( $post['post_title'] ) : sanitize_title( $post_title ) ), + 'post_status' => $post['post_status'], + 'post_parent' => $post_parent, + 'menu_order' => $post['menu_order'], + 'post_type' => 'shop_coupon', + 'post_password' => $post['post_password'], + 'comment_status' => $post['comment_status'], + ); + + $update_existing_coupons = get_option( 'wc_sc_update_existing_coupons' ); + + $_coupon = new WC_Coupon( $postdata['post_title'] ); + + if ( 'yes' === $update_existing_coupons ) { + $coupon_id = $_coupon->get_id(); + if ( empty( $coupon_id ) ) { + $this->skipped++; + update_option( 'skipped_tasks_count_woo_sc', $this->skipped, 'no' ); + unset( $post ); + return; + } + } else { + $_coupon->set_id( 0 ); + } + + $_coupon->set_date_created( $postdata['post_date'] ); + $_coupon->set_description( $postdata['post_excerpt'] ); + + if ( $this->is_wc_greater_than( '6.1.2' ) && $this->is_callable( $_coupon, 'set_status' ) ) { + $_coupon->set_status( $postdata['post_status'] ); + } + + $post_id = $_coupon->save(); + + if ( ! empty( $post_id ) ) { + $postdata = array_diff_key( $postdata, array_flip( array( 'post_date', 'post_excerpt', 'post_title', 'post_status', 'post_type' ) ) ); + $postdata['ID'] = $post_id; + wp_update_post( $postdata ); + } else { + $this->skipped++; + update_option( 'skipped_tasks_count_woo_sc', $this->skipped, 'no' ); + unset( $post ); + return; + } + + unset( $postdata ); + + // map pre-import ID to local ID. + if ( empty( $post['post_id'] ) ) { + $post['post_id'] = $post_id; + } + $this->processed_posts[ intval( $post['post_id'] ) ] = $post_id; + + $coupon_code = strtolower( $post_title ); + + $_coupon = new WC_Coupon( $_coupon ); + + // add/update post meta. + if ( ! empty( $post['postmeta'] ) && is_array( $post['postmeta'] ) ) { + + $postmeta = array(); + foreach ( $post['postmeta'] as $meta ) { + $postmeta[ $meta['key'] ] = $meta['value']; + } + + $is_callable_update_meta_data = $this->is_callable( $_coupon, 'update_meta_data' ); + + foreach ( $postmeta as $meta_key => $meta_value ) { + switch ( $meta_key ) { + + case 'customer_email': + $customer_emails = maybe_unserialize( $meta_value ); + break; + + case 'coupon_amount': + $coupon_amount = maybe_unserialize( $meta_value ); + $discount_type = ! empty( $postmeta['discount_type'] ) ? $postmeta['discount_type'] : ''; + if ( ! empty( $discount_type ) && 'smart_coupon' === $discount_type ) { + if ( true === $is_callable_update_meta_data ) { + $_coupon->update_meta_data( 'wc_sc_original_amount', $coupon_amount ); + } else { + update_post_meta( $post_id, 'wc_sc_original_amount', $coupon_amount ); + } + } + break; + + case 'expiry_date': + if ( empty( $meta_value ) && ! empty( $postmeta['sc_coupon_validity'] ) && ! empty( $postmeta['validity_suffix'] ) ) { + $sc_coupon_validity = $postmeta['sc_coupon_validity']; + $validity_suffix = $postmeta['validity_suffix']; + $meta_value = gmdate( 'Y-m-d', $this->strtotime( "+$sc_coupon_validity $validity_suffix" ) ); + } + break; + + case 'discount_type': + $discount_type = maybe_unserialize( $meta_value ); + break; + + case 'free_shipping': + $allowed_free_shipping = maybe_unserialize( $meta_value ); + break; + + case '_used_by': + if ( ! empty( $meta_value ) ) { + $used_by = explode( '|', $meta_value ); + if ( ! empty( $used_by ) && is_array( $used_by ) ) { + if ( $this->is_callable( $_coupon, 'set_used_by' ) ) { + $_coupon->set_used_by( $used_by ); + } else { + foreach ( $used_by as $_used_by ) { + add_post_meta( $post_id, $meta_key, $_used_by ); + } + } + } + } + break; + + case 'wc_sc_add_product_details': + if ( ! empty( $meta_value ) ) { + $add_product_details = array(); + $product_details = explode( '|', $meta_value ); + if ( ! empty( $product_details ) ) { + foreach ( $product_details as $index => $product_detail ) { + $data = array_map( 'trim', explode( ',', $product_detail ) ); + if ( empty( $data[0] ) ) { + continue; + } + $product_data['product_id'] = $data[0]; + $product_data['quantity'] = ( ! empty( $data[1] ) ) ? absint( $data[1] ) : 1; + $product_data['discount_amount'] = ( ! empty( $data[2] ) ) ? $data[2] : ''; + $product_data['discount_type'] = ( ! empty( $data[3] ) ) ? $data[3] : 'percent'; + $add_product_details[] = $product_data; + } + } + $meta_value = $add_product_details; + } + break; + + default: + $meta_value = apply_filters( + 'wc_sc_process_coupon_meta_value_for_import', + $meta_value, + array( + 'meta_key' => $meta_key, // phpcs:ignore + 'postmeta' => $postmeta, + 'post' => $post, + 'coupon_importer' => $this, + ) + ); + + } + + if ( $meta_key ) { + if ( 'customer_email' === $meta_key && ! empty( $postmeta['sc_disable_email_restriction'] ) && 'yes' === $postmeta['sc_disable_email_restriction'] ) { + continue; + } + if ( '_used_by' === $meta_key ) { + continue; + } + $is_import_meta = apply_filters( + 'wc_sc_is_import_meta', + true, + array( + 'meta_key' => $meta_key, // phpcs:ignore + 'postmeta' => $postmeta, + 'post' => $post, + 'coupon_importer' => $this, + ) + ); + if ( true === $is_import_meta ) { + if ( $this->is_wc_gte_30() ) { + if ( 'expiry_date' === $meta_key ) { + if ( ! empty( $meta_value ) ) { + $meta_value = $this->wc_string_to_datetime_to_timestamp( $meta_value ); + $meta_value = $this->get_date_expires_value( $meta_value ); + } else { + $meta_value = null; + } + if ( true === $is_callable_update_meta_data ) { + $_coupon->set_date_expires( $meta_value ); + } else { + update_post_meta( $post_id, 'date_expires', $meta_value ); + } + } else { + $key = ! empty( $meta_key ) && is_string( $meta_key ) ? ltrim( $meta_key, '_' ) : ''; + $key_to_props = array( + 'coupon_amount' => 'amount', + 'customer_email' => 'email_restrictions', + 'exclude_product_categories' => 'excluded_product_categories', + 'exclude_product_ids' => 'excluded_product_ids', + ); + if ( array_key_exists( $key, $key_to_props ) ) { + $key = $key_to_props[ $key ]; + } + $function = 'set_' . $key; + $has_setter = $this->is_callable( $_coupon, $function ); + if ( true === $has_setter ) { + if ( in_array( $key, array( 'individual_use', 'free_shipping', 'exclude_sale_items' ), true ) ) { + $value = $this->wc_string_to_bool( maybe_unserialize( $meta_value ) ); + } elseif ( in_array( $key, array( 'product_ids', 'exclude_product_ids', 'excluded_product_ids' ), true ) ) { + $value = maybe_unserialize( $meta_value ); + if ( ! is_array( $value ) ) { + if ( false !== strpos( $value, ',' ) ) { + $value = explode( ',', $value ); + $value = array_filter( array_map( 'intval', $value ) ); + } else { + $value = array( $value ); + } + } + } else { + $value = maybe_unserialize( $meta_value ); + } + $_coupon->{$function}( $value ); + } elseif ( true === $is_callable_update_meta_data ) { + $_coupon->update_meta_data( $meta_key, maybe_unserialize( $meta_value ) ); + } else { + update_post_meta( $post_id, $meta_key, maybe_unserialize( $meta_value ) ); + } + } + } else { + if ( true === $is_callable_update_meta_data ) { + $_coupon->update_meta_data( $meta_key, maybe_unserialize( $meta_value ) ); + } else { + update_post_meta( $post_id, $meta_key, maybe_unserialize( $meta_value ) ); + } + } + } + } + } + + if ( $this->is_callable( $_coupon, 'save' ) ) { + $_coupon->save(); + } + + unset( $post['postmeta'] ); + } + + // Update term data. + if ( ! empty( $post['term_data'] ) && is_array( $post['term_data'] ) ) { + foreach ( $post['term_data'] as $data ) { + if ( isset( $data['key'] ) && 'sc_coupon_category' === $data['key'] ) { + if ( ! empty( $data['value'] ) ) { + $coupon_cat_details = explode( '|', $data['value'] ); + wp_set_post_terms( $post_id, $coupon_cat_details, 'sc_coupon_category', true ); + } + } + } + unset( $post['term_data'] ); + } + + $posted_data = get_option( 'woo_sc_generate_coupon_posted_data', true ); + if ( isset( $posted_data['sc_coupon_category'] ) && ! empty( $posted_data['sc_coupon_category'] ) ) { + wp_set_post_terms( $post_id, $posted_data['sc_coupon_category'], 'sc_coupon_category', true ); + } + + $is_email_imported_coupons = get_option( 'woo_sc_is_email_imported_coupons' ); + + if ( 'yes' === $is_email_imported_coupons && ! empty( $customer_emails ) && ! is_scalar( $customer_emails ) && ( ! empty( $coupon_amount ) || 'yes' === $allowed_free_shipping ) && ! empty( $coupon_code ) && ! empty( $discount_type ) ) { + $coupon = array( + 'amount' => $coupon_amount, + 'code' => $coupon_code, + ); + $coupon_title = array(); + foreach ( $customer_emails as $customer_email ) { + $coupon_title[ $customer_email ] = $coupon; + } + + $message = ''; + if ( ! empty( $posted_data ) && is_array( $posted_data ) ) { + $message = ( ! empty( $posted_data['smart_coupon_message'] ) ) ? $posted_data['smart_coupon_message'] : ''; + } + + $sending_timestamp = strtotime( $post['post_date'] ); + $current_timestamp = time(); + if ( $woocommerce_smart_coupon->is_valid_timestamp( $sending_timestamp ) && $sending_timestamp > $current_timestamp ) { + + foreach ( $coupon_title as $coupon_receiver_email => $coupon_data ) { + $action_args = array( + 'auto_generate' => 'no', + 'coupon_id' => $post_id, + 'parent_id' => ( ! empty( $post['post_parent'] ) ) ? $post['post_parent'] : 0, // Parent coupon id. + 'receiver_email' => $coupon_receiver_email, + 'ref_key' => uniqid(), // A unique timestamp key to relate action schedulers with their coupons. + ); + + $is_scheduled = $woocommerce_smart_coupon->schedule_coupon_email( $action_args, $sending_timestamp ); + + if ( ! $is_scheduled ) { + /* translators: 1. Receiver email 2. Coupon code */ + $woocommerce_smart_coupon->log( 'error', sprintf( __( 'Failed to schedule email to "%1$s" for coupon "%2$s".', 'woocommerce-smart-coupons' ), $coupon_receiver_email, $coupon_data['code'] ) ); + } + } + } else { + $woocommerce_smart_coupon->sa_email_coupon( $coupon_title, $discount_type, 0, '', $message ); + } + } + + $this->imported++; + + // code for handling global coupons option. + if ( ( ! empty( $post['post_status'] ) && 'publish' === $post['post_status'] ) + && ( isset( $postmeta['customer_email'] ) && array() === $postmeta['customer_email'] ) + && ( isset( $postmeta['sc_is_visible_storewide'] ) && 'yes' === $postmeta['sc_is_visible_storewide'] ) + && ( isset( $postmeta['auto_generate_coupon'] ) && 'yes' !== $postmeta['auto_generate_coupon'] ) + && ( isset( $postmeta['discount_type'] ) && 'smart_coupon' !== $postmeta['discount_type'] ) ) { + + $global_coupon_id = $post_id; + } + + unset( $post ); + + return $global_coupon_id; + } + + /** + * Parses the CSV file and prepares us for the task of processing parsed data + * + * @param string $file Path to the CSV file for importing. + */ + public function import_start( $file ) { + + if ( ! is_file( $file ) ) { + echo '

          ' . esc_html__( 'Sorry, there has been an error.', 'woocommerce-smart-coupons' ) . '
          '; + echo esc_html__( 'The file does not exist, please try again.', 'woocommerce-smart-coupons' ) . '

          '; + die(); + } + + $this->parser = new WC_SC_Coupon_Parser( 'shop_coupon' ); + $import_data = $this->parser->parse_data( $file ); + + $this->parsed_data = $import_data[0]; + $this->raw_headers = $import_data[1]; + + unset( $import_data ); + + wp_defer_term_counting( true ); + wp_defer_comment_counting( true ); + + } + + /** + * Added to http_request_timeout filter to force timeout at 60 seconds during import + * + * @param int $val The current value. + * @return int 60 + */ + public function bump_request_timeout( $val ) { + return 60; + } + + /** + * Performs post-import cleanup of files and the cache + */ + public function import_end() { + + wp_cache_flush(); + + wp_defer_term_counting( false ); + wp_defer_comment_counting( false ); + + do_action( 'import_end' ); + + } + + /** + * Handles the CSV upload and initial parsing of the file to prepare for + * displaying author import options + * + * @return bool False if error uploading or invalid file, true otherwise + */ + public function handle_upload() { + + $post_file_url = ( ! empty( $_POST['file_url'] ) ) ? wc_clean( wp_unslash( $_POST['file_url'] ) ) : ''; // phpcs:ignore + + if ( empty( $post_file_url ) ) { + $file = wp_import_handle_upload(); + + if ( isset( $file['error'] ) ) { + echo '

          ' . esc_html__( 'Sorry, there has been an error.', 'woocommerce-smart-coupons' ) . '
          '; + echo esc_html( $file['error'] ) . '

          '; + return false; + } + + $this->id = absint( $file['id'] ); + + } else { + + if ( file_exists( ABSPATH . $post_file_url ) ) { + $this->file_url = esc_attr( $post_file_url ); + } else { + echo '

          ' . esc_html__( 'Sorry, there has been an error.', 'woocommerce-smart-coupons' ) . '

          '; + return false; + } + } + + return true; + } + + /** + * Function to validate import CSV file is following correct format + * + * @param array $header File headers. + * @return bool + */ + public function validate_file_header( $header = array() ) { + + $is_valid = true; + + if ( empty( $header ) || count( $header ) < 21 ) { + $is_valid = false; + } else { + $default = array( + 'post_title', + 'post_excerpt', + 'post_status', + 'post_parent', + 'menu_order', + 'post_date', + 'discount_type', + 'coupon_amount', + 'free_shipping', + 'expiry_date', + 'minimum_amount', + 'maximum_amount', + 'individual_use', + 'exclude_sale_items', + 'product_ids', + 'exclude_product_ids', + 'product_categories', + 'exclude_product_categories', + 'customer_email', + 'usage_limit', + 'usage_limit_per_user', + ); + } + + return $is_valid; + } + + /** + * Display pre-import options + */ + public function import_options() { + $j = 0; + + if ( $this->id ) { + $file = get_attached_file( $this->id ); + } else { + $file = ( ! empty( $this->file_url ) ) ? ABSPATH . $this->file_url : ''; + } + + // Set locale. + $enc = $this->mb_detect_encoding( $file, 'UTF-8, ISO-8859-1', true ); + if ( $enc ) { + setlocale( LC_ALL, 'en_US.' . $enc ); + } + if ( ! $this->is_php_gte( '8.0.0' ) ) { + ini_set( 'auto_detect_line_endings', true ); // phpcs:ignore + } + + $is_email_present = false; + + $handle = fopen( $file, 'r' ); // phpcs:ignore + + if ( false !== $handle ) { + + $row = array(); + $raw_headers = array(); + + $header = fgetcsv( $handle, 0 ); // gets header of the file. + + $is_valid = $this->validate_file_header( $header ); + + if ( ! $is_valid ) { + fclose( $handle ); // phpcs:ignore + ?> +
          +

          ' . esc_html__( 'Coupon Import Error', 'woocommerce-smart-coupons' ) . ': ' . esc_html__( 'Invalid CSV file. Make sure your CSV file contains all columns, header row, and data in correct format.', 'woocommerce-smart-coupons' ) . ' ' . esc_html__( 'Download a sample.csv to confirm', 'woocommerce-smart-coupons' ) . '.'; ?>

          +
          + greet(); + return; + } + + while ( false !== ( $postmeta = fgetcsv( $handle, 0 ) ) ) { // phpcs:ignore + foreach ( $header as $key => $heading ) { + if ( ! $heading ) { + continue; + } + + $s_heading = strtolower( $heading ); + $row[ $s_heading ] = ( isset( $postmeta[ $key ] ) ) ? $this->format_data_from_csv( $postmeta[ $key ], $enc ) : ''; + if ( ! $is_email_present && 'customer_email' === $header[ $key ] ) { + if ( ! empty( $row[ $s_heading ] ) && is_email( $row[ $s_heading ] ) ) { + $is_email_present = true; + } + } + $raw_headers[ $s_heading ] = $heading; + } + // Thanks to: Rohit Kumar. + if ( true === $is_email_present ) { + break; + } + } + + fclose( $handle ); // phpcs:ignore + } + ?> + + 'wc-smart-coupons', + 'tab' => 'import-smart-coupons', + 'step' => '2', + ), + admin_url( 'admin.php' ) + ); + ?> +
          + + + + +
          +
          +

          + +
          +
            +
          • +
          • +
          +

          + +

          + is_email_template_enabled(); ?> + +

          + +

          + +
          +
          +
          +
          + +
          + + + +
          +

          +

          ' . esc_html__( 'Click here to download a sample', 'woocommerce-smart-coupons' ) . ', ' . esc_html__( 'and create your CSV based on that.', 'woocommerce-smart-coupons' ); // phpcs:ignore ?>

          +

          +

          +
          +
          +
          + 'wc-smart-coupons', + 'tab' => 'import-smart-coupons', + 'step' => '1', + ), + 'admin.php' + ); + + $bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() ); + $size = size_format( $bytes ); + $upload_dir = wp_get_upload_dir(); + + if ( ! empty( $upload_dir['error'] ) ) { + ?> +
          +

          +

          +
          + +
          +
          + + + +

          +

          +

          ' . esc_html__( 'Enter location on the server', 'woocommerce-smart-coupons' ) . ':'; ?>

          + +   +
          +
          + +
          +
          +
          +
          + + + 'wc_coupon_message', + 'textarea_rows' => 10, + 'editor_class' => 'wp_editor_coupon_message', + 'media_buttons' => true, + 'tinymce' => true, + ); + echo '
          '; + ?> +

          + + get_post_meta( $post->ID, 'wc_coupon_message', true ); ?> + +

          + 'wc_email_message', + 'label' => __( 'Email message?', 'woocommerce-smart-coupons' ), + 'description' => __( + 'Check this box to include above message in order confirmation email', + 'woocommerce-smart-coupons' + ), + ) + ); + echo '
          '; + } + + /** + * Function to save coupon plus data in coupon's meta + * + * @since 1.0 + * + * @param integer $post_id Coupon's id. + * @param WC_Coupon $coupon Current coupon object. + */ + public function wc_process_coupon_message_meta( $post_id = 0, $coupon = null ) { + + if ( empty( $post_id ) ) { + return; + } + + $coupon = new WC_Coupon( $coupon ); + + $allowed_html = wp_kses_allowed_html( 'post' ); + + $additional_allowed_html = array( + 'style' => array(), + ); + + $additional_allowed_html = apply_filters( 'wc_sc_kses_allowed_html_for_coupon_message', $additional_allowed_html, array( 'source' => $this ) ); + + if ( ! empty( $additional_allowed_html ) ) { + foreach ( $additional_allowed_html as $tag => $attributes ) { + if ( ! empty( $attributes ) && array_key_exists( $tag, $allowed_html ) ) { + $allowed_html[ $tag ] = array_merge( $allowed_html[ $tag ], $attributes ); + } else { + $allowed_html[ $tag ] = $attributes; + } + } + } + + if ( $this->is_callable( $coupon, 'update_meta_data' ) && $this->is_callable( $coupon, 'save' ) ) { + if ( isset( $_POST['wc_coupon_message'] ) ) { // phpcs:ignore + $coupon->update_meta_data( 'wc_coupon_message', wp_kses( wp_unslash( $_POST['wc_coupon_message'] ), $allowed_html ) ); // phpcs:ignore + } + if ( isset( $_POST['wc_email_message'] ) ) { // phpcs:ignore + $coupon->update_meta_data( 'wc_email_message', wc_clean( wp_unslash( $_POST['wc_email_message'] ) ) ); // phpcs:ignore + } else { + $coupon->update_meta_data( 'wc_email_message', 'no' ); + } + $coupon->save(); + } else { + if ( isset( $_POST['wc_coupon_message'] ) ) { // phpcs:ignore + update_post_meta( $post_id, 'wc_coupon_message', wp_kses( wp_unslash( $_POST['wc_coupon_message'] ), $allowed_html ) ); // phpcs:ignore + } + if ( isset( $_POST['wc_email_message'] ) ) { // phpcs:ignore + update_post_meta( $post_id, 'wc_email_message', wc_clean( wp_unslash( $_POST['wc_email_message'] ) ) ); // phpcs:ignore + } else { + update_post_meta( $post_id, 'wc_email_message', 'no' ); + } + } + + } + + /** + * Function to print coupon message + * + * @param array $applied_coupons Applied coupons. + */ + public function print_coupon_message( $applied_coupons = array() ) { + + if ( empty( $applied_coupons ) ) { + echo '
          '; + return; + } + + foreach ( $applied_coupons as $coupon_code ) { + + $coupon = new WC_Coupon( $coupon_code ); + if ( ! $this->is_valid( $coupon ) ) { + continue; + } + if ( $this->is_wc_gte_30() ) { + $coupon_id = ( ! empty( $coupon ) && is_callable( array( $coupon, 'get_id' ) ) ) ? $coupon->get_id() : 0; + } else { + $coupon_id = ( ! empty( $coupon->id ) ) ? $coupon->id : 0; + } + $wc_coupon_message = ( $this->is_callable( $coupon, 'get_meta' ) ) ? $coupon->get_meta( 'wc_coupon_message' ) : get_post_meta( $coupon_id, 'wc_coupon_message', true ); + if ( empty( $wc_coupon_message ) ) { + continue; + } + ?> +
          +
          + $this, + 'called_by' => current_filter(), + 'coupon_object' => $coupon, + ) + ); + if ( true === $is_filter_content ) { + $wc_coupon_message = apply_filters( 'the_content', $wc_coupon_message ); + } + ?> + +
          +
          + cart ) || WC()->cart->is_empty() ) { + return; + } + + $applied_coupons = WC()->cart->get_applied_coupons(); + + ?> +
          + print_coupon_message( $applied_coupons ); ?> +
          + cart->get_applied_coupons(); + + $this->print_coupon_message( $applied_coupons ); + + die(); + } + + /** + * Function to add coupon's message in email + * + * @since 1.0 + * + * @param WC_Order $order Order's object. + * @param boolean $bool Not used in this function. + * @param boolean $plain_text Not used in this function. + */ + public function wc_add_coupons_message_in_email( $order = null, $bool = false, $plain_text = false ) { + $used_coupons = $this->get_coupon_codes( $order ); + if ( count( $used_coupons ) <= 0 ) { + return; + } + $show_coupon_message_title = false; + $coupon_messages = ''; + foreach ( $used_coupons as $coupon_code ) { + $coupon = new WC_Coupon( $coupon_code ); + if ( $this->is_wc_gte_30() ) { + $coupon_id = ( ! empty( $coupon ) && is_callable( array( $coupon, 'get_id' ) ) ) ? $coupon->get_id() : 0; + } else { + $coupon_id = ( ! empty( $coupon->id ) ) ? $coupon->id : 0; + } + $is_callable_coupon_get_meta = $this->is_callable( $coupon, 'get_meta' ); + if ( true === $is_callable_coupon_get_meta ) { + $coupon_message = $coupon->get_meta( 'wc_coupon_message' ); + $include_in_email = $coupon->get_meta( 'wc_email_message' ); + } else { + $coupon_message = get_post_meta( $coupon_id, 'wc_coupon_message', true ); + $include_in_email = get_post_meta( $coupon_id, 'wc_email_message', true ); + } + if ( ! empty( $coupon_message ) && 'yes' === $include_in_email ) { + $is_filter_content = apply_filters( + 'wc_sc_is_filter_content_coupon_message', + true, + array( + 'source' => $this, + 'called_by' => current_filter(), + 'coupon_object' => $coupon, + 'order_object' => $order, + ) + ); + if ( true === $is_filter_content ) { + $coupon_messages .= apply_filters( 'the_content', $coupon_message ); + } else { + $coupon_messages .= $coupon_message; + } + $show_coupon_message_title = true; + } + } + if ( $show_coupon_message_title ) { + ?> +

          + '; + echo wp_kses_post( $coupon_messages ); // phpcs:ignore + echo '
          '; + } + } + + /** + * Add meta in export headers + * + * @param array $headers Existing headers. + * @return array + */ + public function export_headers( $headers = array() ) { + + $cm_headers = array( + 'wc_coupon_message' => __( 'Coupon Message', 'woocommerce-smart-coupons' ), + 'wc_email_message' => __( 'Is Email Coupon Message', 'woocommerce-smart-coupons' ), + ); + + return array_merge( $headers, $cm_headers ); + + } + + /** + * Post meta defaults for CM's meta + * + * @param array $defaults Existing postmeta defaults. + * @return array + */ + public function postmeta_defaults( $defaults = array() ) { + + $cm_defaults = array( + 'wc_coupon_message' => '', + 'wc_email_message' => '', + ); + + return array_merge( $defaults, $cm_defaults ); + } + + /** + * Add CM's meta with value in coupon meta + * + * @param array $data The row data. + * @param array $post The POST values. + * @return array Modified data + */ + public function generate_coupon_meta( $data = array(), $post = array() ) { + + $data['wc_coupon_message'] = ( ! empty( $post['wc_coupon_message'] ) ) ? wp_kses_post( $post['wc_coupon_message'] ) : ''; + $data['wc_email_message'] = ( ! empty( $post['wc_email_message'] ) ) ? wc_clean( wp_unslash( $post['wc_email_message'] ) ) : 'no'; + + return $data; + } + + /** + * Make meta data of SC CM, protected + * + * @param bool $protected Is protected. + * @param string $meta_key The meta key. + * @param string $meta_type The meta type. + * @return bool $protected + */ + public function make_action_meta_protected( $protected, $meta_key, $meta_type ) { + $sc_meta = array( + 'wc_coupon_message' => '', + 'wc_email_message' => '', + ); + if ( in_array( $meta_key, $sc_meta, true ) ) { + return true; + } + return $protected; + } + + /** + * Function to copy CM meta in newly generated coupon + * + * @param array $args The arguments. + */ + public function copy_coupon_action_meta( $args = array() ) { + + $new_coupon_id = ( ! empty( $args['new_coupon_id'] ) ) ? absint( $args['new_coupon_id'] ) : 0; + $coupon = ( ! empty( $args['ref_coupon'] ) ) ? $args['ref_coupon'] : false; + + if ( empty( $new_coupon_id ) || empty( $coupon ) ) { + return; + } + + $new_coupon = new WC_Coupon( $new_coupon_id ); + + if ( $this->is_callable( $new_coupon, 'get_meta' ) && $this->is_callable( $new_coupon, 'update_meta_data' ) && $this->is_callable( $new_coupon, 'save' ) ) { + $coupon_message = $coupon->get_meta( 'wc_coupon_message' ); + $email_message = $coupon->get_meta( 'wc_email_message' ); + $new_coupon->update_meta_data( 'wc_coupon_message', wp_filter_post_kses( $coupon_message ) ); + $new_coupon->update_meta_data( 'wc_email_message', $email_message ); + } else { + $old_coupon_id = ( ! empty( $coupon->id ) ) ? $coupon->id : 0; + $coupon_message = get_post_meta( $old_coupon_id, 'wc_coupon_message', true ); + $email_message = get_post_meta( $old_coupon_id, 'wc_email_message', true ); + update_post_meta( $new_coupon_id, 'wc_coupon_message', wp_filter_post_kses( $coupon_message ) ); + update_post_meta( $new_coupon_id, 'wc_email_message', $email_message ); + } + + } + + } + +} + +WC_SC_Coupon_Message::get_instance(); diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupon-parser.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupon-parser.php new file mode 100644 index 00000000..2a38e9c0 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupon-parser.php @@ -0,0 +1,454 @@ +post_type = $post_type; + + $this->reserved_fields = array( + 'id', + 'post_id', + 'post_type', + 'menu_order', + 'postmeta', + 'post_status', + 'post_title', + 'post_name', + 'comment_status', + 'post_date', + 'post_date_gmt', + 'post_content', + 'post_excerpt', + 'post_parent', + 'post_password', + 'discount_type', + 'coupon_amount', + 'free_shipping', + 'expiry_date', + 'minimum_amount', + 'maximum_amount', + 'individual_use', + 'exclude_sale_items', + 'product_ids', + 'exclude_product_ids', + 'product_categories', + 'exclude_product_categories', + 'customer_email', + 'usage_limit', + 'usage_limit_per_user', + 'limit_usage_to_x_items', + 'usage_count', + '_used_by', + ); + + $this->post_defaults = array( + 'post_type' => $this->post_type, + 'menu_order' => '', + 'postmeta' => array(), + 'post_status' => 'publish', + 'post_title' => '', + 'post_name' => '', + 'comment_status' => 'closed', + 'post_date' => '', + 'post_date_gmt' => '', + 'post_content' => '', + 'post_excerpt' => '', + 'post_parent' => 0, + 'post_password' => '', + 'post_author' => get_current_user_id(), + ); + + $this->postmeta_defaults = apply_filters( + 'smart_coupons_parser_postmeta_defaults', + array( + 'discount_type' => 'fixed_cart', + 'coupon_amount' => '', + 'free_shipping' => '', + 'expiry_date' => '', + 'sc_coupon_validity' => '', + 'validity_suffix' => '', + 'auto_generate_coupon' => '', + 'coupon_title_prefix' => '', + 'coupon_title_suffix' => '', + 'is_pick_price_of_product' => '', + 'minimum_amount' => '', + 'maximum_amount' => '', + 'individual_use' => '', + 'exclude_sale_items' => '', + 'product_ids' => '', + 'exclude_product_ids' => '', + 'product_categories' => '', + 'exclude_product_categories' => '', + 'customer_email' => '', + 'sc_disable_email_restriction' => '', + 'usage_limit' => '', + 'usage_limit_per_user' => '', + 'limit_usage_to_x_items' => '', + 'sc_is_visible_storewide' => '', + 'usage_count' => '', + '_used_by' => '', + 'sc_restrict_to_new_user' => '', + 'wc_sc_max_discount' => '', + ) + ); + + $this->term_defaults = array( + 'sc_coupon_category' => '', + ); + } + + /** + * Handle call to functions which is not available in this class + * + * @param string $function_name The function name. + * @param array $arguments Array of arguments passed while calling $function_name. + * @return result of function call + */ + public function __call( $function_name, $arguments = array() ) { + + global $woocommerce_smart_coupon; + + if ( ! is_callable( array( $woocommerce_smart_coupon, $function_name ) ) ) { + return; + } + + if ( ! empty( $arguments ) ) { + return call_user_func_array( array( $woocommerce_smart_coupon, $function_name ), $arguments ); + } else { + return call_user_func( array( $woocommerce_smart_coupon, $function_name ) ); + } + + } + + /** + * Format data passed from CSV + * + * @param array $data The data to format. + * @param string $enc encoding The encoding. + */ + public function format_data_from_csv( $data, $enc ) { + return ( 'UTF-8' === $enc ) ? $data : utf8_encode( $data ); + } + + /** + * Parse data + * + * @param string $file Imported file. + * @return array parsed data with headers + */ + public function parse_data( $file ) { + + // Set locale. + $enc = $this->mb_detect_encoding( $file, 'UTF-8, ISO-8859-1', true ); + if ( $enc ) { + setlocale( LC_ALL, 'en_US.' . $enc ); + } + if ( ! $this->is_php_gte( '8.0.0' ) ) { + ini_set( 'auto_detect_line_endings', true ); // phpcs:ignore + } + + $parsed_data = array(); + + $handle = fopen( $file, 'r' ); // phpcs:ignore + + // Put all CSV data into an associative array. + if ( false !== $handle ) { + + $header = fgetcsv( $handle, 0 ); + + while ( false !== ( $postmeta = fgetcsv( $handle, 0 ) ) ) { // phpcs:ignore + $row = array(); + foreach ( $header as $key => $heading ) { + + $s_heading = strtolower( $heading ); + + $row[ $s_heading ] = ( isset( $postmeta[ $key ] ) ) ? $this->format_data_from_csv( stripslashes( $postmeta[ $key ] ), $enc ) : ''; + + $raw_headers[ $s_heading ] = $heading; + } + + $parsed_data[] = $row; + + unset( $postmeta, $row ); + + } + + fclose( $handle ); // phpcs:ignore + } + + return array( $parsed_data, $raw_headers ); + } + + /** + * Parse data one row at a time + * + * @param boolean $file_handler CSV file handler. + * @param array $header CSV header meta column name. + * @param integer $file_position file pointer posistion to read from. + * @param string $encoding Character encoding. + * @return array $result parsed data with current file pointer position + */ + public function parse_data_by_row( $file_handler = false, $header = array(), $file_position = 0, $encoding = '' ) { + + $parsed_csv_data = array(); + + $reading_completed = false; + + if ( false !== $file_handler ) { + + if ( $file_position > 0 ) { + + fseek( $file_handler, (int) $file_position ); + + } + + if ( false !== ( $postmeta = fgetcsv( $file_handler, 0 ) ) ) { // phpcs:ignore + $row = array(); + foreach ( $header as $key => $heading ) { + + $s_heading = strtolower( $heading ); + + // Put all CSV data into an associative array by row. + $row[ $s_heading ] = ( isset( $postmeta[ $key ] ) ) ? $this->format_data_from_csv( stripslashes( $postmeta[ $key ] ), $encoding ) : ''; + } + + $parsed_csv_data = $row; + + unset( $postmeta, $row ); + + } else { + + $reading_completed = true; + + } + + $file_position = ftell( $file_handler ); + } + + $result = array( + 'parsed_csv_data' => $parsed_csv_data, + 'file_position' => $file_position, + 'reading_completed' => $reading_completed, + ); + + return $result; + } + + /** + * Parse coupon + * + * @param array $item The imported item. + * @return array $coupon + */ + public function parse_coupon( $item ) { + global $wc_csv_coupon_import; + + $this->row++; + $postmeta = array(); + $term_data = array(); + $coupon = array(); + + $post_id = ( ! empty( $item['id'] ) ) ? absint( $item['id'] ) : 0; + $post_id = ( ! empty( $item['post_id'] ) ) ? absint( $item['post_id'] ) : $post_id; + + $product['post_id'] = $post_id; + + // Get post fields. + foreach ( $this->post_defaults as $column => $default ) { + if ( isset( $item[ $column ] ) ) { + $product[ $column ] = $item[ $column ]; + } + } + + // Get custom fields. + foreach ( $this->postmeta_defaults as $column => $default ) { + if ( isset( $item[ $column ] ) ) { + $postmeta[ $column ] = (string) $item[ $column ]; + } elseif ( isset( $item[ '_' . $column ] ) ) { + $postmeta[ $column ] = (string) $item[ '_' . $column ]; + } + } + + // Get term fields. + foreach ( $this->term_defaults as $column => $default ) { + if ( isset( $item[ $column ] ) ) { + $term_data[ $column ] = $item[ $column ]; + } + } + + // Merge post meta with defaults. + $coupon = wp_parse_args( $product, $this->post_defaults ); + $postmeta = wp_parse_args( $postmeta, $this->postmeta_defaults ); + $term_data = wp_parse_args( $term_data, $this->term_defaults ); + + $all_discount_types = wc_get_coupon_types(); + + if ( ! empty( $postmeta['discount_type'] ) ) { + $discount_type = __( $postmeta['discount_type'], 'woocommerce' ); // phpcs:ignore + } else { + if ( $this->is_wc_gte_30() ) { + $discount_type = __( 'Percentage discount', 'woocommerce' ); + } else { + $discount_type = __( 'Cart % Discount', 'woocommerce' ); + } + } + + $discount_type = ( ! empty( $discount_type ) && in_array( $discount_type, $all_discount_types, true ) ) ? $discount_type : $postmeta['discount_type']; + + // discount types. + if ( ! empty( $discount_type ) ) { + + if ( in_array( $discount_type, $all_discount_types, true ) ) { + $postmeta['discount_type'] = array_search( $discount_type, $all_discount_types, true ); + } + + if ( empty( $postmeta['discount_type'] ) ) { + $postmeta['discount_type'] = 'percent'; + } + } + + // product_ids. + if ( isset( $postmeta['product_ids'] ) && ! is_array( $postmeta['product_ids'] ) ) { + $ids = array_filter( array_map( 'trim', explode( '|', $postmeta['product_ids'] ) ) ); + $ids = implode( ',', $ids ); + $postmeta['product_ids'] = $ids; + } + + // exclude_product_ids. + if ( isset( $postmeta['exclude_product_ids'] ) && ! is_array( $postmeta['exclude_product_ids'] ) ) { + $ids = array_filter( array_map( 'trim', explode( '|', $postmeta['exclude_product_ids'] ) ) ); + $ids = implode( ',', $ids ); + $postmeta['exclude_product_ids'] = $ids; + } + + // product_categories. + if ( isset( $postmeta['product_categories'] ) && ! is_array( $postmeta['product_categories'] ) ) { + $ids = array_filter( array_map( 'trim', explode( '|', $postmeta['product_categories'] ) ) ); + $postmeta['product_categories'] = $ids; + } + + // exclude_product_categories. + if ( isset( $postmeta['exclude_product_categories'] ) && ! is_array( $postmeta['exclude_product_categories'] ) ) { + $ids = array_filter( array_map( 'trim', explode( '|', $postmeta['exclude_product_categories'] ) ) ); + $postmeta['exclude_product_categories'] = $ids; + } + + // customer_email. + if ( isset( $postmeta['customer_email'] ) && ! is_array( $postmeta['customer_email'] ) ) { + $email_ids = array_filter( array_map( 'trim', explode( ',', $postmeta['customer_email'] ) ) ); + $postmeta['customer_email'] = $email_ids; + } + + // expiry date. + if ( isset( $postmeta['expiry_date'] ) ) { + $timestamp_expiry_date = ''; + if ( ! empty( $postmeta['expiry_date'] ) ) { + $timestamp_expiry_date = ( function_exists( 'wc_string_to_timestamp' ) ) ? wc_string_to_timestamp( $postmeta['expiry_date'] ) : 0; + } + if ( ! empty( $postmeta['expiry_date'] ) && empty( $timestamp_expiry_date ) ) { + /* translators: 1. Coupon code 2. Expiry date */ + $this->log( 'error', sprintf( __( 'Incorrect format for expiry date of coupon "%1$s". Entered date is %2$s. Expected date format: YYYY-MM-DD', 'woocommerce-smart-coupons' ), $coupon['post_title'], $postmeta['expiry_date'] ) ); + } + $postmeta['expiry_date'] = ( ! empty( $timestamp_expiry_date ) ) ? gmdate( 'Y-m-d', $timestamp_expiry_date ) : ''; + } + + // usage count. + if ( isset( $postmeta['usage_count'] ) ) { + $postmeta['usage_count'] = ( ! empty( $postmeta['usage_count'] ) ) ? $postmeta['usage_count'] : 0; + } + + // used_by. + if ( isset( $postmeta['_used_by'] ) ) { + $postmeta['_used_by'] = ( ! empty( $postmeta['_used_by'] ) ) ? $postmeta['_used_by'] : ''; + } + + // Put set core product postmeta into product array. + foreach ( $postmeta as $key => $value ) { + $coupon['postmeta'][] = array( + 'key' => esc_attr( $key ), + 'value' => $value, + ); + } + + // term data. + foreach ( $term_data as $key => $value ) { + $coupon['term_data'][] = array( + 'key' => esc_attr( $key ), + 'value' => $value, + ); + } + + unset( $item, $postmeta ); + + return $coupon; + + } + } + +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupon-process.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupon-process.php new file mode 100644 index 00000000..7c075cad --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupon-process.php @@ -0,0 +1,1864 @@ +get_coupon_receiver_details_session(); + $request_gift_receiver_email = ( isset( $gift_receiver_session['gift_receiver_email'] ) ) ? wc_clean( wp_unslash( $gift_receiver_session['gift_receiver_email'] ) ) : array(); + $request_gift_receiver_message = ( isset( $gift_receiver_session['gift_receiver_message'] ) ) ? wc_clean( wp_unslash( $gift_receiver_session['gift_receiver_message'] ) ) : array(); + $request_gift_sending_timestamp = ( isset( $gift_receiver_session['gift_sending_timestamp'] ) ) ? wc_clean( wp_unslash( $gift_receiver_session['gift_sending_timestamp'] ) ) : array(); + $request_billing_email = ( isset( $gift_receiver_session['billing_email'] ) ) ? wc_clean( wp_unslash( $gift_receiver_session['billing_email'] ) ) : ''; + $request_is_gift = ( isset( $gift_receiver_session['is_gift'] ) ) ? wc_clean( wp_unslash( $gift_receiver_session['is_gift'] ) ) : ''; + $request_sc_send_to = ( isset( $gift_receiver_session['sc_send_to'] ) ) ? wc_clean( wp_unslash( $gift_receiver_session['sc_send_to'] ) ) : ''; + } + } + + if ( in_array( $payment_type, array( 'google_pay', 'apple_pay' ), true ) && ( empty( $request_gift_receiver_email ) || count( $request_gift_receiver_email ) <= 0 ) ) { + $product_ids = array(); + $cart = ( isset( WC()->cart ) ) ? WC()->cart : ''; + if ( $cart instanceof WC_Cart && is_callable( array( $cart, 'get_cart' ) ) ) { + $cart_contents = $cart->get_cart(); + if ( ! empty( $cart_contents ) && is_array( $cart_contents ) ) { + $product_ids = wp_list_pluck( $cart_contents, 'product_id' ); + } + } + + if ( ! empty( $product_ids ) ) { + foreach ( $product_ids as $product_id ) { + $product = wc_get_product( $product_id ); + $coupons = $this->get_coupon_titles( array( 'product_object' => $product ) ); + if ( ! empty( $coupons ) ) { + foreach ( $coupons as $coupon_title ) { + $coupon_of_product = new WC_Coupon( $coupon_title ); + $discount_type_of_product = ( is_object( $coupon_of_product ) && is_callable( array( $coupon_of_product, 'get_discount_type' ) ) ) ? $coupon_of_product->get_discount_type() : ''; + if ( 'smart_coupon' === $discount_type_of_product ) { + $id = $coupon_of_product->get_id(); + $request_gift_receiver_email[ $id ][] = $request_billing_email; + } + } + } + } + } + } + + if ( empty( $request_gift_receiver_email ) || count( $request_gift_receiver_email ) <= 0 ) { + return; + } + + $order_id = absint( $order_id ); + $order = ( ! empty( $order_id ) ) ? wc_get_order( $order_id ) : null; + + if ( ! empty( $request_gift_receiver_email ) || ( ! empty( $request_billing_email ) && $request_billing_email !== $request_gift_receiver_email ) ) { + + $is_callable_update_meta_data = $this->is_callable( $order, 'update_meta_data' ); + + $schedule_store_credit = get_option( 'smart_coupons_schedule_store_credit' ); + $schedule_gift_sending = ( 'yes' === $schedule_store_credit && 'yes' === $request_is_gift && ( isset( $_REQUEST['wc_sc_schedule_gift_sending'] ) ) ) ? wc_clean( wp_unslash( $_REQUEST['wc_sc_schedule_gift_sending'] ) ) : ''; // phpcs:ignore + + if ( 'yes' === $request_is_gift ) { + if ( ! empty( $request_sc_send_to ) ) { + switch ( $request_sc_send_to ) { + case 'one': + $email_for_one = ( isset( $request_gift_receiver_email[0][0] ) && ! empty( $request_gift_receiver_email[0][0] ) && is_email( $request_gift_receiver_email[0][0] ) ) ? $request_gift_receiver_email[0][0] : $request_billing_email; + $message_for_one = ( isset( $request_gift_receiver_message[0][0] ) && ! empty( $request_gift_receiver_message[0][0] ) ) ? $request_gift_receiver_message[0][0] : ''; + $schedule_for_one = ( isset( $request_gift_sending_timestamp[0][0] ) && ! empty( $request_gift_sending_timestamp[0][0] ) ) ? $request_gift_sending_timestamp[0][0] : ''; + unset( $request_gift_receiver_email[0][0] ); + unset( $request_gift_receiver_message[0][0] ); + unset( $request_gift_sending_timestamp[0][0] ); + foreach ( $request_gift_receiver_email as $coupon_id => $emails ) { + foreach ( $emails as $key => $email ) { + $request_gift_receiver_email[ $coupon_id ][ $key ] = $email_for_one; + $request_gift_receiver_message[ $coupon_id ][ $key ] = $message_for_one; + $request_gift_sending_timestamp[ $coupon_id ][ $key ] = $schedule_for_one; + } + } + if ( ! empty( $request_gift_receiver_message ) && '' !== $request_gift_receiver_message ) { + if ( true === $is_callable_update_meta_data ) { + $order->update_meta_data( 'gift_receiver_message', $request_gift_receiver_message ); + } else { + update_post_meta( $order_id, 'gift_receiver_message', $request_gift_receiver_message ); + } + } + if ( ! empty( $request_gift_sending_timestamp ) && '' !== $request_gift_sending_timestamp ) { + if ( true === $is_callable_update_meta_data ) { + $order->update_meta_data( 'gift_sending_timestamp', $request_gift_sending_timestamp ); + } else { + update_post_meta( $order_id, 'gift_sending_timestamp', $request_gift_sending_timestamp ); + } + } + break; + + case 'many': + if ( isset( $request_gift_receiver_email[0][0] ) && ! empty( $request_gift_receiver_email[0][0] ) ) { + unset( $request_gift_receiver_email[0][0] ); + } + if ( isset( $request_gift_receiver_message[0][0] ) && ! empty( $request_gift_receiver_message[0][0] ) ) { + unset( $request_gift_receiver_message[0][0] ); + } + if ( isset( $request_gift_sending_timestamp[0][0] ) && ! empty( $request_gift_sending_timestamp[0][0] ) ) { + unset( $request_gift_sending_timestamp[0][0] ); + } + if ( ! empty( $request_gift_receiver_message ) && '' !== $request_gift_receiver_message ) { + if ( true === $is_callable_update_meta_data ) { + $order->update_meta_data( 'gift_receiver_message', $request_gift_receiver_message ); + } else { + update_post_meta( $order_id, 'gift_receiver_message', $request_gift_receiver_message ); + } + } + if ( ! empty( $request_gift_sending_timestamp ) && '' !== $request_gift_sending_timestamp ) { + if ( true === $is_callable_update_meta_data ) { + $order->update_meta_data( 'gift_sending_timestamp', $request_gift_sending_timestamp ); + } else { + update_post_meta( $order_id, 'gift_sending_timestamp', $request_gift_sending_timestamp ); + } + } + break; + } + } + if ( true === $is_callable_update_meta_data ) { + $order->update_meta_data( 'is_gift', 'yes' ); + } else { + update_post_meta( $order_id, 'is_gift', 'yes' ); + } + if ( ! empty( $schedule_gift_sending ) ) { + if ( true === $is_callable_update_meta_data ) { + $order->update_meta_data( 'wc_sc_schedule_gift_sending', $schedule_gift_sending ); + } else { + update_post_meta( $order_id, 'wc_sc_schedule_gift_sending', $schedule_gift_sending ); + } + } + } else { + if ( ! empty( $request_gift_receiver_email[0][0] ) && is_array( $request_gift_receiver_email[0][0] ) ) { + unset( $request_gift_receiver_email[0][0] ); + foreach ( $request_gift_receiver_email as $coupon_id => $emails ) { + foreach ( $emails as $key => $email ) { + $request_gift_receiver_email[ $coupon_id ][ $key ] = $request_billing_email; + } + } + } + if ( true === $is_callable_update_meta_data ) { + $order->update_meta_data( 'is_gift', 'no' ); + } else { + update_post_meta( $order_id, 'is_gift', 'no' ); + } + } + + if ( true === $is_callable_update_meta_data ) { + $order->update_meta_data( 'gift_receiver_email', $request_gift_receiver_email ); + } else { + update_post_meta( $order_id, 'gift_receiver_email', $request_gift_receiver_email ); + } + + if ( $this->is_callable( $order, 'save' ) ) { + $order->save(); + } + } + + } + + /** + * Function to verify gift certificate form details + */ + public function verify_gift_certificate_receiver_details() { + + $post_gift_receiver_email = ( ! empty( $_POST['gift_receiver_email'] ) ) ? wc_clean( wp_unslash( $_POST['gift_receiver_email'] ) ) : array(); // phpcs:ignore + $post_billing_email = ( ! empty( $_POST['billing_email'] ) ) ? wc_clean( wp_unslash( $_POST['billing_email'] ) ) : ''; // phpcs:ignore + $is_gift = ( ! empty( $_POST['is_gift'] ) ) ? wc_clean( wp_unslash( $_POST['is_gift'] ) ) : ''; // phpcs:ignore + $send_to = ( isset( $_POST['sc_send_to'] ) ) ? wc_clean( wp_unslash( $_POST['sc_send_to'] ) ) : ''; // phpcs:ignore + + if ( 'no' === $is_gift ) { + return; + } + + if ( empty( $post_gift_receiver_email ) || ! is_array( $post_gift_receiver_email ) ) { + return; + } + + $is_email_required = apply_filters( 'wc_sc_is_email_required_for_sending_coupon', $this->sc_get_option( 'wc_sc_is_email_required_for_sending_coupon', 'no' ), array( 'source' => $this ) ); + + if ( 'yes' === $is_gift && 'yes' === $is_email_required ) { + if ( 'one' === $send_to ) { + $gift_receiver_email_to_one = array( + $post_gift_receiver_email[0], + ); + $post_gift_receiver_email = $gift_receiver_email_to_one; + } elseif ( 'many' === $send_to ) { + unset( $post_gift_receiver_email[0] ); + } + } + + foreach ( $post_gift_receiver_email as $key => $emails ) { + if ( ! empty( $emails ) ) { + foreach ( $emails as $index => $email ) { + + $placeholder = __( 'Email address', 'woocommerce-smart-coupons' ); + $placeholder .= '...'; + + if ( empty( $email ) || $email === $placeholder ) { + if ( 'yes' === $is_gift && 'yes' === $is_email_required ) { + $this->sc_add_notice_for_gift_card_receiver_validation(); + return; + } + $post_gift_receiver_email[ $key ][ $index ] = ( ! empty( $post_billing_email ) ) ? $post_billing_email : ''; + } elseif ( ! empty( $email ) && ! is_email( $email ) ) { + $this->sc_add_notice_for_gift_card_receiver_validation(); + return; + } + } + } + } + + $_POST['gift_receiver_email'] = $post_gift_receiver_email; // phpcs:ignore + + } + + /** + * Function will add notice if gift card receiver details are not verified. + * + * @return void + */ + public function sc_add_notice_for_gift_card_receiver_validation() { + global $store_credit_label; + if ( ! empty( $store_credit_label['singular'] ) ) { + /* translators: %s: singular name for store credit */ + wc_add_notice( sprintf( __( 'Error: %s Receiver’s E-mail address is invalid.', 'woocommerce-smart-coupons' ), ucwords( $store_credit_label['singular'] ) ), 'error' ); + } else { + wc_add_notice( __( 'Error: Gift Card Receiver’s E-mail address is invalid.', 'woocommerce-smart-coupons' ), 'error' ); + } + } + + /** + * Function to save Smart Coupon's contribution in discount + * + * @param int $order_id The order id. + */ + public function smart_coupons_contribution( $order_id = 0 ) { + + $applied_coupons = ( is_object( WC()->cart ) && isset( WC()->cart->applied_coupons ) ) ? WC()->cart->applied_coupons : array(); + + if ( ! empty( $applied_coupons ) ) { + + $order_id = absint( $order_id ); + $order = ( ! empty( $order_id ) ) ? wc_get_order( $order_id ) : null; + + foreach ( $applied_coupons as $code ) { + + $smart_coupon = new WC_Coupon( $code ); + + if ( $this->is_wc_gte_30() ) { + $discount_type = $smart_coupon->get_discount_type(); + } else { + $discount_type = ( ! empty( $smart_coupon->discount_type ) ) ? $smart_coupon->discount_type : ''; + } + + if ( 'smart_coupon' === $discount_type ) { + + $this->update_post_meta( $order_id, 'smart_coupons_contribution', WC()->cart->smart_coupon_credit_used, true, $order ); + + } + } + } + } + + /** + * Function to delete Smart Coupons contribution on removal of coupon + */ + public function delete_smart_coupons_contribution() { + + $post_action = ( ! empty( $_POST['action'] ) ) ? wc_clean( wp_unslash( $_POST['action'] ) ) : ''; // phpcs:ignore + $post_order_id = ( ! empty( $_POST['order_id'] ) ) ? wc_clean( wp_unslash( $_POST['order_id'] ) ) : 0; // phpcs:ignore + $post_coupon = ( ! empty( $_POST['coupon'] ) ) ? wc_clean( wp_unslash( $_POST['coupon'] ) ) : ''; // phpcs:ignore + + if ( 'woocommerce_remove_order_coupon' === $post_action && ! empty( $post_order_id ) && ! empty( $post_coupon ) ) { + $order = wc_get_order( $post_order_id ); + + $smart_coupons_contribution = $this->get_post_meta( $post_order_id, 'smart_coupons_contribution', true, true ); + + if ( isset( $smart_coupons_contribution[ $post_coupon ] ) ) { + unset( $smart_coupons_contribution[ $post_coupon ] ); + + $_POST['smart_coupon_removed'] = $post_coupon; + + if ( empty( $smart_coupons_contribution ) ) { + $this->delete_post_meta( $post_order_id, 'smart_coupons_contribution', null, $order ); + } else { + $this->update_post_meta( $post_order_id, 'smart_coupons_contribution', $smart_coupons_contribution, true, $order ); + } + } + + $order_status = $order->get_status(); + + $pending_statuses = $this->get_pending_statuses(); + + if ( $order->has_status( $pending_statuses ) ) { + $this->sa_restore_smart_coupon_amount( $post_order_id ); + } + } + } + + /** + * Function to update Store Credit / Gift Certificate balance + * + * @param int $order_id The order id. + */ + public function update_smart_coupon_balance( $order_id ) { + + $post_type = ( $this->is_hpos() && ! empty( $order_id ) ) ? $this->get_post_type( $order_id ) : ( ( ! empty( $_POST['post_type'] ) ) ? wc_clean( wp_unslash( $_POST['post_type'] ) ) : '' ); // phpcs:ignore + + if ( ( 'shop_order' === $post_type && ! empty( $_POST['action'] ) && in_array( wc_clean( wp_unslash( $_POST['action'] ) ), array( 'edit_order', 'editpost' ), true ) && !in_array( $_POST['post_status'] , array( 'draft','trash' ) ) ) // phpcs:ignore + || ( ! empty( $_GET['action'] ) && in_array( $_GET['action'], array( 'woocommerce_mark_order_status', 'mark_on-hold', 'mark_processing', 'mark_completed' ), true ) ) // phpcs:ignore + ) { + return; + } + + $order = wc_get_order( $order_id ); + + $order_used_coupons = $order->get_coupons(); + + if ( ! empty( $order_used_coupons ) ) { + + $smart_coupons_contribution = $this->get_post_meta( $order_id, 'smart_coupons_contribution', true, true ); + + if ( empty( $smart_coupons_contribution ) || ! is_array( $smart_coupons_contribution ) ) { + $this->update_smart_coupon_balance_by_used_coupon( $order_id ); + return; + } + + foreach ( $order_used_coupons as $coupon_item ) { + if ( $coupon_item->get_meta( 'sc_coupon_deduction_done' ) !== 'yes' ) { + $coupon_item->add_meta_data( 'sc_coupon_deduction_done', 'yes', true ); + $coupon_item->save(); + $code = $coupon_item->get_code(); + + if ( array_key_exists( $code, $smart_coupons_contribution ) ) { + + $smart_coupon = new WC_Coupon( $code ); + + if ( $this->is_wc_gte_30() ) { + if ( ! is_object( $smart_coupon ) ) { + continue; + } + $coupon_id = ( is_callable( array( $smart_coupon, 'get_id' ) ) ) ? $smart_coupon->get_id() : 0; + if ( empty( $coupon_id ) ) { + $coupon_id = function_exists( 'wc_get_coupon_id_by_code' ) ? wc_get_coupon_id_by_code( $code ) : 0; + if ( empty( $coupon_id ) ) { + continue; + } + } + $discount_type = ( is_callable( array( $smart_coupon, 'get_discount_type' ) ) ) ? $smart_coupon->get_discount_type() : ''; + } else { + $coupon_id = ( ! empty( $smart_coupon->id ) ) ? $smart_coupon->id : 0; + $discount_type = ( ! empty( $smart_coupon->discount_type ) ) ? $smart_coupon->discount_type : ''; + } + + if ( 'smart_coupon' === $discount_type ) { + + $coupon_amount = $this->get_amount( $smart_coupon, true, $order ); + $credit_remaining = round( ( $coupon_amount - $smart_coupons_contribution[ $code ] ), get_option( 'woocommerce_price_num_decimals', 2 ) ); + $credit_remaining = max( 0, $credit_remaining ); + + // Allow 3rd party plugin to modify the remaining balance of the store credit. + $credit_remaining = apply_filters( + 'wc_sc_credit_remaining', + $credit_remaining, + array( + 'source' => $this, + 'order_obj' => $order, + 'coupon_obj' => $smart_coupon, + ) + ); + + $credit_remaining = ( $credit_remaining < 0 ) ? 0 : $credit_remaining; + + if ( $credit_remaining <= 0 && get_option( 'woocommerce_delete_smart_coupon_after_usage' ) === 'yes' ) { + $this->update_post_meta( $coupon_id, 'coupon_amount', 0, true, $order ); + wp_trash_post( $coupon_id ); + } else { + $this->update_post_meta( $coupon_id, 'coupon_amount', $credit_remaining, true, $order ); + } + } + } + } + } + } + } + + /** + * Update smart coupon balance by used coupon. + * + * @param int $order_id Integer. + * @return void + */ + public function update_smart_coupon_balance_by_used_coupon( $order_id = 0 ) { + + if ( empty( $order_id ) ) { + return; + } + + $order = function_exists( 'wc_get_order' ) ? wc_get_order( $order_id ) : null; + + if ( ! is_object( $order ) || ! is_a( $order, 'WC_Order' ) ) { + return; + } + + $order_items = is_callable( array( $order, 'get_items' ) ) ? $order->get_items( 'coupon' ) : array(); + + if ( ! empty( $order_items ) ) { + $item_titles = array_map( + function( $item ) { + return ( $this->is_callable( $item, 'get_name' ) ) ? $item->get_name() : ''; + }, + $order_items + ); + $posts = $this->get_post_by_title( $item_titles, OBJECT, 'shop_coupon' ); + foreach ( $order_items as $item_id => $item ) { + $coupon_code = ( $this->is_callable( $item, 'get_name' ) ) ? $item->get_name() : ''; + $sanitized_coupon_code = sanitize_title( $coupon_code ); // The generated string will be checked in an array key to locate post object. + $coupon_post_obj = ( ! empty( $posts[ $sanitized_coupon_code ] ) ) ? $posts[ $sanitized_coupon_code ] : null; + $coupon_id = isset( $coupon_post_obj->ID ) ? $coupon_post_obj->ID : 0; + $coupon_code = isset( $coupon_post_obj->post_title ) ? $coupon_post_obj->post_title : ''; + $smart_coupon = new WC_Coupon( $coupon_id ); + if ( is_a( $smart_coupon, 'WC_Coupon' ) ) { + + if ( $this->is_wc_gte_30() ) { + if ( ! is_object( $smart_coupon ) || ! is_callable( array( $smart_coupon, 'get_id' ) ) ) { + continue; + } + $coupon_id = $smart_coupon->get_id(); + if ( empty( $coupon_id ) ) { + $coupon_id = wc_get_coupon_id_by_code( $coupon_code ); + if ( empty( $coupon_id ) ) { + continue; + } + } + $discount_type = is_callable( array( $smart_coupon, 'get_discount_type' ) ) ? $smart_coupon->get_discount_type() : ''; + } else { + $coupon_id = ( ! empty( $smart_coupon->id ) ) ? $smart_coupon->id : 0; + $discount_type = ( ! empty( $smart_coupon->discount_type ) ) ? $smart_coupon->discount_type : ''; + } + + if ( 'smart_coupon' === $discount_type ) { + $coupon_amount = $this->get_amount( $smart_coupon ); + $order_discount_amount = $this->get_order_item_meta( $item_id, 'discount_amount', true ); + $order_discount_tax_amount = $this->get_order_item_meta( $item_id, 'discount_amount_tax', true ); + + $sc_include_tax = $this->is_store_credit_include_tax(); + // Add discount on tax if it has been given on tax. + if ( 'yes' === $sc_include_tax && ! empty( $order_discount_tax_amount ) ) { + $order_discount_amount += $order_discount_tax_amount; + } + + $credit_remaining = round( ( $coupon_amount - $order_discount_amount ), get_option( 'woocommerce_price_num_decimals', 2 ) ); + + // Allow 3rd party plugin to modify the remaining balance of the store credit. + $credit_remaining = apply_filters( + 'wc_sc_credit_remaining', + $credit_remaining, + array( + 'source' => $this, + 'order_obj' => $order, + 'coupon_obj' => $smart_coupon, + ) + ); + + $credit_remaining = ( $credit_remaining < 0 ) ? 0 : $credit_remaining; + + if ( $credit_remaining <= 0 && get_option( 'woocommerce_delete_smart_coupon_after_usage' ) === 'yes' ) { + $this->update_post_meta( $coupon_id, 'coupon_amount', 0 ); + wp_trash_post( $coupon_id ); + } else { + $this->update_post_meta( $coupon_id, 'coupon_amount', $credit_remaining ); + } + } + } + } + } + } + + /** + * Handle Coupon Process on 3rd party order statuses + * + * @param integer $order_id The order id. + * @param string $old_status Old order status. + * @param string $new_status New order status. + */ + public function handle_coupon_process_on_3rd_party_order_statuses( $order_id = 0, $old_status = '', $new_status = '' ) { + + if ( empty( $order_id ) ) { + return; + } + + $hooks_available_for_statuses = array( 'on-hold', 'pending', 'processing', 'completed', 'failed', 'refunded', 'cancelled' ); + + if ( in_array( $old_status, $hooks_available_for_statuses, true ) || in_array( $new_status, $hooks_available_for_statuses, true ) ) { + return; + } + + $paid_statuses = wc_get_is_paid_statuses(); + $pending_statuses = wc_get_is_pending_statuses(); + $return_statuses = apply_filters( 'wc_sc_return_order_statuses', array() ); + + if ( in_array( $new_status, $paid_statuses, true ) ) { + $this->sa_add_coupons( $order_id ); + $this->coupons_used( $order_id ); + } + + if ( in_array( $new_status, $return_statuses, true ) ) { + $this->sa_remove_coupons( $order_id ); + } + + if ( in_array( $old_status, $paid_statuses, true ) && in_array( $new_status, $return_statuses, true ) ) { + $this->sa_restore_smart_coupon_amount( $order_id ); + } + + if ( in_array( $old_status, $pending_statuses, true ) && in_array( $new_status, $paid_statuses, true ) ) { + $this->update_smart_coupon_balance( $order_id ); + } + + if ( in_array( $old_status, $return_statuses, true ) && in_array( $new_status, $paid_statuses, true ) ) { + $this->update_smart_coupon_balance( $order_id ); + } + + } + + /** + * Update discount details in PayPal args if store credit is applied + * + * @param array $args PayPal args. + * @param WC_Order $order The order object. + * + * @return array $args Modified PayPal args + */ + public function modify_paypal_args( $args = array(), $order = null ) { + global $store_credit_label; + + $apply_before_tax = get_option( 'woocommerce_smart_coupon_apply_before_tax', 'no' ); + + if ( 'yes' === $apply_before_tax ) { + return $args; + } + + $is_order_contains_store_credit = $this->is_order_contains_store_credit( $order ); + + if ( ! $is_order_contains_store_credit ) { + return $args; + } + + $discount_amount_cart = ( ! empty( $args['discount_amount_cart'] ) ) ? $args['discount_amount_cart'] : 0; + + if ( empty( $discount_amount_cart ) ) { + return $args; + } + + $item_total = 0; + + foreach ( $args as $key => $value ) { + if ( strpos( $key, 'amount_' ) === 0 ) { + $index = str_replace( 'amount_', '', $key ); + $qty = ( ! empty( $args[ 'quantity_' . $index ] ) ) ? $args[ 'quantity_' . $index ] : 1; + $item_total += ( $value * $qty ); + } + } + + if ( $discount_amount_cart > $item_total ) { + $difference = $discount_amount_cart - $item_total; + $args['discount_amount_cart'] = $item_total; + + if ( $this->is_wc_gte_30() ) { + $order_id = ( is_object( $order ) && is_callable( array( $order, 'get_id' ) ) ) ? $order->get_id() : 0; + } else { + $order_id = ( ! empty( $order->id ) ) ? $order->id : 0; + } + + if ( ! empty( $order_id ) && ! is_a( $order, 'WC_Order' ) ) { + $order = wc_get_order( $order_id ); + } + + $coupons = $order->get_items( 'coupon' ); + $order_total = $order->get_total(); + $order_note = array(); + + foreach ( $coupons as $item_id => $item ) { + if ( empty( $difference ) ) { + break; + } + $code = ( is_object( $item ) && is_callable( array( $item, 'get_name' ) ) ) ? $item->get_name() : trim( $item['name'] ); + $coupon = new WC_Coupon( $code ); + if ( $this->is_wc_gte_30() ) { + $discount_type = $coupon->get_discount_type(); + } else { + $discount_type = ( ! empty( $coupon->discount_type ) ) ? $coupon->discount_type : ''; + } + $discount = ( is_object( $item ) && is_callable( array( $item, 'get_discount' ) ) ) ? $item->get_discount() : $item['discount_amount']; + if ( 'smart_coupon' === $discount_type && ! empty( $discount ) ) { + $new_discount = 0; + $item_discount = $discount; + $cut_amount = min( $difference, $item_discount ); + $new_discount = $item_discount - $cut_amount; + $difference -= $cut_amount; + $item_args = array( + 'discount_amount' => $new_discount, + ); + if ( $this->is_wc_gte_30() ) { + $item = $order->get_item( $item_id ); + + if ( ! is_object( $item ) || ! is_callable( array( $item, 'get_id' ) ) ) { + continue; + } + + if ( ! is_object( $item ) || ! $item->is_type( 'coupon' ) ) { + $discount_updated = false; + } + if ( ! $order->get_id() ) { + $order->save(); // Order must exist. + } + + // BW compatibility for old args. + if ( isset( $item_args['discount_amount'] ) ) { + $item_args['discount'] = $item_args['discount_amount']; + } + if ( isset( $item_args['discount_amount_tax'] ) ) { + $item_args['discount_tax'] = $item_args['discount_amount_tax']; + } + + unset( $item_args['discount_amount'] ); // deprecated offset. + unset( $item_args['discount_amount_tax'] ); // deprecated offset. + + $item->set_order_id( $order->get_id() ); + $item->set_props( $item_args ); + $item->save(); + + do_action( 'woocommerce_order_update_coupon', $order->get_id(), $item->get_id(), $item_args ); + $discount_updated = true; + } else { + $discount_updated = $order->update_coupon( $item_id, $item_args ); + } + + if ( $discount_updated ) { + $order_total += $cut_amount; + $smart_coupons_contribution = $this->get_post_meta( $order_id, 'smart_coupons_contribution', true, true ); + if ( empty( $smart_coupons_contribution ) || ! is_array( $smart_coupons_contribution ) ) { + $smart_coupons_contribution = array(); + } + $smart_coupons_contribution[ $code ] = ( $this->is_wc_gte_30() ) ? $item_args['discount'] : $item_args['discount_amount']; + $this->update_post_meta( $order_id, 'smart_coupons_contribution', $smart_coupons_contribution, true, $order ); + + if ( ! empty( $store_credit_label['singular'] ) ) { + /* translators: 1. amount of store credit 2. store credit label 3. coupon code */ + $order_note[] = sprintf( __( '%1$s worth of %2$s restored to coupon %3$s.', 'woocommerce-smart-coupons' ), '' . wc_price( $cut_amount ) . '', ucwords( $store_credit_label['singular'] ), '' . $code . '' ); + } else { + /* translators: 1. amount of store credit 2. coupon code */ + $order_note[] = sprintf( __( '%1$s worth of Store Credit restored to coupon %2$s.', 'woocommerce-smart-coupons' ), '' . wc_price( $cut_amount ) . '', '' . $code . '' ); + } + } + } + } + $order->set_total( $order_total, 'total' ); + if ( ! empty( $order_note ) ) { + /* translators: Order notes */ + $note = sprintf( __( '%s Because PayPal doesn\'t accept discount on shipping & tax.', 'woocommerce-smart-coupons' ), implode( ', ', $order_note ) ); + $order->add_order_note( $note ); + if ( ! wc_has_notice( $note ) ) { + wc_add_notice( $note ); + } + } + } + + return $args; + } + + /** + * Function to track whether coupon is used or not + * + * @param int $order_id The order id. + */ + public function coupons_used( $order_id ) { + + $order = wc_get_order( $order_id ); + + $email = ( $this->is_callable( $order, 'get_meta' ) ) ? $order->get_meta( 'gift_receiver_email' ) : get_post_meta( $order_id, 'gift_receiver_email', true ); + + $used_coupons = $this->get_coupon_codes( $order ); + if ( ! empty( $used_coupons ) ) { + $this->update_coupons( $used_coupons, $email, '', 'remove' ); + } + } + + /** + * Function to update details related to coupons + * + * @param array $coupon_titles The coupon codes. + * @param mixed $email Email addresses. + * @param array $product_ids Array of product ids. + * @param string $operation Operation to perform. + * @param array $order_item The order item. + * @param array $gift_certificate_receiver Array of gift receiver emails. + * @param array $gift_certificate_receiver_name Array of gift receiver name. + * @param string $message_from_sender The message from sender. + * @param string $gift_certificate_sender_name Name of the sender. + * @param string $gift_certificate_sender_email Email address of the sender. + * @param int $order_id The order id. + */ + public function update_coupons( $coupon_titles = array(), $email = array(), $product_ids = '', $operation = '', $order_item = null, $gift_certificate_receiver = false, $gift_certificate_receiver_name = '', $message_from_sender = '', $gift_certificate_sender_name = '', $gift_certificate_sender_email = '', $order_id = '' ) { + + global $smart_coupon_codes; + + $order = null; + + $temp_gift_card_receivers_emails = array(); + if ( ! empty( $order_id ) ) { + $order = wc_get_order( $order_id ); + if ( $this->is_callable( $order, 'get_meta' ) ) { + $receivers_messages = $order->get_meta( 'gift_receiver_message' ); + $temp_gift_card_receivers_emails = $order->get_meta( 'temp_gift_card_receivers_emails' ); + $schedule_gift_sending = $order->get_meta( 'wc_sc_schedule_gift_sending' ); + $sending_timestamps = $order->get_meta( 'gift_sending_timestamp' ); + } else { + $receivers_messages = get_post_meta( $order_id, 'gift_receiver_message', true ); + $temp_gift_card_receivers_emails = get_post_meta( $order_id, 'temp_gift_card_receivers_emails', true ); + $schedule_gift_sending = get_post_meta( $order_id, 'wc_sc_schedule_gift_sending', true ); + $sending_timestamps = get_post_meta( $order_id, 'gift_sending_timestamp', true ); + } + } + + if ( ! is_a( $order, 'WC_Order' ) ) { + $order = ( is_object( $order_item ) && is_callable( array( $order_item, 'get_order' ) ) ) ? $order_item->get_order() : null; + } + + $prices_include_tax = ( get_option( 'woocommerce_prices_include_tax' ) === 'yes' ) ? true : false; + + if ( ! empty( $coupon_titles ) ) { + + if ( $this->is_wc_gte_30() ) { + $item_qty = ( ! empty( $order_item ) && is_callable( array( $order_item, 'get_quantity' ) ) ) ? $order_item->get_quantity() : 1; + $item_total = ( ! empty( $order_item ) && is_callable( array( $order_item, 'get_total' ) ) ) ? $order_item->get_total() : 0; + $item_tax = ( ! empty( $order_item ) && is_callable( array( $order_item, 'get_total_tax' ) ) ) ? $order_item->get_total_tax() : 0; + $item_product = ( ! empty( $order_item ) && is_callable( array( $order_item, 'get_product' ) ) ) ? $order_item->get_product() : null; + } else { + $item_qty = ( ! empty( $order_item['qty'] ) ) ? $order_item['qty'] : 1; + $item_total = ( ! empty( $order_item['line_total'] ) ) ? $order_item['line_total'] : 0; + $item_tax = ( ! empty( $order_item['line_tax'] ) ) ? $order_item['line_tax'] : 0; + $item_product = null; + } + + $item_sc_called_credit = ( is_a( $order_item, 'WC_Order_Item' ) ) ? $this->get_meta( $order_item, 'sc_called_credit' ) : ''; + + $qty = ( ! empty( $item_qty ) ) ? $item_qty : 1; + + foreach ( $coupon_titles as $coupon_title ) { + + $coupon = new WC_Coupon( $coupon_title ); + + $is_callable_coupon_get_meta = $this->is_callable( $coupon, 'get_meta' ); + + if ( $this->is_wc_gte_30() ) { + if ( ! is_object( $coupon ) || ! is_callable( array( $coupon, 'get_id' ) ) ) { + continue; + } + $coupon_id = $coupon->get_id(); + if ( empty( $coupon_id ) ) { + continue; + } + $is_free_shipping = ( $coupon->get_free_shipping() ) ? 'yes' : 'no'; + $discount_type = $coupon->get_discount_type(); + $coupon_code = $coupon->get_code(); + $coupon_amount = ( $this->is_callable( $coupon, 'get_amount' ) ) ? $coupon->get_amount() : 0; + } else { + $coupon_id = ( ! empty( $coupon->id ) ) ? $coupon->id : 0; + $is_free_shipping = ( ! empty( $coupon->free_shipping ) ) ? $coupon->free_shipping : ''; + $discount_type = ( ! empty( $coupon->discount_type ) ) ? $coupon->discount_type : ''; + $coupon_code = ( ! empty( $coupon->code ) ) ? $coupon->code : ''; + $coupon_amount = ( ! empty( $coupon->amount ) ) ? $coupon->amount : 0; + } + + $auto_generation_of_code = ( true === $is_callable_coupon_get_meta ) ? $coupon->get_meta( 'auto_generate_coupon' ) : get_post_meta( $coupon_id, 'auto_generate_coupon', true ); + + if ( ! empty( $item_sc_called_credit ) && 'smart_coupon' === $discount_type ) { + continue; // because it is already processed. + } + + $email_id = ( 'yes' === $auto_generation_of_code && 'smart_coupon' !== $discount_type && ! empty( $temp_gift_card_receivers_emails[ $coupon_id ][0] ) ) ? $temp_gift_card_receivers_emails[ $coupon_id ][0] : $gift_certificate_sender_email; + + if ( ( 'yes' === $auto_generation_of_code || 'smart_coupon' === $discount_type ) && 'add' === $operation ) { + + $is_pick_price_of_product = ( true === $is_callable_coupon_get_meta ) ? $coupon->get_meta( 'is_pick_price_of_product' ) : get_post_meta( $coupon_id, 'is_pick_price_of_product', true ); + + if ( 'yes' === $is_pick_price_of_product && 'smart_coupon' === $discount_type ) { + + $amount = 0; + $sell_sc_at_less_price = get_option( 'smart_coupons_sell_store_credit_at_less_price', 'no' ); + + if ( is_object( $order_item ) && is_a( $order_item, 'WC_Order_Item_Product' ) ) { + $subtotal = ( is_callable( array( $order_item, 'get_subtotal' ) ) ) ? $order_item->get_subtotal() : 0; + $subtotal_tax = ( is_callable( array( $order_item, 'get_subtotal_tax' ) ) ) ? $order_item->get_subtotal_tax() : 0; + $amount = $subtotal + $subtotal_tax; + $amount = round( $amount, get_option( 'woocommerce_price_num_decimals', 2 ) ); + } + + if ( 'yes' === $sell_sc_at_less_price ) { + + $args = array( + 'qty' => $qty, + 'price' => ( is_object( $item_product ) && is_callable( array( $item_product, 'get_regular_price' ) ) ) ? $item_product->get_regular_price() : '', + ); + + if ( ! $prices_include_tax ) { + $products_price = function_exists( 'wc_get_price_excluding_tax' ) ? wc_get_price_excluding_tax( $item_product, $args ) : $item_total; + } else { + $products_price = function_exists( 'wc_get_price_including_tax' ) ? wc_get_price_including_tax( $item_product, $args ) : $item_total + $item_tax; + } + } else { + $products_price = ( ! $prices_include_tax ) ? $item_total : $item_total + $item_tax; + } + + $amount = ( empty( $products_price ) ) ? $amount : $products_price; + + $amount = $amount / $qty; + + $amount = apply_filters( + 'wc_sc_auto_generated_coupon_pick_price_of_product', + $amount, + array( + 'calculated_product_price' => $amount, + 'order_item' => $order_item, + ) + ); + + } else { + if ( false === stripos( $discount_type, 'percent' ) ) { + $coupon_amount = $this->write_price( $coupon_amount, true, $order ); + } + $amount = $coupon_amount; + } + + if ( ! empty( $temp_gift_card_receivers_emails ) ) { + $email = $temp_gift_card_receivers_emails; + } + + $is_auto_generate = $amount > 0 || 'yes' === $is_free_shipping; + + $is_auto_generate = apply_filters( + 'wc_sc_is_auto_generate', + $is_auto_generate, + array( + 'coupon_id' => $coupon_id, + 'auto_generate' => $auto_generation_of_code, + 'coupon_obj' => $coupon, + 'coupon_amount' => $amount, + 'current_receiver' => $email_id, + 'receiver_email_ids' => $email, + 'receivers_messages' => $receivers_messages, + 'order_id' => $order_id, + 'order_item' => $order_item, + ) + ); + + if ( $is_auto_generate ) { + $message_index = ( ! empty( $email[ $coupon_id ] ) && is_array( $email[ $coupon_id ] ) ) ? array_search( $email_id, $email[ $coupon_id ], true ) : false; + + if ( false !== $message_index && isset( $receivers_messages[ $coupon_id ][ $message_index ] ) && ! empty( $receivers_messages[ $coupon_id ][ $message_index ] ) ) { + $message_from_sender = $receivers_messages[ $coupon_id ][ $message_index ]; + unset( $email[ $coupon_id ][ $message_index ] ); + $this->update_post_meta( $order_id, 'temp_gift_card_receivers_emails', $email, false, $order ); + } else { + $message_from_sender = ''; + } + if ( false !== $message_index && isset( $sending_timestamps[ $coupon_id ][ $message_index ] ) && ! empty( $sending_timestamps[ $coupon_id ][ $message_index ] ) ) { + $sending_timestamp = $sending_timestamps[ $coupon_id ][ $message_index ]; + } else { + $sending_timestamp = ''; + } + for ( $i = 0; $i < $qty; $i++ ) { + if ( 'yes' === $auto_generation_of_code || 'smart_coupon' === $discount_type ) { + $email_id = ! empty( $temp_gift_card_receivers_emails[ $coupon_id ][ $i ] ) ? $temp_gift_card_receivers_emails[ $coupon_id ][ $i ] : $gift_certificate_sender_email; + if ( isset( $receivers_messages[ $coupon_id ][ $i ] ) && ! empty( $receivers_messages[ $coupon_id ][ $i ] ) ) { + $message_from_sender = $receivers_messages[ $coupon_id ][ $i ]; + unset( $email[ $coupon_id ][ $i ] ); + $this->update_post_meta( $order_id, 'temp_gift_card_receivers_emails', $email, false, $order ); + } else { + $message_from_sender = ''; + } + if ( isset( $sending_timestamps[ $coupon_id ][ $i ] ) && ! empty( $sending_timestamps[ $coupon_id ][ $i ] ) ) { + $sending_timestamp = $sending_timestamps[ $coupon_id ][ $i ]; + } else { + $sending_timestamp = ''; + } + $this->generate_smart_coupon( $email_id, $amount, $order_id, $coupon, $discount_type, $gift_certificate_receiver_name, $message_from_sender, $gift_certificate_sender_name, $gift_certificate_sender_email, $sending_timestamp ); + $smart_coupon_codes = array(); + } + } + } + } else { + + $coupon_receiver_email = ( ! empty( $temp_gift_card_receivers_emails[ $coupon_id ][0] ) ) ? $temp_gift_card_receivers_emails[ $coupon_id ][0] : $gift_certificate_sender_email; + + $sc_disable_email_restriction = ( true === $is_callable_coupon_get_meta ) ? $coupon->get_meta( 'sc_disable_email_restriction' ) : get_post_meta( $coupon_id, 'sc_disable_email_restriction', true ); + $is_update_email_restrictions = false; + + if ( ( 'no' === $sc_disable_email_restriction || empty( $sc_disable_email_restriction ) ) ) { + $old_customers_email_ids = ( $this->is_callable( $coupon, 'get_email_restrictions' ) ) ? (array) maybe_unserialize( $coupon->get_email_restrictions() ) : (array) maybe_unserialize( get_post_meta( $coupon_id, 'customer_email', true ) ); + } + + if ( 'add' === $operation && 'yes' !== $auto_generation_of_code && 'smart_coupon' !== $discount_type ) { + $message_index = ( ! empty( $temp_gift_card_receivers_emails[ $coupon_id ] ) && is_array( $temp_gift_card_receivers_emails[ $coupon_id ] ) ) ? array_search( $email_id, $temp_gift_card_receivers_emails[ $coupon_id ], true ) : false; + + if ( false !== $message_index && isset( $receivers_messages[ $coupon_id ][ $message_index ] ) && ! empty( $receivers_messages[ $coupon_id ][ $message_index ] ) ) { + $message_from_sender = $receivers_messages[ $coupon_id ][ $message_index ]; + unset( $temp_gift_card_receivers_emails[ $coupon_id ][ $message_index ] ); + $this->update_post_meta( $order_id, 'temp_gift_card_receivers_emails', $temp_gift_card_receivers_emails, false, $order ); + } else { + $message_from_sender = ''; + } + + if ( false !== $message_index && isset( $sending_timestamps[ $coupon_id ][ $message_index ] ) && ! empty( $sending_timestamps[ $coupon_id ][ $message_index ] ) ) { + $sending_timestamp = $sending_timestamps[ $coupon_id ][ $message_index ]; + } else { + $sending_timestamp = ''; + } + + for ( $i = 0; $i < $qty; $i++ ) { + + $coupon_receiver_email = ( ! empty( $temp_gift_card_receivers_emails[ $coupon_id ][ $i ] ) ) ? $temp_gift_card_receivers_emails[ $coupon_id ][ $i ] : $coupon_receiver_email; + $message_from_sender = ( ! empty( $receivers_messages[ $coupon_id ][ $i ] ) ) ? $receivers_messages[ $coupon_id ][ $i ] : ''; + $sending_timestamp = ( ! empty( $sending_timestamps[ $coupon_id ][ $i ] ) ) ? $sending_timestamps[ $coupon_id ][ $i ] : ''; + + if ( false === stripos( $discount_type, 'percent' ) ) { + $coupon_amount = $this->write_price( $coupon_amount, true, $order ); + } + + $coupon_details = array( + $coupon_receiver_email => array( + 'parent' => $coupon_id, + 'code' => $coupon_title, + 'amount' => $coupon_amount, + ), + ); + + $receiver_name = ''; + + if ( 'yes' === $schedule_gift_sending && $this->is_valid_timestamp( $sending_timestamp ) ) { + $sender_message_index_key = ( ! empty( $receivers_messages[ $coupon_id ][ $i ] ) ) ? $coupon_id . ':' . $i : ''; + $action_args = array( + 'auto_generate' => 'no', + 'coupon_id' => $coupon_id, + 'parent_id' => $coupon_id, // Parent coupon id. + 'order_id' => $order_id, + 'receiver_email' => $coupon_receiver_email, + 'message_index_key' => $sender_message_index_key, + 'ref_key' => uniqid(), // A unique timestamp key to relate action schedulers with their coupons. + ); + $is_scheduled = $this->schedule_coupon_email( $action_args, $sending_timestamp ); + if ( ! $is_scheduled ) { + /* translators: 1. Receiver email 2. Coupon code 3. Order id */ + $this->log( 'error', sprintf( __( 'Failed to schedule email to "%1$s" for coupon "%2$s" received from order #%3$s.', 'woocommerce-smart-coupons' ), $coupon_receiver_email, $coupon_title, $order_id ) ); + } + } else { + $this->sa_email_coupon( $coupon_details, $discount_type, $order_id, $receiver_name, $message_from_sender ); + } + } + + if ( $qty > 0 && ( 'no' === $sc_disable_email_restriction || empty( $sc_disable_email_restriction ) ) ) { + for ( $i = 0; $i < $qty; $i++ ) { + $sending_timestamp = ( ! empty( $sending_timestamps[ $coupon_id ][ $i ] ) ) ? $sending_timestamps[ $coupon_id ][ $i ] : ''; + // Add receiver email to coupon only if it is not scheduled otherwise it would be added by action scheduler later on. + if ( ! ( 'yes' === $schedule_gift_sending && $this->is_valid_timestamp( $sending_timestamp ) ) ) { + $old_customers_email_ids[] = $coupon_receiver_email; + $is_update_email_restrictions = true; + } + } + } + } elseif ( 'remove' === $operation && 'smart_coupon' !== $discount_type && ( 'no' === $sc_disable_email_restriction || empty( $sc_disable_email_restriction ) ) ) { + + $key = array_search( $coupon_receiver_email, $old_customers_email_ids, true ); + + if ( false !== $key ) { + unset( $old_customers_email_ids[ $key ] ); + $is_update_email_restrictions = true; + } + } + + if ( ( 'no' === $sc_disable_email_restriction || empty( $sc_disable_email_restriction ) ) && true === $is_update_email_restrictions ) { + if ( $this->is_callable( $coupon, 'set_defaults' ) && $this->is_callable( $coupon, 'set_email_restrictions' ) && $this->is_callable( $coupon, 'save' ) ) { + $coupon->set_defaults(); // This is to make sure that no other changes done to $coupon will be saved. Because this functionality is only to update 'email_restrictions'. + $coupon->set_object_read( true ); + $coupon->set_email_restrictions( $old_customers_email_ids ); + $coupon->save(); + } else { + update_post_meta( $coupon_id, 'customer_email', $old_customers_email_ids ); + } + } + } + } + } + + } + + /** + * Get receiver's email addresses + * + * @param array $coupon_details The coupon details. + * @param string $gift_certificate_sender_email Sender email address. + * @return array $receivers_email Array of receiver's email + */ + public function get_receivers_detail( $coupon_details = array(), $gift_certificate_sender_email = '' ) { + + if ( count( $coupon_details ) <= 0 ) { + return 0; + } + + $all_discount_types = wc_get_coupon_types(); + + $receivers_email = array(); + + foreach ( $coupon_details as $coupon_id => $emails ) { + $discount_type = ( ! empty( $coupon_id ) ) ? $this->get_post_meta( $coupon_id, 'discount_type', true ) : 'fixed_cart'; + if ( ! empty( $discount_type ) && array_key_exists( $discount_type, $all_discount_types ) ) { + $receivers_email = array_merge( $receivers_email, array_diff( $emails, array( $gift_certificate_sender_email ) ) ); + } + } + + return $receivers_email; + } + + /** + * Function to process coupons based on change in order status + * + * @param int $order_id The order id. + * @param string $operation Operation. + */ + public function process_coupons( $order_id, $operation ) { + global $smart_coupon_codes, $woocommerce_smart_coupon; + + $smart_coupon_codes = array(); + $message_from_sender = ''; + $sending_timestamp = ''; + + $order = wc_get_order( $order_id ); + $is_callable_order_get_meta = $this->is_callable( $order, 'get_meta' ); + + if ( true === $is_callable_order_get_meta ) { + $receivers_emails = $order->get_meta( 'gift_receiver_email' ); + $receivers_messages = $order->get_meta( 'gift_receiver_message' ); + $sending_timestamps = $order->get_meta( 'gift_sending_timestamp' ); + $is_coupon_sent = $order->get_meta( 'coupon_sent' ); + } else { + $receivers_emails = get_post_meta( $order_id, 'gift_receiver_email', true ); + $receivers_messages = get_post_meta( $order_id, 'gift_receiver_message', true ); + $sending_timestamps = get_post_meta( $order_id, 'gift_sending_timestamp', true ); + $is_coupon_sent = get_post_meta( $order_id, 'coupon_sent', true ); + } + $is_send_email = $this->is_email_template_enabled(); + + if ( 'yes' === $is_coupon_sent ) { + return; + } + + $order_items = ( is_object( $order ) && is_callable( array( $order, 'get_items' ) ) ) ? $order->get_items() : array(); + + $receivers_data = $receivers_emails; + $sc_called_credit_details = $this->get_post_meta( $order_id, 'sc_called_credit_details', true, false, $order ); + + if ( count( $order_items ) <= 0 ) { + return; + } + + if ( $this->is_wc_gte_30() ) { + $order_billing_email = ( is_object( $order ) && is_callable( array( $order, 'get_billing_email' ) ) ) ? $order->get_billing_email() : ''; + $order_billing_first_name = ( is_object( $order ) && is_callable( array( $order, 'get_billing_first_name' ) ) ) ? $order->get_billing_first_name() : ''; + $order_billing_last_name = ( is_object( $order ) && is_callable( array( $order, 'get_billing_last_name' ) ) ) ? $order->get_billing_last_name() : ''; + } else { + $order_billing_email = ( ! empty( $order->billing_email ) ) ? $order->billing_email : ''; + $order_billing_first_name = ( ! empty( $order->billing_first_name ) ) ? $order->billing_first_name : ''; + $order_billing_last_name = ( ! empty( $order->billing_last_name ) ) ? $order->billing_last_name : ''; + } + + if ( is_array( $receivers_emails ) && ! empty( $receivers_emails ) ) { + + foreach ( $receivers_emails as $coupon_id => $emails ) { + foreach ( $emails as $key => $email ) { + if ( empty( $email ) ) { + $email = $order_billing_email; + $receivers_emails[ $coupon_id ][ $key ] = $email; + } + } + } + + if ( count( $receivers_emails ) > 1 && isset( $receivers_emails[0][0] ) ) { + unset( $receivers_emails[0] ); // Disable sending to one customer. + } + $email = $receivers_emails; + } else { + $email = ''; + } + + $receivers_emails_list = $receivers_emails; + if ( ! empty( $email ) ) { + $this->update_post_meta( $order_id, 'temp_gift_card_receivers_emails', $email, false, $order ); + } + + $gift_certificate_receiver = true; + $gift_certificate_sender_name = $order_billing_first_name . ' ' . $order_billing_last_name; + $gift_certificate_sender_email = $order_billing_email; + $gift_certificate_receiver_name = ''; + + $receivers_detail = array(); + $email_to_credit = array(); + $receiver_count = 0; + + if ( is_array( $sc_called_credit_details ) && count( $sc_called_credit_details ) > 0 && 'add' === $operation ) { + + foreach ( $order_items as $item_id => $item ) { + + $product = ( is_object( $item ) && is_callable( array( $item, 'get_product' ) ) ) ? $item->get_product() : $order->get_product_from_item( $item ); + $item_qty = ( is_object( $item ) && is_callable( array( $item, 'get_quantity' ) ) ) ? $item->get_quantity() : $item['qty']; + + if ( $this->is_wc_gte_30() ) { + $product_type = ( is_object( $product ) && is_callable( array( $product, 'get_type' ) ) ) ? $product->get_type() : ''; + $product_id = ( in_array( $product_type, array( 'variable', 'variable-subscription', 'variation', 'subscription_variation' ), true ) ) ? ( ( is_object( $product ) && is_callable( array( $product, 'get_parent_id' ) ) ) ? $product->get_parent_id() : 0 ) : ( ( is_object( $product ) && is_callable( array( $product, 'get_id' ) ) ) ? $product->get_id() : 0 ); + } else { + $product_id = ( ! empty( $product->id ) ) ? $product->id : 0; + } + + $coupon_titles = $this->get_coupon_titles( array( 'product_object' => $product ) ); + + if ( $coupon_titles ) { + + foreach ( $coupon_titles as $coupon_title ) { + $coupon = new WC_Coupon( $coupon_title ); + if ( $this->is_wc_gte_30() ) { + if ( ! is_object( $coupon ) || ! is_callable( array( $coupon, 'get_id' ) ) ) { + continue; + } + $coupon_id = $coupon->get_id(); + if ( empty( $coupon_id ) ) { + continue; + } + } else { + $coupon_id = ( ! empty( $coupon->id ) ) ? $coupon->id : 0; + } + + $coupon_amount = $this->get_amount( $coupon, true, $order ); + + if ( ! isset( $receivers_emails[ $coupon_id ] ) ) { + continue; + } + for ( $i = 0; $i < $item_qty; $i++ ) { + if ( isset( $receivers_emails[ $coupon_id ][0] ) ) { + if ( ! isset( $email_to_credit[ $receivers_emails[ $coupon_id ][0] ] ) ) { + $email_to_credit[ $receivers_emails[ $coupon_id ][0] ] = array(); + } + if ( isset( $sc_called_credit_details[ $item_id ] ) && ! empty( $sc_called_credit_details[ $item_id ] ) ) { + + if ( $this->is_coupon_amount_pick_from_product_price( array( $coupon_title ) ) ) { + $credit_price = $sc_called_credit_details[ $item_id ]; + // Allow 3rd party plugins to modify the amount before generating credit. + $credit_price = apply_filters( + 'wc_sc_credit_called_price_order', + $credit_price, + array( + 'source' => $this, + 'item_id' => $item_id, + 'order_obj' => $order, + ) + ); + $email_to_credit[ $receivers_emails[ $coupon_id ][0] ][] = $coupon_id . ':' . $credit_price; + } else { + $email_to_credit[ $receivers_emails[ $coupon_id ][0] ][] = $coupon_id . ':' . $coupon_amount; + } + + unset( $receivers_emails[ $coupon_id ][0] ); + $receivers_emails[ $coupon_id ] = array_values( $receivers_emails[ $coupon_id ] ); + } + } + } + } + } + if ( $this->is_coupon_amount_pick_from_product_price( $coupon_titles ) && is_object( $product ) && is_callable( array( $product, 'get_price' ) ) && $product->get_price() >= 0 ) { + $sc_called_credit = ( ! empty( $sc_called_credit_details[ $item_id ] ) ) ? $sc_called_credit_details[ $item_id ] : ''; + $woocommerce_smart_coupon->update_meta_data( $item, 'sc_called_credit', $sc_called_credit ); + } + } + } + + if ( ! empty( $email_to_credit ) && count( $email_to_credit ) > 0 ) { + $update_temp_email = false; + $temp_email = $email; + foreach ( $email_to_credit as $email_id => $credits ) { + $email_to_credit[ $email_id ] = array_count_values( $credits ); + foreach ( $email_to_credit[ $email_id ] as $coupon_credit => $qty ) { + $coupon_details = explode( ':', $coupon_credit ); + $coupon_title = get_the_title( $coupon_details[0] ); + $coupon = new WC_Coupon( $coupon_title ); + $credit_amount = $coupon_details[1]; + if ( $this->is_wc_gte_30() ) { + if ( ! is_object( $coupon ) || ! is_callable( array( $coupon, 'get_id' ) ) ) { + continue; + } + $coupon_id = $coupon->get_id(); + if ( empty( $coupon_id ) ) { + continue; + } + $discount_type = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_discount_type' ) ) ) ? $coupon->get_discount_type() : ''; + } else { + $coupon_id = ( ! empty( $coupon->id ) ) ? $coupon->id : 0; + $discount_type = ( ! empty( $coupon->discount_type ) ) ? $coupon->discount_type : ''; + } + + for ( $i = 0; $i < $qty; $i++ ) { + if ( 'smart_coupon' !== $discount_type ) { + continue; // only process smart_coupon here, rest coupon will be processed by function update_coupon. + } + + $message_index = array_search( $email_id, $temp_email[ $coupon_id ], true ); + + if ( false !== $message_index ) { + $temp_email[ $coupon_id ][ $message_index ] = ''; // Empty value at found index so that we don't get same index in next loop run. + } + if ( false !== $message_index && isset( $receivers_messages[ $coupon_id ][ $message_index ] ) && ! empty( $receivers_messages[ $coupon_id ][ $message_index ] ) ) { + $message_from_sender = $receivers_messages[ $coupon_id ][ $message_index ]; + } else { + $message_from_sender = ''; + } + if ( false !== $message_index && isset( $sending_timestamps[ $coupon_id ][ $message_index ] ) && ! empty( $sending_timestamps[ $coupon_id ][ $message_index ] ) ) { + $sending_timestamp = $sending_timestamps[ $coupon_id ][ $message_index ]; + } else { + $sending_timestamp = ''; + } + + $this->generate_smart_coupon( $email_id, $credit_amount, $order_id, $coupon, 'smart_coupon', $gift_certificate_receiver_name, $message_from_sender, $gift_certificate_sender_name, $gift_certificate_sender_email, $sending_timestamp ); + $smart_coupon_codes = array(); + } + } + } + foreach ( $email_to_credit as $email => $coupon_detail ) { + if ( $email === $gift_certificate_sender_email ) { + continue; + } + $receiver_count += count( $coupon_detail ); + } + } + + $order = wc_get_order( $order_id ); // Refresh order object to get latest updates in the order object. + + if ( count( $order_items ) > 0 ) { + + $flag = false; + + foreach ( $order_items as $item_id => $item ) { + + $product = ( is_object( $item ) && is_callable( array( $item, 'get_product' ) ) ) ? $item->get_product() : ( ( is_object( $order ) && is_callable( array( $order, 'get_product_from_item' ) ) ) ? $order->get_product_from_item( $item ) : new stdClass() ); + if ( $this->is_wc_gte_30() ) { + $product_type = ( is_object( $product ) && is_callable( array( $product, 'get_type' ) ) ) ? $product->get_type() : ''; + $product_id = ( in_array( $product_type, array( 'variable', 'variable-subscription', 'variation', 'subscription_variation' ), true ) ) ? ( ( is_object( $product ) && is_callable( array( $product, 'get_parent_id' ) ) ) ? $product->get_parent_id() : 0 ) : ( ( is_object( $product ) && is_callable( array( $product, 'get_id' ) ) ) ? $product->get_id() : 0 ); + } else { + $product_id = ( ! empty( $product->id ) ) ? $product->id : 0; + } + + $coupon_titles = $this->get_coupon_titles( array( 'product_object' => $product ) ); + + if ( $coupon_titles ) { + + $flag = true; + + if ( $this->is_coupon_amount_pick_from_product_price( $coupon_titles ) && is_object( $product ) && is_callable( array( $product, 'get_price' ) ) && $product->get_price() >= 0 ) { + $sc_called_credit = ( ! empty( $sc_called_credit_details[ $item_id ] ) ) ? $sc_called_credit_details[ $item_id ] : ''; + $woocommerce_smart_coupon->update_meta_data( $item, 'sc_called_credit', $sc_called_credit ); + } + + $this->update_coupons( $coupon_titles, $email, '', $operation, $item, $gift_certificate_receiver, $gift_certificate_receiver_name, $message_from_sender, $gift_certificate_sender_name, $gift_certificate_sender_email, $order_id ); + + if ( 'add' === $operation && ! empty( $receivers_emails_list ) ) { + $receivers_detail += $this->get_receivers_detail( $receivers_emails_list, $gift_certificate_sender_email ); + } + } + } + + $order = wc_get_order( $order_id ); // Refresh order object to get latest updates in the order object. + + if ( $flag && 'add' === $operation ) { + $combine_emails = $this->is_email_template_enabled( 'combine' ); + if ( 'yes' === $is_send_email && 'yes' === $combine_emails ) { + $coupon_receiver_details = ( true === $is_callable_order_get_meta ) ? $order->get_meta( 'sc_coupon_receiver_details' ) : get_post_meta( $order_id, 'sc_coupon_receiver_details', true ); + if ( is_array( $coupon_receiver_details ) && ! empty( $coupon_receiver_details ) ) { + $combined_coupon_receiver_details = array(); + foreach ( $coupon_receiver_details as $receiver_detail ) { + $receiver_email = $receiver_detail['email']; + if ( ! isset( $combined_coupon_receiver_details[ $receiver_email ] ) || ! is_array( $combined_coupon_receiver_details[ $receiver_email ] ) ) { + $combined_coupon_receiver_details[ $receiver_email ] = array(); + } + $combined_coupon_receiver_details[ $receiver_email ][] = array( + 'code' => $receiver_detail['code'], + 'message' => $receiver_detail['message'], + ); + } + if ( ! empty( $combined_coupon_receiver_details ) ) { + foreach ( $combined_coupon_receiver_details as $combined_receiver_email => $combined_receiver_details ) { + $this->send_combined_coupon_email( $combined_receiver_email, $combined_receiver_details, $order_id, $gift_certificate_sender_name, $gift_certificate_sender_email ); + } + } + } + } + $this->update_post_meta( $order_id, 'coupon_sent', 'yes', false, $order ); // to know whether coupon has sent or not. + } + } + + $email_scheduled_details = array(); + // Assign scheduled timestamps to each user's email. + if ( ! empty( $receivers_data ) && is_array( $receivers_data ) && ! empty( $sending_timestamps ) ) { + foreach ( $receivers_data as $coupon_id => $receivers ) { + $scheduled_timestamp = ! empty( $sending_timestamps[ $coupon_id ] ) ? $sending_timestamps[ $coupon_id ] : ''; + // Get the receivers by coupon codes. + if ( ! empty( $scheduled_timestamp ) && is_array( $receivers ) && ! empty( $receivers ) ) { + foreach ( $receivers as $key => $receiver_email ) { + $before_timestamps = ! empty( $email_scheduled_details[ $receiver_email ] ) ? $email_scheduled_details[ $receiver_email ] : ''; + $timestamps = ! empty( $scheduled_timestamp[ $key ] ) ? array( $scheduled_timestamp[ $key ] ) : array(); + $email_scheduled_details[ $receiver_email ] = ! empty( $before_timestamps ) && is_array( $before_timestamps ) ? array_merge( $before_timestamps, $timestamps ) : $timestamps; + } + } + } + } + + if ( 'yes' === $is_send_email && ( count( $receivers_detail ) + $receiver_count ) > 0 ) { + $current_filter = current_filter(); + $order_actions_to_ignore_for_email = $this->order_actions_to_ignore_for_email(); + if ( ! in_array( $current_filter, $order_actions_to_ignore_for_email, true ) ) { + WC()->mailer(); + + $contains_core_coupons = false; + if ( ! empty( $receivers_emails_list ) ) { + $coupon_ids_to_be_sent = array_keys( $receivers_emails_list ); + if ( ! empty( $coupon_ids_to_be_sent ) ) { + foreach ( $coupon_ids_to_be_sent as $coupon_id ) { + $discount_type = ( ! empty( $coupon_id ) ) ? $this->get_post_meta( $coupon_id, 'discount_type', true ) : 'fixed_cart'; + if ( ! empty( $discount_type ) && 'smart_coupon' !== $discount_type ) { + $contains_core_coupons = true; + break; + } + } + } + } + + $action_args = apply_filters( + 'wc_sc_acknowledgement_email_notification_args', + array( + 'email' => $gift_certificate_sender_email, + 'order_id' => $order_id, + 'receivers_detail' => $receivers_detail, + 'receiver_name' => $gift_certificate_receiver_name, + 'receiver_count' => count( $receivers_detail ), + 'scheduled_email' => array_filter( $email_scheduled_details ), + 'contains_core_coupons' => ( true === $contains_core_coupons ) ? 'yes' : 'no', + ) + ); + + // Trigger email notification. + do_action( 'wc_sc_acknowledgement_email_notification', $action_args ); + } + } + + if ( 'add' === $operation ) { + $this->delete_post_meta( $order_id, 'temp_gift_card_receivers_emails', null, $order ); + } + unset( $smart_coupon_codes ); + } + + /** + * Whether to auto generate coupon or not + * + * @param int $order_id The order id. + * @return boolean + */ + public function should_coupon_auto_generate( $order_id = 0 ) { + $should_auto_generate = true; + $valid_order_statuses = get_option( 'wc_sc_valid_order_statuses_for_coupon_auto_generation', wc_get_is_paid_statuses() ); + if ( ! empty( $valid_order_statuses ) ) { + $valid_order_statuses = apply_filters( 'wc_sc_valid_order_statuses_for_coupon_auto_generation', $valid_order_statuses, $order_id ); + if ( ! empty( $valid_order_statuses ) ) { + $order = wc_get_order( $order_id ); + $order_status = $order->get_status(); + if ( ! in_array( $order_status, $valid_order_statuses, true ) ) { + $should_auto_generate = false; + } + } + } + return apply_filters( + 'wc_sc_should_coupon_auto_generate', + $should_auto_generate, + array( + 'source' => $this, + 'order_id' => $order_id, + ) + ); + } + + /** + * Function to add details to coupons + * + * @param int $order_id The order id. + */ + public function sa_add_coupons( $order_id ) { + if ( ! $this->should_coupon_auto_generate( $order_id ) ) { + return; + } + $this->process_coupons( $order_id, 'add' ); + } + + /** + * Function to remove details from coupons + * + * @param int $order_id The order id. + */ + public function sa_remove_coupons( $order_id ) { + $this->process_coupons( $order_id, 'remove' ); + } + + /** + * Function to Restore Smart Coupon Amount back, when an order which was created using this coupon, is refunded or cancelled, + * + * @param int $order_id The order id. + */ + public function sa_restore_smart_coupon_amount( $order_id = 0 ) { + + if ( empty( $order_id ) ) { + return; + } + + $order = wc_get_order( $order_id ); + + $order_id = ( is_object( $order ) && is_callable( array( $order, 'get_id' ) ) ) ? $order->get_id() : 0; + + if ( empty( $order_id ) ) { + return; + } + + $coupons = $order->get_items( 'coupon' ); + + if ( ! empty( $coupons ) ) { + + foreach ( $coupons as $item_id => $item ) { + + $code = ( is_object( $item ) && is_callable( array( $item, 'get_name' ) ) ) ? $item->get_name() : trim( $item['name'] ); + + if ( empty( $code ) ) { + continue; + } + + $coupon = new WC_Coupon( $code ); + + if ( $this->is_wc_gte_30() ) { + if ( ! is_object( $coupon ) || ! is_callable( array( $coupon, 'get_id' ) ) ) { + continue; + } + $coupon_id = $coupon->get_id(); + if ( empty( $coupon_id ) ) { + continue; + } + $discount_type = $coupon->get_discount_type(); + $usage_count = $coupon->get_usage_count(); + } else { + $coupon_id = ( ! empty( $coupon->id ) ) ? $coupon->id : 0; + $discount_type = ( ! empty( $coupon->discount_type ) ) ? $coupon->discount_type : ''; + $usage_count = ( ! empty( $coupon->usage_count ) ) ? $coupon->usage_count : 0; + } + + $coupon_amount = $this->get_amount( $coupon, true, $order ); + + if ( empty( $discount_type ) || 'smart_coupon' !== $discount_type ) { + continue; + } + + if ( ! empty( $_POST['action'] ) && 'woocommerce_remove_order_coupon' === wc_clean( wp_unslash( $_POST['action'] ) ) && ! empty( $_POST['smart_coupon_removed'] ) && sanitize_text_field( wp_unslash( $_POST['smart_coupon_removed'] ) ) !== $code ) { // phpcs:ignore + continue; + } + + $discount = ( is_object( $item ) && is_callable( array( $item, 'get_discount' ) ) ) ? (float) $item->get_discount() : (float) $item['discount_amount']; + $discount_tax = ( is_object( $item ) && is_callable( array( $item, 'get_discount_tax' ) ) ) ? (float) $item->get_discount_tax() : (float) $item['discount_amount_tax']; + + $sc_refunded_discount = (float) $this->get_order_item_meta( $item_id, 'sc_refunded_discount', true ); + $sc_refunded_discount_tax = (float) $this->get_order_item_meta( $item_id, 'sc_refunded_discount_tax', true ); + $sc_refunded_coupon_id = $this->get_order_item_meta( $item_id, 'sc_refunded_coupon_id', true ); + + if ( absint( $coupon_id ) === absint( $sc_refunded_coupon_id ) ) { + $discount -= $sc_refunded_discount; + $discount_tax -= $sc_refunded_discount_tax; + } + + $update = false; + if ( floatval( $discount ) > floatval( 0 ) ) { + $coupon_amount += $discount; + + $sc_include_tax = $this->is_store_credit_include_tax(); + // Add discount on tax if it has been given on tax. + if ( 'yes' === $sc_include_tax && ! empty( $discount_tax ) ) { + $coupon_amount += $discount_tax; + } + $update = true; + } + + if ( $update ) { + $user = ( function_exists( 'get_current_user_id' ) ) ? get_current_user_id() : 0; + $local_time = ( function_exists( 'current_datetime' ) ) ? current_datetime() : ''; + $get_timestamp = ( is_object( $local_time ) && is_callable( array( $local_time, 'getTimestamp' ) ) ) ? $local_time->getTimestamp() : ''; + $get_offset = ( is_object( $local_time ) && is_callable( array( $local_time, 'getOffset' ) ) ) ? $local_time->getOffset() : ''; + $current_time_stamp = $get_timestamp + $get_offset; + + $this->update_post_meta( $coupon_id, 'coupon_amount', $coupon_amount, true, $order ); + $this->update_order_item_meta( $item_id, 'sc_refunded_discount', ( $sc_refunded_discount + $discount ), true, $order ); + $this->update_order_item_meta( $item_id, 'sc_refunded_discount_tax', ( $sc_refunded_discount_tax + $discount_tax ), true, $order ); + $this->update_order_item_meta( $item_id, 'sc_refunded_user_id', $user ); + $this->update_order_item_meta( $item_id, 'sc_refunded_timestamp', $current_time_stamp ); + $this->update_order_item_meta( $item_id, 'sc_refunded_coupon_id', $coupon_id ); + } + + $usage_count = intval( $usage_count ); + $usage_count--; + if ( $usage_count < 0 ) { + $usage_count = 0; + } + if ( $this->is_callable( $coupon, 'set_usage_count' ) && $this->is_callable( $coupon, 'save' ) ) { + $coupon->set_usage_count( $usage_count ); + $coupon->save(); + } else { + update_post_meta( $coupon_id, 'usage_count', $usage_count ); + } + } + } + + } + + /** + * Allow overriding of Smart Coupon's template for email + * + * @param string $template The template name. + * @return mixed $template + */ + public function woocommerce_gift_certificates_email_template_path( $template = '' ) { + + $template_name = 'email.php'; + + $template = $this->locate_template_for_smart_coupons( $template_name, $template ); + + return $template; + + } + + /** + * Allow overriding of Smart Coupon's template for combined emails template + * + * @param string $template The template name. + * @return mixed $template + */ + public function woocommerce_combined_gift_certificates_email_template_path( $template = '' ) { + + $template_name = 'combined-email.php'; + + $template = $this->locate_template_for_smart_coupons( $template_name, $template ); + + return $template; + + } + + /** + * Virtual downloadable order item needs update smart coupon balance. + * + * @param boolean $virtual_downloadable_item true/false. + * @param object $_product line item. + * @param int $order_id order id. + * @return bool|mixed + */ + public function virtual_downloadable_item_needs_update_smart_coupon_balance( $virtual_downloadable_item = true, $_product = null, $order_id = 0 ) { + if ( empty( $order_id ) ) { + return $virtual_downloadable_item; + } + $order = wc_get_order( $order_id ); + $hooks_available_for_statuses = array( 'on-hold', 'pending', 'processing', 'completed', 'failed', 'refunded', 'cancelled' ); + $order_status = ( is_object( $order ) && is_callable( array( $order, 'get_status' ) ) ) ? $order->get_status() : ''; + if ( ! in_array( $order_status, $hooks_available_for_statuses, true ) ) { + return $virtual_downloadable_item; + } + + if ( did_action( 'wc_sc_balance_updated_for_virtual_downloadable_item' ) >= 1 ) { + return $virtual_downloadable_item; + } + + $order_items = ( is_object( $order ) && is_callable( array( $order, 'get_items' ) ) ) ? $order->get_items() : array(); + + if ( false === $virtual_downloadable_item ) { + $is_included_other_products_in_cart = false; + if ( ! empty( $order_items ) ) { + foreach ( $order_items as $item ) { + if ( $item->is_type( 'line_item' ) ) { + $product = ( is_object( $item ) && is_callable( array( $item, 'get_product' ) ) ) ? $item->get_product() : null; + + if ( ! is_a( $product, 'WC_Product' ) ) { + continue; + } + + $is_virtual_downloadable_item = $product->is_downloadable() && $product->is_virtual(); + + if ( false === $is_virtual_downloadable_item ) { + $is_included_other_products_in_cart = true; + break; + } + } + } + } + $order_used_coupons = $this->get_coupon_codes( $order ); + + if ( ! empty( $order_used_coupons ) ) { + foreach ( $order_used_coupons as $code ) { + $smart_coupon = new WC_Coupon( $code ); + if ( $this->is_wc_gte_30() ) { + $discount_type = $smart_coupon->get_discount_type(); + } else { + $discount_type = ( ! empty( $smart_coupon->discount_type ) ) ? $smart_coupon->discount_type : ''; + } + if ( 'smart_coupon' === $discount_type ) { + if ( false === $is_included_other_products_in_cart ) { + remove_action( 'woocommerce_order_status_pending_to_completed', array( $this, 'update_smart_coupon_balance' ) ); + remove_action( 'woocommerce_order_status_pending_to_on-hold', array( $this, 'update_smart_coupon_balance' ) ); + remove_action( 'woocommerce_order_status_failed_to_on-hold', array( $this, 'update_smart_coupon_balance' ) ); + remove_action( 'woocommerce_order_status_failed_to_processing', array( $this, 'update_smart_coupon_balance' ) ); + remove_action( 'woocommerce_order_status_failed_to_completed', array( $this, 'update_smart_coupon_balance' ) ); + $this->update_smart_coupon_balance( $order_id ); + do_action( + 'wc_sc_balance_updated_for_virtual_downloadable_item', + array( + 'order_id' => $order_id, + 'product' => $_product, + 'source' => $this, + ) + ); + break; + } + } + } + } + } + return $virtual_downloadable_item; + } + + /** + * Check if the product is only going to generate/issue coupon, if so, tell the system that this product doesn't needs processing & can proceed with completing the order. + * + * @param boolean $needs_processing Whether needs processing or not. + * @param WC_Product $product The product object. + * @param integer $order_id The order id. + * @return boolean + */ + public function coupon_product_dont_need_processing( $needs_processing = true, $product = null, $order_id = 0 ) { + $coupon_titles = $this->get_coupon_titles( array( 'product_object' => $product ) ); + if ( $product->is_virtual() && ! empty( $coupon_titles ) ) { + $needs_processing = apply_filters( + 'wc_sc_coupon_product_need_processing', + $this->sc_get_option( 'wc_sc_coupon_product_need_processing', 'no' ), + array( + 'source' => $this, + 'original_needs_processing' => $needs_processing, + 'product' => $product, + 'order_id' => $order_id, + ) + ); + $needs_processing = ( 'yes' !== $needs_processing ) ? 'no' : $needs_processing; + return wc_string_to_bool( $needs_processing ); + } + return $needs_processing; + } + + /** + * Additional order actions + * + * @param array $actions Existing order actions. + * @param WC_Order $order The order object. + * @return array + */ + public function order_actions( $actions = array(), $order = null ) { + if ( is_null( $order ) || ! $this->is_wc_gte_30() ) { + return $actions; + } + if ( false === $this->would_order_generate_coupons( $order ) ) { + return $actions; + } + $sc_actions = array(); + $coupon_receiver_details = ( is_object( $order ) && $this->is_callable( $order, 'get_meta' ) ) ? $order->get_meta( 'sc_coupon_receiver_details' ) : array(); + if ( ! empty( $coupon_receiver_details ) ) { + $sc_actions['wc_sc_resend_coupons'] = _x( 'Resend coupon emails', 'Order edit admin page', 'woocommerce-smart-coupons' ); + } else { + $sc_actions['wc_sc_regenerate_coupons'] = _x( 'Regenerate coupons', 'Order edit admin page', 'woocommerce-smart-coupons' ); + $sc_actions['wc_sc_regenerate_resend_coupons'] = _x( 'Regenerate & resend coupon emails', 'Order edit admin page', 'woocommerce-smart-coupons' ); + } + $actions = array_merge( $actions, $sc_actions ); + return $actions; + } + + /** + * Handle order coupon actions + * + * @param WC_Order $order The order object. + */ + public function order_coupon_actions( $order = null ) { + if ( $this->is_wc_gte_30() ) { + $order_id = $this->is_callable( $order, 'get_id' ) ? $order->get_id() : 0; + if ( ! empty( $order_id ) ) { + $note = ''; + $current_filter = current_filter(); + switch ( $current_filter ) { + case 'woocommerce_order_action_wc_sc_regenerate_coupons': + case 'woocommerce_order_action_wc_sc_regenerate_resend_coupons': + if ( $this->is_callable( $order, 'update_meta_data' ) && $this->is_callable( $order, 'save' ) ) { + $order = wc_get_order( $order ); + $order->update_meta_data( 'coupon_sent', 'no' ); + $order->save(); + } + $this->sa_add_coupons( $order_id ); + if ( 'woocommerce_order_action_wc_sc_regenerate_coupons' === $current_filter ) { + $note = _x( 'Coupons manually regenerated.', 'Order edit admin page', 'woocommerce-smart-coupons' ); + } else { + $note = _x( 'Coupons manually regenerated & sent.', 'Order edit admin page', 'woocommerce-smart-coupons' ); + } + break; + case 'woocommerce_order_action_wc_sc_resend_coupons': + $this->resend_coupons( $order_id ); + $note = _x( 'Coupon details manually sent.', 'Order edit admin page', 'woocommerce-smart-coupons' ); + break; + } + if ( ! empty( $note ) && $this->is_callable( $order, 'add_order_note' ) ) { + $order->add_order_note( $note ); + } + } + } + } + + } + +} + +WC_SC_Coupon_Process::get_instance(); diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupon-refund-process.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupon-refund-process.php new file mode 100644 index 00000000..7f5ceec0 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupon-refund-process.php @@ -0,0 +1,862 @@ + + + + + + is_callable( $order, 'get_total' ) ? $order->get_total() : 0; + $order_items = ( is_object( $order ) && $this->is_callable( $order, 'get_items' ) ) ? $order->get_items( 'coupon' ) : array(); + $tax_data = ( function_exists( 'wc_tax_enabled' ) && wc_tax_enabled() && is_object( $order ) && $this->is_callable( $order, 'get_taxes' ) ) ? $order->get_taxes() : array(); + + if ( ! class_exists( 'WC_SC_Order_Fields' ) ) { + include_once 'class-wc-sc-order-fields.php'; + } + $sc_order_fields = WC_SC_Order_Fields::get_instance(); + $total_credit_used_in_order = $sc_order_fields->get_total_credit_used_in_order( $order ); + + $i = 1; + if ( ! empty( $order_items ) ) { + $is_apply_before_tax = get_option( 'woocommerce_smart_coupon_apply_before_tax', 'no' ); + $is_readonly = ( 'yes' !== $is_apply_before_tax ) ? true : false; + $allow_custom_refund_amount = apply_filters( + 'wc_sc_allow_custom_refund_amount', + ( false === $is_readonly ), + array( + 'source' => $this, + 'order_obj' => $order, + ) + ); + $is_old_sc_order = $this->is_old_sc_order( $order_id ); + $item_titles = array_map( + function( $item ) { + return ( $this->is_callable( $item, 'get_name' ) ) ? $item->get_name() : ''; + }, + $order_items + ); + $posts = $this->get_post_by_title( $item_titles, OBJECT, 'shop_coupon' ); + foreach ( $order_items as $item_id => $item ) { + $order_discount_amount = $sc_refunded_discount = $sc_refunded_discount_tax = $order_discount_tax_amount = 0; // phpcs:ignore + $coupon_code = ( $this->is_callable( $item, 'get_name' ) ) ? $item->get_name() : ''; + $sanitized_coupon_code = sanitize_title( $coupon_code ); // The generated string will be checked in an array key to locate post object. + $coupon_post_obj = ( ! empty( $posts[ $sanitized_coupon_code ] ) ) ? $posts[ $sanitized_coupon_code ] : null; + $coupon_id = isset( $coupon_post_obj->ID ) ? $coupon_post_obj->ID : ''; + $coupon_title = isset( $coupon_post_obj->post_title ) ? $coupon_post_obj->post_title : ''; + $coupon = new WC_Coupon( $coupon_id ); + if ( is_a( $coupon, 'WC_Coupon' ) ) { + if ( $coupon->is_type( 'smart_coupon' ) ) { + + if ( 1 === $i ) { + ?> + + + + + + + + + + + + + + + + + + + + + + + + get_order_item_meta( $item_id, 'discount_amount', true ); + $sc_refunded_discount = (float) $this->get_order_item_meta( $item_id, 'sc_refunded_discount', true ); + $sc_refunded_discount_tax = (float) $this->get_order_item_meta( $item_id, 'sc_refunded_discount_tax', true ); + $order_discount_tax_amount = (float) $this->get_order_item_meta( $item_id, 'discount_amount_tax', true ); + } + + ?> + + +
          + + + + +
          + + + +
          + +
          + + +   +   + + +
          + + + +
          + + + + + + + +
          + + + +
          + + + + + + 1 ) { ?> + + + + + + + + + is_old_sc_order( $order_id ) && $total_credit_used_in_order > 0 ) { ?> + + + get_order_item_meta( $item_id, 'discount_amount', true ); + $refunded_amount = $this->get_order_item_meta( $item_id, 'sc_refunded_discount', true ); + $refunded_tax_amount = $this->get_order_item_meta( $item_id, 'sc_refunded_discount_tax', true ); + $order_discount_tax_amount = $this->get_order_item_meta( $item_id, 'discount_amount_tax', true ); + } + + if ( floatval( $order_discount_amount ) === floatval( $refunded_amount ) && floatval( $order_discount_tax_amount ) === floatval( $refunded_tax_amount ) ) { + continue; + } + + if ( $refunded_amount ) { + $total_refunded = $refund_amount + $refunded_amount; + } + + if ( $refunded_tax_amount ) { + $total_refunded_tax = $order_sc_refund_tax_amount + $refunded_tax_amount; + } + if ( $order_discount_amount >= $refund_amount && $order_discount_amount >= $total_refunded && $order_discount_tax_amount >= $order_sc_refund_tax_amount && $order_discount_tax_amount >= $total_refunded_tax && ! empty( $smart_coupon_id ) ) { + $coupon = new WC_Coupon( $smart_coupon_id ); + + if ( is_a( $coupon, 'WC_Coupon' ) ) { + if ( $this->is_wc_gte_30() ) { + $discount_type = ( is_callable( array( $coupon, 'get_discount_type' ) ) ) ? $coupon->get_discount_type() : ''; + } else { + $discount_type = ( ! empty( $coupon->discount_type ) ) ? $coupon->discount_type : ''; + } + $coupon_amount = $this->get_amount( $coupon, true, $order ); + if ( 'smart_coupon' === $discount_type && is_numeric( $refund_amount ) && is_numeric( $order_sc_refund_tax_amount ) ) { + $amount = $coupon_amount + $refund_amount + $order_sc_refund_tax_amount; + $this->update_post_meta( $smart_coupon_id, 'coupon_amount', $amount, true, $order ); + $user = ( function_exists( 'get_current_user_id' ) ) ? get_current_user_id() : 0; + $local_time = ( function_exists( 'current_datetime' ) ) ? current_datetime() : ''; + $get_timestamp = ( is_object( $local_time ) && is_callable( array( $local_time, 'getTimestamp' ) ) ) ? $local_time->getTimestamp() : ''; + $get_offset = ( is_object( $local_time ) && is_callable( array( $local_time, 'getOffset' ) ) ) ? $local_time->getOffset() : ''; + $current_time_stamp = $get_timestamp + $get_offset; + + if ( 0 < $total_refunded ) { + $refund_amount = $total_refunded; + } + + if ( 0 < $total_refunded_tax ) { + $order_sc_refund_tax_amount = $total_refunded_tax; + } + + if ( is_callable( array( $this, 'update_order_item_meta' ) ) ) { + $this->update_order_item_meta( $item_id, 'sc_refunded_discount_tax', $order_sc_refund_tax_amount ); + $this->update_order_item_meta( $item_id, 'sc_refunded_discount', $refund_amount ); + $this->update_order_item_meta( $item_id, 'sc_refunded_user_id', $user ); + $this->update_order_item_meta( $item_id, 'sc_refunded_timestamp', $current_time_stamp ); + $this->update_order_item_meta( $item_id, 'sc_refunded_coupon_id', $smart_coupon_id ); + $message = __( 'Successfully updated store credit refund details.', 'woocommerce-smart-coupons' ); + } else { + $message = __( 'Failed to update store credit refund details.', 'woocommerce-smart-coupons' ); + $woocommerce_smart_coupon->log( 'notice', $message . ' ' . __FILE__ . ' ' . __LINE__ ); + } + $response['message'] = $message; + } + } + } + } + } + wp_send_json_success( $response ); + } else { + $response['message'] = __( 'Nonce verification failed for action "wc_sc_refund_store_credit".', 'woocommerce-smart-coupons' ); + wp_send_json_error( $response ); + } + } + + /** + * Render refund store credit UI in order page + * + * @param int $order_id order id. + * @return void revoke refund html + */ + public function render_refunded_store_credits_details( $order_id ) { + global $store_credit_label; + ?> + + + + get_items( 'coupon' ) : array(); + $tax_data = ( function_exists( 'wc_tax_enabled' ) && wc_tax_enabled() && is_object( $order ) && is_callable( array( $order, 'get_taxes' ) ) ) ? $order->get_taxes() : array(); + if ( ! empty( $order_items ) ) { + $item_titles = array_map( + function( $item ) { + return $item->get_name(); + }, + $order_items + ); + $posts = $this->get_post_by_title( $item_titles, OBJECT, 'shop_coupon' ); + foreach ( $order_items as $item_id => $item ) { + $sc_refunded_discount = $sc_refunded_discount_tax = $sc_refunded_user = $sc_refunded_timestamp = 0; // phpcs:ignore + $coupon_code = ( $this->is_callable( $item, 'get_name' ) ) ? $item->get_name() : ''; + $sanitized_coupon_code = sanitize_title( $coupon_code ); // The generated string will be checked in an array key to locate post object. + $coupon_post_obj = ( ! empty( $posts[ $sanitized_coupon_code ] ) ) ? $posts[ $sanitized_coupon_code ] : null; + $coupon_id = isset( $coupon_post_obj->ID ) ? $coupon_post_obj->ID : ''; + $coupon_title = isset( $coupon_post_obj->post_title ) ? $coupon_post_obj->post_title : ''; + $coupon = new WC_Coupon( $coupon_id ); + if ( is_callable( array( $this, 'get_order_item_meta' ) ) ) { + $sc_refunded_discount = (float) $this->get_order_item_meta( $item_id, 'sc_refunded_discount', true ); + $sc_refunded_discount_tax = (float) $this->get_order_item_meta( $item_id, 'sc_refunded_discount_tax', true ); + $sc_refunded_user = $this->get_order_item_meta( $item_id, 'sc_refunded_user_id', true ); + $sc_refunded_timestamp = $this->get_order_item_meta( $item_id, 'sc_refunded_timestamp', true ); + } + if ( empty( $sc_refunded_timestamp ) ) { + $sc_refunded_timestamp = time() + $this->wc_timezone_offset(); + } + $sc_refunded_discount = empty( $sc_refunded_discount ) ? 0 : $sc_refunded_discount; + $sc_refunded_discount_tax = empty( $sc_refunded_discount_tax ) ? 0 : $sc_refunded_discount_tax; + + if ( is_a( $coupon, 'WC_Coupon' ) ) { + if ( $coupon->is_type( 'smart_coupon' ) && ( ! empty( $sc_refunded_discount ) || ! empty( $sc_refunded_discount_tax ) ) ) { + $who_refunded = new WP_User( $sc_refunded_user ); + $refunder_id = isset( $who_refunded->ID ) ? $who_refunded->ID : 0; + $refunder_name = isset( $who_refunded->display_name ) ? $who_refunded->display_name : ''; + ?> + + + +
          + + + exists() ) { + printf( + /* translators: 1: refund id 2: refund date 3: username */ + esc_html__( 'Refund %1$s - %2$s by %3$s', 'woocommerce-smart-coupons' ), + sprintf( '%s - %s', ( ! empty( $store_credit_label['singular'] ) ? esc_html( $store_credit_label['singular'] ) : esc_html__( 'Store Credit', 'woocommerce-smart-coupons' ) ), esc_html( $coupon_title ) ), + esc_html( $this->format_date( $sc_refunded_timestamp ) ), + sprintf( + '%2$s', + /* translators: 1: ID who refunded */ + sprintf( esc_attr__( 'ID: %d', 'woocommerce-smart-coupons' ), absint( $refunder_id ) ), + esc_html( $refunder_name ) + ) + ); + } else { + printf( + /* translators: 1: refund id 2: refund date */ + esc_html__( 'Refund %1$s - %2$s', 'woocommerce-smart-coupons' ), + sprintf( '%s - %s', ( ! empty( $store_credit_label['singular'] ) ? esc_html( $store_credit_label['singular'] ) : esc_html__( 'Store Credit', 'woocommerce-smart-coupons' ) ), esc_html( $coupon_title ) ), + esc_html( $this->format_date( $sc_refunded_timestamp ) ) + ); + } + ?> + + +   +   + + +
          + +
          + + + + + 1 ) { + ?> + + + + + +
          + +
          + + + get_order_item_meta( $wc_sc_refunded_id, 'discount_amount', true ); + $order_discount_tax_amount = $this->get_order_item_meta( $wc_sc_refunded_id, 'discount_amount_tax', true ); + if ( $order_discount_amount >= $refunded_amount && $order_discount_tax_amount >= $refunded_amount_tax && ! empty( $smart_coupon_id ) ) { + $coupon = new WC_Coupon( $smart_coupon_id ); + if ( is_a( $coupon, 'WC_Coupon' ) ) { + if ( $this->is_wc_gte_30() ) { + $discount_type = ( is_callable( array( $coupon, 'get_discount_type' ) ) ) ? $coupon->get_discount_type() : ''; + } else { + $discount_type = ( ! empty( $coupon->discount_type ) ) ? $coupon->discount_type : ''; + } + $coupon_amount = $this->get_amount( $coupon, true, $order ); + if ( 'smart_coupon' === $discount_type ) { + if ( ! is_numeric( $refunded_amount ) ) { + $refunded_amount = 0; + } + if ( ! is_numeric( $refunded_amount_tax ) ) { + $refunded_amount_tax = 0; + } + $refund_amount = $refunded_amount + $refunded_amount_tax; + $amount = $coupon_amount - $refund_amount; + $this->update_post_meta( $smart_coupon_id, 'coupon_amount', $amount, true, $order ); + $user = ( function_exists( 'get_current_user_id' ) ) ? get_current_user_id() : 0; + $local_time = ( function_exists( 'current_datetime' ) ) ? current_datetime() : ''; + $get_timestamp = ( is_object( $local_time ) && is_callable( array( $local_time, 'getTimestamp' ) ) ) ? $local_time->getTimestamp() : 0; + $get_offset = ( is_object( $local_time ) && is_callable( array( $local_time, 'getOffset' ) ) ) ? $local_time->getOffset() : 0; + $current_time_stamp = $get_timestamp + $get_offset; + + if ( is_callable( array( $this, 'update_order_item_meta' ) ) ) { + $this->update_order_item_meta( $wc_sc_refunded_id, 'sc_revoke_refunded_discount', $refunded_amount, true ); + $this->update_order_item_meta( $wc_sc_refunded_id, 'sc_revoke_refunded_discount_tax', $refunded_amount_tax, true ); + $this->update_order_item_meta( $wc_sc_refunded_id, 'sc_revoke_refunded_user_id', $user ); + $this->update_order_item_meta( $wc_sc_refunded_id, 'sc_revoke_refunded_timestamp', $current_time_stamp ); + $this->update_order_item_meta( $wc_sc_refunded_id, 'sc_revoke_refunded_coupon_id', $smart_coupon_id ); + + $this->update_order_item_meta( $wc_sc_refunded_id, 'sc_refunded_discount', 0 ); + $this->update_order_item_meta( $wc_sc_refunded_id, 'sc_refunded_discount_tax', 0 ); + } + } + } + } + } + wp_send_json_success(); + } else { + wp_send_json_error(); + } + } + + /** + * Change order status when fully refunded. + * + * @param string $status order status. + * @param number $order_id order id. + * @param number $refund_id refund id. + * @return false|mixed order status + */ + public function update_fully_refunded_status( $status, $order_id, $refund_id ) { + $order = wc_get_order( $order_id ); + $order_items = ( is_object( $order ) && is_callable( array( $order, 'get_items' ) ) ) ? $order->get_items( 'coupon' ) : array(); + if ( ! empty( $order_items ) ) { + $item_titles = array_map( + function( $item ) { + return $item->get_name(); + }, + $order_items + ); + $posts = $this->get_post_by_title( $item_titles, OBJECT, 'shop_coupon' ); + foreach ( $order_items as $item_id => $item ) { + $sc_refunded_discount = $sc_refunded_discount_tax = $order_discount_amount = $order_discount_tax_amount = 0; // phpcs:ignore + $coupon_code = ( $this->is_callable( $item, 'get_name' ) ) ? $item->get_name() : ''; + $sanitized_coupon_code = sanitize_title( $coupon_code ); // The generated string will be checked in an array key to locate post object. + $coupon_post_obj = ( ! empty( $posts[ $sanitized_coupon_code ] ) ) ? $posts[ $sanitized_coupon_code ] : null; + $coupon_id = isset( $coupon_post_obj->ID ) ? $coupon_post_obj->ID : ''; + $coupon = new WC_Coupon( $coupon_id ); + if ( is_callable( array( $this, 'get_order_item_meta' ) ) ) { + $sc_refunded_discount = $this->get_order_item_meta( $item_id, 'sc_refunded_discount', true ); + $sc_refunded_discount_tax = $this->get_order_item_meta( $item_id, 'sc_refunded_discount_tax', true ); + $order_discount_amount = $this->get_order_item_meta( $item_id, 'discount_amount', true ); + $order_discount_tax_amount = $this->get_order_item_meta( $item_id, 'discount_amount_tax', true ); + } + + if ( is_a( $coupon, 'WC_Coupon' ) ) { + if ( $coupon->is_type( 'smart_coupon' ) ) { + $get_order_total = ( is_object( $order ) && is_callable( array( $order, 'get_total' ) ) ) ? $order->get_total() : 0; + $refunded_order_total = ( is_object( $order ) && is_callable( array( $order, 'get_total_refunded' ) ) ) ? $order->get_total_refunded() : 0; + if ( empty( $get_order_total ) && empty( $sc_refunded_discount_tax ) && empty( $order_discount_tax_amount ) && $order_discount_amount !== $sc_refunded_discount ) { + return false; + } elseif ( empty( $get_order_total ) && ! empty( $sc_refunded_discount_tax ) && ! empty( $order_discount_tax_amount ) && $order_discount_amount !== $sc_refunded_discount && $sc_refunded_discount_tax !== $order_discount_tax_amount ) { + return false; + } elseif ( ! empty( $get_order_total ) && empty( $sc_refunded_discount_tax ) && empty( $order_discount_tax_amount ) && $get_order_total === $refunded_order_total && $order_discount_amount !== $sc_refunded_discount ) { + return false; + } elseif ( ! empty( $get_order_total ) && ! empty( $sc_refunded_discount_tax ) && ! empty( $order_discount_tax_amount ) && $get_order_total === $refunded_order_total && $order_discount_amount !== $sc_refunded_discount && $sc_refunded_discount_tax !== $order_discount_tax_amount ) { + return false; + } elseif ( empty( $sc_refunded_discount_tax ) && ! empty( $order_discount_tax_amount ) ) { + return false; + } + } + } + } + } + return $status; + } + } +} +WC_SC_Coupon_Refund_Process::get_instance(); diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupons-by-excluded-email.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupons-by-excluded-email.php new file mode 100644 index 00000000..af2b001c --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupons-by-excluded-email.php @@ -0,0 +1,573 @@ +get_meta( 'wc_sc_excluded_customer_email' ) : get_post_meta( $coupon_id, 'wc_sc_excluded_customer_email', true ); + + if ( ! is_array( $excluded_emails ) || empty( $excluded_emails ) ) { + $excluded_emails = array(); + } + + woocommerce_wp_text_input( + array( + 'id' => 'wc_sc_excluded_customer_email', + 'label' => __( 'Excluded emails', 'woocommerce-smart-coupons' ), + 'placeholder' => __( 'No restrictions', 'woocommerce-smart-coupons' ), + 'description' => __( 'List of excluded billing emails to check against when an order is placed. Separate email addresses with commas. You can also use an asterisk (*) to match parts of an email. For example "*@gmail.com" would match all gmail addresses.', 'woocommerce-smart-coupons' ), + 'value' => implode( ', ', $excluded_emails ), + 'desc_tip' => true, + 'type' => 'email', + 'class' => '', + 'custom_attributes' => array( + 'multiple' => 'multiple', + ), + ) + ); + + } + + /** + * Save coupon by excluded email data in meta + * + * @param Integer $post_id The coupon post ID. + * @param WC_Coupon $coupon The coupon object. + */ + public function process_meta( $post_id = 0, $coupon = null ) { + if ( empty( $post_id ) ) { + return; + } + + $coupon = new WC_Coupon( $coupon ); + + $excluded_emails = ( isset( $_POST['wc_sc_excluded_customer_email'] ) ) ? wc_clean( wp_unslash( $_POST['wc_sc_excluded_customer_email'] ) ) : ''; // phpcs:ignore + $excluded_emails = explode( ',', $excluded_emails ); + $excluded_emails = array_map( 'trim', $excluded_emails ); + $excluded_emails = array_filter( $excluded_emails, 'is_email' ); + $excluded_emails = array_filter( $excluded_emails ); + + if ( $this->is_callable( $coupon, 'update_meta_data' ) && $this->is_callable( $coupon, 'save' ) ) { + $coupon->update_meta_data( 'wc_sc_excluded_customer_email', $excluded_emails ); + $coupon->save(); + } else { + update_post_meta( $post_id, 'wc_sc_excluded_customer_email', $excluded_emails ); + } + + } + + /** + * Validate the coupon based on user role + * + * @param boolean $valid Is valid or not. + * @param WC_Coupon $coupon The coupon object. + * @param WC_Discounts $discounts The discount object. + * + * @throws Exception If the coupon is invalid. + * @return boolean Is valid or not + */ + public function validate( $valid = false, $coupon = object, $discounts = null ) { + + // If coupon is invalid already, no need for further checks. + if ( false === $valid ) { + return $valid; + } + + $post_action = ( ! empty( $_POST['action'] ) ) ? wc_clean( wp_unslash( $_POST['action'] ) ) : ''; // phpcs:ignore + + if ( is_admin() && wp_doing_ajax() && 'woocommerce_add_coupon_discount' === $post_action ) { // This condition will allow the addition of coupon from admin side, in the order even if the user role is not matching. + return true; + } + + $is_auto_applied = did_action( 'wc_sc_before_auto_apply_coupons' ) > 0; + + $cart = ( function_exists( 'WC' ) && isset( WC()->cart ) ) ? WC()->cart : null; + + $coupon_id = ( $this->is_wc_gte_30() ) ? $coupon->get_id() : $coupon->id; + if ( ! is_a( $coupon, 'WC_Coupon' ) ) { + $coupon = new WC_Coupon( $coupon_id ); + } + if ( $this->is_callable( $coupon, 'get_meta' ) ) { + $coupon_code = ( $this->is_callable( $coupon, 'get_code' ) ) ? $coupon->get_code() : ''; + $customer_email = ( $this->is_callable( $coupon, 'get_email_restrictions' ) ) ? $coupon->get_email_restrictions() : array(); + $exclude_customer_email = ( $this->is_callable( $coupon, 'get_meta' ) ) ? $coupon->get_meta( 'wc_sc_excluded_customer_email' ) : array(); + } else { + $coupon_code = ( ! empty( $coupon->code ) ) ? $coupon->code : ''; + $customer_email = get_post_meta( $coupon_id, 'customer_email', true ); + $exclude_customer_email = get_post_meta( $coupon_id, 'wc_sc_excluded_customer_email', true ); + } + + $wc_customer = WC()->customer; + $wc_customer_email = ( $this->is_callable( $wc_customer, 'get_email' ) ) ? $wc_customer->get_email() : ''; + $wc_customer_billing_email = ( $this->is_callable( $wc_customer, 'get_billing_email' ) ) ? $wc_customer->get_billing_email() : ''; + $current_user = ( is_user_logged_in() ) ? wp_get_current_user() : null; + $user_email = ( ! is_null( $current_user ) && ! empty( $current_user->user_email ) ) ? $current_user->user_email : ''; + $billing_email = ( ! empty( $_REQUEST['billing_email'] ) ) ? wc_clean( wp_unslash( $_REQUEST['billing_email'] ) ) : ''; // phpcs:ignore + $check_emails = array_unique( + array_filter( + array_map( + 'strtolower', + array_map( + 'sanitize_email', + array( + $billing_email, + $wc_customer_billing_email, + $wc_customer_email, + $user_email, + ) + ) + ) + ) + ); + + if ( false === $is_auto_applied && empty( $check_emails ) ) { + return $valid; + } + + $is_callable_coupon_emails_allowed = $this->is_callable( $cart, 'is_coupon_emails_allowed' ); + + $is_validate_allowed_emails = apply_filters( + 'wc_sc_force_validate_allowed_emails', + true, + array( + 'source' => $this, + 'is_valid' => $valid, + 'coupon_obj' => $coupon, + 'discounts_obj' => $discounts, + ) + ); + + if ( true === $is_validate_allowed_emails && is_array( $customer_email ) && 0 < count( $customer_email ) && true === $is_callable_coupon_emails_allowed && ! $cart->is_coupon_emails_allowed( $check_emails, $customer_email ) ) { + if ( true === $is_auto_applied ) { + $valid = false; + if ( $this->is_callable( $cart, 'has_discount' ) && $cart->has_discount( $coupon_code ) && $this->is_callable( $cart, 'remove_coupon' ) ) { + if ( class_exists( 'WC_Coupon' ) && $this->is_callable( $coupon, 'add_coupon_message' ) ) { + $coupon->add_coupon_message( WC_Coupon::E_WC_COUPON_NOT_YOURS_REMOVED ); + } + $cart->remove_coupon( $coupon_code ); + } + } else { + throw new Exception( __( 'This coupon is not valid for you.', 'woocommerce-smart-coupons' ) ); + } + } + + if ( is_array( $exclude_customer_email ) && 0 < count( $exclude_customer_email ) && true === $is_callable_coupon_emails_allowed && $cart->is_coupon_emails_allowed( $check_emails, $exclude_customer_email ) ) { + if ( true === $is_auto_applied ) { + $valid = false; + if ( $this->is_callable( $cart, 'has_discount' ) && $cart->has_discount( $coupon_code ) && $this->is_callable( $cart, 'remove_coupon' ) ) { + if ( class_exists( 'WC_Coupon' ) && $this->is_callable( $coupon, 'add_coupon_message' ) ) { + $coupon->add_coupon_message( WC_Coupon::E_WC_COUPON_NOT_YOURS_REMOVED ); + } + $cart->remove_coupon( $coupon_code ); + } + } else { + throw new Exception( __( 'This coupon is not valid for you.', 'woocommerce-smart-coupons' ) ); + } + } + + return $valid; + + } + + /** + * Now that we have billing email, check if the coupon is excluded to be used for the user or billing email + * + * Credit: WooCommerce + * + * @param array $posted Post data. + */ + public function check_customer_coupons( $posted = array() ) { + $cart = ( function_exists( 'WC' ) && isset( WC()->cart ) ) ? WC()->cart : null; + if ( is_a( $cart, 'WC_Cart' ) ) { + $is_cart_empty = is_callable( array( $cart, 'is_empty' ) ) && $cart->is_empty(); + if ( false === $is_cart_empty ) { + $applied_coupons = ( is_callable( array( $cart, 'get_applied_coupons' ) ) ) ? $cart->get_applied_coupons() : array(); + if ( ! empty( $applied_coupons ) ) { + foreach ( $applied_coupons as $code ) { + $coupon = new WC_Coupon( $code ); + + if ( $this->is_valid( $coupon ) ) { + + // Get user and posted emails to compare. + $current_user = ( is_user_logged_in() ) ? wp_get_current_user() : null; + $user_email = ( ! is_null( $current_user ) && ! empty( $current_user->user_email ) ) ? $current_user->user_email : ''; + $billing_email = isset( $posted['billing_email'] ) ? $posted['billing_email'] : ''; + $check_emails = array_unique( + array_filter( + array_map( + 'strtolower', + array_map( + 'sanitize_email', + array( + $billing_email, + $user_email, + ) + ) + ) + ) + ); + + if ( is_object( $coupon ) && is_callable( array( $coupon, 'get_meta' ) ) ) { + $exclude_restrictions = $coupon->get_meta( 'wc_sc_excluded_customer_email' ); + } else { + if ( is_object( $coupon ) && is_callable( array( $coupon, 'get_id' ) ) ) { + $coupon_id = $coupon->get_id(); + } else { + $coupon_id = ( ! empty( $coupon->id ) ) ? $coupon->id : 0; + } + $exclude_restrictions = ( ! empty( $coupon_id ) ) ? get_post_meta( $coupon_id, 'wc_sc_excluded_customer_email', true ) : array(); + } + + if ( is_array( $exclude_restrictions ) && 0 < count( $exclude_restrictions ) && is_callable( array( $coupon, 'add_coupon_message' ) ) && is_callable( array( $cart, 'remove_coupon' ) ) && is_callable( array( $cart, 'is_coupon_emails_allowed' ) ) && $cart->is_coupon_emails_allowed( $check_emails, $exclude_restrictions ) ) { + $coupon->add_coupon_message( WC_Coupon::E_WC_COUPON_NOT_YOURS_REMOVED ); + $cart->remove_coupon( $code ); + } + + /* + |===========================================================================================================================================================================| + | | + | Before this method, WooCommerce checks for Allowed emails. | + | And in that method, it already checks for the usage limit whether it is allowed to apply the coupon or not. | + | 1. If it's allowed, it means the usage limit is within reach & we can proceed with checking for excluded email. | + | Because the main purpose of excluded email is to prevent application of coupon. And since the usage limit is already checked, it's not needed to check it again | + | 2. If it's not allowed, the process will not reach in this method, as it's already invalidated. | + | | + |===========================================================================================================================================================================| + */ + } + } + } + } + } + } + + /** + * Add meta in export headers + * + * @param array $headers Existing headers. + * @return array + */ + public function export_headers( $headers = array() ) { + + $headers['wc_sc_excluded_customer_email'] = __( 'Excluded emails', 'woocommerce-smart-coupons' ); + + return $headers; + + } + + /** + * Post meta defaults for excluded email ids meta + * + * @param array $defaults Existing postmeta defaults. + * @return array $defaults Modified postmeta defaults + */ + public function postmeta_defaults( $defaults = array() ) { + + $defaults['wc_sc_excluded_customer_email'] = ''; + + return $defaults; + } + + /** + * Make meta data of excluded email ids protected + * + * @param bool $protected Is protected. + * @param string $meta_key The meta key. + * @param string $meta_type The meta type. + * @return bool $protected + */ + public function make_action_meta_protected( $protected = false, $meta_key = '', $meta_type = '' ) { + + $sc_excluded_email_keys = array( + 'wc_sc_excluded_customer_email', + ); + + if ( in_array( $meta_key, $sc_excluded_email_keys, true ) ) { + return true; + } + + return $protected; + } + + /** + * Add excluded email in coupon meta + * + * @param array $data The row data. + * @param array $post The POST values. + * @return array Modified data + */ + public function generate_coupon_meta( $data = array(), $post = array() ) { + + $excluded_emails = ( isset( $post['wc_sc_excluded_customer_email'] ) ) ? wc_clean( wp_unslash( $post['wc_sc_excluded_customer_email'] ) ) : ''; // phpcs:ignore + $excluded_emails = explode( ',', $excluded_emails ); + $excluded_emails = array_map( 'trim', $excluded_emails ); + $excluded_emails = array_filter( $excluded_emails, 'is_email' ); + $excluded_emails = array_filter( $excluded_emails ); + $excluded_emails = implode( ',', $excluded_emails ); + + $data['wc_sc_excluded_customer_email'] = $excluded_emails; + + return $data; + } + + /** + * Process coupon meta value for import + * + * @param mixed $meta_value The meta value. + * @param array $args Additional Arguments. + * @return mixed $meta_value + */ + public function import_coupon_meta( $meta_value = null, $args = array() ) { + if ( ! empty( $args['meta_key'] ) && 'wc_sc_excluded_customer_email' === $args['meta_key'] ) { + $excluded_emails = ( isset( $args['postmeta']['wc_sc_excluded_customer_email'] ) ) ? wc_clean( wp_unslash( $args['postmeta']['wc_sc_excluded_customer_email'] ) ) : ''; // phpcs:ignore + $excluded_emails = explode( ',', $excluded_emails ); + $excluded_emails = array_map( 'trim', $excluded_emails ); + $excluded_emails = array_filter( $excluded_emails, 'is_email' ); + $meta_value = array_filter( $excluded_emails ); + } + return $meta_value; + } + + /** + * Function to copy excluded email meta in newly generated coupon + * + * @param array $args The arguments. + */ + public function copy_coupon_meta( $args = array() ) { + + $new_coupon_id = ( ! empty( $args['new_coupon_id'] ) ) ? absint( $args['new_coupon_id'] ) : 0; + $coupon = ( ! empty( $args['ref_coupon'] ) ) ? $args['ref_coupon'] : false; + + if ( empty( $new_coupon_id ) || empty( $coupon ) ) { + return; + } + + if ( $this->is_wc_gte_30() && is_object( $coupon ) && is_callable( array( $coupon, 'get_meta' ) ) ) { + $excluded_emails = $coupon->get_meta( 'wc_sc_excluded_customer_email' ); + } else { + $old_coupon_id = ( ! empty( $coupon->id ) ) ? $coupon->id : 0; + $excluded_emails = get_post_meta( $old_coupon_id, 'wc_sc_excluded_customer_email', true ); + } + + if ( ! is_array( $excluded_emails ) || empty( $excluded_emails ) ) { + $excluded_emails = array(); + } + + $new_coupon = new WC_Coupon( $new_coupon_id ); + + if ( is_object( $new_coupon ) && is_callable( array( $new_coupon, 'update_meta_data' ) ) && is_callable( array( $new_coupon, 'save' ) ) ) { + $new_coupon->update_meta_data( 'wc_sc_excluded_customer_email', $excluded_emails ); + $new_coupon->save(); + } else { + update_post_meta( $new_coupon_id, 'wc_sc_excluded_customer_email', $excluded_emails ); + } + + } + + /** + * Define which columns to show on this screen. + * + * @param array $columns Existing columns. + * @return array + */ + public function define_columns( $columns = array() ) { + + if ( ! is_array( $columns ) || empty( $columns ) ) { + $columns = array(); + } + + $columns['wc_sc_coupon_allowed_emails'] = __( 'Allowed emails', 'woocommerce-smart-coupons' ); + $columns['wc_sc_coupon_excluded_emails'] = __( 'Excluded emails', 'woocommerce-smart-coupons' ); + + return $columns; + } + + /** + * Render individual columns. + * + * @param string $column Column ID to render. + * @param int $post_id Post ID being shown. + */ + public function render_columns( $column = '', $post_id = 0 ) { + + if ( empty( $post_id ) || empty( $column ) || ! in_array( $column, array( 'wc_sc_coupon_allowed_emails', 'wc_sc_coupon_excluded_emails' ), true ) ) { + return; + } + + $coupon = new WC_Coupon( $post_id ); + + switch ( $column ) { + case 'wc_sc_coupon_allowed_emails': + $this->render_allowed_emails_column( $post_id, $coupon ); + break; + case 'wc_sc_coupon_excluded_emails': + $this->render_excluded_emails_column( $post_id, $coupon ); + break; + } + + } + + /** + * Function to render allowed emails column on coupons dashboard. + * + * @param int $post_id The coupon ID. + * @param WC_Coupon $coupon The coupon object. + */ + public function render_allowed_emails_column( $post_id = 0, $coupon = null ) { + $emails = ( $this->is_callable( $coupon, 'get_email_restrictions' ) ) ? $coupon->get_email_restrictions() : $this->get_post_meta( $post_id, 'customer_email', true ); + echo wp_kses_post( + $this->email_column_value( + $emails, + array( + 'coupon_id' => $post_id, + 'coupon_obj' => $coupon, + 'filter' => true, // Allow filtering coupon list by selected "allowed email". + ) + ) + ); + } + + /** + * Function to render excluded emails column on coupons dashboard. + * + * @param int $post_id The coupon ID. + * @param WC_Coupon $coupon The coupon object. + */ + public function render_excluded_emails_column( $post_id = 0, $coupon = null ) { + $emails = ( $this->is_callable( $coupon, 'get_meta' ) ) ? $coupon->get_meta( 'wc_sc_excluded_customer_email' ) : $this->get_post_meta( $post_id, 'wc_sc_excluded_customer_email', true ); + echo wp_kses_post( + $this->email_column_value( + $emails, + array( + 'coupon_id' => $post_id, + 'coupon_obj' => $coupon, + ) + ) + ); + } + + /** + * Get value for email columns. + * + * @param array $emails The list of email addresses. + * @param array $args Additional arguments. + * @return string $value + */ + public function email_column_value( $emails = array(), $args = array() ) { + $coupon_id = ( ! empty( $args['coupon_id'] ) ) ? absint( $args['coupon_id'] ) : 0; + $coupon = ( ! empty( $args['coupon_obj'] ) ) ? $args['coupon_obj'] : null; + $filter = ( ! empty( $args['filter'] ) ) ? $args['filter'] : false; + $value = ''; + if ( ! empty( $emails ) ) { + $email_count = apply_filters( + 'wc_sc_email_column_max_count', + $this->sc_get_option( 'wc_sc_email_column_max_count', 5 ), + array( + 'source' => $this, + 'coupon_id' => $coupon_id, + 'coupon_obj' => $coupon, + 'filter' => $filter, + ) + ); + $visible_emails = ( ! empty( $email_count ) && is_array( $emails ) ) ? array_slice( $emails, 0, $email_count ) : array(); + if ( ! empty( $visible_emails ) ) { + $mapped_emails = ( true === $filter ) ? array_map( array( $this, 'filter_by_email_link' ), $visible_emails ) : $visible_emails; + $value = implode( ', ', $mapped_emails ); + } + } + return $value; + } + + } +} + +WC_SC_Coupons_By_Excluded_Email::get_instance(); diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupons-by-location.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupons-by-location.php new file mode 100644 index 00000000..059ecf44 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupons-by-location.php @@ -0,0 +1,710 @@ +global_additional_locations ) ) { + $this->global_additional_locations = get_option( 'sa_cbl_additional_locations', array() ); + } + } + + /** + * Styles & scripts + */ + public function enqueue_admin_javascript_css() { + + global $woocommerce_smart_coupon; + + $post_type = $this->get_post_type(); + $get_page = ( ! empty( $_GET['page'] ) ) ? wc_clean( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore + + if ( 'shop_coupon' !== $post_type && 'wc-smart-coupons' !== $get_page ) { + return; + } + + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; + + // Add customized chosen javascript library for adding new location from same field. + wp_register_script( 'sa_coupons_by_location_chosen', plugins_url( '/', dirname( __FILE__ ) ) . 'assets/js/chosen.jquery' . $suffix . '.js', array( 'jquery' ), $woocommerce_smart_coupon->plugin_data['Version'], true ); + wp_enqueue_style( 'sa_coupons_by_location_css', plugins_url( '/', dirname( __FILE__ ) ) . 'assets/css/cbl-admin' . $suffix . '.css', array(), $woocommerce_smart_coupon->plugin_data['Version'] ); + + } + + /** + * Display field for coupon by location + */ + public function usage_restriction() { + global $post; + + if ( ! wp_script_is( 'sa_coupons_by_location_chosen' ) ) { + wp_enqueue_script( 'sa_coupons_by_location_chosen' ); + } + + $coupon = ( ! empty( $post->ID ) ) ? new WC_Coupon( $post->ID ) : null; + $is_callable_coupon_get_meta = $this->is_callable( $coupon, 'get_meta' ); + + $this->locations_lookup_in = ( true === $is_callable_coupon_get_meta ) ? $coupon->get_meta( 'sa_cbl_locations_lookup_in' ) : get_post_meta( $post->ID, 'sa_cbl_locations_lookup_in', true ); + if ( ! is_array( $this->locations_lookup_in ) || empty( $this->locations_lookup_in ) ) { + $this->locations_lookup_in = array( 'address' => 'billing' ); + $this->update_post_meta( $post->ID, 'sa_cbl_locations_lookup_in', $this->locations_lookup_in ); + } + + $this->address = $this->locations_lookup_in['address']; + + $is_wc_countries = function_exists( 'WC' ) && is_object( WC()->countries ); + + $continents = ( $is_wc_countries && $this->is_callable( WC()->countries, 'get_continents' ) ) ? WC()->countries->get_continents() : array(); + $countries = ( $is_wc_countries && $this->is_callable( WC()->countries, 'get_countries' ) ) ? WC()->countries->get_countries() : array(); + $all_states = ( $is_wc_countries && $this->is_callable( WC()->countries, 'get_states' ) ) ? WC()->countries->get_states() : array(); + + ?> + +
          +

          + +   + +

          +

          + + get_meta( 'sa_cbl_' . $this->address . '_locations' ) : get_post_meta( $post->ID, 'sa_cbl_' . $this->address . '_locations', true ); + if ( empty( $locations ) || ! is_array( $locations ) ) { + $locations = array(); + } + if ( ! array_key_exists( 'additional_locations', $locations ) || ! is_array( $locations['additional_locations'] ) ) { + $locations['additional_locations'] = array(); + } + $this->additional_locations = array_map( 'html_entity_decode', $locations['additional_locations'] ); + $this->countries = WC()->countries->countries; + + echo ''; + ?> +

          + +
          + locations_lookup_in['address'] = ( ! empty( $_POST['sa_cbl_search_in']['address'] ) ) ? wc_clean( wp_unslash( $_POST['sa_cbl_search_in']['address'] ) ) : ''; // phpcs:ignore + + if ( $this->is_callable( $coupon, 'update_meta_data' ) && $this->is_callable( $coupon, 'save' ) ) { + $coupon->update_meta_data( 'sa_cbl_' . $this->locations_lookup_in['address'] . '_locations', $locations ); + if ( isset( $this->locations_lookup_in['address'] ) && ! empty( $this->locations_lookup_in['address'] ) ) { + $coupon->update_meta_data( 'sa_cbl_locations_lookup_in', $this->locations_lookup_in ); + } + $coupon->save(); + } else { + update_post_meta( $post_id, 'sa_cbl_' . $this->locations_lookup_in['address'] . '_locations', $locations ); + if ( isset( $this->locations_lookup_in['address'] ) && ! empty( $this->locations_lookup_in['address'] ) ) { + update_post_meta( $post_id, 'sa_cbl_locations_lookup_in', $this->locations_lookup_in ); + } + } + + $this->countries = array_map( 'strtolower', WC()->countries->countries ); + if ( ! empty( $locations['additional_locations'] ) ) { + $this->additional_locations = array_map( 'strtolower', $locations['additional_locations'] ); + } + + if ( count( $this->additional_locations ) > 0 ) { + + // Loop through all location entered in Billing location of coupons. + // and collect those location which is not available in WooCommerce countries. + foreach ( $this->additional_locations as $location ) { + if ( ! in_array( $location, $this->countries, true ) ) { + $this->custom_locations[] = strtolower( $location ); + } + } + + // Add new location with already saved locations. + if ( false !== $this->global_additional_locations && ! empty( $this->global_additional_locations ) ) { + $this->global_additional_locations = array_merge( $this->global_additional_locations, $this->custom_locations ); + } else { + $this->global_additional_locations = $this->custom_locations; + } + + // Discard duplicate values, arrange alphabetically & save. + $this->global_additional_locations = array_unique( $this->global_additional_locations ); + sort( $this->global_additional_locations ); + update_option( 'sa_cbl_additional_locations', $this->global_additional_locations, 'no' ); + } + + } + + /** + * Validate the coupon based on location + * + * @param boolean $valid Is valid or not. + * @param WC_Coupon $coupon The coupon object. + * @param WC_Discounts $discounts The discount object. + * + * @throws Exception If the coupon is invalid. + * @return boolean Is valid or not + */ + public function validate( $valid, $coupon, $discounts = null ) { + global $checkout; + + // If coupon is invalid already, no need for further checks. + if ( ! $valid ) { + return $valid; + } + + $coupon_id = ( $this->is_wc_gte_30() ) ? $coupon->get_id() : $coupon->id; + $is_callable_coupon_get_meta = $this->is_callable( $coupon, 'get_meta' ); + + $this->locations_lookup_in = ( true === $is_callable_coupon_get_meta ) ? $coupon->get_meta( 'sa_cbl_locations_lookup_in' ) : get_post_meta( $coupon_id, 'sa_cbl_locations_lookup_in', true ); + + if ( empty( $this->locations_lookup_in ) || empty( $this->locations_lookup_in['address'] ) ) { + return $valid; + } + + $locations = ( true === $is_callable_coupon_get_meta ) ? $coupon->get_meta( 'sa_cbl_' . $this->locations_lookup_in['address'] . '_locations' ) : get_post_meta( $coupon_id, 'sa_cbl_' . $this->locations_lookup_in['address'] . '_locations', true ); + + if ( ! empty( $locations ) && is_array( $locations ) && ! empty( $locations['additional_locations'] ) && is_array( $locations['additional_locations'] ) && array_key_exists( 'additional_locations', $locations ) ) { + + $wc_customer = WC()->customer; + $wc_countries = WC()->countries; + + $check_live_details = false; + $wc_ajax_action = ( ! empty( $_REQUEST['wc-ajax'] ) ) ? wc_clean( wp_unslash( $_REQUEST['wc-ajax'] ) ) : ''; // phpcs:ignore + if ( defined( 'WC_DOING_AJAX' ) && WC_DOING_AJAX && 'update_order_review' === $wc_ajax_action ) { + check_ajax_referer( 'update-order-review', 'security' ); + $check_live_details = true; + } + + // Collect country, state & city. + if ( 'billing' === $this->locations_lookup_in['address'] ) { + + if ( $this->is_wc_gte_30() ) { + $customer_billing_country = ( true === $check_live_details && ! empty( $_REQUEST['country'] ) ) ? wc_clean( wp_unslash( $_REQUEST['country'] ) ) : $wc_customer->get_billing_country(); // phpcs:ignore + $customer_billing_state = ( true === $check_live_details && ! empty( $_REQUEST['state'] ) ) ? wc_clean( wp_unslash( $_REQUEST['state'] ) ) : $wc_customer->get_billing_state(); // phpcs:ignore + $customer_billing_city = ( true === $check_live_details && ! empty( $_REQUEST['city'] ) ) ? wc_clean( wp_unslash( $_REQUEST['city'] ) ) : $wc_customer->get_billing_city(); // phpcs:ignore + $customer_billing_postcode = ( true === $check_live_details && ! empty( $_REQUEST['postcode'] ) ) ? wc_clean( wp_unslash( $_REQUEST['postcode'] ) ) : $wc_customer->get_billing_postcode(); // phpcs:ignore + + $current_country = ( ! empty( $customer_billing_country ) ) ? $customer_billing_country : ''; + $current_state = ( ! empty( $customer_billing_state ) ) ? $customer_billing_state : ''; + $current_city = ( ! empty( $customer_billing_city ) ) ? $customer_billing_city : ''; + $current_post_code = ( ! empty( $customer_billing_postcode ) ) ? $customer_billing_postcode : ''; + } else { + $current_country = ( ! empty( $wc_customer->country ) ) ? $wc_customer->country : ''; + $current_state = ( ! empty( $wc_customer->state ) ) ? $wc_customer->state : ''; + $current_city = ( ! empty( $wc_customer->city ) ) ? $wc_customer->city : ''; + $current_post_code = ( ! empty( $wc_customer->postcode ) ) ? $wc_customer->postcode : ''; + } + } else { + if ( $this->is_wc_gte_30() ) { + $customer_shipping_country = ( true === $check_live_details && ! empty( $_REQUEST['s_country'] ) ) ? wc_clean( wp_unslash( $_REQUEST['s_country'] ) ) : $wc_customer->get_shipping_country(); // phpcs:ignore + $customer_shipping_state = ( true === $check_live_details && ! empty( $_REQUEST['s_state'] ) ) ? wc_clean( wp_unslash( $_REQUEST['s_state'] ) ) : $wc_customer->get_shipping_state(); // phpcs:ignore + $customer_shipping_city = ( true === $check_live_details && ! empty( $_REQUEST['s_city'] ) ) ? wc_clean( wp_unslash( $_REQUEST['s_city'] ) ) : $wc_customer->get_shipping_city(); // phpcs:ignore + $customer_shipping_postcode = ( true === $check_live_details && ! empty( $_REQUEST['s_postcode'] ) ) ? wc_clean( wp_unslash( $_REQUEST['s_postcode'] ) ) : $wc_customer->get_shipping_postcode(); // phpcs:ignore + + $current_country = ( ! empty( $customer_shipping_country ) ) ? $customer_shipping_country : ''; + $current_state = ( ! empty( $customer_shipping_state ) ) ? $customer_shipping_state : ''; + $current_city = ( ! empty( $customer_shipping_city ) ) ? $customer_shipping_city : ''; + $current_post_code = ( ! empty( $customer_shipping_postcode ) ) ? $customer_shipping_postcode : ''; + } else { + $current_country = ( ! empty( $wc_customer->shipping_country ) ) ? $wc_customer->shipping_country : ''; + $current_state = ( ! empty( $wc_customer->shipping_state ) ) ? $wc_customer->shipping_state : ''; + $current_city = ( ! empty( $wc_customer->shipping_city ) ) ? $wc_customer->shipping_city : ''; + $current_post_code = ( ! empty( $wc_customer->shipping_postcode ) ) ? $wc_customer->shipping_postcode : ''; + } + } + + // Convert country code or state code to actual country & state. + $country = ( ! empty( $wc_countries->countries[ $current_country ] ) ) ? strtolower( $wc_countries->countries[ $current_country ] ) : ''; + $state = ( ! empty( $wc_countries->states[ $current_country ][ $current_state ] ) ) ? strtolower( $wc_countries->states[ $current_country ][ $current_state ] ) : strtolower( $current_state ); + $city = ( ! empty( $current_city ) ) ? strtolower( $current_city ) : ''; + $post_code = ( ! empty( $current_post_code ) ) ? strtolower( $current_post_code ) : ''; + + // Loop through additional_locations and return true on matching with either country, state or city. + // Return false otherwise. + foreach ( $locations['additional_locations'] as $additional_location ) { + if ( false !== strpos( $additional_location, '::' ) ) { + $exploded_location = explode( '::', $additional_location ); + $additional_location_country = ( ! empty( $exploded_location[0] ) ) ? $exploded_location[0] : ''; + $additional_location_state = ( ! empty( $exploded_location[1] ) ) ? $exploded_location[1] : ''; + if ( $current_country === $additional_location_country && $current_state === $additional_location_state ) { + return true; + } + } + if ( $current_country === $additional_location || $current_state === $additional_location || $country === $additional_location || $state === $additional_location || $city === $additional_location || $post_code === $additional_location ) { + return true; + } + } + throw new Exception( __( 'Coupon is not valid for the', 'woocommerce-smart-coupons' ) . ' ' . ( ( 'billing' === $this->locations_lookup_in['address'] ) ? __( 'billing address', 'woocommerce-smart-coupons' ) : __( 'shipping address', 'woocommerce-smart-coupons' ) ) ); + } + + return $valid; + } + + /** + * Add meta in export headers + * + * @param array $headers Existing headers. + * @return array + */ + public function export_headers( $headers = array() ) { + + $cbl_headers = array( + 'sa_cbl_locations_lookup_in' => __( 'Locations lookup in', 'woocommerce-smart-coupons' ), + 'sa_cbl_billing_locations' => __( 'Billing Locations', 'woocommerce-smart-coupons' ), + 'sa_cbl_shipping_locations' => __( 'Shipping Locations', 'woocommerce-smart-coupons' ), + ); + + return array_merge( $headers, $cbl_headers ); + + } + + /** + * Function to handle coupon meta data during export of existing coupons + * + * @param mixed $meta_value The meta value. + * @param array $args Additional arguments. + * @return string Processed meta value + */ + public function export_coupon_meta_data( $meta_value = '', $args = array() ) { + + if ( ! empty( $args['meta_key'] ) && in_array( $args['meta_key'], array( 'sa_cbl_billing_locations', 'sa_cbl_shipping_locations' ), true ) ) { + switch ( $args['meta_key'] ) { + case 'sa_cbl_billing_locations': + case 'sa_cbl_shipping_locations': + $meta_value = ( ! empty( $meta_value['additional_locations'] ) ) ? implode( '|', wc_clean( wp_unslash( $meta_value['additional_locations'] ) ) ) : ''; + break; + } + } + + return $meta_value; + + } + + /** + * Post meta defaults for CBL's meta + * + * @param array $defaults Existing postmeta defaults. + * @return array + */ + public function postmeta_defaults( $defaults = array() ) { + + $cbl_defaults = array( + 'sa_cbl_locations_lookup_in' => '', + 'sa_cbl_billing_locations' => '', + 'sa_cbl_shipping_locations' => '', + ); + + return array_merge( $defaults, $cbl_defaults ); + } + + /** + * Add CBL's meta with value in coupon meta + * + * @param array $data The row data. + * @param array $post The POST values. + * @return array Modified data + */ + public function generate_coupon_meta( $data = array(), $post = array() ) { + + $data['sa_cbl_locations_lookup_in'] = ( ! empty( $post['sa_cbl_search_in']['address'] ) ) ? wc_clean( wp_unslash( $post['sa_cbl_search_in']['address'] ) ) : ''; + $data['sa_cbl_billing_locations'] = ( ! empty( $data['sa_cbl_locations_lookup_in'] ) && 'billing' === $data['sa_cbl_locations_lookup_in'] && ! empty( $post['locations']['additional_locations'] ) && is_array( $post['locations']['additional_locations'] ) ) ? implode( '|', wc_clean( wp_unslash( $post['locations']['additional_locations'] ) ) ) : ''; + $data['sa_cbl_shipping_locations'] = ( ! empty( $data['sa_cbl_locations_lookup_in'] ) && 'shipping' === $data['sa_cbl_locations_lookup_in'] && ! empty( $post['locations']['additional_locations'] ) && is_array( $post['locations']['additional_locations'] ) ) ? implode( '|', wc_clean( wp_unslash( $post['locations']['additional_locations'] ) ) ) : ''; + + if ( ! empty( $post['locations']['additional_locations'] ) ) { + $additional_locations = wc_clean( wp_unslash( $post['locations']['additional_locations'] ) ); + $this->update_global_additional_locations( $additional_locations ); + } + + return $data; + } + + /** + * Make meta data of SC CBL, protected + * + * @param bool $protected Is protected. + * @param string $meta_key The meta key. + * @param string $meta_type The meta type. + * @return bool $protected + */ + public function make_action_meta_protected( $protected, $meta_key, $meta_type ) { + $sc_meta = array( + 'sa_cbl_locations_lookup_in' => '', + 'sa_cbl_billing_locations' => '', + 'sa_cbl_shipping_locations' => '', + ); + if ( in_array( $meta_key, $sc_meta, true ) ) { + return true; + } + return $protected; + } + + /** + * Function to copy CBL meta in newly generated coupon + * + * @param array $args The arguments. + */ + public function copy_coupon_action_meta( $args = array() ) { + + $new_coupon_id = ( ! empty( $args['new_coupon_id'] ) ) ? absint( $args['new_coupon_id'] ) : 0; + $coupon = ( ! empty( $args['ref_coupon'] ) ) ? $args['ref_coupon'] : false; + + if ( empty( $new_coupon_id ) || empty( $coupon ) ) { + return; + } + + if ( $this->is_wc_gte_30() ) { + $locations_lookup_in = $coupon->get_meta( 'sa_cbl_locations_lookup_in' ); + $billing_locations = $coupon->get_meta( 'sa_cbl_billing_locations' ); + $shipping_locations = $coupon->get_meta( 'sa_cbl_shipping_locations' ); + } else { + $old_coupon_id = ( ! empty( $coupon->id ) ) ? $coupon->id : 0; + $locations_lookup_in = get_post_meta( $old_coupon_id, 'sa_cbl_locations_lookup_in', true ); + $billing_locations = get_post_meta( $old_coupon_id, 'sa_cbl_billing_locations', true ); + $shipping_locations = get_post_meta( $old_coupon_id, 'sa_cbl_shipping_locations', true ); + } + + $new_coupon = new WC_Coupon( $new_coupon_id ); + + if ( $this->is_callable( $new_coupon, 'update_meta_data' ) && $this->is_callable( $new_coupon, 'save' ) ) { + $new_coupon->update_meta_data( 'sa_cbl_locations_lookup_in', $locations_lookup_in ); + $new_coupon->update_meta_data( 'sa_cbl_billing_locations', $billing_locations ); + $new_coupon->update_meta_data( 'sa_cbl_shipping_locations', $shipping_locations ); + $new_coupon->save(); + } else { + update_post_meta( $new_coupon_id, 'sa_cbl_locations_lookup_in', $locations_lookup_in ); + update_post_meta( $new_coupon_id, 'sa_cbl_billing_locations', $billing_locations ); + update_post_meta( $new_coupon_id, 'sa_cbl_shipping_locations', $shipping_locations ); + } + + if ( ! empty( $billing_locations['additional_locations'] ) ) { + $this->update_global_additional_locations( $billing_locations['additional_locations'] ); + } + + if ( ! empty( $shipping_locations['additional_locations'] ) ) { + $this->update_global_additional_locations( $shipping_locations['additional_locations'] ); + } + + } + + /** + * Process coupon meta value for import + * + * @param mixed $meta_value The meta value. + * @param array $args Additional Arguments. + * @return mixed $meta_value + */ + public function process_coupon_meta_value_for_import( $meta_value = null, $args = array() ) { + + if ( ! empty( $args['meta_key'] ) && in_array( $args['meta_key'], array( 'sa_cbl_locations_lookup_in', 'sa_cbl_billing_locations', 'sa_cbl_shipping_locations' ), true ) ) { + switch ( $args['meta_key'] ) { + case 'sa_cbl_locations_lookup_in': + $meta_value = ( ! empty( $args['postmeta']['sa_cbl_locations_lookup_in'] ) ) ? array( 'address' => wc_clean( wp_unslash( $args['postmeta']['sa_cbl_locations_lookup_in'] ) ) ) : array(); + break; + case 'sa_cbl_billing_locations': + $meta_value = ( ! empty( $args['postmeta']['sa_cbl_billing_locations'] ) ) ? array( 'additional_locations' => explode( '|', wc_clean( wp_unslash( $args['postmeta']['sa_cbl_billing_locations'] ) ) ) ) : array(); + break; + case 'sa_cbl_shipping_locations': + $meta_value = ( ! empty( $args['postmeta']['sa_cbl_shipping_locations'] ) ) ? array( 'additional_locations' => explode( '|', wc_clean( wp_unslash( $args['postmeta']['sa_cbl_shipping_locations'] ) ) ) ) : array(); + break; + } + if ( in_array( $args['meta_key'], array( 'sa_cbl_billing_locations', 'sa_cbl_shipping_locations' ), true ) && ! empty( $meta_value['additional_locations'] ) ) { + $this->update_global_additional_locations( $meta_value['additional_locations'] ); + } + } + + return $meta_value; + } + + /** + * Update global additional locations + * + * @param array $additional_locations The locations. + */ + public function update_global_additional_locations( $additional_locations = array() ) { + + if ( empty( $additional_locations ) ) { + return; + } + + $additional_locations = array_map( 'strtolower', $additional_locations ); + $wc_countries = array_map( 'strtolower', WC()->countries->countries ); + + foreach ( $wc_countries as $index => $country ) { + $encoding = $this->mb_detect_encoding( $country, 'UTF-8, ISO-8859-1', true ); + $wc_countries[ $index ] = ( false !== $encoding ) ? html_entity_decode( $country, ENT_COMPAT, $encoding ) : $country; + } + + if ( count( $additional_locations ) > 0 ) { + + $custom_locations = array(); + + // Loop through all location entered in Billing location of coupons. + // and collect those location which is not available in WooCommerce countries. + foreach ( $additional_locations as $location ) { + if ( ! in_array( $location, $wc_countries, true ) ) { + $custom_locations[] = $location; + } + } + + $global_additional_locations = ( ! empty( $this->global_additional_locations ) ) ? $this->global_additional_locations : get_option( 'sa_cbl_additional_locations', array() ); + + // Add new location with already saved locations. + if ( false !== $global_additional_locations && ! empty( $global_additional_locations ) ) { + $global_additional_locations = array_merge( $global_additional_locations, $custom_locations ); + } else { + $global_additional_locations = $custom_locations; + } + + // Discard duplicate values, arrange alphabetically & save. + $global_additional_locations = array_unique( $global_additional_locations ); + sort( $global_additional_locations ); + update_option( 'sa_cbl_additional_locations', $global_additional_locations, 'no' ); + } + + } + + } +} + +WC_SC_Coupons_By_Location::get_instance(); diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupons-by-payment-method.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupons-by-payment-method.php new file mode 100644 index 00000000..19248b52 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupons-by-payment-method.php @@ -0,0 +1,420 @@ +get_post_meta( $coupon_id, 'wc_sc_payment_method_ids', true ); + if ( empty( $payment_method_ids ) || ! is_array( $payment_method_ids ) ) { + $payment_method_ids = array(); + } + } + $available_payment_methods = WC()->payment_gateways->get_available_payment_gateways(); + ?> +
          +

          + + + +

          +
          + is_callable( $coupon, 'update_meta_data' ) && $this->is_callable( $coupon, 'save' ) ) { + $coupon->update_meta_data( 'wc_sc_payment_method_ids', $payment_method_ids ); + $coupon->save(); + } else { + $this->update_post_meta( $post_id, 'wc_sc_payment_method_ids', $payment_method_ids ); + } + } + + /** + * Validate the coupon based on payment method + * + * @param boolean $valid Is valid or not. + * @param WC_Coupon $coupon The coupon object. + * @param WC_Discounts $discounts The discount object. + * + * @throws Exception If the coupon is invalid. + * @return boolean Is valid or not + */ + public function validate( $valid = false, $coupon = object, $discounts = object ) { + + // If coupon is already invalid, no need for further checks. + if ( false === $valid ) { + return $valid; + } + + if ( ! $coupon instanceof WC_Coupon ) { + return $valid; + } + + if ( ! $discounts instanceof WC_Discounts ) { + return $valid; + } + + if ( $this->is_wc_gte_30() ) { + $coupon_id = ( ! empty( $coupon ) && is_callable( array( $coupon, 'get_id' ) ) ) ? $coupon->get_id() : 0; + $coupon_code = ( ! empty( $coupon ) && is_callable( array( $coupon, 'get_code' ) ) ) ? $coupon->get_code() : ''; + } else { + $coupon_id = ( ! empty( $coupon->id ) ) ? $coupon->id : 0; + $coupon_code = ( ! empty( $coupon->code ) ) ? $coupon->code : ''; + } + + if ( empty( $coupon_id ) ) { + return $valid; + } + + $payment_method_ids = $this->get_post_meta( $coupon_id, 'wc_sc_payment_method_ids', true ); + $cart_or_order_object = is_callable( array( $discounts, 'get_object' ) ) ? $discounts->get_object() : null; + $is_wc_session = is_a( $cart_or_order_object, 'WC_Cart' ) && function_exists( 'WC' ) && isset( WC()->session ) && is_object( WC()->session ); + $needs_payment = ( $this->is_callable( $cart_or_order_object, 'needs_payment' ) ) ? $cart_or_order_object->needs_payment() : true; + $posted_data = array(); + $post_data = isset( $_POST['post_data'] ) && ! empty( $_POST['post_data'] ) ? wc_clean( wp_unslash( $_POST['post_data'] ) ) : ''; // phpcs:ignore + wp_parse_str( $post_data, $posted_data ); + + if ( true === $needs_payment && is_array( $payment_method_ids ) && ! empty( $payment_method_ids ) ) { + $payment_titles = $this->get_payment_method_titles_by_ids( $payment_method_ids ); + $chosen_payment_method = ''; + if ( is_a( $cart_or_order_object, 'WC_Order' ) ) { + $chosen_payment_method = is_callable( array( $cart_or_order_object, 'get_payment_method' ) ) ? $cart_or_order_object->get_payment_method() : ''; + } elseif ( ! empty( $posted_data ) && isset( $posted_data['payment_method'] ) ) { + $chosen_payment_method = $posted_data['payment_method']; + } elseif ( true === $is_wc_session ) { + $chosen_payment_method = ( WC()->session->__isset( 'chosen_payment_method' ) ) ? WC()->session->get( 'chosen_payment_method' ) : ''; + } + if ( ! in_array( $chosen_payment_method, $payment_method_ids, true ) ) { + if ( true === $is_wc_session && is_callable( array( WC()->session, 'set' ) ) ) { + WC()->session->set( 'wc_sc_reload_payment_method', 'yes' ); + } + + $applied_coupons = ( WC()->cart instanceof WC_Cart && is_callable( array( WC()->cart, 'get_applied_coupons' ) ) ) ? WC()->cart->get_applied_coupons() : array(); + if ( ! empty( $applied_coupons ) && in_array( $coupon_code, $applied_coupons, true ) ) { + WC()->cart->remove_coupon( $coupon_code ); + /* translators: 1. The coupon code 2. The text 'payment method/s' 3. List of payment method names 4. Link to the checkout page */ + wc_add_notice( sprintf( __( 'Coupon code %1$s has been removed. It is valid only for %2$s: %3$s. You can change the payment method from the %4$s page.', 'woocommerce-smart-coupons' ), '' . $coupon_code . '', _n( 'payment method', 'payment methods', count( $payment_titles ), 'woocommerce-smart-coupons' ), '"' . implode( '", "', $payment_titles ) . '"', '' . __( 'Checkout', 'woocommerce-smart-coupons' ) . '' ), 'error' ); + } + + /* translators: 1. The coupon code 2. The text 'payment method/s' 3. List of payment method names 4. Link to the checkout page */ + throw new Exception( sprintf( __( 'Coupon code %1$s is valid only for %2$s: %3$s. You can change payment method from the %4$s page.', 'woocommerce-smart-coupons' ), '' . $coupon_code . '', _n( 'payment method', 'payment methods', count( $payment_titles ), 'woocommerce-smart-coupons' ), '"' . implode( '", "', $payment_titles ) . '"', '' . __( 'Checkout', 'woocommerce-smart-coupons' ) . '' ) ); + } + if ( true === $is_wc_session && is_callable( array( WC()->session, 'set' ) ) ) { + WC()->session->set( 'wc_sc_reload_payment_method', 'no' ); + } + } + + return $valid; + + } + + /** + * Add meta in export headers + * + * @param array $headers Existing headers. + * @return array + */ + public function export_headers( $headers = array() ) { + + $headers['wc_sc_payment_method_ids'] = __( 'Payment methods', 'woocommerce-smart-coupons' ); + + return $headers; + + } + + /** + * Function to handle coupon meta data during export of existing coupons + * + * @param mixed $meta_value The meta value. + * @param array $args Additional arguments. + * @return string Processed meta value + */ + public function export_coupon_meta_data( $meta_value = '', $args = array() ) { + + if ( ! empty( $args['meta_key'] ) && 'wc_sc_payment_method_ids' === $args['meta_key'] ) { + if ( isset( $args['meta_value'] ) && ! empty( $args['meta_value'] ) ) { + $payment_method_ids = maybe_unserialize( stripslashes( $args['meta_value'] ) ); + if ( is_array( $payment_method_ids ) && ! empty( $payment_method_ids ) ) { + $payment_method_titles = $this->get_payment_method_titles_by_ids( $payment_method_ids ); + if ( is_array( $payment_method_titles ) && ! empty( $payment_method_titles ) ) { + $meta_value = implode( '|', wc_clean( wp_unslash( $payment_method_titles ) ) ); // Replace payment method ids with their respective method titles. + } + } + } + } + + return $meta_value; + + } + + /** + * Post meta defaults for payment method ids meta + * + * @param array $defaults Existing postmeta defaults. + * @return array $defaults Modified postmeta defaults + */ + public function postmeta_defaults( $defaults = array() ) { + + $defaults['wc_sc_payment_method_ids'] = ''; + + return $defaults; + } + + /** + * Add payment method's meta with value in coupon meta + * + * @param array $data The row data. + * @param array $post The POST values. + * @return array $data Modified row data + */ + public function generate_coupon_meta( $data = array(), $post = array() ) { + + $payment_method_titles = ''; + + if ( ! empty( $post['wc_sc_payment_method_ids'] ) && is_array( $post['wc_sc_payment_method_ids'] ) ) { + $payment_method_titles = $this->get_payment_method_titles_by_ids( $post['wc_sc_payment_method_ids'] ); + if ( is_array( $payment_method_titles ) && ! empty( $payment_method_titles ) ) { + $payment_method_titles = implode( '|', wc_clean( wp_unslash( $payment_method_titles ) ) ); + } + } + + $data['wc_sc_payment_method_ids'] = $payment_method_titles; // Replace payment method ids with their respective method titles. + + return $data; + } + + /** + * Function to get payment method titles for given payment method ids + * + * @param array $payment_method_ids ids of payment methods. + * @return array $payment_method_titles titles of payment methods + */ + public function get_payment_method_titles_by_ids( $payment_method_ids = array() ) { + + $payment_method_titles = array(); + + if ( is_array( $payment_method_ids ) && ! empty( $payment_method_ids ) ) { + $available_payment_methods = WC()->payment_gateways->get_available_payment_gateways(); + foreach ( $payment_method_ids as $index => $payment_method_id ) { + $payment_method = ( isset( $available_payment_methods[ $payment_method_id ] ) && ! empty( $available_payment_methods[ $payment_method_id ] ) ) ? $available_payment_methods[ $payment_method_id ] : ''; + if ( ! empty( $payment_method ) && is_a( $payment_method, 'WC_Payment_Gateway' ) ) { + $payment_method_title = is_callable( array( $payment_method, 'get_title' ) ) ? $payment_method->get_title() : ''; + if ( ! empty( $payment_method_title ) ) { + $payment_method_titles[ $index ] = $payment_method_title; // Replace payment method id with it's repective title. + } else { + $payment_method_titles[ $index ] = $payment_method->id; // In case of empty payment method title replace it with method id. + } + } + } + } + + return $payment_method_titles; + } + + /** + * Process coupon meta value for import + * + * @param mixed $meta_value The meta value. + * @param array $args Additional Arguments. + * @return mixed $meta_value + */ + public function process_coupon_meta_value_for_import( $meta_value = null, $args = array() ) { + + if ( ! empty( $args['meta_key'] ) && 'wc_sc_payment_method_ids' === $args['meta_key'] ) { + + $meta_value = ( ! empty( $args['postmeta']['wc_sc_payment_method_ids'] ) ) ? explode( '|', wc_clean( wp_unslash( $args['postmeta']['wc_sc_payment_method_ids'] ) ) ) : array(); + if ( is_array( $meta_value ) && ! empty( $meta_value ) ) { + $available_payment_methods = WC()->payment_gateways->get_available_payment_gateways(); + if ( is_array( $available_payment_methods ) && ! empty( $available_payment_methods ) ) { + foreach ( $meta_value as $index => $payment_method_title ) { + foreach ( $available_payment_methods as $payment_method ) { + $method_title = is_callable( array( $payment_method, 'get_title' ) ) ? $payment_method->get_title() : ''; + if ( $method_title === $payment_method_title && ! empty( $payment_method->id ) ) { + $meta_value[ $index ] = $payment_method->id; // Replace payment method title with it's respective id. + } + } + } + } + } + } + + return $meta_value; + } + + /** + * Function to copy payment method restriction meta in newly generated coupon + * + * @param array $args The arguments. + */ + public function copy_coupon_payment_method_meta( $args = array() ) { + + // Copy meta data to new coupon. + $this->copy_coupon_meta_data( + $args, + array( 'wc_sc_payment_method_ids' ) + ); + + } + + /** + * Make meta data of payment method ids protected + * + * @param bool $protected Is protected. + * @param string $meta_key The meta key. + * @param string $meta_type The meta type. + * @return bool $protected + */ + public function make_action_meta_protected( $protected = false, $meta_key = '', $meta_type = '' ) { + + if ( 'wc_sc_payment_method_ids' === $meta_key ) { + return true; + } + return $protected; + } + + /** + * Function to add styles & scripts + */ + public function styles_and_scripts() { + + if ( is_woocommerce() || is_cart() || is_checkout() || is_product_category() || is_product_tag() || is_account_page() ) { + $js = " + try { + let checkoutForm = document.querySelector('form.checkout'); + if( checkoutForm ){ + + checkoutForm.addEventListener('change', function(event) { + + if (event.target && event.target.name === 'payment_method') { + setTimeout(function() { + document.body.dispatchEvent(new Event('update_checkout')); + }, 1000); + } + }); + } + + } catch( error ) { + console.error( '" . __( 'An error occurred:', 'woocommerce-smart-coupons' ) . "', error); + }"; + wc_enqueue_js( $js ); + } + + } + } +} + +WC_SC_Coupons_By_Payment_Method::get_instance(); diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupons-by-product-attribute.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupons-by-product-attribute.php new file mode 100644 index 00000000..6290b144 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupons-by-product-attribute.php @@ -0,0 +1,644 @@ + $coupon_label ) { + if ( ! in_array( $coupon_type, $product_coupon_types, true ) ) { + $non_product_coupon_types[] = $coupon_label; + } + } + if ( ! empty( $non_product_coupon_types ) ) { + $non_product_coupon_types_label = '"' . implode( ', ', $non_product_coupon_types ) . '"'; + } else { + $non_product_coupon_types_label = ''; + } + if ( ! empty( $coupon_id ) ) { + $coupon = ( ! empty( $coupon_id ) ) ? new WC_Coupon( $coupon_id ) : null; + $is_callable_coupon_get_meta = $this->is_callable( $coupon, 'get_meta' ); + + $product_attribute_ids = ( true === $is_callable_coupon_get_meta ) ? $coupon->get_meta( 'wc_sc_product_attribute_ids' ) : get_post_meta( $coupon_id, 'wc_sc_product_attribute_ids', true ); + if ( ! empty( $product_attribute_ids ) ) { + $product_attribute_ids = explode( '|', $product_attribute_ids ); + } else { + $product_attribute_ids = array(); + } + + $exclude_product_attribute_ids = ( true === $is_callable_coupon_get_meta ) ? $coupon->get_meta( 'wc_sc_exclude_product_attribute_ids' ) : get_post_meta( $coupon_id, 'wc_sc_exclude_product_attribute_ids', true ); + if ( ! empty( $exclude_product_attribute_ids ) ) { + $exclude_product_attribute_ids = explode( '|', $exclude_product_attribute_ids ); + } else { + $exclude_product_attribute_ids = array(); + } + } + + $attribute_taxonomies = wc_get_attribute_taxonomies(); + $attribute_options = array(); + $attribute_taxonomies_label = array(); + + if ( ! empty( $attribute_taxonomies ) && is_array( $attribute_taxonomies ) ) { + $attribute_taxonomies_name = array(); + foreach ( $attribute_taxonomies as $attribute_taxonomy ) { + $attribute_name = isset( $attribute_taxonomy->attribute_name ) ? $attribute_taxonomy->attribute_name : ''; + $attribute_label = isset( $attribute_taxonomy->attribute_label ) ? $attribute_taxonomy->attribute_label : ''; + if ( ! empty( $attribute_name ) && ! empty( $attribute_label ) ) { + $attribute_taxonomy_name = wc_attribute_taxonomy_name( $attribute_name ); + $attribute_taxonomies_name[] = $attribute_taxonomy_name; + $attribute_taxonomies_label[ $attribute_taxonomy_name ] = $attribute_label; + } + } + if ( ! empty( $attribute_taxonomies_name ) ) { + $args = array( + 'orderby' => 'name', + 'hide_empty' => 0, + ); + $args = apply_filters( 'woocommerce_product_attribute_terms', $args ); + if ( version_compare( $wp_version, '4.5.0', '>=' ) ) { + $attribute_taxonomies_terms = get_terms( + array_merge( + array( + 'taxonomy' => $attribute_taxonomies_name, + ), + $args + ) + ); + } else { + $attribute_taxonomies_terms = get_terms( $attribute_taxonomies_name, $args ); + } + if ( ! empty( $attribute_taxonomies_terms ) && is_array( $attribute_taxonomies_terms ) ) { + foreach ( $attribute_taxonomies_terms as $attribute_taxonomy_term ) { + $attribute_taxonomy = $attribute_taxonomy_term->taxonomy; + $attribute_taxonomy_label = isset( $attribute_taxonomies_label[ $attribute_taxonomy ] ) ? $attribute_taxonomies_label[ $attribute_taxonomy ] : ''; + if ( empty( $attribute_taxonomy_label ) ) { + continue; + } + $attribute_term_id = $attribute_taxonomy_term->term_id; + $attribute_term_name = $attribute_taxonomy_term->name; + $attribute_title = __( 'Attribute=', 'woocommerce-smart-coupons' ) . $attribute_taxonomy_label . ':' . __( 'Value=', 'woocommerce-smart-coupons' ) . $attribute_term_name; + $attribute_label = $attribute_taxonomy_label . ': ' . $attribute_term_name; + + $attribute_options[ $attribute_term_id ] = array( + 'title' => $attribute_title, + 'label' => $attribute_label, + ); + } + } + } + } + ?> +
          +

          + + + +

          +
          +
          +

          + + + +

          +
          + is_callable( $coupon, 'update_meta_data' ); + + $product_attribute_ids = ( isset( $_POST['wc_sc_product_attribute_ids'] ) ) ? wc_clean( wp_unslash( $_POST['wc_sc_product_attribute_ids'] ) ) : array(); // phpcs:ignore + $product_attribute_ids = implode( '|', $product_attribute_ids ); // Store attribute ids as delimited data instead of serialized data. + if ( true === $is_callable_coupon_update_meta ) { + $coupon->update_meta_data( 'wc_sc_product_attribute_ids', $product_attribute_ids ); + } else { + update_post_meta( $post_id, 'wc_sc_product_attribute_ids', $product_attribute_ids ); + } + + $exclude_product_attribute_ids = ( isset( $_POST['wc_sc_exclude_product_attribute_ids'] ) ) ? wc_clean( wp_unslash( $_POST['wc_sc_exclude_product_attribute_ids'] ) ) : array(); // phpcs:ignore + $exclude_product_attribute_ids = implode( '|', $exclude_product_attribute_ids ); // Store attribute ids as delimited data instead of serialized data. + if ( true === $is_callable_coupon_update_meta ) { + $coupon->update_meta_data( 'wc_sc_exclude_product_attribute_ids', $exclude_product_attribute_ids ); + } else { + update_post_meta( $post_id, 'wc_sc_exclude_product_attribute_ids', $exclude_product_attribute_ids ); + } + + if ( $this->is_callable( $coupon, 'save' ) ) { + $coupon->save(); + } + } + + /** + * Function to validate coupons for against product attributes + * + * @param bool $valid Coupon validity. + * @param WC_Product|null $product Product object. + * @param WC_Coupon|null $coupon Coupon object. + * @param array|null $values Values. + * @return bool $valid + */ + public function validate( $valid = false, $product = null, $coupon = null, $values = null ) { + + $backtrace = wp_list_pluck( debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ), 'function' ); // phpcs:ignore + + // If coupon is already invalid, no need for further checks. + // Ignore this check if the discount type is a non-product-type discount. + if ( true !== $valid && ! in_array( 'handle_non_product_type_coupons', $backtrace, true ) ) { + return $valid; + } + + if ( empty( $product ) || empty( $coupon ) ) { + return $valid; + } + + if ( $this->is_wc_gte_30() ) { + $coupon_id = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_id' ) ) ) ? $coupon->get_id() : 0; + } else { + $coupon_id = ( ! empty( $coupon->id ) ) ? $coupon->id : 0; + } + + if ( ! empty( $coupon_id ) ) { + $coupon = ( ! empty( $coupon_id ) ) ? new WC_Coupon( $coupon_id ) : null; + + if ( $this->is_callable( $coupon, 'get_meta' ) ) { + $product_attribute_ids = $coupon->get_meta( 'wc_sc_product_attribute_ids' ); + $exclude_product_attribute_ids = $coupon->get_meta( 'wc_sc_exclude_product_attribute_ids' ); + } else { + $product_attribute_ids = get_post_meta( $coupon_id, 'wc_sc_product_attribute_ids', true ); + $exclude_product_attribute_ids = get_post_meta( $coupon_id, 'wc_sc_exclude_product_attribute_ids', true ); + } + + if ( ! empty( $product_attribute_ids ) || ! empty( $exclude_product_attribute_ids ) ) { + $current_product_attribute_ids = $this->get_product_attributes( $product ); + if ( ! empty( $product_attribute_ids ) ) { + $product_attribute_ids = explode( '|', $product_attribute_ids ); + } + $product_attribute_found = true; + if ( ! empty( $product_attribute_ids ) && is_array( $product_attribute_ids ) ) { + $common_attribute_ids = array_intersect( $product_attribute_ids, $current_product_attribute_ids ); + if ( count( $common_attribute_ids ) > 0 ) { + $product_attribute_found = true; + } else { + $product_attribute_found = false; + } + } + + if ( ! empty( $exclude_product_attribute_ids ) ) { + $exclude_product_attribute_ids = explode( '|', $exclude_product_attribute_ids ); + } + + $exclude_attribute_found = false; + if ( ! empty( $exclude_product_attribute_ids ) && is_array( $exclude_product_attribute_ids ) ) { + $common_exclude_attribute_ids = array_intersect( $exclude_product_attribute_ids, $current_product_attribute_ids ); + if ( count( $common_exclude_attribute_ids ) > 0 ) { + $exclude_attribute_found = true; + } else { + $exclude_attribute_found = false; + } + } + + if ( false === $product_attribute_found && false === $exclude_attribute_found ) { + $product_parent_id = is_callable( array( $product, 'get_parent_id' ) ) ? $product->get_parent_id() : 0; + if ( ! empty( $product_parent_id ) ) { + $parent_product = ( function_exists( 'wc_get_product' ) ) ? wc_get_product( $product_parent_id ) : null; + if ( ! empty( $parent_product ) ) { + $parent_product_attribute_ids = $this->get_product_attributes( $parent_product ); + if ( apply_filters( 'wc_sc_check_parent_attributes', true, $product ) && ! empty( $product_attribute_ids ) && is_array( $product_attribute_ids ) ) { + $parent_product_attribute_id = array_intersect( $product_attribute_ids, $parent_product_attribute_ids ); + if ( count( $parent_product_attribute_id ) > 0 ) { + $product_attribute_found = true; + } else { + $product_attribute_found = false; + } + } + if ( apply_filters( 'wc_sc_check_parent_attributes', true, $product ) && ! empty( $exclude_product_attribute_ids ) && is_array( $exclude_product_attribute_ids ) ) { + $exclude_parent_product_attribute_id = array_intersect( $exclude_product_attribute_ids, $parent_product_attribute_ids ); + if ( count( $exclude_parent_product_attribute_id ) > 0 ) { + $exclude_attribute_found = true; + } else { + $exclude_attribute_found = false; + } + } + } + } + } + + $valid = ( $product_attribute_found && ! $exclude_attribute_found ) ? true : false; + } + } + + return $valid; + } + + /** + * Function to get product attributes of a given product. + * + * @param WC_Product $product Product. + * @return array $product_attributes_ids IDs of product attributes + */ + public function get_product_attributes( $product = null ) { + + $product_attributes_ids = array(); + + if ( ! is_a( $product, 'WC_Product' ) ) { + // Check if product id has been passed. + if ( is_numeric( $product ) ) { + $product = wc_get_product( $product ); + } + } + + if ( ! is_a( $product, 'WC_Product' ) ) { + return $product_attribute_ids; + } + + $product_attributes = $product->get_attributes(); + if ( ! empty( $product_attributes ) ) { + if ( true === $product->is_type( 'variation' ) ) { + foreach ( $product_attributes as $variation_taxonomy => $variation_slug ) { + $variation_attribute = get_term_by( 'slug', $variation_slug, $variation_taxonomy ); + if ( is_object( $variation_attribute ) ) { + $product_attributes_ids[] = $variation_attribute->term_id; + } + } + } else { + $product_id = ( is_object( $product ) && is_callable( array( $product, 'get_id' ) ) ) ? $product->get_id() : 0; + if ( ! empty( $product_id ) ) { + $is_variable = $product->is_type( 'variable' ); + foreach ( $product_attributes as $attribute ) { + if ( true === $is_variable && isset( $attribute['is_variation'] ) && ! empty( $attribute['is_variation'] ) ) { + continue; + } + if ( isset( $attribute['is_taxonomy'] ) && ! empty( $attribute['is_taxonomy'] ) ) { + $attribute_taxonomy_name = $attribute['name']; + $product_term_ids = wc_get_product_terms( $product_id, $attribute_taxonomy_name, array( 'fields' => 'ids' ) ); + if ( ! empty( $product_term_ids ) && is_array( $product_term_ids ) ) { + foreach ( $product_term_ids as $product_term_id ) { + $product_attributes_ids[] = $product_term_id; + } + } + } + } + } + } + } + + return $product_attributes_ids; + } + + /** + * Function to validate non product type coupons against product attribute restriction + * We need to remove coupon if it does not pass attribute validation even for single cart item in case of non product type coupons e.g fixed_cart, smart_coupon since these coupon type require all products in the cart to be valid + * + * @param boolean $valid Coupon validity. + * @param WC_Coupon $coupon Coupon object. + * @param WC_Discounts $discounts Discounts object. + * @throws Exception Validation exception. + * @return boolean $valid Coupon validity + */ + public function handle_non_product_type_coupons( $valid = true, $coupon = null, $discounts = null ) { + + // If coupon is already invalid, no need for further checks. + if ( true !== $valid ) { + return $valid; + } + + if ( ! is_a( $coupon, 'WC_Coupon' ) ) { + return $valid; + } + + if ( $this->is_wc_gte_30() ) { + $coupon_id = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_id' ) ) ) ? $coupon->get_id() : 0; + $discount_type = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_discount_type' ) ) ) ? $coupon->get_discount_type() : ''; + } else { + $coupon_id = ( ! empty( $coupon->id ) ) ? $coupon->id : 0; + $discount_type = ( ! empty( $coupon->discount_type ) ) ? $coupon->discount_type : ''; + } + + if ( ! empty( $coupon_id ) ) { + if ( $this->is_callable( $coupon, 'get_meta' ) ) { + $product_attribute_ids = $coupon->get_meta( 'wc_sc_product_attribute_ids' ); + $exclude_product_attribute_ids = $coupon->get_meta( 'wc_sc_exclude_product_attribute_ids' ); + } else { + $product_attribute_ids = get_post_meta( $coupon_id, 'wc_sc_product_attribute_ids', true ); + $exclude_product_attribute_ids = get_post_meta( $coupon_id, 'wc_sc_exclude_product_attribute_ids', true ); + } + // If product attributes are not set in coupon, stop further processing and return from here. + if ( empty( $product_attribute_ids ) && empty( $exclude_product_attribute_ids ) ) { + return $valid; + } + } else { + return $valid; + } + + $product_coupon_types = wc_get_product_coupon_types(); + + // Proceed if it is non product type coupon. + if ( ! in_array( $discount_type, $product_coupon_types, true ) ) { + if ( class_exists( 'WC_Discounts' ) && isset( WC()->cart ) ) { + $wc_cart = WC()->cart; + $wc_discounts = new WC_Discounts( $wc_cart ); + $items_to_validate = array(); + if ( is_callable( array( $wc_discounts, 'get_items_to_validate' ) ) ) { + $items_to_validate = $wc_discounts->get_items_to_validate(); + } elseif ( is_callable( array( $wc_discounts, 'get_items' ) ) ) { + $items_to_validate = $wc_discounts->get_items(); + } elseif ( isset( $wc_discounts->items ) && is_array( $wc_discounts->items ) ) { + $items_to_validate = $wc_discounts->items; + } + if ( ! empty( $items_to_validate ) && is_array( $items_to_validate ) ) { + $valid_products = array(); + $invalid_products = array(); + foreach ( $items_to_validate as $item ) { + $cart_item = clone $item; // Clone the item so changes to wc_discounts item do not affect the originals. + $item_product = isset( $cart_item->product ) ? $cart_item->product : null; + $item_object = isset( $cart_item->object ) ? $cart_item->object : null; + if ( ! is_null( $item_product ) && ! is_null( $item_object ) ) { + if ( $coupon->is_valid_for_product( $item_product, $item_object ) ) { + $valid_products[] = $item_product; + } else { + $invalid_products[] = $item_product; + } + } + } + + // If cart does not have any valid product then throw Exception. + if ( 0 === count( $valid_products ) ) { + $error_message = __( 'Sorry, this coupon is not applicable to selected products.', 'woocommerce-smart-coupons' ); + $error_code = defined( 'E_WC_COUPON_NOT_APPLICABLE' ) ? E_WC_COUPON_NOT_APPLICABLE : 0; + throw new Exception( $error_message, $error_code ); + } elseif ( count( $invalid_products ) > 0 && ! empty( $exclude_product_attribute_ids ) ) { + + $exclude_product_attribute_ids = explode( '|', $exclude_product_attribute_ids ); + $excluded_products = array(); + foreach ( $invalid_products as $invalid_product ) { + $product_attributes = $this->get_product_attributes( $invalid_product ); + if ( ! empty( $product_attributes ) && is_array( $product_attributes ) ) { + $common_exclude_attribute_ids = array_intersect( $exclude_product_attribute_ids, $product_attributes ); + if ( count( $common_exclude_attribute_ids ) > 0 ) { + $excluded_products[] = $invalid_product->get_name(); + } else { + $product_parent_id = is_callable( array( $invalid_product, 'get_parent_id' ) ) ? $invalid_product->get_parent_id() : 0; + if ( ! empty( $product_parent_id ) ) { + $parent_product = ( function_exists( 'wc_get_product' ) ) ? wc_get_product( $product_parent_id ) : ''; + if ( ! empty( $parent_product ) ) { + $parent_product_attribute_ids = $this->get_product_attributes( $parent_product ); + if ( apply_filters( 'wc_sc_check_parent_attributes', true, $invalid_product ) && ! empty( $exclude_product_attribute_ids ) && is_array( $exclude_product_attribute_ids ) ) { + $exclude_parent_product_attribute_id = array_intersect( $exclude_product_attribute_ids, $parent_product_attribute_ids ); + if ( count( $exclude_parent_product_attribute_id ) > 0 ) { + $excluded_products[] = $invalid_product->get_name(); + } + } + } + } + } + } + } + + if ( count( $excluded_products ) > 0 ) { + // If cart contains any excluded product and it is being excluded from our excluded product attributes then throw Exception. + /* translators: 1. Singular/plural label for product(s) 2. Excluded product names */ + $error_message = sprintf( __( 'Sorry, this coupon is not applicable to the %1$s: %2$s.', 'woocommerce-smart-coupons' ), _n( 'product', 'products', count( $excluded_products ), 'woocommerce-smart-coupons' ), implode( ', ', $excluded_products ) ); + $error_code = defined( 'E_WC_COUPON_EXCLUDED_PRODUCTS' ) ? E_WC_COUPON_EXCLUDED_PRODUCTS : 0; + throw new Exception( $error_message, $error_code ); + } + } + } + } + } + + return $valid; + } + + /** + * Add meta in export headers + * + * @param array $headers Existing headers. + * @return array + */ + public function export_headers( $headers = array() ) { + + $headers['wc_sc_product_attribute_ids'] = __( 'Product Attributes', 'woocommerce-smart-coupons' ); + $headers['wc_sc_exclude_product_attribute_ids'] = __( 'Exclude Attributes', 'woocommerce-smart-coupons' ); + + return $headers; + + } + + /** + * Post meta defaults for product attribute ids meta + * + * @param array $defaults Existing postmeta defaults. + * @return array $defaults Modified postmeta defaults + */ + public function postmeta_defaults( $defaults = array() ) { + + $defaults['wc_sc_product_attribute_ids'] = ''; + $defaults['wc_sc_exclude_product_attribute_ids'] = ''; + + return $defaults; + } + + /** + * Make meta data of product attribute ids protected + * + * @param bool $protected Is protected. + * @param string $meta_key The meta key. + * @param string $meta_type The meta type. + * @return bool $protected + */ + public function make_action_meta_protected( $protected = false, $meta_key = '', $meta_type = '' ) { + + $sc_product_attribute_keys = array( + 'wc_sc_product_attribute_ids', + 'wc_sc_exclude_product_attribute_ids', + ); + + if ( in_array( $meta_key, $sc_product_attribute_keys, true ) ) { + return true; + } + + return $protected; + } + + /** + * Add product's attribute in coupon meta + * + * @param array $data The row data. + * @param array $post The POST values. + * @return array Modified data + */ + public function generate_coupon_attribute_meta( $data = array(), $post = array() ) { + + $product_attribute_ids = ( isset( $post['wc_sc_product_attribute_ids'] ) ) ? wc_clean( wp_unslash( $post['wc_sc_product_attribute_ids'] ) ) : array(); // phpcs:ignore + $data['wc_sc_product_attribute_ids'] = implode( '|', $product_attribute_ids ); // Store attribute ids as delimited data instead of serialized data. + + $exclude_product_attribute_ids = ( isset( $post['wc_sc_exclude_product_attribute_ids'] ) ) ? wc_clean( wp_unslash( $post['wc_sc_exclude_product_attribute_ids'] ) ) : array(); // phpcs:ignore + $data['wc_sc_exclude_product_attribute_ids'] = implode( '|', $exclude_product_attribute_ids ); // Store attribute ids as delimited data instead of serialized data. + + return $data; + } + + /** + * Function to copy product's attribute meta in newly generated coupon + * + * @param array $args The arguments. + */ + public function copy_coupon_attributes_meta( $args = array() ) { + + $new_coupon_id = ( ! empty( $args['new_coupon_id'] ) ) ? absint( $args['new_coupon_id'] ) : 0; + $coupon = ( ! empty( $args['ref_coupon'] ) ) ? $args['ref_coupon'] : false; + + if ( empty( $new_coupon_id ) || empty( $coupon ) ) { + return; + } + + if ( $this->is_wc_gte_30() ) { + $product_attribute_ids = $coupon->get_meta( 'wc_sc_product_attribute_ids' ); + $exclude_product_attribute_ids = $coupon->get_meta( 'wc_sc_exclude_product_attribute_ids' ); + } else { + $old_coupon_id = ( ! empty( $coupon->id ) ) ? $coupon->id : 0; + $product_attribute_ids = get_post_meta( $old_coupon_id, 'wc_sc_product_attribute_ids', true ); + $exclude_product_attribute_ids = get_post_meta( $old_coupon_id, 'wc_sc_exclude_product_attribute_ids', true ); + } + + $new_coupon = new WC_Coupon( $new_coupon_id ); + + if ( $this->is_callable( $new_coupon, 'update_meta_data' ) && $this->is_callable( $new_coupon, 'save' ) ) { + $new_coupon->update_meta_data( 'wc_sc_product_attribute_ids', $product_attribute_ids ); + $new_coupon->update_meta_data( 'wc_sc_exclude_product_attribute_ids', $exclude_product_attribute_ids ); + $new_coupon->save(); + } else { + update_post_meta( $new_coupon_id, 'wc_sc_product_attribute_ids', $product_attribute_ids ); + update_post_meta( $new_coupon_id, 'wc_sc_exclude_product_attribute_ids', $exclude_product_attribute_ids ); + } + + } + } +} + +WC_SC_Coupons_By_Product_Attribute::get_instance(); diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupons-by-product-quantity.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupons-by-product-quantity.php new file mode 100644 index 00000000..c7d47d6c --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupons-by-product-quantity.php @@ -0,0 +1,1025 @@ +is_callable( $coupon, 'get_meta' ) ) { + $product_quantity_restrictions = $coupon->get_meta( 'wc_sc_product_quantity_restrictions' ); + } else { + $product_quantity_restrictions = $this->get_post_meta( $coupon_id, 'wc_sc_product_quantity_restrictions', true ); + } + + if ( ! is_array( $product_quantity_restrictions ) ) { + $product_quantity_restrictions = array(); + } + + $cart_min_quantity = ! empty( $product_quantity_restrictions['values']['cart']['min'] ) ? intval( $product_quantity_restrictions['values']['cart']['min'] ) : ''; + $cart_max_quantity = ! empty( $product_quantity_restrictions['values']['cart']['max'] ) ? intval( $product_quantity_restrictions['values']['cart']['max'] ) : ''; + $product_quantity_restrictions_type = ! empty( $product_quantity_restrictions['type'] ) ? $product_quantity_restrictions['type'] : 'cart'; + ?> +
          +

          +

          + + + + +

          +

          + + +

          +

          + + +

          +
          + $value ) { + if ( 0 !== $product_id ) { + $product = wc_get_product( $product_id ); + if ( ! empty( $product ) && is_object( $product ) ) { + $product_name = is_callable( array( $product, 'get_name' ) ) ? $product->get_name() : ''; + $product_max_quantity = ! empty( $value['max'] ) ? intval( $value['max'] ) : ''; + $product_min_quantity = ! empty( $value['min'] ) ? intval( $value['min'] ) : ''; + ?> +

          + + + + + + + + +

          + +

          + + +

          + +
          +
          + $value ) { + if ( 0 !== $category_id ) { + $term = get_term_by( 'id', $category_id, 'product_cat', ARRAY_A ); + if ( ! empty( $term ) && is_array( $term ) ) { + $category_name = ! empty( $term['name'] ) ? $term['name'] : ''; + ?> +

          + + + + + + + + +

          + +

          + + +

          + +
          +
          + + + + + + + + + + + + + + + $restrictions ) { + if ( 'values' === $restriction_key ) { + // Max quantity feature not included for product quantity. + foreach ( $restrictions['product'] as $id => $restriction ) { + $id = absint( $id ); + if ( 0 !== $id && isset( $product_quantity_restrictions['values']['product'][ $id ]['max'] ) ) { + $product_quantity_restrictions['values']['product'][ $id ]['max'] = ! empty( $restriction['max'] ) ? intval( $restriction['max'] ) : ''; + } + } + + // Max quantity feature not included for product category quantity. + foreach ( $restrictions['product_category'] as $id => $restriction ) { + $id = absint( $id ); + if ( 0 !== $id && isset( $product_quantity_restrictions['values']['product_category'][ $id ]['max'] ) ) { + $product_quantity_restrictions['values']['product_category'][ $id ]['max'] = ! empty( $restriction['max'] ) ? intval( $restriction['max'] ) : ''; + } + } + } + } + } + + if ( $this->is_callable( $coupon, 'update_meta_data' ) && $this->is_callable( $coupon, 'save' ) ) { + $coupon->update_meta_data( 'wc_sc_product_quantity_restrictions', $product_quantity_restrictions ); + $coupon->save(); + } else { + $this->update_post_meta( $post_id, 'wc_sc_product_quantity_restrictions', $product_quantity_restrictions ); + } + } + + /** + * Validate the coupon based on product quantity + * + * @param boolean $valid Is valid or not. + * @param WC_Coupon $coupon The coupon object. + * @param WC_Discounts $wc_discounts The discounts object. + * + * @return boolean Is valid or not + * @throws Exception If the coupon is invalid. + */ + public function validate( $valid = false, $coupon = null, $wc_discounts = null ) { + + // If coupon is invalid already, no need for further checks. + if ( false === $valid ) { + return $valid; + } + + if ( ! is_a( $coupon, 'WC_Coupon' ) ) { + return $valid; + } + if ( ! is_a( $wc_discounts, 'WC_Discounts' ) ) { + return $valid; + } + + $items_to_validate = array(); + $cart_quantity = 0; + + if ( is_callable( array( $wc_discounts, 'get_items_to_validate' ) ) ) { + $items_to_validate = $wc_discounts->get_items_to_validate(); + } else { + return $valid; + } + + if ( ! empty( $items_to_validate ) ) { + foreach ( $items_to_validate as $key => $cart_content ) { + $cart_item = ! empty( $cart_content->object ) ? $cart_content->object : array(); + $cart_quantity += ! empty( $cart_item['quantity'] ) ? intval( $cart_item['quantity'] ) : 0; + } + } else { + return $valid; + } + + // If the cart quantity is empty the rule will not work. + if ( $cart_quantity <= 0 ) { + return $valid; + } + + $coupon_id = is_callable( array( $coupon, 'get_id' ) ) ? $coupon->get_id() : 0; + + if ( $this->is_callable( $coupon, 'get_meta' ) ) { + $product_quantity_restrictions = $coupon->get_meta( 'wc_sc_product_quantity_restrictions' ); + } else { + $product_quantity_restrictions = $this->get_post_meta( $coupon_id, 'wc_sc_product_quantity_restrictions', true ); + } + if ( is_array( $product_quantity_restrictions ) && ! empty( $product_quantity_restrictions ) ) { + $type = ! empty( $product_quantity_restrictions['type'] ) ? $product_quantity_restrictions['type'] : ''; + $values = ! empty( $product_quantity_restrictions['values'] ) ? $product_quantity_restrictions['values'] : ''; + $condition = ! empty( $product_quantity_restrictions['condition'] ) ? $product_quantity_restrictions['condition'] : 'any'; + + switch ( $type ) { + case 'cart': + $min = ! empty( $product_quantity_restrictions['values']['cart']['min'] ) ? intval( $product_quantity_restrictions['values']['cart']['min'] ) : 0; + $max = ! empty( $product_quantity_restrictions['values']['cart']['max'] ) ? intval( $product_quantity_restrictions['values']['cart']['max'] ) : 0; + $messages = array( + __( 'Your cart does not meet the quantity requirement.', 'woocommerce-smart-coupons' ), + ); + + if ( empty( $min ) && empty( $max ) ) { + return $valid; + } elseif ( empty( $min ) && ! empty( $max ) && $cart_quantity <= $max ) { + return $valid; + } elseif ( empty( $max ) && ! empty( $min ) && $cart_quantity >= $min ) { + return $valid; + } elseif ( ! empty( $min ) && ! empty( $max ) && $cart_quantity >= $min && $cart_quantity <= $max ) { + return $valid; + } else { + if ( $cart_quantity > $max ) { + /* translators: 1. Number of quantity 2. Singular or plural text based on number of quantities */ + $messages[] = sprintf( __( 'Your cart should have a maximum of %1$d %2$s in total.', 'woocommerce-smart-coupons' ), $max, _n( 'quantity', 'quantities', $max ) ); + } + if ( $cart_quantity < $min ) { + /* translators: 1. Number of quantity 2. Singular or plural text based on number of quantities */ + $messages[] = sprintf( __( 'Your cart should have a minimum of %1$d %2$s in total.', 'woocommerce-smart-coupons' ), $min, _n( 'quantity', 'quantities', $min ) ); + } + throw new Exception( implode( ' ', $messages ) ); + } + break; + default: + case 'product': + $product_quantity_restrictions = ! empty( $values['product'] ) ? $values['product'] : array(); + $product_category_quantity_restrictions = ! empty( $values['product_category'] ) ? $values['product_category'] : array(); + + $params = array( + 'condition' => $condition, + 'items_to_validate' => $items_to_validate, + ); + $product_condition = $this->process_product_quantities( $product_quantity_restrictions, $params ); + $product_category_condition = $this->process_category_quantities( $product_category_quantity_restrictions, $params ); + + if ( false === $product_condition && false === $product_category_condition ) { + throw new Exception( __( 'Your cart does not meet the product quantity requirement.', 'woocommerce-smart-coupons' ) ); + } elseif ( 'empty' === $product_condition && false === $product_category_condition ) { + throw new Exception( __( 'Your cart does not meet the product quantity requirement.', 'woocommerce-smart-coupons' ) ); + } elseif ( false === $product_condition && 'empty' === $product_category_condition ) { + throw new Exception( __( 'Your cart does not meet the product quantity requirement.', 'woocommerce-smart-coupons' ) ); + } + break; + } + } + + return $valid; + + } + + /** + * Make meta data of this plugin, protected + * + * @param bool $protected Is protected. + * @param string $meta_key the meta key. + * @param string $meta_type The meta type. + * @return bool $protected + */ + public function make_sc_meta_protected( $protected, $meta_key, $meta_type ) { + if ( 'wc_sc_product_quantity_restrictions' === $meta_key ) { + return true; + } + return $protected; + } + + /** + * Add product quantity restriction meta with value in coupon meta + * + * @param array $data The row data. + * @param array $post The POST values. + * @return array Modified data + */ + public function generate_coupon_meta( $data = array(), $post = array() ) { + + if ( isset( $post['wc_sc_product_quantity_restrictions'] ) && is_array( $post['wc_sc_product_quantity_restrictions'] ) ) { + $data['wc_sc_product_quantity_restrictions'] = $this->product_quantity_restrictions_encode( $post['wc_sc_product_quantity_restrictions'] ); + } + + return $data; + } + + /** + * Post meta defaults for product quantity restriction meta + * + * @param array $defaults Existing postmeta defaults. + * @return array + */ + public function postmeta_defaults( $defaults = array() ) { + return array_merge( $defaults, array( 'wc_sc_product_quantity_restrictions' => '' ) ); + } + + + + /** + * Function to handle coupon meta data during export of existing coupons + * + * @param mixed $meta_value The meta value. + * @param array $args Additional arguments. + * @return string Processed meta value + */ + public function export_coupon_meta( $meta_value = '', $args = array() ) { + + $index = ( ! empty( $args['index'] ) ) ? $args['index'] : -1; + $meta_keys = ( ! empty( $args['meta_keys'] ) ) ? $args['meta_keys'] : array(); + $meta_values = ( ! empty( $args['meta_values'] ) ) ? $args['meta_values'] : array(); + + if ( $index >= 0 && ! empty( $meta_keys[ $index ] ) && 'wc_sc_product_quantity_restrictions' === $meta_keys[ $index ] && ! empty( $meta_values[ $index ] ) ) { + $meta_value = maybe_unserialize( $meta_values[ $index ] ); // phpcs:ignore + $meta_value = $this->product_quantity_restrictions_encode( $meta_value ); + } + + return $meta_value; + + } + + /** + * Process coupon meta value for import + * + * @param mixed $meta_value The meta value. + * @param array $args Additional Arguments. + * @return mixed $meta_value + */ + public function process_coupon_meta_value_for_import( $meta_value = null, $args = array() ) { + + if ( ! empty( $args['meta_key'] ) && 'wc_sc_product_quantity_restrictions' === $args['meta_key'] && ! empty( $args['postmeta']['wc_sc_product_quantity_restrictions'] ) ) { + $meta_value = $this->product_quantity_restrictions_decode( $args['postmeta']['wc_sc_product_quantity_restrictions'] ); + } + + return $meta_value; + } + + /** + * Add product quantity restriction meta in export headers + * + * @param array $headers Existing headers. + * @return array + */ + public function export_headers( $headers = array() ) { + + $product_quantity_restriction_headers = array( + 'wc_sc_product_quantity_restrictions' => __( 'Product quantity based restrictions', 'woocommerce-smart-coupons' ), + ); + + return array_merge( $headers, $product_quantity_restriction_headers ); + + } + + /** + * Function to copy coupon product quantity restriction meta in newly generated coupon + * + * @param array $args The arguments. + */ + public function copy_meta( $args = array() ) { + + $new_coupon_id = ( ! empty( $args['new_coupon_id'] ) ) ? absint( $args['new_coupon_id'] ) : 0; + $coupon = ( ! empty( $args['ref_coupon'] ) ) ? $args['ref_coupon'] : false; + + if ( empty( $new_coupon_id ) || empty( $coupon ) ) { + return; + } + + $add_product_details = array(); + if ( $this->is_wc_gte_30() && $this->is_callable( $coupon, 'get_meta' ) && $this->is_callable( $coupon, 'update_meta_data' ) && $this->is_callable( $coupon, 'save' ) ) { + $add_product_details = $coupon->get_meta( 'wc_sc_product_quantity_restrictions' ); + $coupon->update_meta_data( 'wc_sc_product_quantity_restrictions', $add_product_details ); + $coupon->save(); + } else { + $old_coupon_id = ( ! empty( $coupon->id ) ) ? $coupon->id : 0; + $add_product_details = $this->get_post_meta( $old_coupon_id, 'wc_sc_product_quantity_restrictions', true ); + $this->update_post_meta( $new_coupon_id, 'wc_sc_product_quantity_restrictions', $add_product_details ); + } + + $new_coupon = new WC_Coupon( $new_coupon_id ); + + if ( $this->is_callable( $new_coupon, 'update_meta_data' ) && $this->is_callable( $new_coupon, 'save' ) ) { + $new_coupon->update_meta_data( 'wc_sc_product_quantity_restrictions', $add_product_details ); + $new_coupon->save(); + } else { + update_post_meta( $new_coupon_id, 'wc_sc_product_quantity_restrictions', $add_product_details ); + } + + } + + /** + * Process cart product quantities + * + * @param array $product_quantity_restrictions values. + * @param array $params condition and cart contents. + * @return bool + * @throws Exception If empty product quantities. + */ + public function process_product_quantities( $product_quantity_restrictions = array(), $params = array() ) { + if ( ! empty( $product_quantity_restrictions ) ) { + $status = array(); + $condition = ! empty( $params['condition'] ) ? $params['condition'] : 'any'; + $items_to_validate = ! empty( $params['items_to_validate'] ) ? $params['items_to_validate'] : array(); + foreach ( $product_quantity_restrictions as $id => $restriction ) { + if ( 0 === $id ) { + continue; + } + $min_quantity = ! empty( $restriction['min'] ) ? intval( $restriction['min'] ) : 0; + $max_quantity = ! empty( $restriction['max'] ) ? intval( $restriction['max'] ) : 0; + $cart_product_quantities = $this->cart_product_quantities( $items_to_validate ); + $product_quantity = ! empty( $cart_product_quantities[ $id ] ) ? intval( $cart_product_quantities[ $id ] ) : 1; + + if ( empty( $min_quantity ) && empty( $max_quantity ) ) { + $status[] = 'empty'; + } elseif ( empty( $min_quantity ) && ! empty( $max_quantity ) && $product_quantity <= $max_quantity ) { + $status[] = 'true'; + } elseif ( empty( $max_quantity ) && ! empty( $min_quantity ) && $product_quantity >= $min_quantity ) { + $status[] = 'true'; + } elseif ( ! empty( $min_quantity ) && ! empty( $max_quantity ) && $product_quantity >= $min_quantity && $product_quantity <= $max_quantity ) { + $status[] = 'true'; + } else { + $status[] = 'false'; + } + } + + switch ( $condition ) { + case 'all': + if ( in_array( 'false', $status, true ) ) { + return false; + } elseif ( in_array( 'true', $status, true ) ) { + return true; + } else { + return 'empty'; + } + default: + case 'any': + if ( in_array( 'true', $status, true ) ) { + return true; + } elseif ( in_array( 'false', $status, true ) ) { + return false; + } else { + return 'empty'; + } + } + } + return 'empty'; + } + + /** + * Process cart category quantities + * + * @param array $product_category_quantity_restrictions values. + * @param array $params condition and cart contents. + * @return bool + * @throws Exception If empty cart category quantities. + */ + public function process_category_quantities( $product_category_quantity_restrictions = array(), $params = array() ) { + + if ( ! empty( $product_category_quantity_restrictions ) ) { + $status = array(); + $condition = ! empty( $params['condition'] ) ? $params['condition'] : 'any'; + $items_to_validate = ! empty( $params['items_to_validate'] ) ? $params['items_to_validate'] : array(); + $cart_product_categories_quantities = $this->cart_product_categories_quantities( $items_to_validate ); + foreach ( $product_category_quantity_restrictions as $id => $restriction ) { + $min_quantity = ! empty( $restriction['min'] ) ? intval( $restriction['min'] ) : ''; + $max_quantity = ! empty( $restriction['max'] ) ? intval( $restriction['max'] ) : ''; + if ( 0 === $id ) { + continue; + } + $category_quantity = ! empty( $cart_product_categories_quantities[ $id ] ) ? intval( $cart_product_categories_quantities[ $id ] ) : 0; + + if ( empty( $min_quantity ) && empty( $max_quantity ) ) { + $status[] = 'empty'; + } elseif ( empty( $min_quantity ) && ! empty( $max_quantity ) && $category_quantity <= $max_quantity ) { + $status[] = 'true'; + } elseif ( empty( $max_quantity ) && ! empty( $min_quantity ) && $category_quantity >= $min_quantity ) { + $status[] = 'true'; + } elseif ( ! empty( $min_quantity ) && ! empty( $max_quantity ) && $category_quantity >= $min_quantity && $category_quantity <= $max_quantity ) { + $status[] = 'true'; + } else { + $status[] = 'false'; + } + } + + switch ( $condition ) { + case 'all': + if ( in_array( 'false', $status, true ) ) { + return false; + } elseif ( in_array( 'true', $status, true ) ) { + return true; + } else { + return 'empty'; + } + default: + case 'any': + if ( in_array( 'true', $status, true ) ) { + return true; + } elseif ( in_array( 'false', $status, true ) ) { + return false; + } else { + return 'empty'; + } + } + } + return 'empty'; + } + + /** + * Calculate product quantities + * + * @param array $cart_contents cart contents. + * @return array + */ + public function cart_product_quantities( $cart_contents = array() ) { + if ( empty( $cart_contents ) ) { + return $cart_contents; + } + $cart_product_quantities = array(); + foreach ( $cart_contents as $cart_content ) { + $cart_item = ! empty( $cart_content->object ) ? $cart_content->object : array(); + $quantity = ! empty( $cart_item['quantity'] ) ? intval( $cart_item['quantity'] ) : 1; + $product_id = ! empty( $cart_item['product_id'] ) ? intval( $cart_item['product_id'] ) : 0; + $variation_id = ! empty( $cart_item['variation_id'] ) ? intval( $cart_item['variation_id'] ) : 0; + if ( empty( $cart_content->object['wc_sc_product_source'] ) ) { + if ( ! empty( $variation_id ) ) { + if ( isset( $cart_product_quantities[ $variation_id ] ) ) { + $cart_product_quantities[ $variation_id ] = $cart_product_quantities[ $variation_id ] + $quantity; + } else { + $cart_product_quantities[ $variation_id ] = $quantity; + } + } + + if ( isset( $cart_product_quantities[ $product_id ] ) ) { + $cart_product_quantities[ $product_id ] = $cart_product_quantities[ $product_id ] + $quantity; + } else { + $cart_product_quantities[ $product_id ] = $quantity; + } + } + } + return $cart_product_quantities; + } + + /** + * Calculate category quantities + * + * @param array $cart_contents cart contents. + * @return array + */ + public function cart_product_categories_quantities( $cart_contents = array() ) { + if ( empty( $cart_contents ) ) { + return $cart_contents; + } + $categories_quantities = array(); + foreach ( $cart_contents as $key => $cart_content ) { + $cart_item = ! empty( $cart_content->object ) ? $cart_content->object : array(); + $product = ! empty( $cart_item['data'] ) ? $cart_item['data'] : array(); + $quantity = ! empty( $cart_item['quantity'] ) ? intval( $cart_item['quantity'] ) : 1; + + if ( is_object( $product ) && is_callable( array( $product, 'get_category_ids' ) ) ) { + $product_variation = ( is_callable( array( $product, 'is_type' ) ) ) ? $product->is_type( 'variation' ) : false; + if ( $product_variation ) { + $parent_id = ( is_callable( array( $product, 'get_parent_id' ) ) ) ? $product->get_parent_id() : 0; + if ( ! empty( $parent_id ) ) { + $product = wc_get_product( $parent_id ); + } + } + $categories = $product->get_category_ids(); + if ( ! empty( $categories ) ) { + foreach ( $categories as $category ) { + if ( isset( $categories_quantities[ $category ] ) ) { + $categories_quantities[ $category ] = $categories_quantities[ $category ] + $quantity; + } else { + $categories_quantities[ $category ] = $quantity; + } + } + } + } + } + return $categories_quantities; + } + + /** + * Calculate category quantities + * + * @param array $input_array . + * @return string + */ + public function product_quantity_restrictions_encode( $input_array = array() ) { + if ( ! is_array( $input_array ) || empty( $input_array ) || ! isset( $input_array['type'] ) ) { + return ''; + } + + $encode_string = ''; + + switch ( $input_array['type'] ) { + case 'cart': + if ( isset( $input_array['values'] ) && isset( $input_array['values']['cart'] ) && ! empty( $input_array['values']['cart'] ) ) { + $cart_data = $input_array['values']['cart']; + $min = isset( $cart_data['min'] ) && ! empty( $cart_data['min'] ) && is_scalar( $cart_data['min'] ) ? (int) $cart_data['min'] : 0; + $max = isset( $cart_data['max'] ) && ! empty( $cart_data['max'] ) && is_scalar( $cart_data['max'] ) ? (int) $cart_data['max'] : 0; + $encode_string = 'cart@' . $min . '_' . $max; + } + break; + case 'product': + $segment = array(); + if ( isset( $input_array['values'] ) && isset( $input_array['values']['product'] ) && ! empty( $input_array['values']['product'] ) ) { + $item_product = array(); + foreach ( $input_array['values']['product'] as $product_id => $product_data ) { + $product_id = (int) $product_id; + $min = isset( $product_data['min'] ) && ! empty( $product_data['min'] ) && is_scalar( $product_data['min'] ) ? (int) $product_data['min'] : 0; + $max = isset( $product_data['max'] ) && ! empty( $product_data['max'] ) && is_scalar( $product_data['max'] ) ? (int) $product_data['max'] : 0; + if ( ! empty( $product_id ) ) { + $item_product[] = $product_id . '-' . $min . '_' . $max; + } + } + if ( ! empty( $item_product ) ) { + $segment[] = 'product@' . implode( '#', $item_product ); + } + } + + if ( isset( $input_array['values'] ) && isset( $input_array['values']['product_category'] ) && ! empty( $input_array['values']['product_category'] ) ) { + $item_category = array(); + foreach ( $input_array['values']['product_category'] as $category_id => $category_data ) { + $category_id = (int) $category_id; + $min = isset( $category_data['min'] ) && ! empty( $category_data['min'] ) && is_scalar( $category_data['min'] ) ? (int) $category_data['min'] : 0; + $max = isset( $category_data['max'] ) && ! empty( $category_data['max'] ) && is_scalar( $category_data['max'] ) ? (int) $category_data['max'] : 0; + if ( ! empty( $category_id ) ) { + $item_category[] = $category_id . '-' . $min . '_' . $max; + } + } + if ( ! empty( $item_category ) ) { + $segment[] = 'category@' . implode( '#', $item_category ); + } + } + + if ( ! empty( $segment ) ) { + $encode_string = implode( '|', $segment ); + } + break; + } + + return $encode_string; + + } + + /** + * Calculate category quantities + * + * @param string $decode_string . + * @return array + */ + public function product_quantity_restrictions_decode( $decode_string = '' ) { + if ( empty( $decode_string ) || ! is_string( $decode_string ) ) { + return array(); + } + $input_array = array( + 'type' => '', + 'values' => array(), + 'condition' => 'any', + ); + + $segments = explode( '|', $decode_string ); + if ( is_array( $segments ) && ! empty( $segments ) ) { + foreach ( $segments as $segment ) { + $parts = explode( '@', $segment ); + + switch ( $parts[0] ) { + case 'cart': + $cart_values = explode( '_', $parts[1] ); + $input_array['type'] = 'cart'; + $input_array['values']['cart'] = array( + 'min' => (int) ( $cart_values[0] ?? 0 ), + 'max' => (int) ( $cart_values[1] ?? 0 ), + ); + break; + case 'product': + $product_values = explode( '#', $parts[1] ); + foreach ( $product_values as $product_item ) { + $product_data = explode( '-', $product_item ); + $input_array['type'] = 'product'; + $min_max = isset( $product_data[1] ) && ! empty( $product_data[1] ) ? explode( '_', $product_data[1] ) : array(); + $input_array['values']['product'][ $product_data[0] ] = array( + 'min' => (int) ( $min_max[0] ?? 0 ), + 'max' => (int) ( $min_max[1] ?? 0 ), + ); + } + break; + case 'category': + $category_values = explode( '#', $parts[1] ); + foreach ( $category_values as $category_item ) { + $category_data = explode( '-', $category_item ); + $input_array['type'] = 'product'; + $min_max = isset( $category_data[1] ) && ! empty( $category_data[1] ) ? explode( '_', $category_data[1] ) : array(); + $input_array['values']['product_category'][ $category_data[0] ] = array( + 'min' => (int) ( $min_max[0] ?? 0 ), + 'max' => (int) ( $min_max[1] ?? 0 ), + ); + } + break; + } + } + } + + return $input_array; + } + + } +} + +WC_SC_Coupons_By_Product_Quantity::get_instance(); diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupons-by-shipping-method.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupons-by-shipping-method.php new file mode 100644 index 00000000..a6a4cbf0 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupons-by-shipping-method.php @@ -0,0 +1,394 @@ +is_callable( $coupon, 'get_meta' ) ) ? $coupon->get_meta( 'wc_sc_shipping_method_ids' ) : $this->get_post_meta( $coupon_id, 'wc_sc_shipping_method_ids', true ); + if ( empty( $shipping_method_ids ) || ! is_array( $shipping_method_ids ) ) { + $shipping_method_ids = array(); + } + } + $available_shipping_methods = WC()->shipping->get_shipping_methods(); + ?> +
          +

          + + + +

          +
          + is_callable( $coupon, 'update_meta_data' ) && $this->is_callable( $coupon, 'save' ) ) { + $coupon->update_meta_data( 'wc_sc_shipping_method_ids', $shipping_method_ids ); + $coupon->save(); + } else { + $this->update_post_meta( $post_id, 'wc_sc_shipping_method_ids', $shipping_method_ids ); + } + } + + /** + * Validate the coupon based on shipping method + * + * @param boolean $valid Is valid or not. + * @param WC_Coupon $coupon The coupon object. + * @param WC_Discounts $discounts The discount object. + * + * @throws Exception If the coupon is invalid. + * @return boolean Is valid or not + */ + public function validate( $valid = false, $coupon = object, $discounts = null ) { + + // If coupon is already invalid, no need for further checks. + if ( false === $valid ) { + return $valid; + } + + $coupon_id = ( $this->is_wc_gte_30() ) ? $coupon->get_id() : $coupon->id; + $shipping_method_ids = ( $this->is_callable( $coupon, 'get_meta' ) ) ? $coupon->get_meta( 'wc_sc_shipping_method_ids' ) : $this->get_post_meta( $coupon_id, 'wc_sc_shipping_method_ids', true ); + + if ( is_array( $shipping_method_ids ) && ! empty( $shipping_method_ids ) ) { + $chosen_shipping_method_data = WC()->session->__isset( 'chosen_shipping_methods' ) ? WC()->session->get( 'chosen_shipping_methods' ) : ''; + $chosen_shipping_method_string = is_array( $chosen_shipping_method_data ) && ! empty( $chosen_shipping_method_data ) ? $chosen_shipping_method_data[0] : ''; + if ( ! empty( $chosen_shipping_method_string ) ) { + $chosen_shipping_method_string = explode( ':', $chosen_shipping_method_string ); + $chosen_shipping_method_id = $chosen_shipping_method_string[0]; + if ( ! in_array( $chosen_shipping_method_id, $shipping_method_ids, true ) ) { + $wc_shipping_packages = ( is_callable( array( WC()->shipping, 'get_packages' ) ) ) ? WC()->shipping->get_packages() : null; + if ( empty( $wc_shipping_packages ) && is_callable( array( WC()->cart, 'calculate_shipping' ) ) ) { + WC()->cart->calculate_shipping(); + } + $chosen_shipping_method_rate_id = is_array( $chosen_shipping_method_data ) && ! empty( $chosen_shipping_method_data ) ? $chosen_shipping_method_data[0] : ''; + $shipping_method_id = ''; + $available_shipping_packages = ( is_callable( array( WC()->shipping, 'get_packages' ) ) ) ? WC()->shipping->get_packages() : ''; + + if ( ! empty( $available_shipping_packages ) ) { + foreach ( $available_shipping_packages as $key => $package ) { + if ( ! empty( $shipping_method_id ) ) { + break; + } + // Loop through Shipping rates. + if ( isset( $package['rates'] ) && ! empty( $package['rates'] ) ) { + foreach ( $package['rates'] as $rate_id => $rate ) { + if ( $chosen_shipping_method_rate_id === $rate_id ) { + $shipping_method_id = ( is_callable( array( $rate, 'get_method_id' ) ) ) ? $rate->get_method_id() : ''; + break; + } + } + } + } + if ( ! in_array( $shipping_method_id, $shipping_method_ids, true ) ) { + if ( ! apply_filters( 'wc_sc_coupon_validate_shipping_method', false, $chosen_shipping_method_id, $shipping_method_ids ) ) { + throw new Exception( __( 'This coupon is not valid for selected shipping method.', 'woocommerce-smart-coupons' ) ); + } + } + } else { + if ( ! apply_filters( 'wc_sc_coupon_validate_shipping_method', false, $chosen_shipping_method_id, $shipping_method_ids ) ) { + throw new Exception( __( 'This coupon is not valid for selected shipping method.', 'woocommerce-smart-coupons' ) ); + } + } + } + } + } + + return $valid; + + } + + /** + * Add meta in export headers + * + * @param array $headers Existing headers. + * @return array + */ + public function export_headers( $headers = array() ) { + + $headers['wc_sc_shipping_method_ids'] = __( 'Shipping methods', 'woocommerce-smart-coupons' ); + + return $headers; + + } + + /** + * Function to handle coupon meta data during export of existing coupons + * + * @param mixed $meta_value The meta value. + * @param array $args Additional arguments. + * @return string Processed meta value + */ + public function export_coupon_meta_data( $meta_value = '', $args = array() ) { + + if ( ! empty( $args['meta_key'] ) && 'wc_sc_shipping_method_ids' === $args['meta_key'] ) { + if ( isset( $args['meta_value'] ) && ! empty( $args['meta_value'] ) ) { + $shipping_method_ids = maybe_unserialize( stripslashes( $args['meta_value'] ) ); + if ( is_array( $shipping_method_ids ) && ! empty( $shipping_method_ids ) ) { + $shipping_method_titles = $this->get_shipping_method_titles_by_ids( $shipping_method_ids ); + if ( is_array( $shipping_method_titles ) && ! empty( $shipping_method_titles ) ) { + $meta_value = implode( '|', wc_clean( wp_unslash( $shipping_method_titles ) ) ); // Replace shipping method ids with their respective method titles. + } + } + } + } + + return $meta_value; + + } + + /** + * Post meta defaults for shipping method ids meta + * + * @param array $defaults Existing postmeta defaults. + * @return array $defaults Modified postmeta defaults + */ + public function postmeta_defaults( $defaults = array() ) { + + $defaults['wc_sc_shipping_method_ids'] = ''; + + return $defaults; + } + + /** + * Add shipping method's meta with value in coupon meta + * + * @param array $data The row data. + * @param array $post The POST values. + * @return array $data Modified row data + */ + public function generate_coupon_meta( $data = array(), $post = array() ) { + + $shipping_method_titles = ''; + + if ( ! empty( $post['wc_sc_shipping_method_ids'] ) && is_array( $post['wc_sc_shipping_method_ids'] ) ) { + $shipping_method_titles = $this->get_shipping_method_titles_by_ids( $post['wc_sc_shipping_method_ids'] ); + if ( is_array( $shipping_method_titles ) && ! empty( $shipping_method_titles ) ) { + $shipping_method_titles = implode( '|', wc_clean( wp_unslash( $shipping_method_titles ) ) ); + } + } + + $data['wc_sc_shipping_method_ids'] = $shipping_method_titles; // Replace shipping method ids with their respective method titles. + + return $data; + } + + /** + * Function to get shipping method titles for given shipping method ids + * + * @param array $shipping_method_ids ids of shipping methods. + * @return array $shipping_method_titles titles of shipping methods + */ + public function get_shipping_method_titles_by_ids( $shipping_method_ids = array() ) { + + $shipping_method_titles = array(); + + if ( is_array( $shipping_method_ids ) && ! empty( $shipping_method_ids ) ) { + $available_shipping_methods = WC()->shipping->load_shipping_methods(); + foreach ( $shipping_method_ids as $index => $shipping_method_id ) { + $shipping_method = ( isset( $available_shipping_methods[ $shipping_method_id ] ) && ! empty( $available_shipping_methods[ $shipping_method_id ] ) ) ? $available_shipping_methods[ $shipping_method_id ] : ''; + if ( ! empty( $shipping_method ) && is_a( $shipping_method, 'WC_Shipping_Method' ) ) { + $shipping_method_title = is_callable( array( $shipping_method, 'get_method_title' ) ) ? $shipping_method->get_method_title() : ''; + if ( ! empty( $shipping_method_title ) ) { + $shipping_method_titles[ $index ] = $shipping_method_title; // Replace shipping method id with it's repective title. + } else { + $shipping_method_titles[ $index ] = $shipping_method->id; // In case of empty shipping method title replace it with method id. + } + } + } + } + + return $shipping_method_titles; + } + + /** + * Process coupon meta value for import + * + * @param mixed $meta_value The meta value. + * @param array $args Additional Arguments. + * @return mixed $meta_value + */ + public function process_coupon_meta_value_for_import( $meta_value = null, $args = array() ) { + + if ( ! empty( $args['meta_key'] ) && 'wc_sc_shipping_method_ids' === $args['meta_key'] ) { + + $meta_value = ( ! empty( $args['postmeta']['wc_sc_shipping_method_ids'] ) ) ? explode( '|', wc_clean( wp_unslash( $args['postmeta']['wc_sc_shipping_method_ids'] ) ) ) : array(); + if ( is_array( $meta_value ) && ! empty( $meta_value ) ) { + $available_shipping_methods = WC()->shipping->load_shipping_methods(); + if ( is_array( $available_shipping_methods ) && ! empty( $available_shipping_methods ) ) { + foreach ( $meta_value as $index => $shipping_method_title ) { + foreach ( $available_shipping_methods as $shipping_method ) { + $method_title = is_callable( array( $shipping_method, 'get_method_title' ) ) ? $shipping_method->get_method_title() : ''; + if ( $method_title === $shipping_method_title && ! empty( $shipping_method->id ) ) { + $meta_value[ $index ] = $shipping_method->id; // Replace shipping method title with it's repective id. + } + } + } + } + } + } + + return $meta_value; + } + + /** + * Function to copy shipping method restriction meta in newly generated coupon + * + * @param array $args The arguments. + */ + public function copy_coupon_shipping_method_meta( $args = array() ) { + + // Copy meta data to new coupon. + $this->copy_coupon_meta_data( + $args, + array( 'wc_sc_shipping_method_ids' ) + ); + + } + + /** + * Make meta data of shipping method ids protected + * + * @param bool $protected Is protected. + * @param string $meta_key The meta key. + * @param string $meta_type The meta type. + * @return bool $protected + */ + public function make_action_meta_protected( $protected = false, $meta_key = '', $meta_type = '' ) { + + if ( 'wc_sc_shipping_method_ids' === $meta_key ) { + return true; + } + return $protected; + } + + /** + * WC Blocks on shipping change should trigger auto-apply coupon. + * + * @param string|null $package_id The sanitized ID of the package being updated. Null if all packages are being updated. + * @param string $rate_id The sanitized chosen rate ID for the package. + * @param \WP_REST_Request $request Full details about the request. + */ + public function wc_blocks_sc_shipping_change_auto_apply_coupon( $package_id, $rate_id, $request ) { + $class_auto_apply = WC_SC_Auto_Apply_Coupon::get_instance(); + $class_auto_apply->auto_apply_coupons(); + } + } +} + +WC_SC_Coupons_By_Shipping_Method::get_instance(); diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupons-by-taxonomy.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupons-by-taxonomy.php new file mode 100644 index 00000000..14d303ae --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupons-by-taxonomy.php @@ -0,0 +1,880 @@ +get_taxonomy_with_label(); + $terms = $this->get_terms_grouped_by_taxonomy(); + $operators = array( + 'incl' => __( 'Include', 'woocommerce-smart-coupons' ), + 'excl' => __( 'Exclude', 'woocommerce-smart-coupons' ), + ); + + $taxonomy_restrictions = ( $this->is_callable( $coupon, 'get_meta' ) ) ? $coupon->get_meta( 'wc_sc_taxonomy_restrictions' ) : $this->get_post_meta( $coupon_id, 'wc_sc_taxonomy_restrictions', true ); + + ?> +
          + get_default_taxonomy_restriction_row(); + } + if ( ! empty( $taxonomy_restrictions ) ) { + $count = count( $taxonomy_restrictions ); + for ( $i = 0; $i < $count; $i++ ) { + $args = array( + 'index' => $i, + 'taxonomy_restriction' => $taxonomy_restrictions[ $i ], + 'taxonomy_to_label' => $taxonomy_to_label, + 'operators' => $operators, + 'terms' => $terms, + ); + $this->get_taxonomy_restriction_row( $args ); + } + } + ?> +
          + +

          + + +

          + get_default_taxonomy_restriction_row(); + + die(); + } + + /** + * Get taxonomy restriction row + * + * @param array $args Arguments. + */ + public function get_taxonomy_restriction_row( $args = array() ) { + $index = ( ! empty( $args['index'] ) ) ? absint( $args['index'] ) : 0; + $taxonomy_restriction = ( ! empty( $args['taxonomy_restriction'] ) ) ? $args['taxonomy_restriction'] : array(); + $taxonomy_to_label = ( ! empty( $args['taxonomy_to_label'] ) ) ? $args['taxonomy_to_label'] : array(); + $terms = ( ! empty( $args['terms'] ) ) ? $args['terms'] : array(); + $operators = ( ! empty( $args['operators'] ) ) ? $args['operators'] : array(); + $tax = $taxonomy_restriction['tax']; + $op = $taxonomy_restriction['op']; + $value = $taxonomy_restriction['val']; + ?> +

          + + $index, + 'column' => 'tax', + 'all' => $taxonomy_to_label, + 'selected' => $tax, + 'width' => '140px', + ); + $this->get_taxonomy_restriction_select_tag( $args ); + ?> + $index, + 'column' => 'op', + 'all' => $operators, + 'selected' => $op, + 'width' => '70px', + ); + $this->get_taxonomy_restriction_select_tag( $args ); + ?> + $index, + 'column' => 'val', + 'all' => $terms[ $tax ], + 'selected' => $value, + ); + $this->get_taxonomy_restriction_select_tag( $args ); + ?> + +

          + + + get_terms_grouped_by_taxonomy(); + + $args = array( + 'index' => $index, + 'column' => 'val', + 'all' => $terms[ $tax ], + ); + $this->get_taxonomy_restriction_select_tag( $args ); + + die(); + } + + /** + * Get taxonomy restriction row HTML via AJAX + */ + public function ajax_taxonomy_restriction_row_html() { + + check_ajax_referer( 'wc-sc-taxonomy-restriction-row', 'security' ); + + $index = ( ! empty( $_POST['index'] ) ) ? sanitize_text_field( wp_unslash( $_POST['index'] ) ) : 0; + + $taxonomy_to_label = $this->get_taxonomy_with_label(); + $terms = $this->get_terms_grouped_by_taxonomy(); + $operators = array( + 'incl' => __( 'Include', 'woocommerce-smart-coupons' ), + 'excl' => __( 'Exclude', 'woocommerce-smart-coupons' ), + ); + + $tax = current( array_keys( $taxonomy_to_label ) ); + $op = current( array_keys( $operators ) ); + + $args = array( + 'index' => $index, + 'taxonomy_restriction' => array( + 'tax' => $tax, + 'op' => $op, + 'val' => array(), + ), + 'taxonomy_to_label' => $taxonomy_to_label, + 'operators' => $operators, + 'terms' => $terms, + ); + $this->get_taxonomy_restriction_row( $args ); + + die(); + } + + /** + * Styles and scripts + */ + public function styles_and_scripts() { + if ( ! wp_script_is( 'jquery' ) ) { + wp_enqueue_script( 'jquery' ); + } + ?> + + + $this ) ); + + if ( ! empty( $wp_taxonomies ) ) { + foreach ( $wp_taxonomies as $taxonomy => $wp_taxonomy ) { + if ( in_array( $taxonomy, $include_taxonomy, true ) ) { + $taxonomy_to_label[ $taxonomy ] = $wp_taxonomy->label; + } + } + } + + return $taxonomy_to_label; + } + + /** + * Get terms grouped by taxonomy + * + * @return array + */ + public function get_terms_grouped_by_taxonomy() { + $terms_by_taxonomy = array(); + + $include_taxonomy = array( + 'product_type', + 'product_visibility', + 'product_tag', + 'product_shipping_class', + ); + $include_taxonomy = apply_filters( 'wc_sc_include_taxonomy_for_restrictions', $include_taxonomy, array( 'source' => $this ) ); + + $args = array( + 'taxonomy' => $include_taxonomy, + 'hide_empty' => false, + ); + + $terms = get_terms( $args ); + + if ( ! empty( $terms ) ) { + foreach ( $terms as $term ) { + if ( empty( $terms_by_taxonomy[ $term->taxonomy ] ) || ! is_array( $terms_by_taxonomy[ $term->taxonomy ] ) ) { + $terms_by_taxonomy[ $term->taxonomy ] = array(); + } + $terms_by_taxonomy[ $term->taxonomy ][ $term->slug ] = $term->name; + } + } + + return $terms_by_taxonomy; + } + + /** + * Save coupon by payment method data in meta + * + * @param Integer $post_id The coupon post ID. + * @param WC_Coupon $coupon The coupon object. + */ + public function process_meta( $post_id = 0, $coupon = null ) { + if ( empty( $post_id ) ) { + return; + } + + $coupon = new WC_Coupon( $coupon ); + + $taxonomy_restrictions = ( isset( $_POST['wc_sc_taxonomy_restrictions'] ) ) ? wc_clean( wp_unslash( $_POST['wc_sc_taxonomy_restrictions'] ) ) : array(); // phpcs:ignore + if ( ! empty( $taxonomy_restrictions ) ) { + $taxonomy_restrictions = array_values( $taxonomy_restrictions ); + } + + if ( $this->is_callable( $coupon, 'update_meta_data' ) && $this->is_callable( $coupon, 'save' ) ) { + $coupon->update_meta_data( 'wc_sc_taxonomy_restrictions', $taxonomy_restrictions ); + $coupon->save(); + } else { + $this->update_post_meta( $post_id, 'wc_sc_taxonomy_restrictions', $taxonomy_restrictions ); + } + } + + /** + * Function to validate coupons against taxonomy + * + * @param bool $valid Coupon validity. + * @param WC_Product|null $product Product object. + * @param WC_Coupon|null $coupon Coupon object. + * @param array|null $values Values. + * @return bool $valid + */ + public function validate( $valid = false, $product = null, $coupon = null, $values = null ) { + + $backtrace = wp_list_pluck( debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ), 'function' ); // phpcs:ignore + + // If coupon is already invalid, no need for further checks. + // Ignore this check if the discount type is a non-product-type discount. + if ( true !== $valid && ! in_array( 'handle_non_product_type_coupons', $backtrace, true ) ) { + return $valid; + } + + if ( empty( $product ) || empty( $coupon ) ) { + return $valid; + } + + $product_ids = array(); + + if ( $this->is_wc_gte_30() ) { + $coupon_id = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_id' ) ) ) ? $coupon->get_id() : 0; + $product_ids[] = ( is_object( $product ) && is_callable( array( $product, 'get_id' ) ) ) ? $product->get_id() : 0; + $product_ids[] = ( is_object( $product ) && is_callable( array( $product, 'get_parent_id' ) ) ) ? $product->get_parent_id() : 0; + } else { + $coupon_id = ( ! empty( $coupon->id ) ) ? $coupon->id : 0; + $product_ids[] = ( ! empty( $product->id ) ) ? $product->id : 0; + $product_ids[] = ( is_object( $product ) && is_callable( array( $product, 'get_parent' ) ) ) ? $product->get_parent() : 0; + } + + $product_ids = array_unique( array_filter( $product_ids ) ); + + if ( ! empty( $coupon_id ) ) { + $taxonomy_restrictions = ( $this->is_callable( $coupon, 'get_meta' ) ) ? $coupon->get_meta( 'wc_sc_taxonomy_restrictions' ) : $this->get_post_meta( $coupon_id, 'wc_sc_taxonomy_restrictions', true ); + + if ( ! empty( $taxonomy_restrictions ) ) { + $term_ids = $this->get_restricted_term_ids( array( 'taxonomy_restrictions' => $taxonomy_restrictions ) ); + + $include_ids = array(); + $exclude_ids = array(); + + if ( isset( $term_ids['include'] ) && is_array( $term_ids['include'] ) ) { + $include_ids = $term_ids['include']; + } + + if ( isset( $term_ids['exclude'] ) && is_array( $term_ids['exclude'] ) ) { + $exclude_ids = $term_ids['exclude']; + } + + $taxonomies = wp_list_pluck( $taxonomy_restrictions, 'tax' ); + $args = array( + 'fields' => 'ids', + ); + $object_term_ids = wp_get_object_terms( $product_ids, $taxonomies, $args ); + $object_term_ids = array_unique( array_filter( $object_term_ids ) ); + + $taxonomy_found = true; + if ( ! empty( $include_ids ) && is_array( $include_ids ) ) { + $common_term_ids = array_intersect( $include_ids, $object_term_ids ); + if ( count( $common_term_ids ) > 0 ) { + $taxonomy_found = true; + } else { + $taxonomy_found = false; + } + } + + $exclude_taxonomy_found = false; + if ( ! empty( $exclude_ids ) && is_array( $exclude_ids ) ) { + $common_exclude_term_ids = array_intersect( $exclude_ids, $object_term_ids ); + if ( count( $common_exclude_term_ids ) > 0 ) { + $exclude_taxonomy_found = true; + } else { + $exclude_taxonomy_found = false; + } + } + + $valid = ( $taxonomy_found && ! $exclude_taxonomy_found ) ? true : false; + } + } + + return $valid; + } + + /** + * Function to validate non product type coupons against taxonomy restriction + * We need to remove coupon if it does not pass taxonomy validation even for single cart item in case of non product type coupons e.g fixed_cart, smart_coupon since these coupon type require all products in the cart to be valid + * + * @param boolean $valid Coupon validity. + * @param WC_Coupon $coupon Coupon object. + * @param WC_Discounts $discounts Discounts object. + * @throws Exception Validation exception. + * @return boolean $valid Coupon validity + */ + public function handle_non_product_type_coupons( $valid = true, $coupon = null, $discounts = null ) { + + // If coupon is already invalid, no need for further checks. + if ( true !== $valid ) { + return $valid; + } + + if ( ! is_a( $coupon, 'WC_Coupon' ) ) { + return $valid; + } + + if ( $this->is_wc_gte_30() ) { + $coupon_id = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_id' ) ) ) ? $coupon->get_id() : 0; + $discount_type = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_discount_type' ) ) ) ? $coupon->get_discount_type() : ''; + } else { + $coupon_id = ( ! empty( $coupon->id ) ) ? $coupon->id : 0; + $discount_type = ( ! empty( $coupon->discount_type ) ) ? $coupon->discount_type : ''; + } + + if ( ! empty( $coupon_id ) ) { + $taxonomy_restrictions = ( $this->is_callable( $coupon, 'get_meta' ) ) ? $coupon->get_meta( 'wc_sc_taxonomy_restrictions' ) : $this->get_post_meta( $coupon_id, 'wc_sc_taxonomy_restrictions', true ); + // If product attributes are not set in coupon, stop further processing and return from here. + if ( empty( $taxonomy_restrictions ) ) { + return $valid; + } + } else { + return $valid; + } + + $product_coupon_types = wc_get_product_coupon_types(); + + // Proceed if it is non product type coupon. + if ( ! in_array( $discount_type, $product_coupon_types, true ) ) { + if ( class_exists( 'WC_Discounts' ) && isset( WC()->cart ) ) { + $wc_cart = WC()->cart; + $wc_discounts = new WC_Discounts( $wc_cart ); + $items_to_validate = array(); + if ( is_callable( array( $wc_discounts, 'get_items_to_validate' ) ) ) { + $items_to_validate = $wc_discounts->get_items_to_validate(); + } elseif ( is_callable( array( $wc_discounts, 'get_items' ) ) ) { + $items_to_validate = $wc_discounts->get_items(); + } elseif ( isset( $wc_discounts->items ) && is_array( $wc_discounts->items ) ) { + $items_to_validate = $wc_discounts->items; + } + if ( ! empty( $items_to_validate ) && is_array( $items_to_validate ) ) { + $term_ids = $this->get_restricted_term_ids( array( 'taxonomy_restrictions' => $taxonomy_restrictions ) ); + + $include_ids = array(); + $exclude_ids = array(); + + if ( isset( $term_ids['include'] ) && is_array( $term_ids['include'] ) ) { + $include_ids = $term_ids['include']; + } + + if ( isset( $term_ids['exclude'] ) && is_array( $term_ids['exclude'] ) ) { + $exclude_ids = $term_ids['exclude']; + } + + $taxonomies = wp_list_pluck( $taxonomy_restrictions, 'tax' ); + + $valid_products = array(); + $invalid_products = array(); + foreach ( $items_to_validate as $item ) { + $cart_item = clone $item; // Clone the item so changes to wc_discounts item do not affect the originals. + $item_product = isset( $cart_item->product ) ? $cart_item->product : null; + $item_object = isset( $cart_item->object ) ? $cart_item->object : null; + if ( ! is_null( $item_product ) && ! is_null( $item_object ) ) { + if ( $coupon->is_valid_for_product( $item_product, $item_object ) ) { + $valid_products[] = $item_product; + } else { + $invalid_products[] = $item_product; + } + } + } + + // If cart does not have any valid product then throw Exception. + if ( 0 === count( $valid_products ) ) { + $error_message = __( 'Sorry, this coupon is not applicable to selected products.', 'woocommerce-smart-coupons' ); + $error_code = defined( 'E_WC_COUPON_NOT_APPLICABLE' ) ? E_WC_COUPON_NOT_APPLICABLE : 0; + throw new Exception( $error_message, $error_code ); + } elseif ( count( $invalid_products ) > 0 && ! empty( $exclude_ids ) ) { + + $excluded_products = array(); + foreach ( $invalid_products as $invalid_product ) { + $product_ids = array(); + $product_ids[] = ( is_object( $invalid_product ) && is_callable( array( $invalid_product, 'get_id' ) ) ) ? $invalid_product->get_id() : 0; + $product_ids[] = ( is_object( $invalid_product ) && is_callable( array( $invalid_product, 'get_parent_id' ) ) ) ? $invalid_product->get_parent_id() : 0; + $product_name = ( is_object( $invalid_product ) && is_callable( array( $invalid_product, 'get_name' ) ) ) ? $invalid_product->get_name() : ''; + + $args = array( + 'fields' => 'ids', + ); + $object_term_ids = wp_get_object_terms( $product_ids, $taxonomies, $args ); + $object_term_ids = array_unique( array_filter( $object_term_ids ) ); + + if ( ! empty( $object_term_ids ) && is_array( $object_term_ids ) ) { + $common_exclude_term_ids = array_intersect( $exclude_ids, $object_term_ids ); + if ( count( $common_exclude_term_ids ) > 0 ) { + $excluded_products[] = $product_name; + } + } + } + + if ( count( $excluded_products ) > 0 ) { + // If cart contains any excluded product and it is being excluded from our excluded product attributes then throw Exception. + /* translators: 1. Singular/plural label for product(s) 2. Excluded product names */ + $error_message = sprintf( __( 'Sorry, this coupon is not applicable to the %1$s: %2$s.', 'woocommerce-smart-coupons' ), _n( 'product', 'products', count( $excluded_products ), 'woocommerce-smart-coupons' ), implode( ', ', $excluded_products ) ); + $error_code = defined( 'E_WC_COUPON_EXCLUDED_PRODUCTS' ) ? E_WC_COUPON_EXCLUDED_PRODUCTS : 0; + throw new Exception( $error_message, $error_code ); + } + } + } + } + } + + return $valid; + } + + /** + * Get restricted term ids + * + * @param array $args Arguments. + * @return array + */ + public function get_restricted_term_ids( $args = array() ) { + global $wp_taxonomies; + + $term_ids = array(); + + $taxonomy_restrictions = ( ! empty( $args['taxonomy_restrictions'] ) ) ? $args['taxonomy_restrictions'] : array(); + + if ( ! empty( $taxonomy_restrictions ) && is_array( $taxonomy_restrictions ) ) { + $include_ids = array(); + $exclude_ids = array(); + foreach ( $taxonomy_restrictions as $taxonomy_restriction ) { + $taxonomy = ( ! empty( $taxonomy_restriction['tax'] ) ) ? $taxonomy_restriction['tax'] : ''; + $operator = ( ! empty( $taxonomy_restriction['op'] ) ) ? $taxonomy_restriction['op'] : ''; + $value = ( ! empty( $taxonomy_restriction['val'] ) ) ? $taxonomy_restriction['val'] : array(); + if ( ! empty( $taxonomy ) && ! empty( $operator ) && ! empty( $value ) ) { + $args = array( + 'taxonomy' => $taxonomy, + 'hide_empty' => false, + 'fields' => 'ids', + 'slug' => $value, + ); + $found_ids = get_terms( $args ); + $found_ids = array_unique( array_filter( $found_ids ) ); + if ( ! empty( $found_ids ) ) { + switch ( $operator ) { + case 'incl': + $include_ids = array_merge( $include_ids, $found_ids ); + break; + case 'excl': + $exclude_ids = array_merge( $exclude_ids, $found_ids ); + break; + } + } + } + } + if ( ! empty( $include_ids ) ) { + $term_ids['include'] = array_unique( array_filter( $include_ids ) ); + } + if ( ! empty( $exclude_ids ) ) { + $term_ids['exclude'] = array_unique( array_filter( $exclude_ids ) ); + } + } + + return $term_ids; + } + + /** + * Function to copy taxonomy restriction meta in newly generated coupon + * + * @param array $args The arguments. + */ + public function copy_coupon_taxonomy_meta( $args = array() ) { + + // Copy meta data to new coupon. + $this->copy_coupon_meta_data( + $args, + array( 'wc_sc_taxonomy_restrictions' ) + ); + + } + + /** + * Make meta data of wc_sc_taxonomy_restrictions protected + * + * @param bool $protected Is protected. + * @param string $meta_key The meta key. + * @param string $meta_type The meta type. + * @return bool $protected + */ + public function make_action_meta_protected( $protected = false, $meta_key = '', $meta_type = '' ) { + + if ( 'wc_sc_taxonomy_restrictions' === $meta_key ) { + return true; + } + return $protected; + } + + /** + * Add taxonomy restriction meta with value in coupon meta + * + * @param array $data The row data. + * @param array $post The POST values. + * @return array Modified data + */ + public function generate_coupon_meta( $data = array(), $post = array() ) { + + if ( isset( $post['wc_sc_taxonomy_restrictions'] ) && is_array( $post['wc_sc_taxonomy_restrictions'] ) && ! empty( $post['wc_sc_taxonomy_restrictions'] ) ) { + $data['wc_sc_taxonomy_restrictions'] = maybe_serialize( array_values( $post['wc_sc_taxonomy_restrictions'] ) ); + } + return $data; + } + + /** + * Post meta defaults for product quantity restriction meta + * + * @param array $defaults Existing postmeta defaults. + * @return array + */ + public function postmeta_defaults( $defaults = array() ) { + return array_merge( $defaults, array( 'wc_sc_taxonomy_restrictions' => '' ) ); + } + + /** + * Process coupon meta value for import + * + * @param mixed $meta_value The meta value. + * @param array $args Additional Arguments. + * @return mixed $meta_value + */ + public function process_coupon_meta_value_for_import( $meta_value = null, $args = array() ) { + + return ( ! empty( $args['meta_key'] ) && 'wc_sc_taxonomy_restrictions' === $args['meta_key'] && ! empty( $args['postmeta'] ) && ! empty( $args['postmeta']['wc_sc_taxonomy_restrictions'] ) ) ? $args['postmeta']['wc_sc_taxonomy_restrictions'] : $meta_value; + } + + + /** + * Add wc_sc_taxonomy_restrictions meta in export headers + * + * @param array $headers Existing headers. + * @return array + */ + public function export_headers( $headers = array() ) { + + $product_wc_sc_taxonomy_restrictions = array( + 'wc_sc_taxonomy_restrictions' => __( 'Taxonomy based restrictions', 'woocommerce-smart-coupons' ), + ); + + return array_merge( $headers, $product_wc_sc_taxonomy_restrictions ); + + } + } +} + +WC_SC_Coupons_By_Taxonomy::get_instance(); diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupons-by-user-role.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupons-by-user-role.php new file mode 100644 index 00000000..e8952972 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-coupons-by-user-role.php @@ -0,0 +1,547 @@ +is_callable( $coupon, 'get_meta' ); + + $user_role_ids = ( true === $is_callable_coupon_get_meta ) ? $coupon->get_meta( 'wc_sc_user_role_ids' ) : get_post_meta( $coupon_id, 'wc_sc_user_role_ids', true ); + if ( empty( $user_role_ids ) || ! is_array( $user_role_ids ) ) { + $user_role_ids = array(); + } + $exclude_user_role_ids = ( true === $is_callable_coupon_get_meta ) ? $coupon->get_meta( 'wc_sc_exclude_user_role_ids' ) : get_post_meta( $coupon_id, 'wc_sc_exclude_user_role_ids', true ); + if ( empty( $exclude_user_role_ids ) || ! is_array( $exclude_user_role_ids ) ) { + $exclude_user_role_ids = array(); + } + } + $available_user_roles = $this->get_available_user_roles(); + ?> +
          +

          + + + +

          +

          + + + +

          +
          + is_callable( $coupon, 'update_meta_data' ) && $this->is_callable( $coupon, 'save' ) ) { + $coupon->update_meta_data( 'wc_sc_user_role_ids', $user_role_ids ); + $coupon->update_meta_data( 'wc_sc_exclude_user_role_ids', $exclude_user_role_ids ); + $coupon->save(); + } else { + update_post_meta( $post_id, 'wc_sc_user_role_ids', $user_role_ids ); + update_post_meta( $post_id, 'wc_sc_exclude_user_role_ids', $exclude_user_role_ids ); + } + + } + + /** + * Validate the coupon based on user role + * + * @param boolean $valid Is valid or not. + * @param WC_Coupon $coupon The coupon object. + * @param WC_Discounts $discounts The discount object. + * + * @throws Exception If the coupon is invalid. + * @return boolean Is valid or not + */ + public function validate( $valid = false, $coupon = object, $discounts = null ) { + + // If coupon is invalid already, no need for further checks. + if ( false === $valid ) { + return $valid; + } + + $coupon_id = ( $this->is_wc_gte_30() ) ? $coupon->get_id() : $coupon->id; + if ( ! is_a( $coupon, 'WC_Coupon' ) ) { + $coupon = new WC_Coupon( $coupon_id ); + } + if ( $this->is_callable( $coupon, 'get_meta' ) ) { + $user_role_ids = $coupon->get_meta( 'wc_sc_user_role_ids' ); + $exclude_user_role_ids = $coupon->get_meta( 'wc_sc_exclude_user_role_ids' ); + } else { + $user_role_ids = get_post_meta( $coupon_id, 'wc_sc_user_role_ids', true ); + $exclude_user_role_ids = get_post_meta( $coupon_id, 'wc_sc_exclude_user_role_ids', true ); + } + + $current_user = wp_get_current_user(); + + $post_action = ( ! empty( $_POST['action'] ) ) ? wc_clean( wp_unslash( $_POST['action'] ) ) : ''; // phpcs:ignore + + if ( is_admin() && wp_doing_ajax() && 'woocommerce_add_coupon_discount' === $post_action ) { // This condition will allow the addition of coupon from admin side, in the order even if the user role is not matching. + return true; + } + + if ( is_array( $user_role_ids ) && ! empty( $user_role_ids ) ) { + // Check if current user's role is allowed. + if ( ! array_intersect( $current_user->roles, $user_role_ids ) ) { + throw new Exception( __( 'This coupon is not valid for you.', 'woocommerce-smart-coupons' ) ); + } + } + + if ( is_array( $exclude_user_role_ids ) && ! empty( $exclude_user_role_ids ) ) { + // Check if current user's role is excluded. + if ( array_intersect( $current_user->roles, $exclude_user_role_ids ) ) { + throw new Exception( __( 'This coupon is not valid for you.', 'woocommerce-smart-coupons' ) ); + } + } + + return $valid; + + } + + /** + * Add meta in export headers + * + * @param array $headers Existing headers. + * @return array + */ + public function export_headers( $headers = array() ) { + + $headers['wc_sc_user_role_ids'] = __( 'User Role', 'woocommerce-smart-coupons' ); + $headers['wc_sc_exclude_user_role_ids'] = __( 'Exclude User Role', 'woocommerce-smart-coupons' ); + + return $headers; + + } + + /** + * Function to handle coupon meta data during export of existing coupons + * + * @param mixed $meta_value The meta value. + * @param array $args Additional arguments. + * @return string Processed meta value + */ + public function export_coupon_meta_data( $meta_value = '', $args = array() ) { + + if ( ! empty( $args['meta_key'] ) ) { + if ( 'wc_sc_user_role_ids' === $args['meta_key'] ) { + if ( isset( $args['meta_value'] ) && ! empty( $args['meta_value'] ) ) { + $user_role_ids = maybe_unserialize( stripslashes( $args['meta_value'] ) ); + if ( is_array( $user_role_ids ) && ! empty( $user_role_ids ) ) { + $user_role_names = $this->get_user_role_names_by_ids( $user_role_ids ); + if ( is_array( $user_role_names ) && ! empty( $user_role_names ) ) { + $meta_value = implode( '|', wc_clean( wp_unslash( $user_role_names ) ) ); // Replace user role ids with their respective role name. + } + } + } + } elseif ( 'wc_sc_exclude_user_role_ids' === $args['meta_key'] ) { + if ( isset( $args['meta_value'] ) && ! empty( $args['meta_value'] ) ) { + $exclude_user_role_ids = maybe_unserialize( stripslashes( $args['meta_value'] ) ); + if ( is_array( $exclude_user_role_ids ) && ! empty( $exclude_user_role_ids ) ) { + $exclude_user_role_names = $this->get_user_role_names_by_ids( $exclude_user_role_ids ); + if ( is_array( $exclude_user_role_names ) && ! empty( $exclude_user_role_names ) ) { + $meta_value = implode( '|', wc_clean( wp_unslash( $exclude_user_role_names ) ) ); // Replace user role ids with their respective role name. + } + } + } + } + } + + return $meta_value; + + } + + /** + * Post meta defaults for user role ids meta + * + * @param array $defaults Existing postmeta defaults. + * @return array + */ + public function postmeta_defaults( $defaults = array() ) { + + $defaults['wc_sc_user_role_ids'] = ''; + $defaults['wc_sc_exclude_user_role_ids'] = ''; + + return $defaults; + } + + /** + * Add user role's meta with value in coupon meta + * + * @param array $data The row data. + * @param array $post The POST values. + * @return array Modified data + */ + public function generate_coupon_meta( $data = array(), $post = array() ) { + + $user_role_names = ''; + $exclude_user_role_names = ''; + + if ( ! empty( $post['wc_sc_user_role_ids'] ) && is_array( $post['wc_sc_user_role_ids'] ) ) { + $user_role_names = $this->get_user_role_names_by_ids( $post['wc_sc_user_role_ids'] ); + if ( is_array( $user_role_names ) && ! empty( $user_role_names ) ) { + $user_role_names = implode( '|', wc_clean( wp_unslash( $user_role_names ) ) ); + } + } + + if ( ! empty( $post['wc_sc_exclude_user_role_ids'] ) && is_array( $post['wc_sc_exclude_user_role_ids'] ) ) { + $exclude_user_role_names = $this->get_user_role_names_by_ids( $post['wc_sc_exclude_user_role_ids'] ); + if ( is_array( $exclude_user_role_names ) && ! empty( $exclude_user_role_names ) ) { + $exclude_user_role_names = implode( '|', wc_clean( wp_unslash( $exclude_user_role_names ) ) ); + } + } + + $data['wc_sc_user_role_ids'] = $user_role_names; // Replace user role ids with their respective role name. + $data['wc_sc_exclude_user_role_ids'] = $exclude_user_role_names; // Replace user role ids with their respective role name. + + return $data; + } + + /** + * Function to get user role titles for given user role ids + * + * @param array $user_role_ids ids of user roles. + * @return array $user_role_names titles of user roles + */ + public function get_user_role_names_by_ids( $user_role_ids = array() ) { + + $user_role_names = array(); + + if ( is_array( $user_role_ids ) && ! empty( $user_role_ids ) ) { + $available_user_roles = $this->get_available_user_roles(); + foreach ( $user_role_ids as $index => $user_role_id ) { + $user_role = ( isset( $available_user_roles[ $user_role_id ] ) && ! empty( $available_user_roles[ $user_role_id ] ) ) ? $available_user_roles[ $user_role_id ] : ''; + if ( is_array( $user_role ) && ! empty( $user_role ) ) { + $user_role_name = ! empty( $user_role['name'] ) ? $user_role['name'] : ''; + if ( ! empty( $user_role_name ) ) { + $user_role_names[ $index ] = $user_role_name; // Replace user role id with it's repective name. + } else { + $user_role_names[ $index ] = $user_role_id; // In case of empty user role name replace it with role id. + } + } + } + } + + return $user_role_names; + } + + /** + * Process coupon meta value for import + * + * @param mixed $meta_value The meta value. + * @param array $args Additional Arguments. + * @return mixed $meta_value + */ + public function process_coupon_meta_value_for_import( $meta_value = null, $args = array() ) { + + if ( ! empty( $args['meta_key'] ) ) { + $available_user_roles = $this->get_available_user_roles(); + if ( 'wc_sc_user_role_ids' === $args['meta_key'] ) { + $meta_value = ( ! empty( $args['postmeta']['wc_sc_user_role_ids'] ) ) ? explode( '|', wc_clean( wp_unslash( $args['postmeta']['wc_sc_user_role_ids'] ) ) ) : array(); + if ( is_array( $meta_value ) && ! empty( $meta_value ) ) { + if ( is_array( $available_user_roles ) && ! empty( $available_user_roles ) ) { + foreach ( $meta_value as $index => $user_role_name ) { + foreach ( $available_user_roles as $role_id => $user_role ) { + $role_name = isset( $user_role['name'] ) ? $user_role['name'] : ''; + if ( $role_name === $user_role_name ) { + $meta_value[ $index ] = $role_id; // Replace user role title with it's repective id. + } + } + } + } + } + } elseif ( 'wc_sc_exclude_user_role_ids' === $args['meta_key'] ) { + $meta_value = ( ! empty( $args['postmeta']['wc_sc_exclude_user_role_ids'] ) ) ? explode( '|', wc_clean( wp_unslash( $args['postmeta']['wc_sc_exclude_user_role_ids'] ) ) ) : array(); + if ( is_array( $meta_value ) && ! empty( $meta_value ) ) { + if ( is_array( $available_user_roles ) && ! empty( $available_user_roles ) ) { + foreach ( $meta_value as $index => $user_role_name ) { + foreach ( $available_user_roles as $role_id => $user_role ) { + $role_name = isset( $user_role['name'] ) ? $user_role['name'] : ''; + if ( $role_name === $user_role_name ) { + $meta_value[ $index ] = $role_id; // Replace user role title with it's repective id. + } + } + } + } + } + } + } + + return $meta_value; + } + + /** + * Make meta data of user role ids protected + * + * @param bool $protected Is protected. + * @param string $meta_key The meta key. + * @param string $meta_type The meta type. + * @return bool $protected + */ + public function make_action_meta_protected( $protected = false, $meta_key = '', $meta_type = '' ) { + + if ( in_array( $meta_key, array( 'wc_sc_user_role_ids', 'wc_sc_exclude_user_role_ids' ), true ) ) { + return true; + } + return $protected; + } + + + /** + * Function to get available user roles which current user use. + * + * @return array $available_user_roles Available user roles + */ + public function get_available_user_roles() { + $available_user_roles = array(); + + if ( ! function_exists( 'get_editable_roles' ) ) { + require_once ABSPATH . 'wp-admin/includes/user.php'; + } + + if ( function_exists( 'get_editable_roles' ) ) { + $available_user_roles = get_editable_roles(); + } + + return $available_user_roles; + } + + /** + * Function to copy user role restriction meta in newly generated coupon + * + * @param array $args The arguments. + */ + public function copy_coupon_user_role_meta( $args = array() ) { + + // Copy meta data to new coupon. + $this->copy_coupon_meta_data( + $args, + array( 'wc_sc_user_role_ids', 'wc_sc_exclude_user_role_ids' ) + ); + + } + + /** + * Validate user role after checkout. + * + * @param array $posted Post data. + * @param WP_Error $errors Validation errors. + * @return void + */ + public function validate_after_checkout( $posted = array(), $errors = object ) { + + $current_user_id = get_current_user_id(); + + if ( ! empty( $current_user_id ) ) { + return; + } + + $billing_email = ! empty( $posted['billing_email'] ) ? $posted['billing_email'] : ''; + + if ( empty( $posted['billing_email'] ) ) { + return; + } + + $cart = ( function_exists( 'WC' ) && isset( WC()->cart ) ) ? WC()->cart : null; + if ( is_a( $cart, 'WC_Cart' ) ) { + $is_cart_empty = is_callable( array( $cart, 'is_empty' ) ) && $cart->is_empty(); + if ( false === $is_cart_empty ) { + $applied_coupons = ( is_callable( array( $cart, 'get_applied_coupons' ) ) ) ? $cart->get_applied_coupons() : array(); + if ( ! empty( $applied_coupons ) ) { + foreach ( $applied_coupons as $code ) { + $coupon = new WC_Coupon( $code ); + if ( ! is_object( $coupon ) ) { + continue; + } + + if ( is_callable( array( $coupon, 'get_meta' ) ) ) { + $user_role_ids = $coupon->get_meta( 'wc_sc_user_role_ids' ); + $exclude_user_role_ids = $coupon->get_meta( 'wc_sc_exclude_user_role_ids' ); + } else { + if ( is_callable( array( $coupon, 'get_id' ) ) ) { + $coupon_id = $coupon->get_id(); + } else { + $coupon_id = ( ! empty( $coupon->id ) ) ? $coupon->id : 0; + } + if ( empty( $coupon_id ) ) { + continue; + } + $user_role_ids = get_post_meta( $coupon_id, 'wc_sc_user_role_ids', true ); + $exclude_user_role_ids = get_post_meta( $coupon_id, 'wc_sc_exclude_user_role_ids', true ); + } + + if ( empty( $exclude_user_role_ids ) && empty( $user_role_ids ) ) { + continue; + } + + $current_user = get_user_by( 'email', $billing_email ); + $current_user_roles = ! empty( $current_user->roles ) ? $current_user->roles : array(); + + $is_message = is_callable( array( $coupon, 'add_coupon_message' ) ); + $is_remove = is_callable( array( $cart, 'remove_coupon' ) ); + + if ( is_array( $user_role_ids ) && ! empty( $user_role_ids ) ) { + // Check if current user's role is allowed. + if ( ! array_intersect( $current_user_roles, $user_role_ids ) ) { + if ( true === $is_message ) { + $coupon->add_coupon_message( WC_Coupon::E_WC_COUPON_NOT_YOURS_REMOVED ); + } + if ( true === $is_remove ) { + $cart->remove_coupon( $code ); + } + } + } + + if ( is_array( $exclude_user_role_ids ) && ! empty( $exclude_user_role_ids ) ) { + // Check if current user's role is excluded. + if ( array_intersect( $current_user_roles, $exclude_user_role_ids ) ) { + if ( true === $is_message ) { + $coupon->add_coupon_message( WC_Coupon::E_WC_COUPON_NOT_YOURS_REMOVED ); + } + if ( true === $is_remove ) { + $cart->remove_coupon( $code ); + } + } + } + } + } + } + } + } + } +} + +WC_SC_Coupons_By_User_Role::get_instance(); diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-display-coupons.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-display-coupons.php new file mode 100644 index 00000000..8a1ffb4f --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-display-coupons.php @@ -0,0 +1,2695 @@ + $this ) ); + $max_coupon_to_show = absint( $max_coupon_to_show ); + + $coupons = array(); + if ( $max_coupon_to_show > 0 ) { + $coupons = $this->sc_get_available_coupons_list( array(), $args ); + } + + if ( empty( $coupons ) ) { + do_action( + 'wc_sc_no_available_coupons', + array( + 'available_coupons_heading' => $available_coupons_heading, + 'page' => $page, + ) + ); + return false; + } + + if ( ! wp_style_is( 'smart-coupon' ) ) { + wp_enqueue_style( 'smart-coupon' ); + } + + $design = get_option( 'wc_sc_setting_coupon_design', 'basic' ); + $background_color = get_option( 'wc_sc_setting_coupon_background_color', '#39cccc' ); + $foreground_color = get_option( 'wc_sc_setting_coupon_foreground_color', '#30050b' ); + $third_color = get_option( 'wc_sc_setting_coupon_third_color', '#39cccc' ); + + $show_coupon_description = get_option( 'smart_coupons_show_coupon_description', 'no' ); + + $valid_designs = $this->get_valid_coupon_designs(); + + if ( ! in_array( $design, $valid_designs, true ) ) { + $design = 'basic'; + } + + ?> + + show_available_coupons_before_checkout_form(); + die(); + } + + /** + * Function to show available coupons before checkout form + */ + public function show_available_coupons_before_checkout_form() { + + $smart_coupon_cart_page_text = get_option( 'smart_coupon_cart_page_text' ); + $smart_coupon_cart_page_text = ( ! empty( $smart_coupon_cart_page_text ) ) ? $smart_coupon_cart_page_text : __( 'Available Coupons (click on a coupon to use it)', 'woocommerce-smart-coupons' ); + $this->show_available_coupons( $smart_coupon_cart_page_text, 'checkout' ); + + } + + /** + * Check if store credit is valid based on amount + * + * @param boolean $is_valid Validity. + * @param array $args Additional arguments. + * @return boolean Validity. + */ + public function show_as_valid( $is_valid = false, $args = array() ) { + + $coupon = ( ! empty( $args['coupon_obj'] ) ) ? $args['coupon_obj'] : false; + + if ( empty( $coupon ) ) { + return $is_valid; + } + + if ( $this->is_wc_gte_30() ) { + $discount_type = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_discount_type' ) ) ) ? $coupon->get_discount_type() : ''; + } else { + $discount_type = ( ! empty( $coupon->discount_type ) ) ? $coupon->discount_type : ''; + } + + $coupon_amount = $this->get_amount( $coupon, true ); + + if ( true === $is_valid && 'smart_coupon' === $discount_type && empty( $coupon_amount ) ) { + return false; + } + + return $is_valid; + } + + /** + * Hooks for handling display of coupons on My Account page + */ + public function myaccount_display_coupons() { + + $is_show_on_my_account = get_option( 'woocommerce_smart_coupon_show_my_account', 'yes' ); + + if ( 'yes' !== $is_show_on_my_account ) { + return; + } + + if ( $this->is_wc_gte_26() ) { + add_filter( 'woocommerce_get_query_vars', array( $this, 'sc_add_query_vars' ) ); + // Change the My Account page title. + add_filter( 'the_title', array( $this, 'sc_endpoint_title' ) ); + // Inserting our new tab/page into the My Account page. + add_filter( 'woocommerce_account_menu_items', array( $this, 'sc_new_menu_items' ) ); + add_action( 'woocommerce_account_' . self::$endpoint . '_endpoint', array( $this, 'sc_endpoint_content' ) ); + } else { + add_action( 'woocommerce_before_my_account', array( $this, 'show_smart_coupon_balance' ) ); + add_action( 'woocommerce_before_my_account', array( $this, 'generated_coupon_details_before_my_account' ) ); + } + + } + + /** + * Function to show gift certificates that are attached with the product + */ + public function show_attached_gift_certificates() { + global $post; + + if ( empty( $post->ID ) ) { + return; + } + + $is_show_associated_coupons = get_option( 'smart_coupons_is_show_associated_coupons', 'no' ); + + if ( 'yes' !== $is_show_associated_coupons ) { + return; + } + + add_action( 'wp_footer', array( $this, 'attached_coupons_styles_and_scripts' ) ); + + ?> +
          + + ID ); + ?> + + get_coupon_titles( array( 'product_object' => $_product ) ); + + if ( $this->is_wc_gte_30() ) { + $product_type = ( is_object( $_product ) && is_callable( array( $_product, 'get_type' ) ) ) ? $_product->get_type() : ''; + } else { + $product_type = ( ! empty( $_product->product_type ) ) ? $_product->product_type : ''; + } + + $sell_sc_at_less_price = get_option( 'smart_coupons_sell_store_credit_at_less_price', 'no' ); + $generated_credit_includes_tax = $this->is_generated_store_credit_includes_tax(); + + if ( 'yes' === $sell_sc_at_less_price ) { + if ( is_a( $_product, 'WC_Product_Variable' ) ) { + $price = ( is_object( $_product ) && is_callable( array( $_product, 'get_variation_regular_price' ) ) ) ? $_product->get_variation_regular_price( 'max' ) : 0; + } else { + $price = ( is_object( $_product ) && is_callable( array( $_product, 'get_regular_price' ) ) ) ? $_product->get_regular_price() : 0; + } + } else { + if ( is_a( $_product, 'WC_Product_Variable' ) ) { + $price = ( is_object( $_product ) && is_callable( array( $_product, 'get_variation_price' ) ) ) ? $_product->get_variation_price( 'max' ) : 0; + } else { + $price = ( is_object( $_product ) && is_callable( array( $_product, 'get_price' ) ) ) ? $_product->get_price() : 0; + } + } + + if ( $coupon_titles && count( $coupon_titles ) > 0 && ! empty( $price ) ) { + + $all_discount_types = wc_get_coupon_types(); + $smart_coupons_product_page_text = get_option( 'smart_coupon_product_page_text' ); + $smart_coupons_product_page_text = ( ! empty( $smart_coupons_product_page_text ) ) ? $smart_coupons_product_page_text : __( 'You will get following coupon(s) when you buy this item:', 'woocommerce-smart-coupons' ); + + $list_started = true; + + ob_start(); + + foreach ( $coupon_titles as $coupon_title ) { + + $coupon = new WC_Coupon( $coupon_title ); + + $is_callable_coupon_get_meta = $this->is_callable( $coupon, 'get_meta' ); + + if ( $this->is_wc_gte_30() ) { + if ( ! is_object( $coupon ) || ! is_callable( array( $coupon, 'get_id' ) ) ) { + continue; + } + $coupon_id = $coupon->get_id(); + if ( empty( $coupon_id ) ) { + continue; + } + $discount_type = $coupon->get_discount_type(); + $is_free_shipping = ( $coupon->get_free_shipping() ) ? 'yes' : 'no'; + $product_ids = $coupon->get_product_ids(); + $excluded_product_ids = $coupon->get_excluded_product_ids(); + $product_categories = $coupon->get_product_categories(); + $excluded_product_categories = $coupon->get_excluded_product_categories(); + } else { + $coupon_id = ( ! empty( $coupon->id ) ) ? $coupon->id : 0; + $discount_type = ( ! empty( $coupon->discount_type ) ) ? $coupon->discount_type : ''; + $is_free_shipping = ( ! empty( $coupon->free_shipping ) ) ? $coupon->free_shipping : ''; + $product_ids = ( ! empty( $coupon->product_ids ) ) ? $coupon->product_ids : array(); + $excluded_product_ids = ( ! empty( $coupon->exclude_product_ids ) ) ? $coupon->exclude_product_ids : array(); + $product_categories = ( ! empty( $coupon->product_categories ) ) ? $coupon->product_categories : array(); + $excluded_product_categories = ( ! empty( $coupon->exclude_product_categories ) ) ? $coupon->exclude_product_categories : array(); + } + + $coupon_amount = $this->get_amount( $coupon, true ); + + $is_pick_price_of_product = ( true === $is_callable_coupon_get_meta ) ? $coupon->get_meta( 'is_pick_price_of_product' ) : get_post_meta( $coupon_id, 'is_pick_price_of_product', true ); + + if ( $list_started && ! empty( $discount_type ) ) { + echo '
          '; + echo '

          ' . esc_html( wp_unslash( $smart_coupons_product_page_text ) ) . ''; + echo '

            '; + $list_started = false; + } + + switch ( $discount_type ) { + + case 'smart_coupon': + /* translators: %s: singular name for store credit */ + $credit_label = ! empty( $store_credit_label['singular'] ) ? sprintf( __( '%s of ', 'woocommerce-smart-coupons' ), esc_html( ucwords( $store_credit_label['singular'] ) ) ) : __( 'Store Credit of ', 'woocommerce-smart-coupons' ); + if ( 'yes' === $is_pick_price_of_product ) { + $amount = ( $price > 0 ) ? $credit_label . wc_price( $price ) : ''; + } else { + $amount = ( ! empty( $coupon_amount ) ) ? $credit_label . wc_price( $coupon_amount ) : ''; + } + + break; + + case 'fixed_cart': + $amount = wc_price( $coupon_amount ) . esc_html__( ' discount on your entire purchase', 'woocommerce-smart-coupons' ); + break; + + case 'fixed_product': + if ( ! empty( $product_ids ) || ! empty( $excluded_product_ids ) || ! empty( $product_categories ) || ! empty( $excluded_product_categories ) ) { + $discount_on_text = esc_html__( 'some products', 'woocommerce-smart-coupons' ); + } else { + $discount_on_text = esc_html__( 'all products', 'woocommerce-smart-coupons' ); + } + $amount = wc_price( $coupon_amount ) . esc_html__( ' discount on ', 'woocommerce-smart-coupons' ) . $discount_on_text; + break; + + case 'percent_product': + if ( ! empty( $product_ids ) || ! empty( $excluded_product_ids ) || ! empty( $product_categories ) || ! empty( $excluded_product_categories ) ) { + $discount_on_text = esc_html__( 'some products', 'woocommerce-smart-coupons' ); + } else { + $discount_on_text = esc_html__( 'all products', 'woocommerce-smart-coupons' ); + } + $amount = $coupon_amount . '%' . esc_html__( ' discount on ', 'woocommerce-smart-coupons' ) . $discount_on_text; + break; + + case 'percent': + if ( ! empty( $product_ids ) || ! empty( $excluded_product_ids ) || ! empty( $product_categories ) || ! empty( $excluded_product_categories ) ) { + $discount_on_text = esc_html__( 'some products', 'woocommerce-smart-coupons' ); + } else { + $discount_on_text = esc_html__( 'your entire purchase', 'woocommerce-smart-coupons' ); + } + $max_discount_text = ''; + $max_discount = $this->get_post_meta( $coupon_id, 'wc_sc_max_discount', true, true ); + if ( ! empty( $max_discount ) && is_numeric( $max_discount ) ) { + /* translators: %s: Maximum coupon discount amount */ + $max_discount_text = sprintf( __( ' upto %s', 'woocommerce-smart-coupons' ), wc_price( $max_discount ) ); + } + $amount = $coupon_amount . '%' . esc_html__( ' discount', 'woocommerce-smart-coupons' ) . $max_discount_text . esc_html__( ' on ', 'woocommerce-smart-coupons' ) . $discount_on_text; + break; + + default: + $default_coupon_type = ( ! empty( $all_discount_types[ $discount_type ] ) ) ? $all_discount_types[ $discount_type ] : ucwords( str_replace( array( '_', '-' ), ' ', $discount_type ) ); + $coupon_amount = apply_filters( 'wc_sc_coupon_amount', $coupon_amount, $coupon ); + /* translators: 1. Discount type 2. Discount amount */ + $amount = sprintf( esc_html__( '%1$s coupon of %2$s', 'woocommerce-smart-coupons' ), $default_coupon_type, $coupon_amount ); + $amount = apply_filters( 'wc_sc_coupon_description', $amount, $coupon ); + break; + + } + + if ( 'yes' === $is_free_shipping && in_array( $discount_type, array( 'fixed_cart', 'fixed_product', 'percent_product', 'percent' ), true ) ) { + /* translators: Add more detail to coupon description */ + $amount = sprintf( esc_html__( '%s Free Shipping', 'woocommerce-smart-coupons' ), ( ( ! empty( $coupon_amount ) ) ? $amount . esc_html__( ' &', 'woocommerce-smart-coupons' ) : '' ) ); + } + + if ( ! empty( $amount ) ) { + // Allow third party developers to modify the text being shown for the linked coupons. + $amount = apply_filters( 'wc_sc_linked_coupon_text', $amount, array( 'coupon' => $coupon ) ); + + // Mostly escaped earlier hence not escaping because it might have some HTML code. + echo '
          • ' . $amount . '
          • '; // phpcs:ignore + } + } + + if ( ! $list_started ) { + echo '

          '; + } + + $response = ob_get_clean(); + + } + } + + echo wp_kses_post( $response ); + + die(); + } + + /** + * Function to allow CSS from this plugin + * + * @param boolean $allow_css Whether the CSS in the test string is considered safe. + * @param string $css_test_string The CSS string to test. + * @return boolean + */ + public function check_safecss( $allow_css = false, $css_test_string = '' ) { + $backtrace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ); // phpcs:ignore + $backtrace_functions = wp_list_pluck( $backtrace, 'function' ); + $allowed_css = array( + 'sc-color', + ); + if ( false === $allow_css && in_array( 'sc_endpoint_content', $backtrace_functions, true ) ) { + foreach ( $allowed_css as $css ) { + if ( false !== strpos( $css_test_string, $css ) ) { + $allow_css = true; + break; + } + } + } + return $allow_css; + } + + /** + * Replace Add to cart button with Select Option button for products which are created for purchasing credit, on shop page + * + * @param string $html Original add to cart button HTML. + * @param mixed|WC_Product $product The product object. + * @param array $args Additional arguments. + * @return string HTML of add to cart button + */ + public function override_add_to_cart_button( $html = '', $product = null, $args = array() ) { + + if ( is_null( $product ) || empty( $product ) || ! $product instanceof WC_Product ) { + return $html; + } + $coupons = $this->get_coupon_titles( array( 'product_object' => $product ) ); + if ( empty( $coupons ) ) { + return $html; + } + if ( $this->is_coupon_amount_pick_from_product_price( $coupons ) && ! ( $product->get_price() > 0 ) ) { + + $html = sprintf( + '%s', + esc_url( $product->get_permalink() ), + esc_attr( ! empty( $args['class'] ) ? $args['class'] : 'button' ), + esc_html( get_option( 'sc_gift_certificate_shop_loop_button_text', __( 'Select options', 'woocommerce-smart-coupons' ) ) ) + ); + + } + return $html; + } + + /** + * Function to show available coupons after cart table + */ + public function show_available_coupons_after_cart_table() { + + $smart_coupon_cart_page_text = get_option( 'smart_coupon_cart_page_text' ); + $smart_coupon_cart_page_text = ( ! empty( $smart_coupon_cart_page_text ) ) ? $smart_coupon_cart_page_text : __( 'Available Coupons (click on a coupon to use it)', 'woocommerce-smart-coupons' ); + $this->show_available_coupons( $smart_coupon_cart_page_text, 'cart' ); + + } + + /** + * Function to display current balance associated with Gift Certificate + */ + public function show_smart_coupon_balance() { + global $store_credit_label; + + $smart_coupon_myaccount_page_text = get_option( 'smart_coupon_myaccount_page_text' ); + + /* translators: %s: plural name for store credit */ + $smart_coupons_myaccount_page_text = ( ! empty( $smart_coupon_myaccount_page_text ) ) ? $smart_coupon_myaccount_page_text : ( ! empty( $store_credit_label['plural'] ) ? sprintf( __( 'Available Coupons & %s', 'woocommerce-smart-coupons' ), ucwords( $store_credit_label['plural'] ) ) : __( 'Available Coupons & Store Credits', 'woocommerce-smart-coupons' ) ); + $this->show_available_coupons( $smart_coupons_myaccount_page_text, 'myaccount' ); + + } + + /** + * Display generated coupon's details on My Account page + */ + public function generated_coupon_details_before_my_account() { + $show_coupon_received_on_my_account = get_option( 'show_coupon_received_on_my_account', 'no' ); + + if ( is_user_logged_in() && 'yes' === $show_coupon_received_on_my_account ) { + $user_id = get_current_user_id(); + $this->get_generated_coupon_data( '', $user_id, true, true ); + } + } + + /** + * Add new query var. + * + * @param array $vars The query vars. + * @return array + */ + public function sc_add_query_vars( $vars = array() ) { + + $vars[ self::$endpoint ] = self::$endpoint; + return $vars; + } + + /** + * Set endpoint title. + * + * @param string $title The title of coupon page. + * @return string + */ + public function sc_endpoint_title( $title ) { + global $wp_query; + + $is_endpoint = isset( $wp_query->query_vars[ self::$endpoint ] ); + + if ( $is_endpoint && ! is_admin() && is_main_query() && in_the_loop() && is_account_page() ) { + // New page title. + $title = __( 'Coupons', 'woocommerce-smart-coupons' ); + remove_filter( 'the_title', array( $this, 'sc_endpoint_title' ) ); + } + + return $title; + } + + /** + * Insert the new endpoint into the My Account menu. + * + * @param array $items Existing menu items. + * @return array + */ + public function sc_new_menu_items( $items ) { + + // Remove the menu items. + if ( isset( $items['edit-address'] ) ) { + $edit_address = $items['edit-address']; + unset( $items['edit-address'] ); + } + + if ( isset( $items['payment-methods'] ) ) { + $payment_methods = $items['payment-methods']; + unset( $items['payment-methods'] ); + } + + if ( isset( $items['edit-account'] ) ) { + $edit_account = $items['edit-account']; + unset( $items['edit-account'] ); + } + + if ( isset( $items['customer-logout'] ) ) { + $logout = $items['customer-logout']; + unset( $items['customer-logout'] ); + } + + // Insert our custom endpoint. + $items[ self::$endpoint ] = __( 'Coupons', 'woocommerce-smart-coupons' ); + + // Insert back the items. + if ( ! empty( $edit_address ) ) { + $items['edit-address'] = $edit_address; + } + if ( ! empty( $payment_methods ) ) { + $items['payment-methods'] = $payment_methods; + } + if ( ! empty( $edit_account ) ) { + $items['edit-account'] = $edit_account; + } + if ( ! empty( $logout ) ) { + $items['customer-logout'] = $logout; + } + + return $items; + } + + /** + * Get coupon HTML + * + * @param array $coupon_data the coupon data. + * @return string Coupon's HTML + */ + public function get_coupon_html( $coupon_data = array() ) { + + ob_start(); + + $design = ( ! empty( $coupon_data['design'] ) ) ? $coupon_data['design'] : null; + $coupon = ( ! empty( $coupon_data['coupon_object'] ) ) ? $coupon_data['coupon_object'] : null; + $is_free_shipping = ( ! empty( $coupon_data['is_free_shipping'] ) ) ? $coupon_data['is_free_shipping'] : null; + $show_coupon_description = ( ! empty( $coupon_data['show_coupon_description'] ) ) ? $coupon_data['show_coupon_description'] : null; + $coupon_description = ( ! empty( $coupon_data['coupon_description'] ) ) ? $coupon_data['coupon_description'] : null; + + $coupon_amount = $this->get_amount( $coupon, true ); + + $coupon_type = ( ! empty( $coupon_data['coupon_type'] ) ) ? $coupon_data['coupon_type'] : ''; + + if ( 'yes' === $is_free_shipping ) { + if ( ! empty( $coupon_type ) ) { + $coupon_type .= __( ' & ', 'woocommerce-smart-coupons' ); + } + $coupon_type .= __( 'Free Shipping', 'woocommerce-smart-coupons' ); + } + + $coupon_description = ( 'yes' === $show_coupon_description ) ? $coupon_description : ''; + + $is_percent = $this->is_percent_coupon( array( 'coupon_object' => $coupon ) ); + + $args = array( + 'coupon_object' => $coupon, + 'coupon_amount' => $coupon_amount, + 'amount_symbol' => ( true === $is_percent ) ? '%' : get_woocommerce_currency_symbol(), + 'discount_type' => wp_strip_all_tags( $coupon_type ), + 'coupon_description' => ( ! empty( $coupon_description ) ) ? $coupon_description : wp_strip_all_tags( $this->generate_coupon_description( array( 'coupon_object' => $coupon ) ) ), + 'coupon_code' => $coupon_data['coupon_code'], + 'coupon_expiry' => ( ! empty( $coupon_data['expiry_date'] ) ) ? $coupon_data['expiry_date'] : __( 'Never expires', 'woocommerce-smart-coupons' ), + 'thumbnail_src' => $this->get_coupon_design_thumbnail_src( + array( + 'design' => $design, + 'coupon_object' => $coupon, + ) + ), + 'classes' => 'apply_coupons_credits', + 'template_id' => $design, + 'is_percent' => $is_percent, + ); + + wc_get_template( 'coupon-design/' . $design . '.php', $args, '', plugin_dir_path( WC_SC_PLUGIN_FILE ) . 'templates/' ); + + $html = ob_get_clean(); + + return $html; + + } + + /** + * Endpoint HTML content. + * To show available coupons on My Account page + */ + public function sc_endpoint_content() { + global $store_credit_label, $woocommerce_smart_coupon; + + $max_coupon_to_show = get_option( 'wc_sc_setting_max_coupon_to_show', 5 ); + $max_coupon_to_show = get_option( 'wc_sc_setting_max_coupon_to_show_on_myaccount', ( $max_coupon_to_show * 10 ) ); + $max_coupon_to_show = apply_filters( 'wc_sc_max_coupon_to_show_on_myaccount', $max_coupon_to_show, array( 'source' => $this ) ); + $max_coupon_to_show = absint( $max_coupon_to_show ); + + $coupons = array(); + if ( $max_coupon_to_show > 0 ) { + $coupons = $this->sc_get_available_coupons_list( array() ); + } + + if ( empty( $coupons ) ) { + ?> +
          + +
          + cart ) && is_callable( array( WC()->cart, 'get_applied_coupons' ) ) ) ? WC()->cart->get_applied_coupons() : array(); + + $available_coupons_heading = get_option( 'smart_coupon_myaccount_page_text' ); + + /* translators: %s: plural name for store credit */ + $available_coupons_heading = ( ! empty( $available_coupons_heading ) ) ? $available_coupons_heading : ( ! empty( $store_credit_label['plural'] ) ? sprintf( __( 'Available Coupons & %s', 'woocommerce-smart-coupons' ), ucwords( $store_credit_label['plural'] ) ) : __( 'Available Coupons & Store Credits', 'woocommerce-smart-coupons' ) ); + + $design = get_option( 'wc_sc_setting_coupon_design', 'basic' ); + $background_color = get_option( 'wc_sc_setting_coupon_background_color', '#39cccc' ); + $foreground_color = get_option( 'wc_sc_setting_coupon_foreground_color', '#30050b' ); + $third_color = get_option( 'wc_sc_setting_coupon_third_color', '#39cccc' ); + $show_coupon_description = get_option( 'smart_coupons_show_coupon_description', 'no' ); + + $valid_designs = $this->get_valid_coupon_designs(); + + if ( ! in_array( $design, $valid_designs, true ) ) { + $design = 'basic'; + } + + ?> + + + + + +

          +

          + + + + array( + 'html' => array(), + ), + 'valid_coupons' => array( + 'html' => array(), + ), + 'invalid_coupons' => array( + 'html' => array(), + ), + ); + + $total_store_credit = 0; + $coupons_to_print = array(); + + foreach ( $coupons as $code ) { + + if ( in_array( $code->post_title, $coupons_applied, true ) ) { + continue; + } + + $coupon_id = wc_get_coupon_id_by_code( $code->post_title ); + + if ( empty( $coupon_id ) ) { + continue; + } + + if ( $max_coupon_to_show <= 0 ) { + break; + } + + $coupon = new WC_Coupon( $code->post_title ); + + if ( $this->is_wc_gte_30() ) { + if ( ! is_object( $coupon ) || ! is_callable( array( $coupon, 'get_id' ) ) ) { + continue; + } + $coupon_id = $coupon->get_id(); + if ( empty( $coupon_id ) ) { + continue; + } + $is_free_shipping = ( $coupon->get_free_shipping() ) ? 'yes' : 'no'; + $discount_type = $coupon->get_discount_type(); + $expiry_date = $coupon->get_date_expires(); + $coupon_code = $coupon->get_code(); + } else { + $coupon_id = ( ! empty( $coupon->id ) ) ? $coupon->id : 0; + $is_free_shipping = ( ! empty( $coupon->free_shipping ) ) ? $coupon->free_shipping : ''; + $discount_type = ( ! empty( $coupon->discount_type ) ) ? $coupon->discount_type : ''; + $expiry_date = ( ! empty( $coupon->expiry_date ) ) ? $coupon->expiry_date : ''; + $coupon_code = ( ! empty( $coupon->code ) ) ? $coupon->code : ''; + } + + $coupon_amount = $this->get_amount( $coupon, true ); + + if ( $this->is_wc_gte_30() && $expiry_date instanceof WC_DateTime ) { + $expiry_date = ( is_callable( array( $expiry_date, 'getTimestamp' ) ) ) ? $expiry_date->getTimestamp() : null; + } elseif ( ! is_int( $expiry_date ) ) { + $expiry_date = $this->strtotime( $expiry_date ); + } + + if ( ! empty( $expiry_date ) && is_int( $expiry_date ) ) { + $expiry_time = ( $this->is_callable( $coupon, 'get_meta' ) ) ? (int) $coupon->get_meta( 'wc_sc_expiry_time' ) : (int) get_post_meta( $coupon_id, 'wc_sc_expiry_time', true ); + if ( ! empty( $expiry_time ) ) { + $expiry_date += $expiry_time; // Adding expiry time to expiry date. + } + } + + if ( empty( $discount_type ) ) { + continue; + } + + $coupon_post = get_post( $coupon_id ); + + $coupon_data = $this->get_coupon_meta_data( $coupon ); + + $block_data = array(); + $block_data['coupon_code'] = $coupon_code; + $block_data['coupon_amount'] = $coupon_data['coupon_amount']; + $block_data['coupon_type'] = $coupon_data['coupon_type']; + $block_data['is_free_shipping'] = $is_free_shipping; + $block_data['coupon_object'] = $coupon; + $block_data['design'] = $design; + $block_data['show_coupon_description'] = $show_coupon_description; + + if ( ! empty( $coupon_post->post_excerpt ) && 'yes' === $show_coupon_description ) { + $block_data['coupon_description'] = $coupon_post->post_excerpt; + } + + if ( ! empty( $expiry_date ) ) { + $block_data['expiry_date'] = $this->get_expiration_format( $expiry_date ); + } else { + $block_data['expiry_date'] = ''; + } + + $show_as_valid = apply_filters( 'wc_sc_show_as_valid', $this->is_valid( $coupon ), array( 'coupon_obj' => $coupon ) ); + + if ( true === $show_as_valid ) { + $coupons_to_print[] = $block_data['coupon_code']; + $html = $this->get_coupon_html( $block_data ); + if ( 'smart_coupon' === $discount_type ) { + $total_store_credit += $coupon_amount; + $coupon_block_data['smart_coupons']['html'][] = $html; + } else { + $coupon_block_data['valid_coupons']['html'][] = $html; + } + } else { + $block_data['is_invalid'] = 'yes'; + $html = $this->get_coupon_html( $block_data ); + $coupon_block_data['invalid_coupons']['html'][] = $html; + } + + $max_coupon_to_show--; + + } + + $coupon_block_data['smart_coupons']['total'] = $total_store_credit; + + $is_print = get_option( 'smart_coupons_is_print_coupon', 'yes' ); + $is_print = apply_filters( 'wc_sc_myaccount_show_print_button', wc_string_to_bool( $is_print ), array( 'source' => $woocommerce_smart_coupon ) ); + + if ( true === $is_print && ! empty( $coupons_to_print ) ) { + $print_url = add_query_arg( + array( + 'print-coupons' => 'yes', + 'source' => 'wc-smart-coupons', + 'coupon-codes' => implode( + ',', + $coupons_to_print + ), + ) + ); + ?> + + + + + array( + 'fill' => true, + 'viewbox' => true, + 'stroke' => true, + 'class' => true, + 'style' => true, + 'xmlns' => true, + 'preserveaspectratio' => true, + ), + 'path' => array( + 'stroke-linecap' => true, + 'stroke-linejoin' => true, + 'stroke-width' => true, + 'd' => true, + 'fill' => true, + 'class' => true, + ), + 'g' => array( + 'stroke-miterlimit' => true, + 'stroke-linecap' => true, + 'stroke-linejoin' => true, + 'stroke-width' => true, + ), + 'circle' => array( + 'cx' => true, + 'cy' => true, + 'r' => true, + ), + 'defs' => array(), + 'style' => array(), + ); + + $additional_allowed_html = apply_filters( 'wc_sc_kses_allowed_html_for_coupon', $additional_allowed_html, array( 'source' => $this ) ); + + if ( ! empty( $additional_allowed_html ) ) { + foreach ( $additional_allowed_html as $tag => $attributes ) { + if ( ! empty( $attributes ) && array_key_exists( $tag, $allowed_html ) ) { + $allowed_html[ $tag ] = array_merge( $allowed_html[ $tag ], $attributes ); + } else { + $allowed_html[ $tag ] = $attributes; + } + } + } + + $smart_coupons_block = ''; + + if ( ! empty( $coupon_block_data['smart_coupons']['html'] ) ) { + $smart_coupons_block = implode( '', $coupon_block_data['smart_coupons']['html'] ); + } + + $smart_coupons_block = trim( $smart_coupons_block ); + + if ( ! empty( $smart_coupons_block ) ) { + ?> +
          +

          +
          +
          + +
          +
          + +
          + +
          +
          + + +
          +

          +
          +
          + +
          +
          +
          +
          + + generated_coupon_details_before_my_account(); + + $is_show_invalid_coupons = get_option( 'smart_coupons_show_invalid_coupons_on_myaccount', 'no' ); + if ( 'yes' === $is_show_invalid_coupons ) { + $invalid_coupons_block = ''; + + if ( ! empty( $coupon_block_data['invalid_coupons']['html'] ) ) { + $invalid_coupons_block = implode( '', $coupon_block_data['invalid_coupons']['html'] ); + } + + $invalid_coupons_block = trim( $invalid_coupons_block ); + + if ( ! empty( $invalid_coupons_block ) ) { + ?> +
          +
          +

          + $this, + 'all_coupon_data' => $coupon_block_data, + ) + ), + $allowed_html + ); + ?> +

          +

          + $this, + 'all_coupon_data' => $coupon_block_data, + ) + ), + $allowed_html + ); + ?> +

          +
          +
          + +
          +
          +
          + frontend_styles_and_scripts( array( 'page' => 'myaccount' ) ); + } + + $js = "var total_store_credit = '" . $total_store_credit . "'; + if ( total_store_credit == 0 ) { + jQuery('#sc_coupons_list').hide(); + } + + if( jQuery('div#all_coupon_container').children().length == 0 ) { + jQuery('#coupons_list').hide(); + } + + if( jQuery('div.woocommerce-MyAccount-content').children().length == 0 ) { + jQuery('.woocommerce-MyAccount-content').append(jQuery('.woocommerce-Message.woocommerce-Message--info.woocommerce-info')); + jQuery('.woocommerce-Message.woocommerce-Message--info.woocommerce-info').show(); + } + + /* to show scroll bar for core coupons */ + var coupons_list = jQuery('#coupons_list'); + var coupons_list_height = coupons_list.height(); + + if ( coupons_list_height > 400 ) { + coupons_list.css('height', '400px'); + coupons_list.css('overflow-y', 'scroll'); + } else { + coupons_list.css('height', ''); + coupons_list.css('overflow-y', ''); + } + "; + + wc_enqueue_js( $js ); + + } + + /** + * Function to get available coupons list + * + * @param array $coupons The coupons. + * @param array $args Additional arguments. + * @return array Modified coupons. + */ + public function sc_get_available_coupons_list( $coupons = array(), $args = array() ) { + + global $wpdb; + + $global_coupons = array(); + + $wpdb->query( $wpdb->prepare( 'SET SESSION group_concat_max_len=%d', 999999 ) ); // phpcs:ignore + + $global_coupons = wp_cache_get( 'wc_sc_global_coupons', 'woocommerce_smart_coupons' ); + + if ( false === $global_coupons ) { + $global_coupons_ids = get_option( 'sc_display_global_coupons' ); + + if ( ! empty( $global_coupons_ids ) ) { + $global_coupons = $wpdb->get_results( // phpcs:ignore + $wpdb->prepare( + "SELECT * + FROM {$wpdb->prefix}posts + WHERE FIND_IN_SET (ID, (SELECT GROUP_CONCAT(option_value SEPARATOR ',') FROM {$wpdb->prefix}options WHERE option_name = %s)) > 0 + AND post_type = %s + GROUP BY ID + ORDER BY post_date DESC", + 'sc_display_global_coupons', + 'shop_coupon' + ) + ); + wp_cache_set( 'wc_sc_global_coupons', $global_coupons, 'woocommerce_smart_coupons' ); + $this->maybe_add_cache_key( 'wc_sc_global_coupons' ); + } + } + + if ( is_scalar( $global_coupons ) ) { + $global_coupons = array(); + } + + $global_coupons = apply_filters( 'wc_smart_coupons_global_coupons', $global_coupons ); + + $args['global_coupons'] = $global_coupons; + + if ( is_user_logged_in() ) { + + global $current_user; + + if ( ! empty( $current_user->user_email ) && ! empty( $current_user->ID ) ) { + + $count_option_current_user = wp_cache_get( 'wc_sc_current_users_option_name_' . $current_user->ID, 'woocommerce_smart_coupons' ); + + if ( false === $count_option_current_user ) { + $count_option_current_user = $wpdb->get_col( // phpcs:ignore + $wpdb->prepare( + "SELECT option_name + FROM {$wpdb->prefix}options + WHERE option_name LIKE %s + ORDER BY option_id DESC", + $wpdb->esc_like( 'sc_display_custom_credit_' . $current_user->ID . '_' ) . '%' + ) + ); + wp_cache_set( 'wc_sc_current_users_option_name_' . $current_user->ID, $count_option_current_user, 'woocommerce_smart_coupons' ); + $this->maybe_add_cache_key( 'wc_sc_current_users_option_name_' . $current_user->ID ); + } + + if ( count( $count_option_current_user ) > 0 ) { + $count_option_current_user = substr( strrchr( $count_option_current_user[0], '_' ), 1 ); + $count_option_current_user = ( ! empty( $count_option_current_user ) ) ? $count_option_current_user + 2 : 1; + } else { + $count_option_current_user = 1; + } + + $coupon_ids = array(); + $coupon_ids = apply_filters( 'wc_sc_available_coupon_ids', $coupon_ids, $args ); + + $option_nm = 'sc_display_custom_credit_' . $current_user->ID . '_' . $count_option_current_user; + $wpdb->query( $wpdb->prepare( 'SET SESSION group_concat_max_len=%d', 999999 ) ); // phpcs:ignore + $wpdb->delete( $wpdb->prefix . 'options', array( 'option_name' => $option_nm ) ); // WPCS: db call ok. + $query_string = "REPLACE INTO {$wpdb->prefix}options (option_name, option_value, autoload) + SELECT %s, + IFNULL(GROUP_CONCAT(DISTINCT p.id SEPARATOR ','), ''), + %s + FROM {$wpdb->prefix}posts AS p + JOIN {$wpdb->prefix}postmeta AS pm + ON(pm.post_id = p.ID + AND p.post_type = %s + AND p.post_status = %s + AND pm.meta_key = %s + AND pm.meta_value LIKE %s"; + + $query_args = array( + $option_nm, + 'no', + 'shop_coupon', + 'publish', + 'customer_email', + '%' . $wpdb->esc_like( '"' . $current_user->user_email . '"' ) . '%', + ); + + if ( ! empty( $coupon_ids ) ) { + $how_many = count( $coupon_ids ); + $placeholders = array_fill( 0, $how_many, '%d' ); + $query_string .= ' AND p.ID IN (' . implode( ',', $placeholders ) . ')'; + $query_args = array_merge( $query_args, $coupon_ids ); + } + + $query_string .= ')'; + + $wpdb->query( // phpcs:ignore + $wpdb->prepare( $query_string, $query_args ) // phpcs:ignore + ); + + $customer_coupon_ids = get_option( $option_nm ); + + // Only execute rest of the queries if coupons found. + if ( ! empty( $customer_coupon_ids ) ) { + $wpdb->query( // phpcs:ignore + $wpdb->prepare( + "UPDATE {$wpdb->prefix}options + SET option_value = (SELECT IFNULL(GROUP_CONCAT(post_id SEPARATOR ','), '') + FROM {$wpdb->prefix}postmeta + WHERE meta_key = %s + AND CAST(meta_value AS SIGNED) >= '0' + AND FIND_IN_SET(post_id, (SELECT option_value FROM (SELECT option_value FROM {$wpdb->prefix}options WHERE option_name = %s) as temp )) > 0 ) + WHERE option_name = %s", + 'coupon_amount', + $option_nm, + $option_nm + ) + ); + } + $coupons = wp_cache_get( 'wc_sc_all_coupon_id_for_user_' . $current_user->ID, 'woocommerce_smart_coupons' ); + + if ( false === $coupons ) { + $coupons = $wpdb->get_results( // phpcs:ignore + $wpdb->prepare( + "SELECT * + FROM {$wpdb->prefix}posts + WHERE FIND_IN_SET (ID, (SELECT option_value FROM {$wpdb->prefix}options WHERE option_name = %s)) > 0 + AND post_status = %s + AND post_type = %s + GROUP BY ID + ORDER BY post_date DESC", + $option_nm, + 'publish', + 'shop_coupon' + ) + ); + wp_cache_set( 'wc_sc_all_coupon_id_for_user_' . $current_user->ID, $coupons, 'woocommerce_smart_coupons' ); + $this->maybe_add_cache_key( 'wc_sc_all_coupon_id_for_user_' . $current_user->ID ); + } + + $wpdb->query( // phpcs:ignore + $wpdb->prepare( + "DELETE FROM {$wpdb->prefix}options WHERE option_name = %s", + $option_nm + ) + ); + } + } + + $coupons = array_merge( $coupons, $global_coupons ); + + $unique_id_to_code = array_unique( array_reverse( wp_list_pluck( $coupons, 'post_title', 'ID' ), true ) ); + + $unique_ids = array_map( 'absint', array_keys( $unique_id_to_code ) ); + + foreach ( $coupons as $index => $coupon ) { + if ( empty( $coupon->ID ) || ! in_array( absint( $coupon->ID ), $unique_ids, true ) ) { + unset( $coupons[ $index ] ); + } + } + + return $coupons; + + } + + /** + * Include frontend styles & scripts + * + * @param array $args Arguments. + */ + public function frontend_styles_and_scripts( $args = array() ) { + + if ( is_account_page() ) { + $show_myaccount_menu_icon = apply_filters( + 'wc_sc_show_myaccount_menu_icon', + $this->sc_get_option( 'wc_sc_show_myaccount_menu_icon' ), + array( + 'source' => $this, + 'args' => $args, + ) + ); + + if ( 'yes' === $show_myaccount_menu_icon ) { + if ( empty( self::$endpoint ) ) { + self::$endpoint = self::get_endpoint(); + } + ?> + + $this ) ) ) { + $current_filter = current_filter(); + $cart_page_id = absint( get_option( 'woocommerce_cart_page_id' ) ); + $checkout_page_id = absint( get_option( 'woocommerce_checkout_page_id' ) ); + $has_available_coupons_block_cart = has_block( 'woocommerce-smart-coupons/available-coupons', absint( $cart_page_id ) ); + $has_available_coupons_block_checkout = has_block( 'woocommerce-smart-coupons/available-coupons', absint( $checkout_page_id ) ); + if ( $has_available_coupons_block_cart && $has_available_coupons_block_checkout ) { // Code to handle apply coupon via blocks. + $js = " + window.addEventListener('load', () => { + handle_display_of_smart_coupons_div(); + }); + + function handle_display_of_smart_coupons_div() { + let sendCouponFormDiv = document.getElementsByClassName('wp-block-woocommerce-smart-coupons-send-coupon-form'); + let availableCouponDiv = document.querySelector('div.wp-block-woocommerce-smart-coupons-available-coupons'); + if ( availableCouponDiv ) { + let firstChildDiv = availableCouponDiv.querySelector('div#coupons_list h3'); + let secondChildDiv = availableCouponDiv.querySelector('div#coupons_list #all_coupon_container'); + + if (secondChildDiv.innerHTML.trim() === '') { + availableCouponDiv.style.display = 'none'; + } else { + availableCouponDiv.style.display = 'flex'; + } + + } + Array.from(sendCouponFormDiv).forEach(childDiv => { + if (childDiv.children.length === 0) { + childDiv.style.display = 'none'; + } + }); + } + + function wc_sc_reload_available_coupons_ajax() { + setTimeout(function(){ + const xhr = new XMLHttpRequest(); + xhr.open('POST', '" . admin_url( 'admin-ajax.php' ) . "', true); + xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); + xhr.onreadystatechange = function () { + if (xhr.readyState === 4 && xhr.status === 200) { + const response = xhr.responseText; + if (response !== undefined && response !== '') { + const couponsList = document.querySelector('div#coupons_list'); + couponsList.parentNode.innerHTML = response; + } + const couponsList = document.querySelector('div#coupons_list'); + couponsList.style.opacity = '1'; + } + }; + const data = { + action: 'sc_get_available_coupons', + security: '" . wp_create_nonce( 'sc-get-available-coupons' ) . "' + }; + let formData = ''; + for (let key in data) { + formData += key + '=' + data[key] + '&'; + } + formData = formData.slice(0, -1); // Remove the trailing '&' + xhr.send(formData); + }, 5000); + handle_display_of_title_for_available_coupons(); + } + + function wc_sc_apply_coupon_js() { + let couponsList = document.querySelector('div#coupons_list'); + let coupon = this; + let coupon_code = coupon.getAttribute('data-coupon_code'); + if (coupon_code !== '' && coupon_code !== undefined) { + couponsList.style.opacity = '0.5'; + // coupon.style.opacity = '0.5'; + let container = document.querySelector('.wp-block-woocommerce-cart-order-summary-coupon-form-block, .wp-block-woocommerce-checkout-order-summary-coupon-form-block'); + let current_element = container.querySelector('.wc-block-components-totals-coupon'); + current_element.querySelector('a').click(); + setTimeout(function () { + let input_element = current_element.querySelector('.wc-block-components-totals-coupon__input input'); + let nativeInputValueSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value').set; + nativeInputValueSetter.call(input_element, coupon_code); + let input_event = new Event('input', { bubbles: true}); + input_element.dispatchEvent(input_event); + setTimeout(function () { + current_element.querySelector('button.wc-block-components-totals-coupon__button').click(); + // coupon.parentNode.removeChild(coupon); + wc_sc_reload_available_coupons_ajax(); + }, 1); + }, 1); + } + } + + document.body.addEventListener('click', function (event) { + const target = event.target.parentNode; + if (target && target.classList && target.classList.contains('wc-block-components-chip__remove')) { + let couponsList = document.querySelector('div#coupons_list'); + couponsList.style.opacity = '0.5'; + wc_sc_reload_available_coupons_ajax(); + } + }); + + "; + } else { + $url = WC_AJAX::get_endpoint( 'apply_coupon' ); + $wp_security_nonce = wp_create_nonce( 'apply-coupon' ); + $js = "function wc_sc_apply_coupon_js() { + let coupon_code = jQuery(this).data('coupon_code'); + if( coupon_code != '' && coupon_code != undefined ) { + jQuery(this).css('opacity', '0.5');"; + + if ( is_cart() ) { + $js .= "block_cart_elements( jQuery( '.woocommerce-cart-form' ) ); + block_cart_elements( jQuery( 'div.cart_totals' ) ); + block_cart_elements( jQuery( '.sc-coupons-list' ) ); "; + } else { + $js .= "block_cart_elements( jQuery( '.sc-coupons-list' ) ); "; + } + $js .= "var data = { + coupon_code: coupon_code, + security: '" . $wp_security_nonce . "' + }; + + jQuery.ajax( { + type: 'POST', + url: '" . $url . "', + data: data, + dataType: 'html',"; + if ( is_cart() ) { + $js .= "success: function( response ) { + jQuery( '.woocommerce-error, .woocommerce-message, .woocommerce-info' ).remove(); + jQuery( '.woocommerce-notices-wrapper:first' ).prepend( response ); + }, + complete: function() { + update_cart(); + jQuery( '.woocommerce-cart-form' ).removeClass( 'processing' ).unblock(); + jQuery( 'div.cart_totals' ).removeClass( 'processing' ).unblock(); + jQuery( '.sc-coupons-list' ).removeClass( 'processing' ).unblock(); + }"; + } elseif ( is_checkout() ) { + $js .= "success: function( response ) { + if ( response ) { + jQuery( '.woocommerce-error, .woocommerce-message' ).remove(); + jQuery( 'form.woocommerce-checkout' ).before( response ); + + $( document.body ).trigger( 'update_checkout', { update_shipping_method: false } ); + } + }, + complete: function() { + jQuery( '.sc-coupons-list' ).removeClass( 'processing' ).unblock(); + }"; + } else { + $js .= "success: function( response ) { + jQuery( '.woocommerce-error, .woocommerce-message, .woocommerce-info' ).remove(); + + if( jQuery('body #sc_coupons_list').length ){ + jQuery( '#sc_coupons_list' ).before( response ); + }else{ + jQuery( '#coupons_list' ).before( response ); + } + scroll_to_notices( jQuery( '[role=\"alert\"]' ) ); + }, + complete: function() { + jQuery( '.sc-coupons-list' ).removeClass( 'processing' ).unblock(); + }"; + } + + $js .= ' } ); + + } + }'; + } + } else { + $js = "function wc_sc_apply_coupon_js() { + let coupon_code = jQuery(this).data('coupon_code'); + + if( coupon_code != '' && coupon_code != undefined ) { + + jQuery(this).css('opacity', '0.5'); + var url = '" . trailingslashit( home_url() ) . ( ( strpos( home_url(), '?' ) === false ) ? '?' : '&' ) . ( ( ! empty( $args['page'] ) ) ? 'sc-page=' . $args['page'] : '' ) . "&coupon-code='+coupon_code; + jQuery(location).attr('href', url); + + } + }"; + } + + $js .= "var show_hide_coupon_list = function() { + if ( jQuery('div#coupons_list').find('div.sc-coupon, div.coupon-container').length > 0 ) { + jQuery('div#coupons_list').slideDown(800); + } else { + jQuery('div#coupons_list').hide(); + } + }; + + var coupon_container_height = jQuery('#all_coupon_container').height(); + if ( coupon_container_height > 400 ) { + jQuery('#all_coupon_container').css('height', '400px'); + jQuery('#all_coupon_container').css('overflow-y', 'scroll'); + } else { + jQuery('#all_coupon_container').css('height', ''); + jQuery('#all_coupon_container').css('overflow-y', ''); + } + + jQuery( document.body ).on('click', '.apply_coupons_credits', wc_sc_apply_coupon_js); + + jQuery('.checkout_coupon').next('#coupons_list').hide(); + + jQuery('a.showcoupon').on('click', function() { + show_hide_coupon_list(); + }); + + jQuery('div#invalid_coupons_list div#all_coupon_container .sc-coupon').removeClass('apply_coupons_credits'); + + function wc_sc_update_checkout() { + jQuery( document.body ).trigger('update_checkout'); + } + + function scroll_to_notices( scrollElement ){ + if ( scrollElement.length ) { + jQuery( 'html, body' ).animate( { + scrollTop: ( scrollElement.offset().top - 100 ) + }, 1000 ); + } + } + + function block_cart_elements( node ){ + if ( ! ( node.is( '.processing' ) || node.parents( '.processing' ).length ) ) { + node.addClass( 'processing' ).block( { + message: null, + overlayCSS: { + background: '#fff', + opacity: 0.6 + } + } ); + } + } + + function unblock_cart_elements ( node ) { + node.removeClass( 'processing' ).unblock(); + }; + + function update_cart() + { + var cart_form = jQuery( '.woocommerce-cart-form' ); + block_cart_elements( cart_form ); + block_cart_elements( jQuery( 'div.cart_totals' ) ); + block_cart_elements( jQuery( '.sc-coupons-list' ) ); + + // Make call to actual form post URL. + jQuery.ajax( { + type: cart_form.attr( 'method' ), + url: cart_form.attr( 'action' ), + data: cart_form.serialize(), + dataType: 'html', + success: function( response ) { + var response_html = jQuery.parseHTML( response ); + var updated_cart_form = jQuery( '.woocommerce-cart-form', response_html ); + var updated_totals = jQuery( '.cart_totals', response_html ); + jQuery( '.woocommerce-cart-form' ).replaceWith( updated_cart_form ); + jQuery( '.woocommerce-cart-form' ).find( ':input[name=\"update_cart\"]' ).prop( 'disabled', true ).attr( 'aria-disabled', true ); + + jQuery( '.cart_totals' ).replaceWith( updated_totals ); + jQuery( document.body ).trigger( 'updated_cart_totals' ); + + }, + complete: function() { + scroll_to_notices( jQuery( '[role=\"alert\"]' ) ); + cart_form.removeClass( 'processing' ).unblock(); + jQuery( 'div.cart_totals' ).removeClass( 'processing' ).unblock(); + jQuery( '.sc-coupons-list' ).removeClass( 'processing' ).unblock(); + + } + } ); + }"; + + if ( is_checkout() ) { + $is_wc_session_get = function_exists( 'WC' ) && isset( WC()->session ) && is_object( WC()->session ) && is_callable( array( WC()->session, 'get' ) ); + if ( true === $is_wc_session_get ) { + $is_reload = WC()->session->get( 'wc_sc_reload_payment_method' ); + if ( 'yes' === $is_reload ) { + $js .= " + jQuery(document.body).off('change', 'input[name=payment_method]', wc_sc_update_checkout); + jQuery(document.body).on('change', 'input[name=payment_method]', wc_sc_update_checkout); + "; + } else { + $js .= " + jQuery(document.body).off('change', 'input[name=payment_method]', wc_sc_update_checkout); + "; + } + } + $js .= " + jQuery(document.body).on('applied_coupon_in_checkout', function( e, data ){ + if ( jQuery('.woocommerce .woocommerce-message').length ) { + jQuery(document.body).off('change', 'input[name=payment_method]', wc_sc_update_checkout); + } else { + jQuery(document.body).on('change', 'input[name=payment_method]', wc_sc_update_checkout); + } + }); + jQuery(document.body).on('updated_checkout', function( e, data ){ + try { + if ( data.fragments.wc_sc_available_coupons ) { + jQuery('div#coupons_list').replaceWith( data.fragments.wc_sc_available_coupons ); + jQuery( document.body ).on('click', '.apply_coupons_credits', wc_sc_apply_coupon_js); + } + } catch(e) {} + show_hide_coupon_list(); + }); + "; + } else { + $js .= ' + show_hide_coupon_list(); + '; + } + + if ( $this->is_wc_gte_26() ) { + $js .= " + if (typeof sc_available_coupons_ajax === 'undefined') { + var sc_available_coupons_ajax = null; + } + sc_available_coupons_ajax_request = null; + jQuery(document.body).on('updated_cart_totals update_checkout', function(){ + jQuery('div#coupons_list').css('opacity', '0.5'); + if (sc_available_coupons_ajax_request != null) { + sc_available_coupons_ajax_request.abort(); + } + + sc_available_coupons_ajax_request = jQuery.ajax({ + url: '" . admin_url( 'admin-ajax.php' ) . "', + type: 'post', + dataType: 'html', + data: { + action: 'sc_get_available_coupons', + security: '" . wp_create_nonce( 'sc-get-available-coupons' ) . "' + }, + success: function( response ) { + if ( response != undefined && response != '' ) { + jQuery('div#coupons_list').replaceWith( response ); + } + show_hide_coupon_list(); + jQuery('div#coupons_list').css('opacity', '1'); + } + }); + });"; + } else { + $js .= " + jQuery('body').on( 'update_checkout', function( e ){ + var coupon_code = jQuery('.woocommerce-remove-coupon').data( 'coupon' ); + if ( coupon_code != undefined && coupon_code != '' ) { + jQuery('div[data-coupon_code=\"'+coupon_code+'\"].apply_coupons_credits').show(); + } + });"; + } + + wc_enqueue_js( $js ); + + do_action( 'wc_smart_coupons_frontend_styles_and_scripts' ); + + } + + /** + * Generate & add available coupons fragments + * + * @param array $fragments Existing fragments. + * @return array $fragments + */ + public function woocommerce_update_order_review_fragments( $fragments = array() ) { + + if ( ! empty( $_POST['post_data'] ) ) { // phpcs:ignore + wp_parse_str( $_POST['post_data'], $posted_data ); // phpcs:ignore + if ( empty( $_REQUEST['billing_email'] ) && ! empty( $posted_data['billing_email'] ) ) { // phpcs:ignore + $_REQUEST['billing_email'] = $posted_data['billing_email']; + } + } + + ob_start(); + $this->show_available_coupons_before_checkout_form(); + $fragments['wc_sc_available_coupons'] = ob_get_clean(); + + return $fragments; + } + + /** + * Get endpoint + * + * @return string The endpoint + */ + public static function get_endpoint() { + self::$endpoint = get_option( 'woocommerce_myaccount_wc_sc_dashboard_endpoint', 'wc-smart-coupons' ); + return self::$endpoint; + } + + /** + * Hooks for handle endpoint + */ + public function endpoint_hooks() { + if ( empty( self::$endpoint ) ) { + self::$endpoint = self::get_endpoint(); + } + if ( $this->is_wc_gte_34() ) { + add_filter( 'woocommerce_get_settings_advanced', array( $this, 'add_endpoint_account_settings' ) ); + } else { + add_filter( 'woocommerce_account_settings', array( $this, 'add_endpoint_account_settings' ) ); + } + } + + /** + * Add UI option for changing Smart Coupons endpoints in WC settings + * + * @param mixed $settings Existing settings. + * @return mixed $settings + */ + public function add_endpoint_account_settings( $settings ) { + + $sc_endpoint_setting = array( + 'title' => __( 'Coupons', 'woocommerce-smart-coupons' ), + 'desc' => __( 'Endpoint for the My Account → Coupons page', 'woocommerce-smart-coupons' ), + 'id' => 'woocommerce_myaccount_wc_sc_dashboard_endpoint', + 'type' => 'text', + 'default' => 'wc-smart-coupons', + 'desc_tip' => true, + ); + + $after_key = 'woocommerce_myaccount_view_order_endpoint'; + + $after_key = apply_filters( + 'wc_sc_endpoint_account_settings_after_key', + $after_key, + array( + 'settings' => $settings, + 'source' => $this, + ) + ); + + WC_Smart_Coupons::insert_setting_after( $settings, $after_key, $sc_endpoint_setting ); + + return $settings; + } + + /** + * Fetch generated coupon's details + * + * Either order_ids or user_ids required + * + * @param array|int $order_ids Order IDs. + * @param array|int $user_ids User IDs. + * @param boolean $html Whether to return only data or html code, optional, default:false. + * @param boolean $header Whether to add a header above the list of generated coupon details, optional, default:false. + * @param string $layout Possible values 'box' or 'table' layout to show generated coupons details, optional, default:box. + * + * @return array $generated_coupon_data associative array containing generated coupon's details + */ + public function get_generated_coupon_data( $order_ids = '', $user_ids = '', $html = false, $header = false, $layout = 'box' ) { + global $wpdb; + + if ( ! is_array( $order_ids ) ) { + $order_ids = ( ! empty( $order_ids ) ) ? array( $order_ids ) : array(); + } + + if ( ! is_array( $user_ids ) ) { + $user_ids = ( ! empty( $user_ids ) ) ? array( $user_ids ) : array(); + } + + $user_order_ids = array(); + + if ( ! empty( $user_ids ) ) { + + if ( $this->is_hpos() ) { + $user_order_ids_query = $wpdb->prepare( + "SELECT DISTINCT id FROM {$wpdb->prefix}wc_orders + WHERE %d + AND customer_id", + 1 + ); + } else { + $user_order_ids_query = $wpdb->prepare( + "SELECT DISTINCT post_id FROM {$wpdb->prefix}postmeta + WHERE %d + AND meta_value", + 1 + ); + } + + if ( count( $user_ids ) === 1 ) { + $user_order_ids_query .= $wpdb->prepare( ' = %d', current( $user_ids ) ); + } else { + $how_many = count( $user_ids ); + $placeholders = array_fill( 0, $how_many, '%d' ); + $user_order_ids_query .= $wpdb->prepare( ' IN ( ' . implode( ',', $placeholders ) . ' )', $user_ids ); // phpcs:ignore + } + + if ( ! $this->is_hpos() ) { + $user_order_ids_query .= $wpdb->prepare( ' AND meta_key = %s', '_customer_user' ); + } + + $unique_user_ids = array_unique( $user_ids ); + + $user_order_ids = wp_cache_get( 'wc_sc_order_ids_by_user_id_' . implode( '_', $unique_user_ids ), 'woocommerce_smart_coupons' ); + + if ( false === $user_order_ids ) { + $user_order_ids = $wpdb->get_col( $user_order_ids_query ); // phpcs:ignore + wp_cache_set( 'wc_sc_order_ids_by_user_id_' . implode( '_', $unique_user_ids ), $user_order_ids, 'woocommerce_smart_coupons' ); + $this->maybe_add_cache_key( 'wc_sc_order_ids_by_user_id_' . implode( '_', $unique_user_ids ) ); + } + } + + $new_order_ids = array_unique( array_merge( $user_order_ids, $order_ids ) ); + + $generated_coupon_data = array(); + foreach ( $new_order_ids as $id ) { + $order = function_exists( 'wc_get_order' ) ? wc_get_order( $id ) : null; + $is_callable_order_get_meta = $this->is_callable( $order, 'get_meta' ); + $data = ( true === $is_callable_order_get_meta ) ? $order->get_meta( 'sc_coupon_receiver_details' ) : get_post_meta( $id, 'sc_coupon_receiver_details', true ); + if ( empty( $data ) ) { + continue; + } + $from = $this->is_callable( $order, 'get_billing_email' ) ? $order->get_billing_email() : get_post_meta( $id, '_billing_email', true ); + if ( empty( $generated_coupon_data[ $from ] ) ) { + $generated_coupon_data[ $from ] = array(); + } + $generated_coupon_data[ $from ] = array_merge( $generated_coupon_data[ $from ], $data ); + } + + $backtrace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ); // phpcs:ignore + $backtrace_functions = wp_list_pluck( $backtrace, 'function' ); + if ( in_array( 'sc_generated_coupon_data_metabox', $backtrace_functions, true ) ) { + reset( $order_ids ); + $order_id = current( $order_ids ); + $from = $this->get_post_meta( $order_id, '_billing_email', true ); + $coupon_ids = $wpdb->get_col( // phpcs:ignore + $wpdb->prepare( + "SELECT DISTINCT p.ID + FROM {$wpdb->posts} AS p + LEFT JOIN {$wpdb->postmeta} AS pm + ON (p.ID = pm.post_id) + WHERE p.post_type = %s + AND p.post_status = %s + AND pm.meta_key = %s + AND (pm.meta_value = %s + OR pm.meta_value = %d )", + 'shop_coupon', + 'future', + 'generated_from_order_id', + $order_id, + $order_id + ) + ); + if ( ! empty( $coupon_ids ) && is_array( $coupon_ids ) ) { + foreach ( $coupon_ids as $coupon_id ) { + $coupon_receiver_details = $this->get_post_meta( $coupon_id, 'wc_sc_coupon_receiver_details', true ); + $from = ( ! empty( $coupon_receiver_details['gift_certificate_sender_email'] ) ) ? $coupon_receiver_details['gift_certificate_sender_email'] : $from; + if ( empty( $generated_coupon_data[ $from ] ) || ! is_array( $generated_coupon_data[ $from ] ) ) { + $generated_coupon_data[ $from ] = array(); + } + $generated_coupon_data[ $from ][] = array( + 'code' => ( ! empty( $coupon_receiver_details['coupon_details']['code'] ) ) ? $coupon_receiver_details['coupon_details']['code'] : '', + 'amount' => ( ! empty( $coupon_receiver_details['coupon_details']['amount'] ) ) ? $coupon_receiver_details['coupon_details']['amount'] : 0, + 'email' => ( ! empty( $coupon_receiver_details['gift_certificate_receiver_email'] ) ) ? $coupon_receiver_details['gift_certificate_receiver_email'] : '', + 'message' => ( ! empty( $coupon_receiver_details['message_from_sender'] ) ) ? $coupon_receiver_details['message_from_sender'] : '', + 'order_id' => ( ! empty( $order_id ) ) ? $order_id : 0, + ); + } + } + if ( empty( $generated_coupon_data ) ) { + $order = ( ! empty( $order_id ) ) ? wc_get_order( $order_id ) : null; + $order_actions = array(); + if ( ! class_exists( 'WC_SC_Coupon_Process' ) ) { + include_once 'class-wc-sc-coupon-process.php'; + } + $wc_sc_coupon_process = ( is_callable( 'WC_SC_Coupon_Process::get_instance' ) ) ? WC_SC_Coupon_Process::get_instance() : null; + if ( $this->is_callable( $wc_sc_coupon_process, 'order_actions' ) ) { + $order_actions = $wc_sc_coupon_process->order_actions( array(), $order ); + } + if ( ! empty( $order_actions ) ) { + $target_actions = array( 'wc_sc_regenerate_coupons', 'wc_sc_regenerate_resend_coupons' ); + $all_actions = array_keys( $order_actions ); + $action_intersect = array_intersect( $target_actions, $all_actions ); + if ( ! empty( $action_intersect ) ) { + ?> +

          + ' . esc_html_x( 'Order actions', 'Generated coupons metabox - Order edit admin page', 'woocommerce-smart-coupons' ) . '', '' . esc_html_x( 'Order actions', 'Generated coupons metabox - Order edit admin page', 'woocommerce-smart-coupons' ) . '', '' . esc_html_x( 'arrow', 'Generated coupons metabox - Order edit admin page', 'woocommerce-smart-coupons' ) . '' ); + ?> +

          +
          +
            + $label ) { + switch ( $action ) { + case 'wc_sc_regenerate_coupons': + ?> +
          • + ' . esc_html( $label ) . '' ); + ?> +
          • + +
          • + ' . esc_html( $label ) . '' ); + ?> +
          • + +
          +
          + get_generated_coupon_data_table( $generated_coupon_data ); + } else { + $this->get_generated_coupon_data_box( $generated_coupon_data ); + } + $coupon_details_html_content = ob_get_clean(); + + $found_coupon = ( 'table' === $layout ) ? ( strpos( $coupon_details_html_content, 'coupon_received_row' ) !== false ) : ( strpos( $coupon_details_html_content, ''; + + if ( $header ) { + echo '

          ' . esc_html__( 'Coupon Received', 'woocommerce-smart-coupons' ) . '

          '; + echo '

          ' . esc_html__( 'List of coupons & their details which you have received from the store. Click on the coupon to see the details.', 'woocommerce-smart-coupons' ) . '

          '; + } + + echo $coupon_details_html_content; // phpcs:ignore + + echo '
          '; + + } + + return; + + } + + return $generated_coupon_data; + } + + /** + * HTML code to display generated coupon's data in box layout + * + * @param array $generated_coupon_data Associative array containing generated coupon's details. + */ + public function get_generated_coupon_data_box( $generated_coupon_data = array() ) { + if ( empty( $generated_coupon_data ) ) { + return; + } + + $design = get_option( 'wc_sc_setting_coupon_design', 'basic' ); + $background_color = get_option( 'wc_sc_setting_coupon_background_color', '#39cccc' ); + $foreground_color = get_option( 'wc_sc_setting_coupon_foreground_color', '#30050b' ); + $third_color = get_option( 'wc_sc_setting_coupon_third_color', '#39cccc' ); + + $show_coupon_description = get_option( 'smart_coupons_show_coupon_description', 'no' ); + + $valid_designs = $this->get_valid_coupon_designs(); + + if ( ! in_array( $design, $valid_designs, true ) ) { + $design = 'basic'; + } + + $current_filter = current_filter(); + if ( 'woocommerce_email_after_order_table' === $current_filter ) { + $design = 'email-coupon'; + } + + $email = $this->get_current_user_email(); + $js = " + var switchMoreLess = function() { + var total = jQuery('details').length; + var open = jQuery('details[open]').length; + if ( open == total ) { + jQuery('a#more_less').text('" . __( 'Less details', 'woocommerce-smart-coupons' ) . "'); + } else { + jQuery('a#more_less').text('" . __( 'More details', 'woocommerce-smart-coupons' ) . "'); + } + }; + switchMoreLess(); + + jQuery('a#more_less').on('click', function(){ + var current = jQuery('details').attr('open'); + if ( current == '' || current == undefined ) { + jQuery('details').attr('open', 'open'); + jQuery('a#more_less').text('" . __( 'Less details', 'woocommerce-smart-coupons' ) . "'); + } else { + jQuery('details').removeAttr('open'); + jQuery('a#more_less').text('" . __( 'More details', 'woocommerce-smart-coupons' ) . "'); + } + }); + + jQuery('summary.generated_coupon_summary').on('mouseup', function(){ + setTimeout( switchMoreLess, 10 ); + }); + + jQuery('span.expand_collapse').show(); + + var generated_coupon_element = jQuery('#all_generated_coupon'); + var generated_coupon_container_height = generated_coupon_element.height(); + if ( generated_coupon_container_height > 400 ) { + generated_coupon_element.css('height', '400px'); + generated_coupon_element.css('overflow-y', 'scroll'); + } else { + generated_coupon_element.css('height', ''); + generated_coupon_element.css('overflow-y', ''); + } + + jQuery('#all_generated_coupon').on('click', '.coupon-container', function(){ + setTimeout(function(){ + var current_element = jQuery(this).find('details'); + var is_open = current_element.attr('open'); + if ( is_open == '' || is_open == undefined ) { + current_element.attr('open', 'open'); + } else { + current_element.removeAttr('open'); + } + }, 1); + }); + + "; + + wc_enqueue_js( $js ); + + ?> + + + + + +
          + +
          +
          + $data ) { + $order = null; + $coupon_codes = wp_list_pluck( $data, 'code' ); + $posts = $this->get_post_by_title( $coupon_codes, ARRAY_A, 'shop_coupon' ); + foreach ( $data as $coupon_data ) { + + if ( ! is_admin() && ! empty( $coupon_data['email'] ) && ! empty( $email ) && $coupon_data['email'] !== $email ) { + continue; + } + + if ( empty( $this->sc_coupon_exists( $coupon_data['code'] ) ) ) { + continue; + } + + $coupon = new WC_Coupon( $coupon_data['code'] ); + $order_id = ( ! empty( $coupon_data['order_id'] ) ) ? absint( $coupon_data['order_id'] ) : 0; + $order = ( ! is_a( $order, 'WC_Order' ) && ! empty( $order_id ) ) ? wc_get_order( $order_id ) : $order; + + if ( $this->is_wc_gte_30() ) { + if ( ! is_object( $coupon ) || ! is_callable( array( $coupon, 'get_id' ) ) ) { + continue; + } + $coupon_id = $coupon->get_id(); + if ( empty( $coupon_id ) ) { + if ( true === $is_meta_box ) { + $coupon_code = ( ! empty( $coupon_data['code'] ) ) ? $coupon_data['code'] : ''; + $sanitized_coupon_code = sanitize_title( $coupon_code ); // The generated string will be checked in an array key to locate post object. + $coupon_post_obj = ( ! empty( $posts[ $sanitized_coupon_code ] ) ) ? $posts[ $sanitized_coupon_code ] : null; + if ( ! empty( $coupon_post['ID'] ) ) { + $coupon = new WC_Coupon( $coupon_post['ID'] ); + $coupon_id = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_id' ) ) ) ? $coupon->get_id() : 0; + } else { + continue; + } + } else { + continue; + } + } + $is_free_shipping = ( $coupon->get_free_shipping() ) ? 'yes' : 'no'; + $discount_type = $coupon->get_discount_type(); + $expiry_date = $coupon->get_date_expires(); + $coupon_code = $coupon->get_code(); + } else { + $coupon_id = ( ! empty( $coupon->id ) ) ? $coupon->id : 0; + $is_free_shipping = ( ! empty( $coupon->free_shipping ) ) ? $coupon->free_shipping : ''; + $discount_type = ( ! empty( $coupon->discount_type ) ) ? $coupon->discount_type : ''; + $expiry_date = ( ! empty( $coupon->expiry_date ) ) ? $coupon->expiry_date : ''; + $coupon_code = ( ! empty( $coupon->code ) ) ? $coupon->code : ''; + } + + $coupon_amount = $this->get_amount( $coupon, true, $order ); + + if ( empty( $coupon_id ) || empty( $discount_type ) ) { + continue; + } + + $coupon_post = get_post( $coupon_id ); + + $coupon_meta = $this->get_coupon_meta_data( $coupon ); + + $coupon_type = ( ! empty( $coupon_meta['coupon_type'] ) ) ? $coupon_meta['coupon_type'] : ''; + + if ( 'yes' === $is_free_shipping ) { + if ( ! empty( $coupon_type ) ) { + $coupon_type .= __( ' & ', 'woocommerce-smart-coupons' ); + } + $coupon_type .= __( 'Free Shipping', 'woocommerce-smart-coupons' ); + } + + if ( $this->is_wc_gte_30() && $expiry_date instanceof WC_DateTime ) { + $expiry_date = ( is_callable( array( $expiry_date, 'getTimestamp' ) ) ) ? $expiry_date->getTimestamp() : null; + } elseif ( ! is_int( $expiry_date ) ) { + $expiry_date = $this->strtotime( $expiry_date ); + } + + if ( ! empty( $expiry_date ) && is_int( $expiry_date ) ) { + $expiry_time = ( $this->is_callable( $coupon, 'get_meta' ) ) ? (int) $coupon->get_meta( 'wc_sc_expiry_time' ) : (int) get_post_meta( $coupon_id, 'wc_sc_expiry_time', true ); + if ( ! empty( $expiry_time ) ) { + $expiry_date += $expiry_time; // Adding expiry time to expiry date. + } + } + + $coupon_description = ''; + if ( ! empty( $coupon_post->post_excerpt ) && 'yes' === $show_coupon_description ) { + $coupon_description = $coupon_post->post_excerpt; + } + + $is_percent = $this->is_percent_coupon( array( 'coupon_object' => $coupon ) ); + + $args = array( + 'coupon_object' => $coupon, + 'coupon_amount' => $coupon_amount, + 'amount_symbol' => ( true === $is_percent ) ? '%' : get_woocommerce_currency_symbol(), + 'discount_type' => wp_strip_all_tags( $coupon_type ), + 'coupon_description' => ( ! empty( $coupon_description ) ) ? $coupon_description : wp_strip_all_tags( $this->generate_coupon_description( array( 'coupon_object' => $coupon ) ) ), + 'coupon_code' => $coupon_code, + 'coupon_expiry' => ( ! empty( $expiry_date ) ) ? $this->get_expiration_format( $expiry_date ) : __( 'Never expires', 'woocommerce-smart-coupons' ), + 'thumbnail_src' => $this->get_coupon_design_thumbnail_src( + array( + 'design' => $design, + 'coupon_object' => $coupon, + ) + ), + 'classes' => '', + 'template_id' => $design, + 'is_percent' => $is_percent, + ); + + ?> +
          +
          + + + +
          +

          :

          +

          :

          + +

          :

          + +
          +
          +
          + +
          +
          +
          + get_current_user_email(); + ?> +
          + + + + + + + + + + + + $data ) { + $email = ( ! empty( $email ) ) ? $email : $from; + foreach ( $data as $coupon_data ) { + if ( ! is_admin() && ! empty( $coupon_data['email'] ) && $coupon_data['email'] !== $email ) { + continue; + } + echo ''; + echo ''; + echo ''; // phpcs:ignore + echo ''; + echo ''; + echo ''; + echo ''; + } + } + ?> + +
          ' . esc_html( $coupon_data['code'] ) . '' . wc_price( $coupon_data['amount'] ) . '' . esc_html( $coupon_data['email'] ) . '' . esc_html( $coupon_data['message'] ) . '' . esc_html( $from ) . '
          +
          + ID, 'billing_email', true ); + $email = ( ! empty( $billing_email ) ) ? $billing_email : $current_user->user_email; + return $email; + } + + /** + * Display generated coupons details after Order table + * + * @param WC_Order $order The order. + * @param boolean $sent_to_admin Whether sent to admin. + * @param boolean $plain_text Whether a plain text email. + */ + public function generated_coupon_details_after_order_table( $order = false, $sent_to_admin = false, $plain_text = false ) { + + if ( $this->is_wc_gte_30() ) { + $order_id = ( is_object( $order ) && is_callable( array( $order, 'get_id' ) ) ) ? $order->get_id() : 0; + $order_refunds = ( ! empty( $order ) && is_callable( array( $order, 'get_refunds' ) ) ) ? $order->get_refunds() : array(); + } else { + $order_id = ( ! empty( $order->id ) ) ? $order->id : 0; + $order_refunds = ( ! empty( $order->refunds ) ) ? $order->refunds : array(); + } + + if ( ! empty( $order_refunds ) ) { + return; + } + + if ( ! empty( $order_id ) ) { + $this->get_generated_coupon_data( $order_id, '', true, true ); + } + } + + /** + * Display generated coupons details on View Order page + * + * @param int $order_id The order id. + */ + public function generated_coupon_details_view_order( $order_id = 0 ) { + if ( ! empty( $order_id ) ) { + $this->get_generated_coupon_data( $order_id, '', true, true ); + } + } + + /** + * Metabox on Order Edit Admin page to show generated coupons during the order + */ + public function add_generated_coupon_details() { + global $post, $theorder; + + if ( is_a( $theorder, 'WC_Order' ) ) { + $post_type = 'shop_order'; + } elseif ( ! empty( $post->ID ) ) { + $post_type = ( ! empty( $post->ID ) ) ? $this->get_post_type( $post->ID ) : $this->get_post_type(); + } + + if ( empty( $post_type ) || 'shop_order' !== $post_type ) { + return; + } + + $screen = ( $this->is_hpos() ) ? wc_get_page_screen_id( 'shop-order' ) : 'shop_order'; + + add_meta_box( 'sc-generated-coupon-data', __( 'Generated coupons', 'woocommerce-smart-coupons' ), array( $this, 'sc_generated_coupon_data_metabox' ), $screen, 'normal' ); + } + + /** + * Metabox content (Generated coupon's details) + */ + public function sc_generated_coupon_data_metabox() { + global $post, $theorder; + $order_id = ( is_object( $theorder ) && is_a( $theorder, 'WC_Order' ) && $this->is_callable( $theorder, 'get_id' ) ) ? $theorder->get_id() : ( ! empty( $post->ID ) ? $post->ID : 0 ); + if ( ! empty( $order_id ) ) { + $this->get_generated_coupon_data( $order_id, '', true, false ); + } + } + + /** + * Modify available variation + * + * @param array $found_variation The found variation. + * @param WC_Product_Variable $product The variable product object. + * @param WC_Product_Variation $variation The variation object. + * @return array + */ + public function modify_available_variation( $found_variation = array(), $product = null, $variation = null ) { + if ( is_a( $product, 'WC_Product_Variable' ) ) { + if ( $this->is_wc_gte_30() ) { + $product_id = ( is_object( $product ) && is_callable( array( $product, 'get_id' ) ) ) ? $product->get_id() : 0; + } else { + $product_id = ( ! empty( $product->id ) ) ? $product->id : 0; + } + + $coupons = $this->get_coupon_titles( array( 'product_object' => $variation ) ); + + if ( ! empty( $coupons ) && $this->is_coupon_amount_pick_from_product_price( $coupons ) ) { + if ( is_a( $variation, 'WC_Product_Variation' ) ) { + $found_variation['price_including_tax'] = wc_round_discount( wc_get_price_including_tax( $variation ), 2 ); + $found_variation['price_including_tax_html'] = wc_price( $found_variation['price_including_tax'] ); + $found_variation['price_excluding_tax'] = wc_round_discount( wc_get_price_excluding_tax( $variation ), 2 ); + $found_variation['price_excluding_tax_html'] = wc_price( $found_variation['price_excluding_tax'] ); + if ( is_callable( array( $variation, 'get_regular_price' ) ) ) { + $regular_price = $variation->get_regular_price(); + $found_variation['regular_price_including_tax'] = wc_round_discount( wc_get_price_including_tax( $variation, array( 'price' => $regular_price ) ), 2 ); + $found_variation['regular_price_including_tax_html'] = wc_price( $found_variation['regular_price_including_tax'] ); + $found_variation['regular_price_excluding_tax'] = wc_round_discount( wc_get_price_excluding_tax( $variation, array( 'price' => $regular_price ) ), 2 ); + $found_variation['regular_price_excluding_tax_html'] = wc_price( $found_variation['regular_price_excluding_tax'] ); + } + } + } + } + return $found_variation; + } + + /** + * Function to check & enable store notice for coupon + */ + public function maybe_enable_store_notice_for_coupon() { + $coupon_code = get_option( 'smart_coupons_storewide_offer_coupon_code' ); + if ( ! empty( $coupon_code ) ) { + $coupon_id = wc_get_coupon_id_by_code( $coupon_code ); + $coupon = new WC_Coupon( $coupon_id ); + $coupon_status = ( $this->is_wc_greater_than( '6.1.2' ) && $this->is_callable( $coupon, 'get_status' ) ) ? $coupon->get_status() : get_post_status( $coupon_id ); + if ( 'publish' === $coupon_status && ! is_store_notice_showing() ) { + update_option( 'woocommerce_demo_store', 'yes' ); + } elseif ( 'publish' !== $coupon_status && is_store_notice_showing() ) { + update_option( 'woocommerce_demo_store', 'no' ); + } + } + } + + /** + * Check if the store notice needs any change & apply the change if required + * + * @param string $displayed_notice The notice to be displayed. + * @param string $raw_notice The raw notice. + * @return string + */ + public function maybe_change_store_notice( $displayed_notice = '', $raw_notice = '' ) { + $current_currency = get_woocommerce_currency(); + $base_currency = get_option( 'woocommerce_currency' ); + if ( $base_currency !== $current_currency ) { + $storewide_offer_coupon_code = get_option( 'smart_coupons_storewide_offer_coupon_code' ); + if ( ! empty( $storewide_offer_coupon_code ) && false !== stripos( $raw_notice, '' . $storewide_offer_coupon_code . '' ) ) { + if ( ! empty( $this->sc_coupon_exists( $storewide_offer_coupon_code ) ) ) { + $coupon = new WC_Coupon( $storewide_offer_coupon_code ); + $is_percent = $this->is_percent_coupon( array( 'coupon_object' => $coupon ) ); + if ( false === $is_percent ) { + $coupon_amount = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_amount' ) ) ) ? $coupon->get_amount( 'edit' ) : 0; + $search = get_woocommerce_currency_symbol( $base_currency ) . $coupon_amount; + $replace = get_woocommerce_currency_symbol( $current_currency ) . $this->convert_price( $coupon_amount, $current_currency, $base_currency ); + $displayed_notice = str_replace( $search, $replace, $displayed_notice ); + } + } + } + } + return $displayed_notice; + } + + } + +} + +WC_SC_Display_Coupons::get_instance(); diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-global-coupons.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-global-coupons.php new file mode 100644 index 00000000..ee7f4278 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-global-coupons.php @@ -0,0 +1,347 @@ +sc_get_option( $global_coupon_option_name ); + $current_sc_version = get_option( 'sa_sc_db_version', '' ); // code for updating the db - for autoload related fix. + + if ( false === $global_coupons ) { + $wpdb->query( $wpdb->prepare( 'SET SESSION group_concat_max_len=%d', 999999 ) ); // phpcs:ignore + $wpdb->delete( $wpdb->prefix . 'options', array( 'option_name' => $global_coupon_option_name ) ); // WPCS: cache ok, db call ok. + $wpdb->query( // phpcs:ignore + $wpdb->prepare( + "REPLACE INTO {$wpdb->prefix}options (option_name, option_value, autoload) + SELECT %s, + IFNULL(GROUP_CONCAT(p.id SEPARATOR ','), ''), + %s + FROM {$wpdb->prefix}posts AS p + JOIN {$wpdb->prefix}postmeta AS pm + ON(pm.post_id = p.ID + AND p.post_type = %s + AND p.post_status = %s + AND pm.meta_key = %s + AND pm.meta_value = %s) + ", + $global_coupon_option_name, + 'no', + 'shop_coupon', + 'publish', + 'sc_is_visible_storewide', + 'yes' + ) + ); + + if ( ! empty( $this->sc_get_option( $global_coupon_option_name ) ) ) { + $wpdb->query( // phpcs:ignore + $wpdb->prepare( + "UPDATE {$wpdb->prefix}options + SET option_value = (SELECT IFNULL(GROUP_CONCAT(DISTINCT pm.post_id SEPARATOR ','), '') + FROM {$wpdb->prefix}postmeta AS pm + WHERE ( ( pm.meta_key = %s AND CAST(pm.meta_value AS CHAR) = %s ) + OR NOT EXISTS( SELECT 1 FROM {$wpdb->prefix}postmeta AS pm1 WHERE pm1.meta_key = %s AND pm.post_id = pm1.post_id ) ) + AND FIND_IN_SET(pm.post_id, (SELECT option_value FROM (SELECT option_value FROM {$wpdb->prefix}options WHERE option_name = %s) as temp )) > 0 ) + WHERE option_name = %s", + 'customer_email', + 'a:0:{}', + 'customer_email', + $global_coupon_option_name, + $global_coupon_option_name + ) + ); + + if ( ! empty( $this->sc_get_option( $global_coupon_option_name ) ) ) { + $wpdb->query( // phpcs:ignore + $wpdb->prepare( + "UPDATE {$wpdb->prefix}options + SET option_value = (SELECT IFNULL(GROUP_CONCAT(post_id SEPARATOR ','), '') + FROM {$wpdb->prefix}postmeta + WHERE meta_key = %s + AND CAST(meta_value AS CHAR) != %s + AND FIND_IN_SET(post_id, (SELECT option_value FROM (SELECT option_value FROM {$wpdb->prefix}options WHERE option_name = %s) as temp )) > 0 ) + WHERE option_name = %s", + 'auto_generate_coupon', + 'yes', + $global_coupon_option_name, + $global_coupon_option_name + ) + ); + + if ( ! empty( $this->sc_get_option( $global_coupon_option_name ) ) ) { + $wpdb->query( // phpcs:ignore + $wpdb->prepare( + "UPDATE {$wpdb->prefix}options + SET option_value = (SELECT IFNULL(GROUP_CONCAT(post_id SEPARATOR ','), '') + FROM {$wpdb->prefix}postmeta + WHERE meta_key = %s + AND CAST(meta_value AS CHAR) != %s + AND FIND_IN_SET(post_id, (SELECT option_value FROM (SELECT option_value FROM {$wpdb->prefix}options WHERE option_name = %s) as temp )) > 0 ) + WHERE option_name = %s", + 'discount_type', + 'smart_coupon', + $global_coupon_option_name, + $global_coupon_option_name + ) + ); + + if ( ! empty( $this->sc_get_option( $global_coupon_option_name ) ) ) { + $wpdb->query( // phpcs:ignore + $wpdb->prepare( + "UPDATE {$wpdb->prefix}options + SET option_value = (SELECT IFNULL(GROUP_CONCAT(DISTINCT pm_expiry_date.post_id SEPARATOR ','), '') + FROM {$wpdb->prefix}postmeta AS pm_expiry_date + JOIN {$wpdb->prefix}postmeta AS pm_expiry_time + on ( pm_expiry_time.post_id = pm_expiry_date.post_id + AND pm_expiry_date.meta_key = %s + AND pm_expiry_time.meta_key = %s + ) + WHERE ( (pm_expiry_date.meta_value IS NULL OR pm_expiry_date.meta_value = '') + OR ( IFNULL(pm_expiry_date.meta_value, 0) + IFNULL(pm_expiry_time.meta_value, 0) ) > %d ) + AND FIND_IN_SET(pm_expiry_date.post_id, (SELECT option_value FROM (SELECT option_value FROM {$wpdb->prefix}options WHERE option_name = %s) as temp )) > 0 ) + WHERE option_name = %s", + 'date_expires', + 'wc_sc_expiry_time', + time(), + $global_coupon_option_name, + $global_coupon_option_name + ) + ); + $global_coupons = $this->sc_get_option( $global_coupon_option_name ); + } + } + } + } + } + + if ( ( empty( $current_sc_version ) || version_compare( $current_sc_version, '3.3.6', '<' ) ) && ! empty( $this->sc_get_option( $global_coupon_option_name ) ) ) { + + $wpdb->query( // phpcs:ignore + $wpdb->prepare( + "UPDATE {$wpdb->prefix}options + SET autoload = %s + WHERE option_name = %s", + 'no', + $global_coupon_option_name + ) + ); + + $current_sc_version = '3.3.6'; + + update_option( 'sa_sc_db_version', $current_sc_version, 'no' ); + } + + } + + /** + * Function to update list of global coupons + * + * @param int $post_id The post id. + * @param string $action Action. + * @param WC_Coupon $coupon The coupon object. + */ + public function sc_update_global_coupons( $post_id, $action = 'add', $coupon = null ) { + if ( empty( $post_id ) ) { + return; + } + if ( 'shop_coupon' !== $this->get_post_type( $post_id ) ) { + return; + } + + $coupon = new WC_Coupon( $post_id ); + + $coupon_status = ( $this->is_wc_greater_than( '6.1.2' ) && $this->is_callable( $coupon, 'get_status' ) ) ? $coupon->get_status() : get_post_status( $post_id ); + + if ( $this->is_callable( $coupon, 'get_meta' ) ) { + $customer_email = $coupon->get_email_restrictions(); + $sc_is_visible_storewide = $coupon->get_meta( 'sc_is_visible_storewide' ); + $auto_generate_coupon = $coupon->get_meta( 'auto_generate_coupon' ); + $discount_type = $coupon->get_discount_type(); + } else { + $coupon_meta = get_post_meta( $post_id ); + $customer_email = ( ! empty( $coupon_meta['customer_email'] ) ) ? $coupon_meta['customer_email'][0] : ''; + $sc_is_visible_storewide = ( ! empty( $coupon_meta['sc_is_visible_storewide'] ) ) ? $coupon_meta['sc_is_visible_storewide'][0] : ''; + $auto_generate_coupon = ( ! empty( $coupon_meta['auto_generate_coupon'] ) ) ? $coupon_meta['auto_generate_coupon'][0] : ''; + $discount_type = ( ! empty( $coupon_meta['discount_type'] ) ) ? $coupon_meta['discount_type'][0] : ''; + } + + $global_coupons_list = get_option( 'sc_display_global_coupons' ); + $global_coupons = ( ! empty( $global_coupons_list ) ) ? explode( ',', $global_coupons_list ) : array(); + $key = array_search( (string) $post_id, $global_coupons, true ); + + if ( ( 'publish' === $coupon_status + && ( empty( $customer_email ) || serialize( array() ) === $customer_email ) // phpcs:ignore + && ( ! empty( $sc_is_visible_storewide ) && 'yes' === $sc_is_visible_storewide ) + && ( ! empty( $auto_generate_coupon ) && 'yes' !== $auto_generate_coupon ) + && ( ! empty( $discount_type ) && 'smart_coupon' !== $discount_type ) ) + || ( 'trash' === $coupon_status && 'delete' === $action ) ) { + + if ( 'add' === $action && false === $key ) { + $global_coupons[] = $post_id; + } elseif ( 'delete' === $action && false !== $key ) { + unset( $global_coupons[ $key ] ); + } + } else { + if ( false !== $key ) { + unset( $global_coupons[ $key ] ); + } + } + + update_option( 'sc_display_global_coupons', implode( ',', array_unique( $global_coupons ) ), 'no' ); + } + + /** + * Function to update list of global coupons on trash / delete coupon + * + * @param int $post_id The post id. + */ + public function sc_delete_global_coupons( $post_id ) { + if ( empty( $post_id ) ) { + return; + } + if ( 'shop_coupon' !== $this->get_post_type( $post_id ) ) { + return; + } + + $this->sc_update_global_coupons( $post_id, 'delete' ); + } + + /** + * Function to update list of global coupons on untrash coupon + * + * @param int $post_id The post id. + */ + public function sc_untrash_global_coupons( $post_id ) { + if ( empty( $post_id ) ) { + return; + } + if ( 'shop_coupon' !== $this->get_post_type( $post_id ) ) { + return; + } + + $this->sc_update_global_coupons( $post_id ); + } + + /** + * Update global coupons data for sheduled coupons + * + * @param WP_Post $post The post object. + */ + public function future_to_publish_global_coupons( $post = null ) { + $post_id = ( ! empty( $post->ID ) ) ? $post->ID : 0; + + if ( empty( $post ) || empty( $post_id ) ) { + return; + } + if ( 'shop_coupon' !== $post->post_type ) { + return; + } + + $this->sc_update_global_coupons( $post_id ); + } + + /** + * Update global coupons on saving coupon + * + * @param int $post_id The post id. + * @param WC_Coupon $coupon The coupon object. + */ + public function update_global_coupons( $post_id = 0, $coupon = null ) { + if ( empty( $post_id ) ) { + return; + } + + if ( is_null( $coupon ) || ! is_a( $coupon, 'WC_Coupon' ) ) { + $coupon = new WC_Coupon( $post_id ); + } + + $this->sc_update_global_coupons( $post_id, 'add', $coupon ); + + } + + } + +} + +WC_SC_Global_Coupons::get_instance(); diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-order-fields.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-order-fields.php new file mode 100644 index 00000000..7fa683e2 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-order-fields.php @@ -0,0 +1,602 @@ +is_old_sc_order( $order ) ) { + $smart_coupons_contribution = ( $this->is_callable( $order, 'get_meta' ) ) ? $order->get_meta( 'smart_coupons_contribution' ) : array(); + + if ( ! empty( $smart_coupons_contribution ) ) { + $total_credit_used = array_sum( $smart_coupons_contribution ); + } + + return $total_credit_used; + } + + $coupons = $order->get_items( 'coupon' ); + + if ( ! empty( $coupons ) ) { + + foreach ( $coupons as $item_id => $item ) { + + $code = ( is_object( $item ) && is_callable( array( $item, 'get_code' ) ) ) ? $item->get_code() : $item['code']; + + if ( empty( $code ) ) { + continue; + } + + $coupon = new WC_Coupon( $code ); + if ( ! empty( $coupon ) && $coupon instanceof WC_Coupon ) { + + if ( $this->is_wc_gte_30() ) { + $coupon_discount_type = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_discount_type' ) ) ) ? $coupon->get_discount_type() : ''; + $discount_type = ( ! empty( $coupon_discount_type ) ) ? $coupon_discount_type : ''; + } else { + $discount_type = ( ! empty( $coupon->discount_type ) ) ? $coupon->discount_type : ''; + } + + if ( 'smart_coupon' !== $discount_type ) { + continue; + } + + $discount = ( is_object( $item ) && is_callable( array( $item, 'get_discount' ) ) ) ? $item->get_discount() : $item['discount_amount']; + $discount_tax = ( is_object( $item ) && is_callable( array( $item, 'get_discount_tax' ) ) ) ? $item->get_discount_tax() : $item['discount_amount_tax']; + + $total_credit_used += $discount; + + $sc_include_tax = $this->is_store_credit_include_tax(); + // Check if discount include tax. + if ( 'yes' === $sc_include_tax && ! empty( $discount_tax ) ) { + $total_credit_used += $discount_tax; + } else { + $prices_include_tax = ( 'incl' === get_option( 'woocommerce_tax_display_cart' ) ) ? true : false; + if ( true === $prices_include_tax ) { + $apply_before_tax = get_option( 'woocommerce_smart_coupon_apply_before_tax', 'no' ); + if ( 'yes' === $apply_before_tax ) { + $_sc_include_tax = get_option( 'woocommerce_smart_coupon_include_tax', 'no' ); + if ( 'no' === $_sc_include_tax ) { + $total_credit_used += $discount_tax; + } + } + } + } + } + } + } + + return $total_credit_used; + + } + + /** + * Function to show store credit used in order admin panel + * + * @param int $order_id The order id. + */ + public function admin_order_totals_add_smart_coupons_discount_details( $order_id = 0 ) { + global $store_credit_label; + + if ( empty( $order_id ) ) { + return; + } + + if ( ! $this->is_old_sc_order( $order_id ) ) { + return; + } + + $order = wc_get_order( $order_id ); + + $total_credit_used = $this->get_total_credit_used_in_order( $order ); + + if ( empty( $total_credit_used ) ) { + return; + } + + ?> + + + + + [?]: + + + is_wc_gte_30() ) { + echo wc_price( $total_credit_used, array( 'currency' => $order->get_currency() ) ); // phpcs:ignore + } else { + echo wc_price( $total_credit_used, array( 'currency' => $order->get_order_currency() ) ); // phpcs:ignore + } + ?> + + + + is_wc_gte_30() ) { + add_filter( 'woocommerce_order_get_total_discount', array( $this, 'smart_coupons_order_amount_total_discount' ), 10, 2 ); + } else { + add_filter( 'woocommerce_order_amount_total_discount', array( $this, 'smart_coupons_order_amount_total_discount' ), 10, 2 ); + } + + } + + /** + * Function to add details of discount coming from Smart Coupons + * + * @param array $total_rows All rows. + * @param WC_Order $order The order object. + * @param string $tax_display Tax to display. + * @return array $total_rows + */ + public function add_smart_coupons_discount_details( $total_rows = array(), $order = null, $tax_display = '' ) { + global $store_credit_label; + + if ( empty( $order ) ) { + return $total_rows; + } + + $total_credit_used = (float) $this->get_total_credit_used_in_order( $order ); + + $offset = array_search( 'order_total', array_keys( $total_rows ), true ); + + if ( false !== $offset && ! empty( $total_credit_used ) && ! empty( $total_rows ) ) { + $total_rows = array_merge( + array_slice( $total_rows, 0, $offset ), + array( + 'smart_coupon' => array( + /* translators: %s: singular name for store credit */ + 'label' => ! empty( $store_credit_label['singular'] ) ? sprintf( __( '%s Used:', 'woocommerce-smart-coupons' ), ucwords( $store_credit_label['singular'] ) ) : __( 'Store Credit Used:', 'woocommerce-smart-coupons' ), + 'value' => '-' . wc_price( $total_credit_used ), + ), + ), + array_slice( $total_rows, $offset, null ) + ); + + $total_discount = (float) $order->get_total_discount(); + // code to check and manipulate 'Discount' amount based on Store Credit used. + if ( $total_discount === $total_credit_used ) { + unset( $total_rows['discount'] ); + } else { + if ( $this->is_old_sc_order( $order ) ) { + $total_discount = $total_discount - $total_credit_used; + $total_rows['discount']['value'] = '-' . wc_price( $total_discount ); + } else { + if ( 'incl' === $tax_display ) { + $total_discount_tax = $order->get_discount_tax(); + $total_discount += $total_discount_tax; + } + if ( $total_discount > $total_credit_used ) { + $total_discount = $total_discount - $total_credit_used; + if ( ! array_key_exists( 'discount', $total_rows ) ) { + $total_rows['discount'] = array(); + } + if ( ! array_key_exists( 'label', $total_rows['discount'] ) ) { + $total_rows['discount']['label'] = __( 'Discount:', 'woocommerce-smart-coupons' ); + } + $total_rows['discount']['value'] = '-' . wc_price( $total_discount ); + } + } + } + } + + return $total_rows; + + } + + /** + * Function to include discounts from Smart Coupons in total discount of order + * + * @param float $total_discount Total discount. + * @param WC_Order $order The order object. + * @return float $total_discount + */ + public function smart_coupons_order_amount_total_discount( $total_discount, $order = null ) { + + if ( ! $this->is_old_sc_order( $order ) ) { + return $total_discount; + } + + // To avoid adding store credit in 'Discount' field on order admin panel. + if ( did_action( 'woocommerce_admin_order_item_headers' ) >= 1 ) { + return $total_discount; + } + + $total_credit_used = $this->get_total_credit_used_in_order( $order ); + if ( $total_credit_used > 0 ) { + $total_discount += $total_credit_used; + } + return $total_discount; + + } + + /** + * Function to add label for smart_coupons in cart total + * + * @param string $default_label Default label. + * @param WC_Coupon $coupon The coupon object. + * @return string $new_label + */ + public function cart_totals_smart_coupons_label( $default_label = '', $coupon = null ) { + global $store_credit_label; + + if ( empty( $coupon ) ) { + return $default_label; + } + + if ( $this->is_wc_gte_30() ) { + $discount_type = ( ! empty( $coupon ) && is_callable( array( $coupon, 'get_discount_type' ) ) ) ? $coupon->get_discount_type() : ''; + $coupon_code = ( ! empty( $coupon ) && is_callable( array( $coupon, 'get_code' ) ) ) ? $coupon->get_code() : ''; + } else { + $discount_type = ( ! empty( $coupon->discount_type ) ) ? $coupon->discount_type : ''; + $coupon_code = ( ! empty( $coupon->code ) ) ? $coupon->code : ''; + } + + if ( ! empty( $discount_type ) && 'smart_coupon' === $discount_type ) { + $credit_label = ! empty( $store_credit_label['singular'] ) ? ucwords( $store_credit_label['singular'] ) . ':' : __( 'Store Credit:', 'woocommerce-smart-coupons' ); + return $credit_label . ' ' . $coupon_code; + } + + return $default_label; + + } + + /** + * Modify Tax detail HTML if store credit is applied, in cart + * + * @param string $html The total html. + * @return string $html + */ + public function cart_totals_order_total_html( $html = null ) { + + if ( empty( $html ) ) { + return $html; + } + + if ( ! class_exists( 'WCS_SC_Compatibility' ) ) { + include_once 'class-wcs-compatibility.php'; + } + + $is_display_price_incl_tax = ( $this->is_wc_gte_33() ) ? WC()->cart->display_prices_including_tax() : ( 'incl' === WC()->cart->tax_display_cart ); + + if ( wc_tax_enabled() && true === $is_display_price_incl_tax ) { + + $applied_coupons = ( is_object( WC()->cart ) && is_callable( array( WC()->cart, 'get_applied_coupons' ) ) ) ? WC()->cart->get_applied_coupons() : array(); + + if ( empty( $applied_coupons ) ) { + return $html; + } + + foreach ( $applied_coupons as $code ) { + $coupon = new WC_Coupon( $code ); + if ( $this->is_wc_gte_30() ) { + $discount_type = $coupon->get_discount_type(); + } else { + $discount_type = ( ! empty( $coupon->discount_type ) ) ? $coupon->discount_type : ''; + } + if ( ! is_a( $coupon, 'WC_Coupon' ) || 'smart_coupon' !== $discount_type ) { + continue; + } + if ( WC()->cart->get_total() === 0 || WC()->cart->get_total() <= WC()->cart->get_taxes_total() ) { + $cart_contains_subscription = WCS_SC_Compatibility::is_cart_contains_subscription(); + $calculation_type = ''; + if ( $cart_contains_subscription ) { + $calculation_type = WC_Subscriptions_Cart::get_calculation_type(); + if ( 'recurring_total' !== $calculation_type ) { + return '' . WC()->cart->get_total() . ' '; + } else { + return $html; + } + } else { + return '' . WC()->cart->get_total() . ' '; + } + } + } + } + + return $html; + } + + + /** + * Modify Tax detail HTML if store credit is applied, in order + * + * @param string $html The order total html. + * @param WC_Order $order The order object (optional). + * @return string $html + */ + public function get_formatted_order_total( $html = null, $order = null ) { + + if ( empty( $html ) || empty( $order ) ) { + return $html; + } + + if ( $this->is_wc_gte_30() ) { + $tax_display = get_option( 'woocommerce_tax_display_cart' ); + } else { + $tax_display = ( ! empty( $order->tax_display_cart ) ) ? $order->tax_display_cart : ''; + } + + if ( wc_tax_enabled() && 'incl' === $tax_display ) { + + $applied_coupons = $this->get_coupon_codes( $order ); + + if ( empty( $applied_coupons ) ) { + return $html; + } + + foreach ( $applied_coupons as $code ) { + $coupon = new WC_Coupon( $code ); + if ( $this->is_wc_gte_30() ) { + $discount_type = $coupon->get_discount_type(); + } else { + $discount_type = ( ! empty( $coupon->discount_type ) ) ? $coupon->discount_type : ''; + } + if ( ! is_a( $coupon, 'WC_Coupon' ) || 'smart_coupon' !== $discount_type ) { + continue; + } + if ( $order->get_total() === 0 || $order->get_total() <= $order->get_total_tax() ) { + return wc_price( $order->get_total() ); + } + } + } + + return $html; + } + + /** + * Function to notify user about remaining balance in Store Credit in "Order Complete" email + * + * @param WC_Order $order The order object. + * @param boolean $send_to_admin Is send to admin. + * @param boolean $plain_text Is plain text email. + */ + public function show_store_credit_balance( $order = false, $send_to_admin = false, $plain_text = false ) { + global $store_credit_label; + + if ( $send_to_admin ) { + return; + } + + if ( $this->is_wc_gte_30() ) { + $order_refunds = ( ! empty( $order ) && is_callable( array( $order, 'get_refunds' ) ) ) ? $order->get_refunds() : array(); + } else { + $order_refunds = ( ! empty( $order->refunds ) ) ? $order->refunds : array(); + } + + if ( ! empty( $order_refunds ) ) { + return; + } + + $used_coupons = $this->get_coupon_codes( $order ); + if ( count( $used_coupons ) > 0 ) { + $store_credit_balance = ''; + foreach ( $used_coupons as $code ) { + if ( ! $code ) { + continue; + } + $coupon = new WC_Coupon( $code ); + if ( $this->is_wc_gte_30() ) { + $discount_type = $coupon->get_discount_type(); + $coupon_code = $coupon->get_code(); + } else { + $discount_type = ( ! empty( $coupon->discount_type ) ) ? $coupon->discount_type : ''; + $coupon_code = ( ! empty( $coupon->code ) ) ? $coupon->code : ''; + } + + $coupon_amount = $this->get_amount( $coupon, true, $order ); + + if ( 'smart_coupon' === $discount_type && $coupon_amount > 0 ) { + $store_credit_balance .= '
        • ' . $coupon_code . ' — ' . wc_price( $coupon_amount ) . '
        • '; + } + } + + if ( ! empty( $store_credit_balance ) ) { + /* translators: %s: singular name for store credit */ + $balance_left_txt = ! empty( $store_credit_label['singular'] ) ? sprintf( __( '%s Balance ', 'woocommerce-smart-coupons' ), esc_html( ucwords( $store_credit_label['singular'] ) ) ) : __( 'Store Credit / Gift Card Balance', 'woocommerce-smart-coupons' ); + echo '

          ' . esc_html( $balance_left_txt ) . ':

          '; + echo '
            ' . wp_kses_post( $store_credit_balance ) . '

          '; // phpcs:ignore + } + } + } + + /** + * Force try to find the coupon's id by code + * in some cases like when coupon is trashed + * + * @param integer $id The coupon's id. + * @param string $code The coupon code. + * @param integer $exclude_id Exclude coupon's id. + * @return integer + */ + public function get_coupon_id_from_code( $id = 0, $code = '', $exclude_id = 0 ) { + if ( empty( $id ) ) { + $backtrace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ); // phpcs:ignore + $backtrace_functions = wp_list_pluck( $backtrace, 'function' ); + if ( in_array( 'get_total_credit_used_in_order', $backtrace_functions, true ) ) { + $index = array_search( 'get_total_credit_used_in_order', $backtrace_functions, true ); + $traced = ( ! empty( $backtrace[ $index ] ) && 'WC_SC_Order_Fields' === $backtrace[ $index ]['class'] && 'get_total_credit_used_in_order' === $backtrace[ $index ]['function'] ); + if ( true === $traced ) { + global $wpdb; + $post_id = $wpdb->get_var( // phpcs:ignore + $wpdb->prepare( + " + SELECT ID + FROM $wpdb->posts + WHERE post_title = %s + AND post_type = 'shop_coupon' + ORDER BY ID DESC + ", + $code + ) + ); + if ( ! empty( $post_id ) ) { + return absint( $post_id ); + } + } + } + } + return $id; + } + + /** + * Function to get total discount applied by store credit. + * + * @param float $discount The original discount. + * @param WC_Order_Item_Coupon $order_item The coupon order item. + * @return float + */ + public function smart_coupon_get_discount( $discount = 0, $order_item = null ) { + if ( ( function_exists( 'wc_tax_enabled' ) && false === wc_tax_enabled() ) || ( get_option( 'woocommerce_calc_taxes' ) === 'no' ) ) { + return $discount; + } + $discount_tax = $this->is_callable( $order_item, 'get_discount_tax' ) ? $order_item->get_discount_tax() : 0; + if ( empty( $discount_tax ) ) { + return $discount; + } + $order_id = ( $this->is_callable( $order_item, 'get_order_id' ) ) ? $order_item->get_order_id() : 0; + if ( $this->is_old_sc_order( $order_id ) ) { + return $discount; + } + if ( is_admin() && $order_item->is_type( 'coupon' ) ) { + if ( $this->is_wc_gte_87() ) { + $coupon_data = json_decode( $order_item->get_meta( 'coupon_info' ), true ); + $discount_type = isset( $coupon_data[2] ) && ! empty( $coupon_data[2] ) ? $coupon_data[2] : ''; + } else { + $coupon_data = $order_item->get_meta( 'coupon_data' ); + $discount_type = isset( $coupon_data['discount_type'] ) && ! empty( $coupon_data['discount_type'] ) ? $coupon_data['discount_type'] : ''; + } + if ( ! empty( $discount_type ) && 'smart_coupon' === $discount_type ) { + $backtrace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ); // phpcs:ignore + if ( ! empty( $backtrace ) && is_array( $backtrace ) ) { + $args = array(); + foreach ( $backtrace as $trace ) { + if ( array_key_exists( 'args', $trace ) ) { + $args = array_merge( $args, array_values( $trace['args'] ) ); + } + } + $args = array_filter( array_unique( $args ) ); + if ( ! empty( $args ) && is_array( $args ) ) { + foreach ( $args as $path ) { + if ( stripos( $path, 'admin/meta-boxes/views/html-order-items.php' ) !== false ) { + $discount += $discount_tax; + break; + } + } + } + } + } + } + return $discount; + } + + } + +} + +WC_SC_Order_Fields::get_instance(); diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-print-coupon.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-print-coupon.php new file mode 100644 index 00000000..181eef9d --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-print-coupon.php @@ -0,0 +1,470 @@ +template_base = dirname( WC_SC_PLUGIN_FILE ) . '/templates/'; + + // Email template location. + $print_style = get_option( 'wc_sc_coupon_print_style', 'default' ); + + $this->template_html = 'print-coupons-' . $print_style . '.php'; + + add_action( 'init', array( $this, 'may_be_save_terms_page' ) ); + add_action( 'admin_notices', array( $this, 'may_be_show_terms_notice' ) ); + add_action( 'wp_ajax_wc_sc_terms_notice_action', array( $this, 'terms_notice_action' ) ); + add_action( 'wp_loaded', array( $this, 'print_coupon_from_url' ), 20 ); + add_filter( 'display_post_states', array( $this, 'display_post_states' ), 10, 2 ); + add_filter( 'pre_delete_post', array( $this, 'prevent_deletion_of_terms_page' ), 10, 3 ); + add_filter( 'pre_trash_post', array( $this, 'prevent_deletion_of_terms_page' ), 10, 2 ); + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts_and_styles' ), 99 ); + } + + /** + * Get single instance of WC_SC_Print_Coupon + * + * @return WC_SC_Print_Coupon Singleton object of WC_SC_Print_Coupon + */ + public static function get_instance() { + // Check if instance is already exists. + if ( is_null( self::$instance ) ) { + self::$instance = new self(); + } + + return self::$instance; + } + + /** + * Handle call to functions which is not available in this class + * + * @param string $function_name The function name. + * @param array $arguments Array of arguments passed while calling $function_name. + * @return result of function call + */ + public function __call( $function_name, $arguments = array() ) { + + global $woocommerce_smart_coupon; + + if ( ! is_callable( array( $woocommerce_smart_coupon, $function_name ) ) ) { + return; + } + + if ( ! empty( $arguments ) ) { + return call_user_func_array( array( $woocommerce_smart_coupon, $function_name ), $arguments ); + } else { + return call_user_func( array( $woocommerce_smart_coupon, $function_name ) ); + } + + } + + /** + * Function to create and save terms page if already not created + */ + public function may_be_save_terms_page() { + $terms_page_option = $this->get_terms_page_option(); + $terms_page_id = get_option( $terms_page_option, false ); + + // If terms page option is not created yet or may be deleted. + if ( empty( $terms_page_id ) ) { + $terms_page_id = $this->add_terms_page(); + $this->update_terms_page_option( $terms_page_id ); + } + } + + /** + * Function to add create terms page + */ + public function add_terms_page() { + + $name = _x( 'wc-sc-coupons-terms', 'Page slug', 'woocommerce-smart-coupons' ); + $title = _x( 'Smart Coupons Terms', 'Page title', 'woocommerce-smart-coupons' ); + $terms_page_id = $this->create_page( $name, $title, '', 'private' ); + + return $terms_page_id; + } + + /** + * Utility function for creating Smart Coupons' pages + * + * @param string $slug Page slug. + * @param string $page_title Page title. + * @param string $page_content Page content. + * @param string $post_status Page status. + * @param int $post_parent Page parent. + * @return int $page_id Create page id + */ + public function create_page( $slug = '', $page_title = '', $page_content = '', $post_status = 'publish', $post_parent = 0 ) { + + $page_id = 0; + if ( empty( $slug ) ) { + return $page_id; + } + + $args = array( + 'role' => 'administrator', + 'orderby' => 'ID', + 'order' => 'ASC', + 'fields' => 'ID', + ); + + $admin_user_ids = get_users( $args ); + + $page_data = array( + 'post_author' => current( $admin_user_ids ), + 'post_status' => $post_status, + 'post_type' => 'page', + 'post_name' => $slug, + 'post_title' => $page_title, + 'post_content' => $page_content, + 'post_parent' => $post_parent, + 'comment_status' => 'closed', + ); + $page_id = wp_insert_post( $page_data ); + + return $page_id; + } + + /** + * Function to get terms page id + */ + public function get_terms_page_id() { + + $terms_page_option = $this->get_terms_page_option(); + $terms_page_id = get_option( $terms_page_option, false ); + + return $terms_page_id; + } + + /** + * Function to get the option key name for terms page + */ + public function get_terms_page_option() { + + // Option key name for Smart Coupons' term page id. + $terms_page_option = 'wc_sc_terms_page_id'; + return $terms_page_option; + } + + /** + * Function to update terms' page id in the options table + * + * @param int $terms_page_id Page parent. + */ + public function update_terms_page_option( $terms_page_id = 0 ) { + + if ( ! empty( $terms_page_id ) && is_numeric( $terms_page_id ) ) { + $terms_page_option = $this->get_terms_page_option(); + update_option( $terms_page_option, $terms_page_id, 'no' ); + } + } + + /** + * Function to show notice for entering terms' page content + */ + public function may_be_show_terms_notice() { + + global $pagenow, $post; + + $is_coupon_enabled = wc_coupons_enabled(); + // Don't show message if coupons are not enabled. + if ( false === $is_coupon_enabled ) { + return; + } + + $terms_page_id = $this->get_terms_page_id(); + // Return if terms page hasn't been set. + if ( empty( $terms_page_id ) ) { + return; + } + + $valid_post_types = array( 'shop_coupon', 'shop_order', 'product' ); + $valid_pagenow = array( 'edit.php', 'post.php', 'plugins.php' ); + $is_show_terms_notice = get_option( 'wc_sc_is_show_terms_notice', false ); + $get_post_type = ( ! empty( $post->ID ) ) ? $this->get_post_type( $post->ID ) : ''; + $get_page = ( ! empty( $_GET['page'] ) ) ? wc_clean( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore + $get_tab = ( ! empty( $_GET['tab'] ) ) ? wc_clean( wp_unslash( $_GET['tab'] ) ) : ''; // phpcs:ignore + + $is_page = ( in_array( $pagenow, $valid_pagenow, true ) || in_array( $get_post_type, $valid_post_types, true ) || ( 'admin.php' === $pagenow && ( 'wc-smart-coupons' === $get_page || 'wc-smart-coupons' === $get_tab ) ) ); + + // Terms page notice. + if ( $is_page && 'no' !== $is_show_terms_notice ) { + if ( ! wp_script_is( 'jquery' ) ) { + wp_enqueue_script( 'jquery' ); + } + ?> + + +
          +
          + +
          +

          + ' . esc_html__( 'here', 'woocommerce-smart-coupons' ) . ''; ?> +

          +
          + 'no', + ); + + $option_updated = update_option( 'wc_sc_is_show_terms_notice', 'no', 'no' ); + if ( true === $option_updated ) { + $response['success'] = 'yes'; + if ( 'redirect' === $post_do ) { + $terms_page_id = $this->get_terms_page_id(); + $terms_edit_url = get_edit_post_link( $terms_page_id, 'edit' ); + if ( ! empty( $terms_edit_url ) ) { + $response['redirect_url'] = $terms_edit_url; + } + } + } + + wp_send_json( $response ); + } + + /** + * Print coupon codes along with terms' page content + */ + public function print_coupon_from_url() { + global $woocommerce_smart_coupon; + + if ( empty( $_SERVER['QUERY_STRING'] ) ) { + return; + } + + parse_str( wp_unslash( $_SERVER['QUERY_STRING'] ), $coupon_args ); // phpcs:ignore + $coupon_args = wc_clean( $coupon_args ); + + if ( ! empty( $coupon_args['print-coupons'] ) && 'yes' === $coupon_args['print-coupons'] && ! empty( $coupon_args['source'] ) && 'wc-smart-coupons' === $coupon_args['source'] && ! empty( $coupon_args['coupon-codes'] ) ) { + + $coupon_args['coupon-codes'] = urldecode( $coupon_args['coupon-codes'] ); + + $coupon_codes = explode( ',', $coupon_args['coupon-codes'] ); + + $coupon_codes = array_filter( $coupon_codes ); // Remove empty coupon codes if any. + + $coupons_data = array(); + + foreach ( $coupon_codes as $coupon_code ) { + + if ( empty( $coupon_code ) ) { + continue; + } + + $coupons_data[] = array( + 'code' => $coupon_code, + ); + } + + if ( ! empty( $coupons_data ) ) { + $terms_page_id = $this->get_terms_page_id(); + $terms_page_title = ''; + $terms_page_content = ''; + if ( ! empty( $terms_page_id ) ) { + $terms_page = get_post( $terms_page_id ); + if ( is_a( $terms_page, 'WP_Post' ) ) { + + $terms_page_title = ( ! empty( $terms_page->post_title ) ) ? $terms_page->post_title : ''; + + $terms_page_content = ( ! empty( $terms_page->post_content ) ) ? $terms_page->post_content : ''; + if ( ! empty( $terms_page_content ) ) { + $terms_page_content = apply_filters( 'the_content', $terms_page_content ); + } + } + } + $design = get_option( 'wc_sc_setting_coupon_design', 'basic' ); + $background_color = get_option( 'wc_sc_setting_coupon_background_color', '#39cccc' ); + $foreground_color = get_option( 'wc_sc_setting_coupon_foreground_color', '#30050b' ); + $third_color = get_option( 'wc_sc_setting_coupon_third_color', '#39cccc' ); + + $show_coupon_description = get_option( 'smart_coupons_show_coupon_description', 'no' ); + + $valid_designs = $this->get_valid_coupon_designs(); + + if ( ! in_array( $design, $valid_designs, true ) ) { + $design = 'basic'; + } + + $coupon_styles = $woocommerce_smart_coupon->get_coupon_styles( $design ); + + $default_path = $this->template_base; + $template_path = $woocommerce_smart_coupon->get_template_base_dir( $this->template_html ); + + wc_get_template( + $this->template_html, + array( + 'coupon_codes' => $coupons_data, + 'terms_page_title' => $terms_page_title, + 'terms_page_content' => $terms_page_content, + 'background_color' => $background_color, + 'foreground_color' => $foreground_color, + 'third_color' => $third_color, + 'coupon_styles' => $coupon_styles, + 'design' => $design, + 'show_coupon_description' => $show_coupon_description, + ), + $template_path, + $default_path + ); + } + exit; + } + + } + + /** + * Add display state for printable coupon's terms page + * + * @param array $post_states An array of post display states. + * @param WP_Post $post The current post object. + */ + public function display_post_states( $post_states, $post ) { + + $terms_page_id = $this->get_terms_page_id(); + + if ( ! empty( $post->ID ) && ! empty( $terms_page_id ) && absint( $terms_page_id ) === absint( $post->ID ) ) { + if ( isset( $post_states['private'] ) ) { + unset( $post_states['private'] ); + } + $post_states['wc_sc_coupons_terms'] = __( 'Used during coupon printing', 'woocommerce-smart-coupons' ); + } + + return $post_states; + } + + /** + * Prevent Deletion Of Terms Page + * + * @param mixed $is_delete Whether to allow deletion or not. + * @param WP_Post $post The post to delete. + * @param boolean $force_delete Whether to permanently delete or not. + * @return mixed + */ + public function prevent_deletion_of_terms_page( $is_delete = null, $post = null, $force_delete = false ) { + $terms_page_id = $this->get_terms_page_id(); + if ( ! empty( $post->ID ) && ! empty( $terms_page_id ) && absint( $terms_page_id ) === absint( $post->ID ) ) { + return false; + } + return $is_delete; + } + + /** + * Scripts & styles + */ + public function enqueue_scripts_and_styles() { + global $woocommerce_smart_coupon; + + if ( empty( $_SERVER['QUERY_STRING'] ) ) { + return; + } + + parse_str( wp_unslash( $_SERVER['QUERY_STRING'] ), $coupon_args ); // phpcs:ignore + $coupon_args = wc_clean( $coupon_args ); + + $design = get_option( 'wc_sc_setting_coupon_design', 'basic' ); + + if ( ! empty( $coupon_args['print-coupons'] ) && 'yes' === $coupon_args['print-coupons'] && ! empty( $coupon_args['source'] ) && 'wc-smart-coupons' === $coupon_args['source'] && ! empty( $coupon_args['coupon-codes'] ) ) { + if ( 'custom-design' !== $design ) { + if ( ! wp_style_is( 'smart-coupon-designs' ) ) { + wp_enqueue_style( 'smart-coupon-designs' ); + } + } + } + } + + } + +} + +WC_SC_Print_Coupon::get_instance(); diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-privacy.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-privacy.php new file mode 100644 index 00000000..dcd8a5dc --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-privacy.php @@ -0,0 +1,835 @@ +plugin_data = WC_Smart_Coupons::get_smart_coupons_plugin_data(); + + parent::__construct( $this->plugin_data['Name'] ); + + /* translators: Plugin's name */ + $this->add_exporter( WC_SC_PLUGIN_DIRNAME . '-coupon-data-exporter', sprintf( __( '%s - Coupon Personal Data Exporter', 'woocommerce-smart-coupons' ), $this->plugin_data['Name'] ), array( $this, 'wc_sc_coupon_data_exporter' ) ); + /* translators: Plugin's name */ + $this->add_eraser( WC_SC_PLUGIN_DIRNAME . '-coupon-data-eraser', sprintf( __( '%s - Coupon Personal Data Eraser', 'woocommerce-smart-coupons' ), $this->plugin_data['Name'] ), array( $this, 'wc_sc_coupon_data_eraser' ) ); + + /* translators: Plugin's name */ + $this->add_exporter( WC_SC_PLUGIN_DIRNAME . '-order-data-exporter', sprintf( __( '%s - Order Personal Data Exporter', 'woocommerce-smart-coupons' ), $this->plugin_data['Name'] ), array( $this, 'wc_sc_order_data_exporter' ) ); + /* translators: Plugin's name */ + $this->add_eraser( WC_SC_PLUGIN_DIRNAME . '-order-data-eraser', sprintf( __( '%s - Order Personal Data Eraser', 'woocommerce-smart-coupons' ), $this->plugin_data['Name'] ), array( $this, 'wc_sc_order_data_eraser' ) ); + + /* translators: Plugin's name */ + $this->add_exporter( WC_SC_PLUGIN_DIRNAME . '-user-data-exporter', sprintf( __( '%s - User Personal Data Exporter', 'woocommerce-smart-coupons' ), $this->plugin_data['Name'] ), array( $this, 'wc_sc_user_data_exporter' ) ); + /* translators: Plugin's name */ + $this->add_eraser( WC_SC_PLUGIN_DIRNAME . '-user-data-eraser', sprintf( __( '%s - User Personal Data Eraser', 'woocommerce-smart-coupons' ), $this->plugin_data['Name'] ), array( $this, 'wc_sc_user_data_eraser' ) ); + + add_action( 'woocommerce_privacy_before_remove_order_personal_data', array( $this, 'remove_order_personal_data' ) ); + + add_filter( 'woocommerce_get_settings_account', array( $this, 'account_settings' ) ); + } + + /** + * Get single instance of WC_SC_Privacy + * + * @return WC_SC_Privacy Singleton object of WC_SC_Privacy + */ + public static function get_instance() { + // Check if instance is already exists. + if ( is_null( self::$instance ) ) { + self::$instance = new self(); + } + + return self::$instance; + } + + /** + * Handle call to functions which is not available in this class + * + * @param string $function_name The function name. + * @param array $arguments Array of arguments passed while calling $function_name. + * @return result of function call + */ + public function __call( $function_name, $arguments = array() ) { + + global $woocommerce_smart_coupon; + + if ( ! is_callable( array( $woocommerce_smart_coupon, $function_name ) ) ) { + return; + } + + if ( ! empty( $arguments ) ) { + return call_user_func_array( array( $woocommerce_smart_coupon, $function_name ), $arguments ); + } else { + return call_user_func( array( $woocommerce_smart_coupon, $function_name ) ); + } + + } + + /** + * Gets the message of the privacy to display. + */ + public function get_privacy_message() { + + $content = '

          ' . esc_html__( 'Store Credit/Gift Certificate', 'woocommerce-smart-coupons' ) . '

          + ' . esc_html__( 'What we access?', 'woocommerce-smart-coupons' ) . ' +
            +
          • ' . esc_html__( 'If you are logged in: We access your billing email address saved in your account & billing email address entered during purchase', 'woocommerce-smart-coupons' ) . '
          • +
          • ' . esc_html__( 'If you are a visitor: We access your billing email address entered during purchase', 'woocommerce-smart-coupons' ) . '
          • +
          + ' . esc_html__( 'What we store & why?', 'woocommerce-smart-coupons' ) . ' +
            +
          • ' . esc_html__( 'Coupon code generated for you', 'woocommerce-smart-coupons' ) . '
          • +
          • ' . esc_html__( 'Coupon code passed via URL', 'woocommerce-smart-coupons' ) . '
          • +
          • ' . esc_html__( 'Coupon amount, email & message entered for gift card receiver', 'woocommerce-smart-coupons' ) . '
          • +
          +

          ' . esc_html__( 'We store these data so that we can process it for you whenever required.', 'woocommerce-smart-coupons' ) . '

          '; + + return $content; + + } + + /** + * Returns Smart Coupons data based on email. + * + * @param string $email_address The email address. + * @param int $page Pagination. + * + * @return array + */ + protected function get_wc_sc_data( $email_address, $page ) { + + global $wpdb; + + $wpdb->query( $wpdb->prepare( 'SET SESSION group_concat_max_len=%d', 999999 ) ); // phpcs:ignore + + $results = wp_cache_get( 'wc_sc_coupon_data_' . sanitize_key( $email_address ), 'woocommerce_smart_coupons' ); + + if ( false === $results ) { + $results = $wpdb->get_results( // phpcs:ignore + $wpdb->prepare( + "SELECT p.ID, + p.post_title, + p.post_date, + GROUP_CONCAT( pm.meta_key ORDER BY pm.meta_id SEPARATOR '###' ) AS meta_keys, + GROUP_CONCAT( pm.meta_value ORDER BY pm.meta_id SEPARATOR '###' ) AS meta_values + FROM $wpdb->posts AS p + LEFT JOIN $wpdb->postmeta AS pm + ON ( p.ID = pm.post_id AND p.post_type = %s AND pm.meta_key IN ( %s, %s, %s ) ) + WHERE pm.meta_value = %s + OR pm.meta_value LIKE %s + OR pm.meta_value <> '' + GROUP BY p.ID + ORDER BY p.ID", + 'shop_coupon', + 'discount_type', + 'customer_email', + 'generated_from_order_id', + 'smart_coupon', + '%' . $wpdb->esc_like( '"' . $email_address . '"' ) . '%' + ), + ARRAY_A + ); + wp_cache_set( 'wc_sc_coupon_data_' . sanitize_key( $email_address ), $results, 'woocommerce_smart_coupons' ); + $this->maybe_add_cache_key( 'wc_sc_coupon_data_' . sanitize_key( $email_address ) ); + } + + $coupon_data = array(); + + if ( ! empty( $results ) ) { + foreach ( $results as $result ) { + + $meta_keys = ( ! empty( $result['meta_keys'] ) ) ? explode( '###', $result['meta_keys'] ) : array(); + $meta_values = ( ! empty( $result['meta_values'] ) ) ? explode( '###', $result['meta_values'] ) : array(); + + if ( count( $meta_keys ) === count( $meta_values ) ) { + $meta_values = array_map( 'maybe_unserialize', $meta_values ); + $meta = array_combine( $meta_keys, $meta_values ); + if ( empty( $meta['discount_type'] ) || 'smart_coupon' !== $meta['discount_type'] ) { + continue; + } + unset( $meta['discount_type'] ); + if ( empty( $meta['customer_email'] ) ) { + continue; + } + $customer_emails = array_unique( $meta['customer_email'] ); + $common_email = array_intersect( array( $email_address ), $customer_emails ); + if ( empty( $common_email ) ) { + continue; + } + $meta['customer_email'] = current( $common_email ); + } else { + continue; + } + + if ( empty( $coupon_data[ $result['ID'] ] ) || ! is_array( $coupon_data[ $result['ID'] ] ) ) { + $coupon_data[ $result['ID'] ] = array(); + } + + $coupon_data[ $result['ID'] ]['coupon_id'] = $result['ID']; + $coupon_data[ $result['ID'] ]['coupon_code'] = $result['post_title']; + $coupon_data[ $result['ID'] ]['created_date'] = $result['post_date']; + + if ( ! empty( $meta ) ) { + foreach ( $meta as $key => $value ) { + $coupon_data[ $result['ID'] ][ $key ] = $value; + } + } + } + } + + return $coupon_data; + } + + /** + * Handle exporting data for Smart Coupons' Coupon data. + * + * @param string $email_address E-mail address to export. + * @param int $page Pagination of data. + * + * @return array + */ + public function wc_sc_coupon_data_exporter( $email_address, $page = 0 ) { + $done = false; + $data_to_export = array(); + + $coupon_data = $this->get_wc_sc_data( $email_address, (int) $page ); + + if ( 0 < count( $coupon_data ) ) { + $data = array(); + $index = 0; + foreach ( $coupon_data as $coupon_id => $coupon ) { + $data[] = array( + 'name' => $coupon['coupon_code'], + 'value' => $coupon['customer_email'], + ); + } + $data_to_export[] = array( + 'group_id' => 'wc_smart_coupons_coupon_data', + 'group_label' => __( 'Store Credit/Gift Certificate - Coupon Data', 'woocommerce-smart-coupons' ), + 'item_id' => 'wc-smart-coupons-coupon-data-' . sanitize_title( $email_address ), + 'data' => $data, + ); + + $done = 10 > count( $coupon_data ); + } else { + $done = true; + } + + return array( + 'data' => $data_to_export, + 'done' => $done, + ); + } + + /** + * Finds and erases Smart Coupons by email address. + * + * @param string $email_address The user email address. + * @param int $page Pagination. + * @return array An array of personal data in name value pairs + */ + public function wc_sc_coupon_data_eraser( $email_address, $page ) { + $coupon_data = $this->get_wc_sc_data( $email_address, (int) $page ); + + $done = false; + $items_removed = false; + $items_retained = false; + $messages = array(); + + foreach ( $coupon_data as $coupon ) { + list( $removed, $retained, $msgs ) = $this->maybe_handle_coupon_data( $coupon ); + $items_removed |= $removed; + $items_retained |= $retained; + $messages = array_merge( $messages, $msgs ); + } + + // Tell core if we have more coupons to work on still. + $done = count( $coupon_data ) < 10; + + return array( + 'items_removed' => $items_removed, + 'items_retained' => $items_retained, + 'messages' => $messages, + 'done' => $done, + ); + } + + /** + * Handle eraser of Coupon data + * + * @param array $coupon The coupon data. + * @return array + */ + protected function maybe_handle_coupon_data( $coupon ) { + if ( empty( $coupon ) || ! $this->is_retention_expired( $coupon['created_date'] ) ) { + return array( false, false, array() ); + } + + if ( $this->is_wc_gte_30() ) { + $_coupon = ( ! empty( $coupon['coupon_id'] ) ) ? new WC_Coupon( $coupon['coupon_id'] ) : null; + if ( $this->is_callable( $_coupon, 'delete_meta_data' ) && $this->is_callable( $_coupon, 'save' ) && $this->is_callable( $_coupon, 'delete' ) ) { + if ( $this->is_callable( $_coupon, 'set_email_restrictions' ) ) { + $_coupon->set_email_restrictions( array() ); + } + $_coupon->delete_meta_data( 'customer_email' ); + $_coupon->delete_meta_data( 'generated_from_order_id' ); + $_coupon->save(); + $_coupon->delete( true ); + } + } else { + delete_post_meta( $coupon['coupon_id'], 'customer_email' ); + delete_post_meta( $coupon['coupon_id'], 'generated_from_order_id' ); + wp_delete_post( $coupon['coupon_id'], true ); + } + + return array( true, false, array( '' . __( 'Store Credit/Gift Certificate', 'woocommerce-smart-coupons' ) . ' - ' . __( 'Removed Coupon Personal Data', 'woocommerce-smart-coupons' ) ) ); + } + + /** + * Returns Smart Coupons data based on email. + * + * @param string $email_address The email addres. + * @param int $page Pagination. + * + * @return array + */ + protected function get_wc_sc_user_data( $email_address, $page ) { + + $user_data = array(); + + $user = get_user_by( 'email', $email_address ); + + if ( ! empty( $user->ID ) ) { + + $sc_shortcode_generated_coupons = get_user_meta( $user->ID, '_sc_shortcode_generated_coupons', true ); + + if ( ! empty( $sc_shortcode_generated_coupons ) ) { + $user_data['shortcode'] = array(); + foreach ( $sc_shortcode_generated_coupons as $sc_shortcode_generated_coupons ) { + $user_data['shortcode'][] = implode( ', ', $sc_shortcode_generated_coupons ); + } + } + + $sc_applied_coupon_from_url = get_user_meta( $user->ID, 'sc_applied_coupon_from_url', true ); + + if ( ! empty( $sc_applied_coupon_from_url ) ) { + $user_data['url'] = implode( ', ', $sc_applied_coupon_from_url ); + } + } + + return $user_data; + } + + /** + * Handle exporting data for Smart Coupons User data. + * + * @param string $email_address E-mail address to export. + * @param int $page Pagination of data. + * + * @return array + */ + public function wc_sc_user_data_exporter( $email_address, $page = 0 ) { + $done = false; + $data_to_export = array(); + + $user_data = $this->get_wc_sc_user_data( $email_address, (int) $page ); + + if ( 0 < count( $user_data ) ) { + $shortcode = array(); + $url = array(); + $index = 0; + foreach ( $user_data as $key => $value ) { + if ( 'shortcode' === $key ) { + foreach ( $value as $val ) { + $shortcode[] = array( + 'name' => __( 'Coupon', 'woocommerce-smart-coupons' ), + 'value' => $val, + ); + } + $data_to_export[] = array( + 'group_id' => 'wc_smart_coupons_coupon_shortcode_data', + 'group_label' => __( 'Generated Coupon Data', 'woocommerce-smart-coupons' ), + 'item_id' => 'wc-smart-coupons-shorcode-data-' . sanitize_title( $email_address ), + 'data' => $shortcode, + ); + } elseif ( 'url' === $key ) { + $url[] = array( + 'name' => __( 'Coupon' ), + 'value' => $value, + ); + $data_to_export[] = array( + 'group_id' => 'wc_smart_coupons_url_data', + 'group_label' => __( 'Coupon passed in URL', 'woocommerce-smart-coupons' ), + 'item_id' => 'wc-smart-coupons-url-data-' . sanitize_title( $email_address ), + 'data' => $url, + ); + } + } + + $done = 10 > count( $user_data ); + } else { + $done = true; + } + + return array( + 'data' => $data_to_export, + 'done' => $done, + ); + } + + /** + * Finds and erases Smart Coupons by email address. + * + * @param string $email_address The user email address. + * @param int $page Pagination. + * @return array An array of personal data in name value pairs + */ + public function wc_sc_user_data_eraser( $email_address, $page ) { + + $user = get_user_by( 'email', $email_address ); + + $done = false; + $items_removed = false; + $items_retained = false; + $messages = array(); + + if ( ! empty( $user->ID ) ) { + + $meta_keys = array( '_sc_shortcode_generated_coupons', 'sc_applied_coupon_from_url' ); + + foreach ( $meta_keys as $meta_key ) { + delete_user_meta( $user->ID, $meta_key ); + $removed = true; + $retained = false; + $msgs = array( '' . __( 'Store Credit/Gift Certificate', 'woocommerce-smart-coupons' ) . ' - ' . __( 'Removed User Personal Data', 'woocommerce-smart-coupons' ) ); + $items_removed |= $removed; + $items_retained |= $retained; + $messages = array_merge( $messages, $msgs ); + } + } + + // Tell core if we have more coupons to work on still. + $done = true; + + return array( + 'items_removed' => $items_removed, + 'items_retained' => $items_retained, + 'messages' => $messages, + 'done' => $done, + ); + } + + /** + * Returns Smart Coupons data based on email. + * + * @param string $email_address The email address. + * @param int $page Pagination. + * + * @return array + */ + protected function get_wc_sc_order_data( $email_address, $page ) { + + global $wpdb; + + $user = get_user_by( 'email', $email_address ); + + $order_ids = wp_cache_get( 'wc_sc_order_ids_for_' . sanitize_key( $email_address ), 'woocommerce_smart_coupons' ); + + if ( false === $order_ids ) { + if ( $this->is_hpos() ) { + $order_ids = $wpdb->get_col( // phpcs:ignore + $wpdb->prepare( + "SELECT id + FROM {$wpdb->prefix}wc_orders + WHERE customer_id = %d", + $user->ID + ) + ); + } else { + $order_ids = $wpdb->get_col( // phpcs:ignore + $wpdb->prepare( + "SELECT pm.post_id + FROM {$wpdb->posts} AS p + LEFT JOIN {$wpdb->postmeta} AS pm + ON ( p.ID = pm.post_id AND p.post_type = %s ) + WHERE pm.meta_key = %s + AND pm.meta_value = %d", + 'shop_order', + '_customer_user', + $user->ID + ) + ); + } + wp_cache_set( 'wc_sc_order_ids_for_' . sanitize_key( $email_address ), $order_ids, 'woocommerce_smart_coupons' ); + $this->maybe_add_cache_key( 'wc_sc_order_ids_for_' . sanitize_key( $email_address ) ); + } + + if ( empty( $order_ids ) ) { + return array(); + } + + $how_many = count( $order_ids ); + $placeholders = array_fill( 0, $how_many, '%d' ); + + if ( $this->is_hpos() ) { + $query = $wpdb->prepare( + "SELECT o.id, + om.meta_value AS sc_coupon_receiver_details + FROM {$wpdb->prefix}wc_orders AS o + LEFT JOIN {$wpdb->prefix}wc_orders_meta AS om + ON ( o.id = om.id AND om.meta_key = %s )", + 'sc_coupon_receiver_details' + ); + + $query .= $wpdb->prepare( 'WHERE o.id IN (' . implode( ',', $placeholders ) . ') ', $order_ids ); // phpcs:ignore + + $query .= $wpdb->prepare( + ' AND om.meta_value <> %s + GROUP BY o.id + ORDER BY o.id', + '' + ); + } else { + $query = $wpdb->prepare( + "SELECT p.ID, + pm.meta_value AS sc_coupon_receiver_details + FROM $wpdb->posts AS p + LEFT JOIN $wpdb->postmeta AS pm + ON ( p.ID = pm.post_id AND p.post_type = %s AND pm.meta_key = %s )", + 'shop_order', + 'sc_coupon_receiver_details' + ); + + $query .= $wpdb->prepare( 'WHERE p.ID IN (' . implode( ',', $placeholders ) . ') ', $order_ids ); // phpcs:ignore + + $query .= $wpdb->prepare( + ' AND pm.meta_value <> %s + GROUP BY p.ID + ORDER BY p.ID', + '' + ); + } + + $unique_order_ids = array_unique( $order_ids ); + + $results = wp_cache_get( 'wc_sc_receiver_detail_in_orders_' . implode( '_', $unique_order_ids ), 'woocommerce_smart_coupons' ); + + if ( false === $results ) { + $results = $wpdb->get_results( $query, ARRAY_A ); // phpcs:ignore + wp_cache_set( 'wc_sc_receiver_detail_in_orders_' . implode( '_', $unique_order_ids ), $results, 'woocommerce_smart_coupons' ); + $this->maybe_add_cache_key( 'wc_sc_receiver_detail_in_orders_' . implode( '_', $unique_order_ids ) ); + } + + $order_data = array(); + + if ( ! empty( $results ) ) { + foreach ( $results as $result ) { + $order_data[ $result['ID'] ] = maybe_unserialize( $result['sc_coupon_receiver_details'] ); + } + } + + return $order_data; + } + + /** + * Handle exporting data for Smart Coupons User data. + * + * @param string $email_address E-mail address to export. + * @param int $page Pagination of data. + * + * @return array + */ + public function wc_sc_order_data_exporter( $email_address, $page = 0 ) { + $done = false; + $data_to_export = array(); + + $order_data = $this->get_wc_sc_order_data( $email_address, (int) $page ); + + if ( 0 < count( $order_data ) ) { + $index = 0; + foreach ( $order_data as $key => $value ) { + foreach ( $value as $val ) { + $index++; + $data = array(); + foreach ( $val as $k => $v ) { + if ( $val['email'] !== $email_address && 'code' === $k ) { + continue; + } + switch ( $k ) { + case 'code': + $name = __( 'Coupon Code', 'woocommerce-smart-coupons' ); + break; + case 'amount': + $name = __( 'Coupon Amount', 'woocommerce-smart-coupons' ); + break; + case 'email': + $name = __( 'Coupon For', 'woocommerce-smart-coupons' ); + break; + case 'message': + $name = __( 'Message', 'woocommerce-smart-coupons' ); + break; + } + $data[] = array( + 'name' => $name, + 'value' => $v, + ); + } + $data_to_export[] = array( + 'group_id' => 'wc_smart_coupons_order_data_' . $index, + 'group_label' => __( 'Store Credit/Gift Certificate - Order Data', 'woocommerce-smart-coupons' ), + 'item_id' => 'wc-smart-coupons-order-data-' . $index, + 'data' => $data, + ); + } + } + + $done = 10 > count( $order_data ); + } else { + $done = true; + } + + return array( + 'data' => $data_to_export, + 'done' => $done, + ); + } + + /** + * Finds and erases Smart Coupons by email address. + * + * @param string $email_address The user email address. + * @param int $page Pagination. + * @return array An array of personal data in name value pairs + */ + public function wc_sc_order_data_eraser( $email_address, $page ) { + + global $wpdb; + + $user = get_user_by( 'email', $email_address ); + + $orders = wp_cache_get( 'wc_sc_order_by_email_for_' . $user->ID, 'woocommerce_smart_coupons' ); + + if ( false === $orders ) { + if ( $this->is_hpos() ) { + $orders = $wpdb->get_results( // phpcs:ignore + $wpdb->prepare( + "SELECT date_created_gmt AS created_date, + id + FROM {$wpdb->prefix}wc_orders + WHERE customer_id = %d", + $user->ID + ), + ARRAY_A + ); + } else { + $orders = $wpdb->get_results( // phpcs:ignore + $wpdb->prepare( + "SELECT p.post_date AS created_date, + pm.post_id + FROM {$wpdb->posts} AS p + LEFT JOIN {$wpdb->postmeta} AS pm + ON ( p.ID = pm.post_id AND p.post_type = %s ) + WHERE pm.meta_key = %s + AND pm.meta_value = %d", + 'shop_order', + '_customer_user', + $user->ID + ), + ARRAY_A + ); + } + wp_cache_set( 'wc_sc_order_by_email_for_' . $user->ID, $orders, 'woocommerce_smart_coupons' ); + $this->maybe_add_cache_key( 'wc_sc_order_by_email_for_' . $user->ID ); + } + + $done = false; + $items_removed = false; + $items_retained = false; + $messages = array(); + + if ( ! empty( $orders ) ) { + foreach ( $orders as $order ) { + list( $removed, $retained, $msgs ) = $this->maybe_handle_order_data( $order ); + $items_removed |= $removed; + $items_retained |= $retained; + $messages = array_merge( $messages, $msgs ); + } + } + + // Tell core if we have more coupons to work on still. + $done = count( $orders ) < 10; + + return array( + 'items_removed' => $items_removed, + 'items_retained' => $items_retained, + 'messages' => $messages, + 'done' => $done, + ); + } + + /** + * Handle eraser of Coupon data + * + * @param array $order The order data. + * @return array + */ + protected function maybe_handle_order_data( $order ) { + if ( empty( $order ) || ! $this->is_retention_expired( $order['created_date'] ) ) { + return array( false, false, array() ); + } + + $order = ( ! empty( $order['post_id'] ) && function_exists( 'wc_get_order' ) ) ? wc_get_order( $order['post_id'] ) : null; + if ( $this->is_callable( $order, 'delete_meta_data' ) && $this->is_callable( $order, 'save' ) ) { + $order->delete_meta_data( 'sc_coupon_receiver_details' ); + $order->delete_meta_data( 'gift_receiver_email' ); + $order->delete_meta_data( 'gift_receiver_message' ); + $order->delete_meta_data( 'gift_sending_timestamp' ); + $order->save(); + } else { + delete_post_meta( $order['post_id'], 'sc_coupon_receiver_details' ); + delete_post_meta( $order['post_id'], 'gift_receiver_email' ); + delete_post_meta( $order['post_id'], 'gift_receiver_message' ); + delete_post_meta( $order['post_id'], 'gift_sending_timestamp' ); + } + + return array( true, false, array( '' . __( 'Store Credit/Gift Certificate', 'woocommerce-smart-coupons' ) . ' - ' . __( 'Removed Order Personal Data', 'woocommerce-smart-coupons' ) ) ); + } + + /** + * Remove Smart Coupons order personal data + * + * @param WC_Order $order The order object. + */ + public function remove_order_personal_data( $order ) { + $created_date = $order->get_date_created(); + $args = array( + 'post_id' => $order->get_id(), + 'created_date' => $created_date, + ); + $result = $this->maybe_handle_order_data( $args ); + } + + /** + * Checks if create date is passed retention duration. + * + * @param string $created_date The date. + */ + public function is_retention_expired( $created_date ) { + $retention = wc_parse_relative_date_option( get_option( 'woocommerce_smart_coupons_retention' ) ); + $is_expired = false; + $time_span = time() - $this->strtotime( $created_date ); + + if ( empty( $retention ) || empty( $created_date ) || ! isset( $retention['number'] ) || ! isset( $retention['unit'] ) ) { + return false; + } + + if ( empty( $retention['number'] ) || ! is_scalar( $retention['number'] ) ) { + return false; + } + + if ( ! is_int( $retention['number'] ) ) { + $retention['number'] = (int) $retention['number']; + } + + switch ( $retention['unit'] ) { + case 'days': + $retention = $retention['number'] * DAY_IN_SECONDS; + + if ( $time_span > $retention ) { + $is_expired = true; + } + break; + case 'weeks': + $retention = $retention['number'] * WEEK_IN_SECONDS; + + if ( $time_span > $retention ) { + $is_expired = true; + } + break; + case 'months': + $retention = $retention['number'] * MONTH_IN_SECONDS; + + if ( $time_span > $retention ) { + $is_expired = true; + } + break; + case 'years': + $retention = $retention['number'] * YEAR_IN_SECONDS; + + if ( $time_span > $retention ) { + $is_expired = true; + } + break; + } + + return $is_expired; + } + + /** + * Add retention settings to account tab. + * + * @param array $settings Settings. + * @return array $settings Updated + */ + public function account_settings( $settings ) { + $insert_setting = array( + array( + 'title' => __( 'Retain Store Credit/Gift Certificate', 'woocommerce-smart-coupons' ), + 'desc_tip' => __( 'Store Credit/Gift Certificate that are stored for customers via coupons. If erased, the customer will not be able to use the coupons.', 'woocommerce-smart-coupons' ), + 'id' => 'woocommerce_smart_coupons_retention', + 'type' => 'relative_date_selector', + 'placeholder' => __( 'N/A', 'woocommerce-smart-coupons' ), + 'default' => '', + 'autoload' => false, + ), + ); + + array_splice( $settings, ( count( $settings ) - 1 ), 0, $insert_setting ); + + return $settings; + } + + } + +} + +WC_SC_Privacy::get_instance(); diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-product-columns.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-product-columns.php new file mode 100644 index 00000000..d323d881 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-product-columns.php @@ -0,0 +1,258 @@ +list_table_type . '_posts_columns', array( $this, 'define_columns' ), 11 ); + add_action( 'manage_' . $this->list_table_type . '_posts_custom_column', array( $this, 'render_columns' ), 10, 2 ); + } + + /** + * Get single instance of WC_SC_Product_Columns + * + * @return WC_SC_Product_Columns Singleton object of WC_SC_Product_Columns + */ + public static function get_instance() { + // Check if instance is already exists. + if ( is_null( self::$instance ) ) { + self::$instance = new self(); + } + + return self::$instance; + } + + /** + * Handle call to functions which is not available in this class + * + * @param string $function_name The function name. + * @param array $arguments Array of arguments passed while calling $function_name. + * @return result of function call + */ + public function __call( $function_name, $arguments = array() ) { + + global $woocommerce_smart_coupon; + + if ( ! is_callable( array( $woocommerce_smart_coupon, $function_name ) ) ) { + return; + } + + if ( ! empty( $arguments ) ) { + return call_user_func_array( array( $woocommerce_smart_coupon, $function_name ), $arguments ); + } else { + return call_user_func( array( $woocommerce_smart_coupon, $function_name ) ); + } + + } + + /** + * Define which columns to show on this screen. + * + * @param array $columns Existing columns. + * @return array Updated columns list. + */ + public function define_columns( $columns = array() ) { + + if ( ! is_array( $columns ) || empty( $columns ) ) { + $columns = array(); + } + + $columns['wc_sc_linked_coupons'] = _x( 'Linked coupons', 'Title for coupon column on the products page', 'woocommerce-smart-coupons' ); + + return $columns; + } + + /** + * Pre-fetch any data for the row each column has access to it. + * + * @param int $post_id Post ID being shown. + */ + protected function prepare_row_data( $post_id = 0 ) { + + if ( empty( $post_id ) ) { + return; + } + + $product_id = 0; + if ( ! empty( $this->object ) ) { + $product = $this->object; + if ( $this->is_wc_gte_30() ) { + $product_id = ( is_object( $product ) && is_callable( array( $product, 'get_id' ) ) ) ? $product->get_id() : 0; + } else { + $product_id = ( ! empty( $product->id ) ) ? $product->id : 0; + } + } + + if ( empty( $this->object ) || $product_id !== $post_id ) { + $this->object = wc_get_product( $post_id ); + } + + } + + /** + * Render individual columns. + * + * @param string $column Column ID to render. + * @param integer $post_id Post ID being shown. + */ + public function render_columns( $column = '', $post_id = 0 ) { + + if ( empty( $post_id ) ) { + return; + } + + if ( empty( $column ) ) { + return; + } + + $this->prepare_row_data( $post_id ); + + switch ( $column ) { + case 'wc_sc_linked_coupons': + $this->render_view_product_coupon_column( $post_id, $this->object ); + break; + } + + } + + /** + * Render linked coupons column on product screen. + * + * @param integer $product_id The Product ID. + * @param WC_Product $product The Product object. + */ + public function render_view_product_coupon_column( $product_id = 0, $product = null ) { + + if ( empty( $product_id ) ) { + return; + } + + $max_coupons_limit = apply_filters( + 'wc_sc_maximum_linked_coupons_limit', + $this->sc_get_option( 'wc_sc_maximum_linked_coupons_limit', 5 ), + array( + 'source' => $this, + 'product_id' => $product_id, + 'product_obj' => $product, + ) + ); + + // Fetch linked coupons from simple & variable products (except variations). + $linked_coupons = ( $this->is_callable( $product, 'get_meta' ) ) ? $product->get_meta( '_coupon_title' ) : $this->get_post_meta( $product_id, '_coupon_title', true ); + + if ( empty( $linked_coupons ) || ! is_array( $linked_coupons ) ) { + $linked_coupons = array(); + } else { + $linked_coupons = array_filter( array_unique( $linked_coupons ) ); + } + + $linked_coupons_count = count( $linked_coupons ); + + if ( $linked_coupons_count > $max_coupons_limit ) { + $linked_coupons = array_slice( $linked_coupons, 0, $max_coupons_limit ); + } elseif ( $linked_coupons_count < $max_coupons_limit ) { // Try to find more linked coupons if number of found coupons are not matching $max_coupons_limit. + // Try to find linked coupons from the variations. + if ( $product->is_type( 'variable' ) && $product->has_child() ) { + $children = $product->get_children(); + foreach ( $children as $variation_id ) { + $variation = wc_get_product( $variation_id ); + $variation_linked_coupons = ( $this->is_callable( $variation, 'get_meta' ) ) ? $variation->get_meta( '_coupon_title' ) : $this->get_post_meta( $variation_id, '_coupon_title', true ); + if ( empty( $variation_linked_coupons ) || ! is_array( $variation_linked_coupons ) ) { + continue; + } + $linked_coupons = array_merge( $linked_coupons, $variation_linked_coupons ); + $linked_coupons = array_filter( array_unique( $linked_coupons ) ); + $linked_coupons_count = count( $linked_coupons ); + if ( $linked_coupons_count === $max_coupons_limit ) { + break; + } elseif ( $linked_coupons_count > $max_coupons_limit ) { + $linked_coupons = array_slice( $linked_coupons, 0, $max_coupons_limit ); + break; + } + } + } + } + + if ( empty( $linked_coupons ) || ! is_array( $linked_coupons ) ) { + echo esc_html( '–' ); + return; + } + + $linked_coupons = array_values( $linked_coupons ); + + $coupon_html = array(); + foreach ( $linked_coupons as $index => $coupon_code ) { + $coupon_id = wc_get_coupon_id_by_code( $coupon_code ); + $coupon_edit_url = add_query_arg( + array( + 'post' => $coupon_id, + 'action' => 'edit', + ), + admin_url( 'post.php' ) + ); + $coupon_html[] = '' . esc_html( $coupon_code ) . ''; + } + + $linked_coupons_html = apply_filters( + 'wc_sc_product_column_linked_coupons_html', + implode( ' , ', $coupon_html ), + array( + 'source' => $this, + 'product_id' => $product_id, + 'product_obj' => $product, + 'maximum_linked_coupons_limit' => $max_coupons_limit, + 'linked_coupons' => $linked_coupons, + ) + ); + + echo wp_kses_post( $linked_coupons_html ); + + } + + } + +} + +WC_SC_Product_Columns::get_instance(); diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-product-fields.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-product-fields.php new file mode 100644 index 00000000..fff2f38f --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-product-fields.php @@ -0,0 +1,524 @@ +ID ); + + $product = ( ! empty( $post->ID ) && function_exists( 'wc_get_product' ) ) ? wc_get_product( $post->ID ) : null; + $is_callable_product_get_meta = $this->is_callable( $product, 'get_meta' ); + + $is_send_coupons_on_renewals = ( true === $is_callable_product_get_meta ) ? $product->get_meta( 'send_coupons_on_renewals' ) : get_post_meta( $post->ID, 'send_coupons_on_renewals', true ); + + echo '
          '; + + $all_discount_types = wc_get_coupon_types(); + + ?> +

          + + + +

          + + product_options_admin_js(); ?> + '; + + } + + /** + * Coupon fields for variation + * + * @param int $loop Position in the loop. + * @param array $variation_data Variation data. + * @param WP_Post $variation Post data. + */ + public function woocommerce_product_options_coupons_variable( $loop = 0, $variation_data = array(), $variation = null ) { + + $variation_id = $variation->ID; + + $all_discount_types = wc_get_coupon_types(); + + $product = ( ! empty( $variation_id ) && function_exists( 'wc_get_product' ) ) ? wc_get_product( $variation_id ) : null; + $is_callable_product_get_meta = $this->is_callable( $product, 'get_meta' ); + + $is_send_coupons_on_renewals = ( true === $is_callable_product_get_meta ) ? $product->get_meta( 'send_coupons_on_renewals' ) : get_post_meta( $variation_id, 'send_coupons_on_renewals', true ); + + ?> +
          +

          + + + +

          +

          + +

          + product_options_admin_js(); ?> +
          + + + is_callable( $product, 'update_meta_data' ); + + if ( ! empty( $post_coupon_title ) ) { + if ( $this->is_wc_gte_30() ) { + $coupon_titles = $post_coupon_title; + } else { + $coupon_titles = array_filter( array_map( 'trim', explode( ',', $post_coupon_title ) ) ); + } + if ( true === $is_callable_product_update_meta ) { + $product->update_meta_data( '_coupon_title', $coupon_titles ); + } else { + update_post_meta( $post_id, '_coupon_title', $coupon_titles ); + } + } else { + if ( true === $is_callable_product_update_meta ) { + $product->update_meta_data( '_coupon_title', array() ); + } else { + update_post_meta( $post_id, '_coupon_title', array() ); + } + } + + if ( isset( $_POST['send_coupons_on_renewals'][ $post_id ] ) ) { // phpcs:ignore + if ( true === $is_callable_product_update_meta ) { + $product->update_meta_data( 'send_coupons_on_renewals', wc_clean( wp_unslash( $_POST['send_coupons_on_renewals'][ $post_id ] ) ) ); // phpcs:ignore + } else { + update_post_meta( $post_id, 'send_coupons_on_renewals', wc_clean( wp_unslash( $_POST['send_coupons_on_renewals'][ $post_id ] ) ) ); // phpcs:ignore + } + } else { + if ( true === $is_callable_product_update_meta ) { + $product->update_meta_data( 'send_coupons_on_renewals', 'no' ); + } else { + update_post_meta( $post_id, 'send_coupons_on_renewals', 'no' ); + } + } + + if ( $this->is_callable( $product, 'save' ) ) { + $product->save(); + } + } + + /** + * Function for saving coupon details in product meta + * + * @param integer $variation_id Variation ID. + * @param integer $i Loop ID. + */ + public function woocommerce_process_product_meta_coupons_variable( $variation_id = 0, $i = 0 ) { + + if ( empty( $variation_id ) ) { + return; + } + + $variation_id = absint( $variation_id ); + $variation = ( ! empty( $variation_id ) ) ? wc_get_product( $variation_id ) : null; + $is_callable_variation_update_meta = $this->is_callable( $variation, 'update_meta_data' ); + + $post_coupon_title = ( ! empty( $_POST['_coupon_title'][ $variation_id ][ $i ] ) ) ? wc_clean( wp_unslash( $_POST['_coupon_title'][ $variation_id ][ $i ] ) ) : ''; // phpcs:ignore + + if ( ! empty( $post_coupon_title ) ) { + if ( $this->is_wc_gte_30() ) { + $coupon_titles = $post_coupon_title; + } else { + $coupon_titles = array_filter( array_map( 'trim', explode( ',', $post_coupon_title ) ) ); + } + if ( true === $is_callable_variation_update_meta ) { + $variation->update_meta_data( '_coupon_title', $coupon_titles ); + } else { + update_post_meta( $variation_id, '_coupon_title', $coupon_titles ); + } + } else { + if ( true === $is_callable_variation_update_meta ) { + $variation->update_meta_data( '_coupon_title', array() ); + } else { + update_post_meta( $variation_id, '_coupon_title', array() ); + } + } + + if ( isset( $_POST['send_coupons_on_renewals'][ $variation_id ][ $i ] ) ) { // phpcs:ignore + if ( true === $is_callable_variation_update_meta ) { + $variation->update_meta_data( 'send_coupons_on_renewals', wc_clean( wp_unslash( $_POST['send_coupons_on_renewals'][ $variation_id ][ $i ] ) ) ); // phpcs:ignore + } else { + update_post_meta( $variation_id, 'send_coupons_on_renewals', wc_clean( wp_unslash( $_POST['send_coupons_on_renewals'][ $variation_id ][ $i ] ) ) ); // phpcs:ignore + } + } else { + if ( true === $is_callable_variation_update_meta ) { + $variation->update_meta_data( 'send_coupons_on_renewals', 'no' ); + } else { + update_post_meta( $variation_id, 'send_coupons_on_renewals', 'no' ); + } + } + + if ( $this->is_callable( $variation, 'save' ) ) { + $variation->save(); + } + + } + + } + +} + +WC_SC_Product_Fields::get_instance(); diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-purchase-credit.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-purchase-credit.php new file mode 100644 index 00000000..0549aa7a --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-purchase-credit.php @@ -0,0 +1,1549 @@ +is_wc_gte_30() ) { + if ( ! is_object( $product ) || ! is_callable( array( $product, 'get_id' ) ) ) { + return; + } + $product_id = $product->get_id(); + if ( empty( $product_id ) ) { + return; + } + } else { + $product_id = ( ! empty( $product->id ) ) ? $product->id : 0; + } + + $coupons = $this->get_coupon_titles( array( 'product_object' => $product ) ); + + if ( ! function_exists( 'is_plugin_active' ) ) { + require_once ABSPATH . 'wp-admin/includes/plugin.php'; + } + + $product_price = $product->get_price(); + + $_nyp = ( $this->is_callable( $product, 'get_meta' ) ) ? $product->get_meta( '_nyp' ) : get_post_meta( $product_id, '_nyp', true ); + + // MADE CHANGES IN THE CONDITION TO SHOW INPUT FIELD FOR PRICE ONLY FOR COUPON AS A PRODUCT. + if ( ! empty( $coupons ) && $this->is_coupon_amount_pick_from_product_price( $coupons ) && ( ! ( ! empty( $product_price ) || ( is_plugin_active( 'woocommerce-name-your-price/woocommerce-name-your-price.php' ) && ( 'yes' === $_nyp ) ) ) ) ) { + + $js = " + const minCreditAmount = parseFloat( jQuery('input#credit_called').attr('min') ); + const maxCreditAmount = parseFloat( jQuery('input#credit_called').attr('max') ); + var validateCreditCalled = function(){ + var enteredCreditAmount = parseFloat( jQuery('input#credit_called').val() ); + if ( isNaN(enteredCreditAmount) || enteredCreditAmount < minCreditAmount || ( maxCreditAmount > 0 && enteredCreditAmount > maxCreditAmount ) ) { + var creditErrorMsg = '" . __( 'Invalid amount.', 'woocommerce-smart-coupons' ) . "'; + if ( isNaN(enteredCreditAmount) ) { + creditErrorMsg += ' " . __( 'Enter a numeric value.', 'woocommerce-smart-coupons' ) . "'; + } + if ( enteredCreditAmount < minCreditAmount ) { + creditErrorMsg += ' " . __( 'The value should not be less than', 'woocommerce-smart-coupons' ) . " ' + minCreditAmount; + } else if ( enteredCreditAmount > maxCreditAmount ) { + creditErrorMsg += ' " . __( 'The value should not be greater than', 'woocommerce-smart-coupons' ) . " ' + maxCreditAmount; + } + jQuery('#error_message').text(creditErrorMsg); + jQuery('input#credit_called').css('border-color', 'red'); + return false; + } else { + jQuery('form.cart').unbind('submit'); + jQuery('#error_message').text(''); + jQuery('input#credit_called').css('border-color', ''); + return true; + } + }; + + jQuery('input#credit_called').bind('change keyup', function(){ + validateCreditCalled(); + jQuery('input#hidden_credit').remove(); + if ( jQuery('input[name=quantity]').length ) { + jQuery('input[name=quantity]').append(''); + } else { + jQuery('input[name=\"add-to-cart\"]').after(''); + } + }); + + jQuery('button.single_add_to_cart_button').on('click', function(e) { + if ( validateCreditCalled() == false ) { + e.preventDefault(); + } + }); + + jQuery('input#credit_called').on( 'keypress', function (e) { + if (e.which == 13) { + jQuery('form.cart').find('button[name=\"add-to-cart\"]').trigger('click'); + } + }); + + // To handle, if the call for credit form is included twice. + jQuery.each( jQuery('body').find('div#call_for_credit'), function(){ + let current_element = jQuery(this); + let is_visible = current_element.is(':visible'); + if ( false === is_visible ) { + current_element.remove(); + } + }); + + "; + + // To handle, if the call for credit form is included twice. + if ( did_action( 'wc_sc_call_for_credit_script_enqueued' ) <= 0 ) { + wc_enqueue_js( $js ); + do_action( 'wc_sc_call_for_credit_script_enqueued', array( 'source' => $this ) ); + } + + $smart_coupon_store_gift_page_text = get_option( 'smart_coupon_store_gift_page_text' ); + + /* translators: %s: singular name for store credit */ + $smart_coupon_store_gift_page_text = ( ! empty( $smart_coupon_store_gift_page_text ) ) ? $smart_coupon_store_gift_page_text . ' ' : ( ! empty( $store_credit_label['singular'] ) ? sprintf( __( 'Purchase %s worth', 'woocommerce-smart-coupons' ), ucwords( $store_credit_label['singular'] ) ) : __( 'Purchase credit worth', 'woocommerce-smart-coupons' ) ) . ' '; + + $custom_classes = array( + 'container' => '', + 'row' => '', + 'label' => '', + 'input' => '', + 'error' => '', + ); + + $custom_classes = apply_filters( 'wc_sc_call_for_credit_template_custom_classes', $custom_classes ); + + $currency_symbol = get_woocommerce_currency_symbol(); + + $input = array( + 'type' => 'number', + 'autocomplete' => 'off', + 'autofocus' => 'autofocus', + 'height' => '', + 'max' => '', + 'maxlength' => '', + 'min' => '1', + 'minlength' => '', + 'name' => '', + 'pattern' => '', + 'placeholder' => '', + 'required' => 'required', + 'size' => '', + 'step' => 'any', + 'width' => '', + 'class' => 'input-text', + ); + + $input = apply_filters( 'wc_sc_call_for_credit_template_input', $input, array( 'source' => $this ) ); + + $input = array_filter( $input ); + + $input['id'] = 'credit_called'; + $input['name'] = $input['id']; + $input['value'] = ''; + + $allowed_html = wp_kses_allowed_html( 'post' ); + + $allowed_html['input'] = array( + 'aria-describedby' => true, + 'aria-details' => true, + 'aria-label' => true, + 'aria-labelledby' => true, + 'aria-hidden' => true, + ); + $input_element = ' $value ) { + $input_element .= $attribute . '="' . esc_attr( $value ) . '" '; + $allowed_html['input'][ $attribute ] = true; + } + $input_element .= ' />'; + + if ( function_exists( 'wc_get_template' ) ) { + $args = array( + 'custom_classes' => $custom_classes, + 'currency_symbol' => $currency_symbol, + 'smart_coupon_store_gift_page_text' => $smart_coupon_store_gift_page_text, + 'allowed_html' => $allowed_html, + 'input' => $input, + 'input_element' => $input_element, + ); + wc_get_template( 'call-for-credit-form.php', $args, '', plugin_dir_path( WC_SC_PLUGIN_FILE ) . 'templates/' ); + } else { + include apply_filters( 'woocommerce_call_for_credit_form_template', 'templates/call-for-credit-form.php' ); + } + } + } + + /** + * Allow overriding of Smart Coupon's template for credit of any amount + * + * @param string $template The template name. + * @return mixed $template + */ + public function woocommerce_call_for_credit_form_template_path( $template ) { + + $template_name = 'call-for-credit-form.php'; + + $template = $this->locate_template_for_smart_coupons( $template_name, $template ); + + // Return what we found. + return $template; + } + + /** + * Make product whose price is set as zero but is for purchasing credit, purchasable + * + * @param boolean $purchasable Is purchasable. + * @param WC_Product $product The product. + * @return boolean $purchasable + */ + public function make_product_purchasable( $purchasable, $product ) { + + if ( $this->is_wc_gte_30() ) { + $product_id = ( is_object( $product ) && is_callable( array( $product, 'get_id' ) ) ) ? $product->get_id() : 0; + } else { + $product_id = ( ! empty( $product->id ) ) ? $product->id : 0; + } + $coupons = $this->get_coupon_titles( array( 'product_object' => $product ) ); + + if ( ! empty( $coupons ) && $product instanceof WC_Product && $product->get_price() === '' && $this->is_coupon_amount_pick_from_product_price( $coupons ) && ! ( $product->get_price() > 0 ) ) { + return true; + } + + return $purchasable; + } + + /** + * Remove price html for product which is selling any amount of storecredit + * + * @param string $price Current price HTML. + * @param WC_Product $product The product object. + * @return string $price + */ + public function price_html_for_purchasing_credit( $price = null, $product = null ) { + + if ( $this->is_wc_gte_30() ) { + $product_id = ( is_object( $product ) && is_callable( array( $product, 'get_id' ) ) ) ? $product->get_id() : 0; + } else { + $product_id = ( ! empty( $product->id ) ) ? $product->id : 0; + } + $coupons = $this->get_coupon_titles( array( 'product_object' => $product ) ); + + $is_product = is_a( $product, 'WC_Product' ); + $is_purchasable_credit = $this->is_coupon_amount_pick_from_product_price( $coupons ); + $product_price = $product->get_price(); + + if ( ! empty( $coupons ) && true === $is_product && true === $is_purchasable_credit && ( ! ( $product_price > 0 ) || empty( $product_price ) ) ) { + return ''; + } + + return $price; + } + + /** + * Set price for store credit to be purchased before calculating total in cart + * + * @param WC_Cart $cart_object The cart object. + */ + public function override_price_before_calculate_totals( $cart_object ) { + + $credit_called = $this->get_session( 'credit_called' ); + + foreach ( $cart_object->cart_contents as $key => $value ) { + + $product = $value['data']; + $credit_amount = ( ! empty( $value['credit_amount'] ) ) ? floatval( $value['credit_amount'] ) : 0; + + if ( $this->is_wc_gte_30() ) { + $product_type = ( is_object( $product ) && is_callable( array( $product, 'get_type' ) ) ) ? $product->get_type() : ''; + $product_id = ( in_array( $product_type, array( 'variable', 'variable-subscription', 'variation', 'subscription_variation' ), true ) ) ? ( ( is_object( $product ) && is_callable( array( $product, 'get_parent_id' ) ) ) ? $product->get_parent_id() : 0 ) : ( ( is_object( $product ) && is_callable( array( $product, 'get_id' ) ) ) ? $product->get_id() : 0 ); + $product_price = ( is_object( $product ) && is_callable( array( $product, 'get_price' ) ) ) ? $product->get_price() : 0; + } else { + $product_id = ( ! empty( $product->id ) ) ? $product->id : 0; + $product_price = ( ! empty( $product->price ) ) ? $product->price : 0; + } + + $coupons = $this->get_coupon_titles( array( 'product_object' => $product ) ); + + if ( ! empty( $coupons ) && $this->is_coupon_amount_pick_from_product_price( $coupons ) && ! ( $product_price > 0 ) ) { + + $price = ( ! empty( $credit_called[ $key ] ) ) ? floatval( $credit_called[ $key ] ) : $credit_amount; + + if ( $price <= 0 ) { + WC()->cart->set_quantity( $key, 0 ); // Remove product from cart if price is not found either in session or in product. + continue; + } + + $price = $this->read_price( $price, true ); + + if ( $this->is_wc_gte_30() && is_callable( array( $cart_object->cart_contents[ $key ]['data'], 'set_price' ) ) ) { + $cart_object->cart_contents[ $key ]['data']->set_price( $price ); + } else { + $cart_object->cart_contents[ $key ]['data']->price = $price; + } + } + } + + } + + /** + * Override empty price of voucher product by 0 to avoid 'non numeric value' warning for product price being triggered on coupon validation. + * + * @param string $price product price. + * @param WC_Product $product WooCommerce product. + * @return integer $price new product price + */ + public function override_voucher_product_empty_price( $price, $product ) { + + if ( ! doing_action( 'woocommerce_single_product_summary' ) ) { + + if ( $this->is_wc_gte_30() ) { + $product_type = ( is_object( $product ) && is_callable( array( $product, 'get_type' ) ) ) ? $product->get_type() : ''; + $product_id = ( in_array( $product_type, array( 'variable', 'variable-subscription', 'variation', 'subscription_variation' ), true ) ) ? ( ( is_object( $product ) && is_callable( array( $product, 'get_parent_id' ) ) ) ? $product->get_parent_id() : 0 ) : ( ( is_object( $product ) && is_callable( array( $product, 'get_id' ) ) ) ? $product->get_id() : 0 ); + } else { + $product_id = ( ! empty( $product->id ) ) ? $product->id : 0; + } + + $coupons = $this->get_coupon_titles( array( 'product_object' => $product ) ); + + // Override product price only if product contains coupon and price is already an empty string. + if ( ! empty( $coupons ) && '' === $price ) { + $price = 0; + } + } + + return $price; + + } + + /** + * Display store credit's value as cart item's price + * + * @param string $product_price The product price HTML. + * @param array $cart_item Associative array of cart item. + * @param string $cart_item_key The cart item key. + * @return string product's price with currency symbol + */ + public function woocommerce_cart_item_price_html( $product_price, $cart_item, $cart_item_key ) { + + $gift_certificate = $this->get_session( 'credit_called' ); + + if ( ! empty( $gift_certificate ) && isset( $gift_certificate[ $cart_item_key ] ) && ! empty( $gift_certificate[ $cart_item_key ] ) ) { + $price = $gift_certificate[ $cart_item_key ]; + $price = $this->read_price( $price, true ); + // Hook for 3rd party plugin to modify value of the credit. + $price = apply_filters( + 'wc_sc_credit_called_price_cart', + $price, + array( + 'source' => $this, + 'cart_item_key' => $cart_item_key, + 'cart_item' => $cart_item, + 'credit_called' => $gift_certificate, + ) + ); + return wc_price( $price ); + } elseif ( ! empty( $cart_item['credit_amount'] ) ) { + $price = $cart_item['credit_amount']; + $price = $this->read_price( $price, true ); + // Hook for 3rd party plugin to modify value of the credit. + $price = apply_filters( + 'wc_sc_credit_called_price_cart', + $price, + array( + 'source' => $this, + 'cart_item_key' => $cart_item_key, + 'cart_item' => $cart_item, + 'credit_called' => $gift_certificate, + ) + ); + return wc_price( $price ); + } + + return $product_price; + + } + + /** + * Receiver Detail Form Styles And Scripts + */ + public function receiver_detail_form_styles_and_scripts() { + global $wp_locale; + if ( ! wp_script_is( 'jquery' ) ) { + wp_enqueue_script( 'jquery' ); + } + $deliver_coupon_option = apply_filters( + 'wc_sc_deliver_coupon', + 'now', + array( + 'source' => $this, + 'cart_contents' => ( isset( WC()->cart->cart_contents ) && is_array( WC()->cart->cart_contents ) ) ? WC()->cart->cart_contents : array(), + 'schedule_store_credit' => get_option( 'smart_coupons_schedule_store_credit' ), + ) + ); + ?> + + + + + get_coupon_receiver_details_session(); + + if ( ! is_null( $coupon_receiver_details_session ) ) { + $is_gift = ( ! empty( $coupon_receiver_details_session['is_gift'] ) ) ? wc_clean( wp_unslash( $coupon_receiver_details_session['is_gift'] ) ) : ''; + $sc_send_to = ( ! empty( $coupon_receiver_details_session['sc_send_to'] ) ) ? wc_clean( wp_unslash( $coupon_receiver_details_session['sc_send_to'] ) ) : ''; + $wc_sc_schedule_gift_sending = ( ! empty( $coupon_receiver_details_session['wc_sc_schedule_gift_sending'] ) ) ? wc_clean( wp_unslash( $coupon_receiver_details_session['wc_sc_schedule_gift_sending'] ) ) : ''; + $gift_receiver_email = ( ! empty( $coupon_receiver_details_session['gift_receiver_email'] ) ) ? wc_clean( wp_unslash( $coupon_receiver_details_session['gift_receiver_email'] ) ) : array(); + $gift_sending_date_time = ( ! empty( $coupon_receiver_details_session['gift_sending_date_time'] ) ) ? wc_clean( wp_unslash( $coupon_receiver_details_session['gift_sending_date_time'] ) ) : array(); + $gift_sending_timestamp = ( ! empty( $coupon_receiver_details_session['gift_sending_timestamp'] ) ) ? wc_clean( wp_unslash( $coupon_receiver_details_session['gift_sending_timestamp'] ) ) : array(); + $gift_receiver_message = ( ! empty( $coupon_receiver_details_session['gift_receiver_message'] ) ) ? wc_clean( wp_unslash( $coupon_receiver_details_session['gift_receiver_message'] ) ) : array(); + } else { + $is_gift = ''; + $sc_send_to = ''; + $wc_sc_schedule_gift_sending = ''; + $gift_receiver_email = array(); + $gift_sending_date_time = array(); + $gift_sending_timestamp = array(); + $gift_receiver_message = array(); + } + + $coupon_receiver_details_session = array( + 'is_gift' => $is_gift, + 'sc_send_to' => $sc_send_to, + 'wc_sc_schedule_gift_sending' => $wc_sc_schedule_gift_sending, + 'gift_receiver_email' => $gift_receiver_email, + 'gift_sending_date_time' => $gift_sending_date_time, + 'gift_sending_timestamp' => $gift_sending_timestamp, + 'gift_receiver_message' => $gift_receiver_message, + ); + + foreach ( WC()->cart->cart_contents as $product ) { + + if ( ! empty( $product['variation_id'] ) ) { + $_product = wc_get_product( $product['variation_id'] ); + } elseif ( ! empty( $product['product_id'] ) ) { + $_product = wc_get_product( $product['product_id'] ); + } else { + continue; + } + + $coupon_titles = $this->get_coupon_titles( array( 'product_object' => $_product ) ); + + $price = $_product->get_price(); + + if ( $coupon_titles ) { + + foreach ( $coupon_titles as $coupon_title ) { + + $coupon = new WC_Coupon( $coupon_title ); + if ( $this->is_wc_gte_30() ) { + if ( ! is_object( $coupon ) || ! is_callable( array( $coupon, 'get_id' ) ) ) { + continue; + } + $coupon_id = $coupon->get_id(); + if ( empty( $coupon_id ) ) { + continue; + } + $discount_type = $coupon->get_discount_type(); + } else { + $coupon_id = ( ! empty( $coupon->id ) ) ? $coupon->id : 0; + $discount_type = ( ! empty( $coupon->discount_type ) ) ? $coupon->discount_type : ''; + } + + $coupon_amount = $this->get_amount( $coupon, true ); + + $pick_price_of_prod = ( $this->is_callable( $coupon, 'get_meta' ) ) ? $coupon->get_meta( 'is_pick_price_of_product' ) : get_post_meta( $coupon_id, 'is_pick_price_of_product', true ); + $smart_coupon_gift_certificate_form_page_text = get_option( 'smart_coupon_gift_certificate_form_page_text' ); + $smart_coupon_gift_certificate_form_page_text = ( ! empty( $smart_coupon_gift_certificate_form_page_text ) ) ? $smart_coupon_gift_certificate_form_page_text : __( 'Send Coupons to...', 'woocommerce-smart-coupons' ); + $smart_coupon_gift_certificate_form_details_text = get_option( 'smart_coupon_gift_certificate_form_details_text' ); + $smart_coupon_gift_certificate_form_details_text = ( ! empty( $smart_coupon_gift_certificate_form_details_text ) ) ? $smart_coupon_gift_certificate_form_details_text : ''; // Enter email address and optional message for Gift Card receiver. + + // MADE CHANGES IN THE CONDITION TO SHOW FORM. + if ( array_key_exists( $discount_type, $all_discount_types ) || ( 'yes' === $pick_price_of_prod && '' === $price ) || ( 'yes' === $pick_price_of_prod && '' !== $price && $coupon_amount > 0 ) ) { + + if ( ! $form_started ) { + $is_show_coupon_receiver_form = get_option( 'smart_coupons_display_coupon_receiver_details_form', 'yes' ); + if ( 'no' === $is_show_coupon_receiver_form ) { + ?> +
          +

          +
          + +
          > +

          + +

          + +
          +

          +
            +
          • />
          • +
          • + /> +
              +
            • />
            • +
            • />
            • +
            + +
          • + + +
          • + + +
          +
          +
          +
          +
          + add_text_field_for_email( $coupon, $product, $coupon_receiver_details_session ); + + } + } + } + } + + if ( $form_started ) { + ?> +
          +
          +
          + + +
          +
          +
          +
          +
          +
          + is_wc_gte_30() ) { + add_action( 'woocommerce_new_order_item', array( $this, 'save_called_credit_details_in_order_item' ), 10, 3 ); + } else { + add_action( 'woocommerce_add_order_item_meta', array( $this, 'save_called_credit_details_in_order_item_meta' ), 10, 2 ); + } + + } + + /** + * Display form to enter receiver's details on checkout page + * + * @param WC_Coupon $coupon The coupon object. + * @param array $product The product object. + * @param array $coupon_receiver_details_session Coupon receiver details from. + */ + public function add_text_field_for_email( $coupon = '', $product = '', $coupon_receiver_details_session = array() ) { + global $total_coupon_amount; + + if ( empty( $coupon ) ) { + return; + } + + extract( $coupon_receiver_details_session ); // phpcs:ignore + + $sell_sc_at_less_price = get_option( 'smart_coupons_sell_store_credit_at_less_price', 'no' ); + + $coupon_data = $this->get_coupon_meta_data( $coupon ); + + if ( $this->is_wc_gte_30() ) { + $coupon_id = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_id' ) ) ) ? $coupon->get_id() : ''; + $coupon_code = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_code' ) ) ) ? $coupon->get_code() : ''; + $product_price = ( is_object( $product['data'] ) && is_callable( array( $product['data'], 'get_price' ) ) ) ? $product['data']->get_price() : 0; + $is_free_shipping = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_free_shipping' ) ) ) ? ( ( $coupon->get_free_shipping() ) ? 'yes' : 'no' ) : ''; + $discount_type = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_discount_type' ) ) ) ? $coupon->get_discount_type() : ''; + } else { + $coupon_id = ( ! empty( $coupon->id ) ) ? $coupon->id : 0; + $coupon_code = ( ! empty( $coupon->code ) ) ? $coupon->code : ''; + $product_price = ( ! empty( $product['data']->price ) ) ? $product['data']->price : 0; + $is_free_shipping = ( ! empty( $coupon->free_shipping ) ) ? $coupon->free_shipping : ''; + $discount_type = ( ! empty( $coupon->discount_type ) ) ? $coupon->discount_type : ''; + } + + $coupon_amount = $this->get_amount( $coupon, true ); + + for ( $i = 0; $i < $product['quantity']; $i++ ) { + + if ( $this->is_coupon_amount_pick_from_product_price( array( $coupon_code ) ) ) { + if ( 'yes' === $sell_sc_at_less_price ) { + $_coupon_amount = ( is_object( $product['data'] ) && is_callable( array( $product['data'], 'get_regular_price' ) ) ) ? $product['data']->get_regular_price() : 0; + if ( empty( $_coupon_amount ) && ! empty( $product_price ) ) { + $_coupon_amount = $product_price; + } + } else { + $_coupon_amount = $product_price; + } + if ( empty( $_coupon_amount ) && ! empty( $product['credit_amount'] ) ) { + $_coupon_amount = (float) $product['credit_amount']; + } + } else { + $_coupon_amount = $coupon_amount; + } + + // NEWLY ADDED CONDITION TO NOT TO SHOW TEXTFIELD IF COUPON AMOUNT IS "0". + // TODO: Free Gift Coupon: Due to coupon amount as zero, following condition is not showing multiple form to send coupon to different people. + if ( '' !== $_coupon_amount || $_coupon_amount > 0 || $coupon_amount > 0 || 'yes' === $is_free_shipping ) { + + $total_coupon_amount += $_coupon_amount; + + $formatted_coupon_text = ''; + $formatted_coupon_amount = 0; + if ( ! empty( $_coupon_amount ) || ! empty( $coupon_amount ) ) { + $formatted_coupon_amount = ( $coupon_amount <= 0 ) ? wc_price( $_coupon_amount ) : $coupon_data['coupon_amount']; + $formatted_coupon_text .= $coupon_data['coupon_type']; + if ( 'yes' === $is_free_shipping ) { + $formatted_coupon_text .= ' & '; + } + } + if ( 'yes' === $is_free_shipping ) { + $formatted_coupon_text .= __( 'Free Shipping coupon', 'woocommerce-smart-coupons' ); + } + if ( 'smart_coupon' !== $discount_type && strpos( $formatted_coupon_text, 'coupon' ) === false ) { + $formatted_coupon_text .= ' ' . __( 'coupon', 'woocommerce-smart-coupons' ); + } + ?> +
          + + + +
          +
          +
          +
          + is_callable( $order, 'get_id' ) ? $order->get_id() : 0; + $this->save_called_credit_details_in_order( $order_id ); + } + } + + /** + * Save entered credit value by customer in order for further processing + * + * @param int $order_id The order id. + * @param array $posted Associative array of posted data. + */ + public function save_called_credit_details_in_order( $order_id = 0, $posted = array() ) { + + $order = wc_get_order( $order_id ); + $order_items = $order->get_items(); + + $sc_called_credit = array(); + $update = false; + + $prices_include_tax = ( get_option( 'woocommerce_prices_include_tax' ) === 'yes' ) ? true : false; + + foreach ( $order_items as $item_id => $order_item ) { + + $item_sc_called_credit = $this->get_meta( $order_item, 'sc_called_credit', true ); + + if ( ! empty( $item_sc_called_credit ) ) { + + $product = ( is_object( $order_item ) && is_callable( array( $order_item, 'get_product' ) ) ) ? $order_item->get_product() : $order->get_product_from_item( $order_item ); + + if ( ! is_object( $product ) ) { + continue; + } + + if ( $this->is_wc_gte_30() ) { + $product_type = ( is_object( $product ) && is_callable( array( $product, 'get_type' ) ) ) ? $product->get_type() : ''; + $product_id = ( in_array( $product_type, array( 'variable', 'variable-subscription', 'variation', 'subscription_variation' ), true ) ) ? ( ( is_object( $product ) && is_callable( array( $product, 'get_parent_id' ) ) ) ? $product->get_parent_id() : 0 ) : ( ( is_object( $product ) && is_callable( array( $product, 'get_id' ) ) ) ? $product->get_id() : 0 ); + $item_qty = ( is_object( $order_item ) && is_callable( array( $order_item, 'get_quantity' ) ) ) ? $order_item->get_quantity() : 1; + $item_tax = ( is_object( $order_item ) && is_callable( array( $order_item, 'get_subtotal_tax' ) ) ) ? $order_item->get_subtotal_tax() : 0; + } else { + $product_id = ( ! empty( $product->id ) ) ? $product->id : 0; + $item_qty = ( ! empty( $order_item['qty'] ) ) ? $order_item['qty'] : 1; + $item_tax = ( ! empty( $order_item['line_subtotal_tax'] ) ) ? $order_item['line_subtotal_tax'] : 0; + } + + if ( true === $prices_include_tax && ! $this->is_generated_store_credit_includes_tax() ) { + $item_total = $item_sc_called_credit - $item_tax; + } elseif ( false === $prices_include_tax && $this->is_generated_store_credit_includes_tax() ) { + $item_total = $item_sc_called_credit + $item_tax; + } else { + $item_total = $item_sc_called_credit; + } + + if ( ! empty( $item_qty ) ) { + $qty = $item_qty; + } else { + $qty = 1; + } + + $coupon_titles = $this->get_coupon_titles( array( 'product_object' => $product ) ); + + if ( $coupon_titles ) { + + foreach ( $coupon_titles as $coupon_title ) { + + $coupon = new WC_Coupon( $coupon_title ); + + if ( $this->is_wc_gte_30() ) { + if ( ! is_object( $coupon ) || ! is_callable( array( $coupon, 'get_id' ) ) ) { + continue; + } + $coupon_id = $coupon->get_id(); + if ( empty( $coupon_id ) ) { + continue; + } + } else { + $coupon_id = ( ! empty( $coupon->id ) ) ? $coupon->id : 0; + } + + if ( $this->is_coupon_amount_pick_from_product_price( array( $coupon_title ) ) ) { + $products_price = ( ! $prices_include_tax ) ? $item_total : $item_total + $item_tax; + $amount = $products_price / $qty; + $sc_called_credit[ $item_id ] = wc_round_discount( $amount, 2 ); + $update = true; + } + } + } + + $this->delete_order_item_meta( $item_id, 'sc_called_credit' ); + } + } + if ( $update ) { + $this->update_post_meta( $order_id, 'sc_called_credit_details', $sc_called_credit, true, $order ); + } + + $this->maybe_clear_credit_called_session(); + + } + + /** + * Save entered credit value by customer in order item meta + * + * @param int $item_id The order item id. + * @param array $values Associative array containing item's details. + */ + public function save_called_credit_details_in_order_item_meta( $item_id = 0, $values = array() ) { + + if ( empty( $item_id ) || empty( $values ) ) { + return; + } + $sell_sc_at_less_price = get_option( 'smart_coupons_sell_store_credit_at_less_price', 'no' ); + if ( $this->is_wc_gte_30() ) { + if ( ! $values instanceof WC_Order_Item_Product ) { + return; + } + $product = $values->get_product(); + if ( ! is_object( $product ) || ! is_a( $product, 'WC_Product' ) ) { + return; + } + $product_type = ( is_object( $product ) && is_callable( array( $product, 'get_type' ) ) ) ? $product->get_type() : ''; + $product_id = ( in_array( $product_type, array( 'variable', 'variable-subscription', 'variation', 'subscription_variation' ), true ) ) ? ( ( is_object( $product ) && is_callable( array( $product, 'get_parent_id' ) ) ) ? $product->get_parent_id() : 0 ) : ( ( is_object( $product ) && is_callable( array( $product, 'get_id' ) ) ) ? $product->get_id() : 0 ); + $qty = ( is_callable( array( $values, 'get_quantity' ) ) ) ? $values->get_quantity() : 1; + $qty = ( ! empty( $qty ) ) ? absint( $qty ) : 1; + + // Check if selling store credit at less price is enabled. + if ( 'yes' === $sell_sc_at_less_price ) { + // For gift certificate of any amount. + if ( isset( $values->legacy_values['credit_amount'] ) && ! empty( $values->legacy_values['credit_amount'] ) ) { + $order_id = ( ! empty( $item_id ) ) ? wc_get_order_id_by_order_item_id( $item_id ) : 0; + $order = ( ! empty( $order_id ) ) ? wc_get_order( $order_id ) : null; + $credit_amount = $this->read_price( $values->legacy_values['credit_amount'], true, $order ); + $product_price = floatval( $credit_amount ) * $qty; + } else { + // For gift certificate of fixed price. + $product_price = ( is_callable( array( $product, 'get_regular_price' ) ) ) ? floatval( $product->get_regular_price() ) * $qty : 0; + } + } else { + $subtotal = ( is_callable( array( $values, 'get_subtotal' ) ) ) ? $values->get_subtotal() : 0; + $product_price = $subtotal; + } + if ( wp_doing_ajax() && defined( 'WP_ADMIN' ) && true === WP_ADMIN ) { + $action = ( ! empty( $_POST['action'] ) ) ? wc_clean( wp_unslash( $_POST['action'] ) ) : ''; // phpcs:ignore + $order_id = ( ! empty( $_POST['order_id'] ) ) ? absint( $_POST['order_id'] ) : 0; + if ( 'woocommerce_add_order_item' === $action && check_ajax_referer( 'order-item', 'security' ) && ! empty( $order_id ) ) { + $product_price = $product_price / $qty; + } + } + } else { + if ( empty( $values['data'] ) ) { + return; + } + $product = $values['data']; + $product_id = ( ! empty( $values['product_id'] ) ) ? $values['product_id'] : 0; + $product_price = ( ! empty( $values['data']->price ) ) ? $values['data']->price : 0; + } + + if ( empty( $product_id ) ) { + return; + } + + $coupon_titles = $this->get_coupon_titles( array( 'product_object' => $product ) ); + + if ( $this->is_coupon_amount_pick_from_product_price( $coupon_titles ) && $product_price > 0 ) { + $this->add_order_item_meta( $item_id, 'sc_called_credit', $product_price, true ); + } + } + + /** + * Save entered credit value by customer in order item + * + * @param int $item_id The order item id. + * @param array $values Associative array containing item's details. + * @param int $order_id The order id. + */ + public function save_called_credit_details_in_order_item( $item_id = 0, $values = array(), $order_id = 0 ) { + + $this->save_called_credit_details_in_order_item_meta( $item_id, $values ); + + } + + /** + * Save entered credit value by customer in order for PayPal Express Checkout + * + * @param WC_Order $order The order object. + */ + public function ppe_save_called_credit_details_in_order( $order ) { + if ( $this->is_wc_gte_30() ) { + $order_id = ( is_object( $order ) && is_callable( array( $order, 'get_id' ) ) ) ? $order->get_id() : 0; + } else { + $order_id = ( ! empty( $order->id ) ) ? $order->id : 0; + } + $this->save_called_credit_details_in_order( $order_id, null ); + } + + /** + * Save entered credit value by customer in cart item data + * + * This function is only for simple products. + * + * @param array $cart_item_data The cart item data. + * @param int $product_id The product id. + * @param int $variation_id The variation id. + * @return array $cart_item_data + */ + public function call_for_credit_cart_item_data( $cart_item_data = array(), $product_id = '', $variation_id = '' ) { + + if ( ! empty( $variation_id ) && $variation_id > 0 || empty( $product_id ) ) { + return $cart_item_data; + } + + $_product = wc_get_product( $product_id ); + + $coupons = ( $this->is_callable( $_product, 'get_meta' ) ) ? $_product->get_meta( '_coupon_title' ) : get_post_meta( $product_id, '_coupon_title', true ); + + if ( ! empty( $coupons ) && $this->is_coupon_amount_pick_from_product_price( $coupons ) && ! ( $_product->get_price() > 0 ) ) { + $request_credit_called = ( ! empty( $_REQUEST['credit_called'] ) ) ? wc_clean( wp_unslash( $_REQUEST['credit_called'] ) ) : array(); // phpcs:ignore + $request_add_to_cart = ( ! empty( $_REQUEST['add-to-cart'] ) ) ? wc_clean( wp_unslash( $_REQUEST['add-to-cart'] ) ) : 0; // phpcs:ignore + $request_wc_ajax = ( ! empty( $_REQUEST['wc-ajax'] ) ) ? wc_clean( wp_unslash( $_REQUEST['wc-ajax'] ) ) : ''; // phpcs:ignore + $request_product_id = ( ! empty( $_REQUEST['product_id'] ) ) ? absint( $_REQUEST['product_id'] ) : 0; // phpcs:ignore + $request_add_to_cart = ( 'add_to_cart' === $request_wc_ajax && ! empty( $request_product_id ) ) ? $request_product_id : $request_add_to_cart; + $product_id = apply_filters( + 'wc_sc_call_for_credit_product_id', + $request_add_to_cart, + array( + 'cart_item_data' => $cart_item_data, + 'product_id' => $product_id, + 'variation_id' => $variation_id, + 'source' => $this, + ) + ); + $cart_item_data['credit_amount'] = ( ! empty( $request_credit_called ) && ! empty( $product_id ) && ! empty( $request_credit_called[ $product_id ] ) ) ? $this->write_price( $request_credit_called[ $product_id ], true ) : 0; + return $cart_item_data; + } + + return $cart_item_data; + } + + /** + * Save entered credit value by customer in session + * + * This function is only for simple products. + * + * @param string $cart_item_key The cart item key. + * @param int $product_id The product id. + * @param int $quantity The product quantity. + * @param int $variation_id The variation id. + * @param array $variation The variation data. + * @param array $cart_item_data The cart item data. + */ + public function save_called_credit_in_session( $cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data ) { + + if ( ! empty( $variation_id ) && $variation_id > 0 ) { + return; + } + if ( ! isset( $cart_item_data['credit_amount'] ) || empty( $cart_item_data['credit_amount'] ) ) { + return; + } + + $_product = wc_get_product( $product_id ); + + $coupons = ( $this->is_callable( $_product, 'get_meta' ) ) ? $_product->get_meta( '_coupon_title' ) : get_post_meta( $product_id, '_coupon_title', true ); + + if ( ! empty( $coupons ) && $this->is_coupon_amount_pick_from_product_price( $coupons ) && ! ( $_product->get_price() > 0 ) ) { + $credit_called = $this->get_session( 'credit_called' ); + if ( empty( $credit_called ) || ! is_array( $credit_called ) ) { + $credit_called = array(); + } + $credit_called[ $cart_item_key ] = $cart_item_data['credit_amount']; + $this->set_session( 'credit_called', $credit_called ); + } + + } + + /** + * Enqueue required styles/scripts for store credit frontend form + */ + public function enqueue_styles_scripts() { + + // Return if gift certificate form is not shown. + if ( ! did_action( 'wc_sc_gift_certificate_form_shown' ) ) { + return; + } + + $this->enqueue_timepicker(); + + ?> + + plugin_url() . '/assets/css/jquery-ui/jquery-ui' . $suffix . '.css', array(), WC()->version ); + } + + if ( ! wp_style_is( 'jquery-ui-timepicker', 'registered' ) ) { + wp_register_style( 'jquery-ui-timepicker', untrailingslashit( plugins_url( '/', WC_SC_PLUGIN_FILE ) ) . '/assets/css/jquery-ui-timepicker-addon' . $suffix . '.css', array( 'jquery-ui-style' ), $version ); + } + + if ( ! wp_style_is( 'jquery-ui-timepicker' ) ) { + wp_enqueue_style( 'jquery-ui-timepicker' ); + } + + if ( ! wp_script_is( 'jquery-ui-timepicker', 'registered' ) ) { + wp_register_script( 'jquery-ui-timepicker', untrailingslashit( plugins_url( '/', WC_SC_PLUGIN_FILE ) ) . '/assets/js/jquery-ui-timepicker-addon' . $suffix . '.js', array( 'jquery', 'jquery-ui-datepicker', 'jquery-ui-slider', 'wp-i18n' ), $version, true ); + } + + if ( ! wp_script_is( 'jquery-ui-timepicker' ) ) { + wp_enqueue_script( 'jquery-ui-timepicker' ); + } + + } + + /** + * Clear session variable credit_called (if set) when cart is empty + */ + public function maybe_clear_credit_called_session() { + if ( WC()->session->__isset( 'credit_called' ) ) { + WC()->session->__unset( 'credit_called' ); + } + } + + /** + * Validate checkout based on whether delivery time is required or not + * + * @param array $fields checkout fields. + * @param WP_Error $errors WP Error Object. + * @return void + */ + public function maybe_required_coupon_delivery_date_time( $fields = array(), $errors = object ) { + + $nonce_value = ( ! empty( $_POST['woocommerce-process-checkout-nonce'] ) ) ? wc_clean( wp_unslash( $_POST['woocommerce-process-checkout-nonce'] ) ) : ''; // phpcs:ignore + if ( ! wp_verify_nonce( $nonce_value, 'woocommerce-process_checkout' ) ) { + return; + } + + global $store_credit_label; + + $is_schedule_gift_sending = ( ! empty( $_POST['wc_sc_schedule_gift_sending'] ) ) ? wc_clean( wp_unslash( $_POST['wc_sc_schedule_gift_sending'] ) ) : ''; // phpcs:ignore + $gift_sending_timestamp = ( ! empty( $_POST['gift_sending_timestamp'] ) && is_array( $_POST['gift_sending_timestamp'] ) ) ? wc_clean( wp_unslash( $_POST['gift_sending_timestamp'] ) ) : array(); // phpcs:ignore + $send_to = ( ! empty( $_POST['sc_send_to'] ) ) ? wc_clean( wp_unslash( $_POST['sc_send_to'] ) ) : ''; // phpcs:ignore + $is_gift = ( ! empty( $_POST['is_gift'] ) ) ? wc_clean( wp_unslash( $_POST['is_gift'] ) ) : ''; // phpcs:ignore + + if ( 'yes' === $is_gift && 'yes' === $is_schedule_gift_sending ) { + $is_date_available = true; + if ( is_array( $gift_sending_timestamp ) && ! empty( $gift_sending_timestamp ) ) { + if ( 'many' === $send_to ) { + foreach ( $gift_sending_timestamp as $coupon_id => $timestamp ) { + if ( 0 === absint( $coupon_id ) ) { + continue; + } + $filtered = array_filter( $timestamp ); + if ( count( $filtered ) !== count( $timestamp ) ) { + $is_date_available = false; + break; + } + } + } elseif ( 'one' === $send_to ) { + if ( empty( $gift_sending_timestamp[0][0] ) ) { + $is_date_available = false; + } + } + } + if ( false === $is_date_available ) { + if ( is_object( $errors ) && is_callable( array( $errors, 'add' ) ) ) { + /* translators: %s: field name */ + $errors->add( 'validation', __( 'Coupon delivery date and time is a required field.', 'woocommerce-smart-coupons' ) ); + } + } + } + } + + /** + * Save coupon receiver details in session + * + * @param array $fields checkout fields. + * @param WP_Error $errors WP Error Object. + */ + public function save_coupon_receiver_details_in_session( $fields = array(), $errors = object ) { + $nonce_value = ( ! empty( $_POST['woocommerce-process-checkout-nonce'] ) ) ? wc_clean( wp_unslash( $_POST['woocommerce-process-checkout-nonce'] ) ) : ''; // phpcs:ignore + if ( ! wp_verify_nonce( $nonce_value, 'woocommerce-process_checkout' ) ) { + return; + } + $posted_data = array_map( 'wp_unslash', $_POST ); // phpcs:ignore + $posted_data = wc_clean( $posted_data ); // phpcs:ignore + $this->set_coupon_receiver_details_session( $posted_data ); + } + + /** + * Set coupon receiver details in session variable + * + * @param array $posted_data The posted data. + */ + public function set_coupon_receiver_details_session( $posted_data = array() ) { + if ( is_callable( 'WC' ) && is_object( WC() ) && is_object( WC()->session ) && is_callable( array( WC()->session, 'set' ) ) ) { + $keys_to_copy = array( 'is_gift', 'sc_send_to', 'wc_sc_schedule_gift_sending', 'gift_receiver_email', 'gift_sending_date_time', 'gift_sending_timestamp', 'gift_receiver_message' ); + $coupon_receiver_details = array(); + foreach ( $keys_to_copy as $key ) { + if ( isset( $posted_data[ $key ] ) ) { + $coupon_receiver_details[ $key ] = $posted_data[ $key ]; + } + } + $coupon_receiver_details = apply_filters( + 'wc_sc_before_set_coupon_receiver_details_session', + $coupon_receiver_details, + array( + 'source' => $this, + 'posted_data' => $posted_data, + ) + ); + if ( ! empty( $coupon_receiver_details ) ) { + WC()->session->set( 'wc_sc_coupon_receiver_details_session', $coupon_receiver_details ); + } else { + WC()->session->set( 'wc_sc_coupon_receiver_details_session', null ); + } + } + } + + /** + * Get coupon receiver details from session variable + */ + public function get_coupon_receiver_details_session() { + if ( is_callable( 'WC' ) && is_object( WC() ) && is_object( WC()->session ) && is_callable( array( WC()->session, 'get' ) ) ) { + return WC()->session->get( 'wc_sc_coupon_receiver_details_session' ); + } + return null; + } + + /** + * Function to cleanup order item meta if not required + * + * @param integer $order_id The order id. + */ + public function cleanup_order_item_meta( $order_id = 0 ) { + if ( empty( $order_id ) ) { + return; + } + + $order = wc_get_order( $order_id ); + $order_items = ( is_object( $order ) && is_callable( array( $order, 'get_items' ) ) ) ? $order->get_items() : array(); + + foreach ( $order_items as $item_id => $order_item ) { + $this->delete_order_item_meta( $item_id, 'sc_called_credit' ); + } + } + + /** + * Save coupon receiver details in session during update order review + * + * @param array $fragments The fragments. + * @return array + */ + public function update_order_review_fragments( $fragments = array() ) { + if ( ! empty( $_POST['post_data'] ) ) { // phpcs:ignore + wp_parse_str( $_POST['post_data'], $posted_data ); // phpcs:ignore + $this->set_coupon_receiver_details_session( $posted_data ); + } + return $fragments; + } + + /** + * Save coupon receiver detail via AJAX + */ + public function ajax_save_coupon_receiver_details() { + + check_ajax_referer( 'wc-sc-save-coupon-receiver-details', 'security' ); + + wp_parse_str( wc_clean( wp_unslash( urldecode_deep( $_POST['data'] ) ) ), $posted_data ); // phpcs:ignore + $this->set_coupon_receiver_details_session( $posted_data ); + + wp_send_json( array( 'success' => 'yes' ) ); + + } + + /** + * Check & clear coupon receiver details from session when cart is emptied (e.g. after creation of order) + */ + public function maybe_clear_coupon_receiver_details_session() { + $coupon_receiver_details_session = $this->get_coupon_receiver_details_session(); + if ( ! is_null( $coupon_receiver_details_session ) ) { + WC()->session->set( 'wc_sc_coupon_receiver_details_session', null ); + } + } + + } + +} + +WC_SC_Purchase_Credit::get_instance(); diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-rest-coupons-controller.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-rest-coupons-controller.php new file mode 100644 index 00000000..7eaa39ea --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-rest-coupons-controller.php @@ -0,0 +1,236 @@ +post_type}_object", array( $this, 'handle_response_data' ), 99, 3 ); + } + + /** + * Register the routes for coupons. + */ + public function register_routes() { + register_rest_route( + $this->namespace, + '/' . $this->rest_base, + array( + array( + 'methods' => WP_REST_Server::CREATABLE, + 'callback' => array( $this, 'create_item' ), + 'permission_callback' => array( $this, 'create_item_permissions_check' ), + 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), + ), + 'schema' => array( $this, 'get_public_item_schema' ), + ) + ); + } + + /** + * Prepare a single coupon for create or update. + * + * @param WP_REST_Request $request Request object. + * @param bool $creating If is creating a new object. + * @return WP_Error|WC_Data + */ + protected function prepare_object_for_database( $request, $creating = false ) { + global $woocommerce_smart_coupon; + + $id = isset( $request['id'] ) ? absint( $request['id'] ) : 0; + $coupon = new WC_Coupon( $id ); + $schema = $this->get_item_schema(); + $data_keys = array_keys( array_filter( $schema['properties'], array( $this, 'filter_writable_props' ) ) ); + $email_restrictions = ( ! empty( $request['email_restrictions'] ) && count( $request['email_restrictions'] ) === 1 ) ? $request['email_restrictions'] : ''; + + // Validate required POST fields. + if ( $creating ) { + if ( empty( $request['code'] ) ) { + $request['code'] = $woocommerce_smart_coupon->generate_unique_code( $email_restrictions ); + } else { + $_coupon = new WC_Coupon( $request['code'] ); + $is_auto_generate = ( is_object( $_coupon ) && is_callable( array( $_coupon, 'get_meta' ) ) ) ? $_coupon->get_meta( 'auto_generate_coupon' ) : 'no'; + if ( 'yes' === $is_auto_generate ) { + $request['code'] = $woocommerce_smart_coupon->generate_unique_code( $email_restrictions ); + foreach ( $data_keys as $key ) { + if ( empty( $request[ $key ] ) ) { + switch ( $key ) { + case 'code': + // do nothing. + break; + case 'meta_data': + $meta_data = ( is_object( $_coupon ) && is_callable( array( $_coupon, 'get_meta_data' ) ) ) ? $_coupon->get_meta_data() : null; + $new_meta_data = array(); + if ( ! empty( $meta_data ) ) { + foreach ( $meta_data as $meta ) { + if ( is_object( $meta ) && is_callable( array( $meta, 'get_data' ) ) ) { + $data = $meta->get_data(); + if ( isset( $data['id'] ) ) { + unset( $data['id'] ); + } + $new_meta_data[] = $data; + } + } + } + $request[ $key ] = $new_meta_data; + break; + case 'description': + $request[ $key ] = ( is_object( $_coupon ) && is_callable( array( $_coupon, 'get_description' ) ) ) ? $_coupon->get_description() : null; + break; + default: + if ( is_callable( array( $_coupon, "get_{$key}" ) ) ) { + $request[ $key ] = $_coupon->{"get_{$key}"}(); + } + break; + } + } + } + } + } + } + + // Handle all writable props. + foreach ( $data_keys as $key ) { + $value = $request[ $key ]; + + if ( ! is_null( $value ) ) { + switch ( $key ) { + case 'code': + $coupon_code = wc_format_coupon_code( $value ); + $id = $coupon->get_id() ? $coupon->get_id() : 0; + $id_from_code = wc_get_coupon_id_by_code( $coupon_code, $id ); + + if ( $id_from_code ) { + return new WP_Error( 'woocommerce_rest_coupon_code_already_exists', __( 'The coupon code already exists', 'woocommerce-smart-coupons' ), array( 'status' => 400 ) ); + } + + $coupon->set_code( $coupon_code ); + break; + case 'meta_data': + if ( is_array( $value ) ) { + foreach ( $value as $meta ) { + $coupon->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' ); + } + } + break; + case 'description': + $coupon->set_description( wp_filter_post_kses( $value ) ); + break; + default: + if ( is_callable( array( $coupon, "set_{$key}" ) ) ) { + $coupon->{"set_{$key}"}( $value ); + } + break; + } + } + } + + /** + * Filters an object before it is inserted via the REST API. + * + * The dynamic portion of the hook name, `$this->post_type`, + * refers to the object type slug. + * + * @param WC_Data $coupon Object object. + * @param WP_REST_Request $request Request object. + * @param bool $creating If is creating a new object. + */ + return apply_filters( "woocommerce_rest_pre_insert_{$this->post_type}_object", $coupon, $request, $creating ); + } + + /** + * Handle REST response data + * + * @param WP_REST_Response|mixed $response The response. + * @param WC_Coupon|mixed $object The object. + * @param WP_REST_Request|mixed $request The request. + * @return WP_REST_Response + */ + public function handle_response_data( $response = null, $object = null, $request = null ) { + global $woocommerce_smart_coupon; + + if ( ! empty( $request['sc_is_send_email'] ) && 'yes' === $request['sc_is_send_email'] ) { + $is_send_email = $woocommerce_smart_coupon->is_email_template_enabled(); + $email_restrictions = ( ! empty( $request['email_restrictions'] ) ) ? current( $request['email_restrictions'] ) : ''; + if ( 'yes' === $is_send_email && ! empty( $email_restrictions ) ) { + $coupon = array( + 'code' => ( is_object( $object ) && is_callable( array( $object, 'get_code' ) ) ) ? $object->get_code() : '', + 'amount' => ( is_object( $object ) && is_callable( array( $object, 'get_amount' ) ) ) ? $object->get_amount() : 0, + ); + $action_args = apply_filters( + 'wc_sc_email_coupon_notification_args', + array( + 'email' => $email_restrictions, + 'coupon' => $coupon, + 'discount_type' => ( is_object( $object ) && is_callable( array( $object, 'get_discount_type' ) ) ) ? $object->get_discount_type() : '', + ) + ); + // Trigger email notification. + do_action( 'wc_sc_email_coupon_notification', $action_args ); + } + } + + if ( ! empty( $request['sc_is_html'] ) && 'yes' === $request['sc_is_html'] ) { + $data = ''; + ob_start(); + do_action( + 'wc_sc_paint_coupon', + array( + 'coupon' => $object, + 'with_css' => 'yes', + 'with_container' => 'yes', + ) + ); + $data = ob_get_clean(); + $response = rest_ensure_response( $data ); + } + + return $response; + } + + } + +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-settings.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-settings.php new file mode 100644 index 00000000..a9d03a9f --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-settings.php @@ -0,0 +1,1071 @@ + + + + + + + get_settings(); + if ( ! is_array( $sc_settings ) || empty( $sc_settings ) ) { + return; + } + + woocommerce_admin_fields( $sc_settings ); + wp_nonce_field( 'wc_smart_coupons_settings', 'sc_security', false ); + $this->sc_settings_page_styles_scripts(); + } + + /** + * Function to get Smart Coupons admin settings + * + * @return array $sc_settings Smart Coupons admin settings. + */ + public function get_settings() { + global $store_credit_label; + + $singular = ( ! empty( $store_credit_label['singular'] ) ) ? $store_credit_label['singular'] : __( 'store credit', 'woocommerce-smart-coupons' ); + $plural = ( ! empty( $store_credit_label['plural'] ) ) ? $store_credit_label['plural'] : __( 'store credits', 'woocommerce-smart-coupons' ); + + $valid_order_statuses = get_option( 'wc_sc_valid_order_statuses_for_coupon_auto_generation' ); + + $paid_statuses = wc_get_is_paid_statuses(); + + if ( false === $valid_order_statuses ) { + add_option( 'wc_sc_valid_order_statuses_for_coupon_auto_generation', $paid_statuses, '', 'no' ); + } elseif ( ! is_array( $valid_order_statuses ) ) { + update_option( 'wc_sc_valid_order_statuses_for_coupon_auto_generation', $paid_statuses, 'no' ); + } + + $all_order_statuses = wc_get_order_statuses(); + $all_paid_order_statuses = array(); + + foreach ( $paid_statuses as $paid_status ) { + $wc_paid_status = 'wc-' . $paid_status; + if ( array_key_exists( $wc_paid_status, $all_order_statuses ) ) { + $all_paid_order_statuses[ $paid_status ] = $all_order_statuses[ $wc_paid_status ]; + } + } + + $all_discount_types = wc_get_coupon_types(); + + $storewide_offer_coupon_option = array(); + $storewide_offer_coupon_code = get_option( 'smart_coupons_storewide_offer_coupon_code' ); + if ( ! empty( $storewide_offer_coupon_code ) ) { + $coupon = new WC_Coupon( $storewide_offer_coupon_code ); + $discount_type = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_discount_type' ) ) ) ? $coupon->get_discount_type() : 'percent'; + /* translators: 1. The coupon code, 2. The discount type */ + $storewide_offer_coupon_option[ $storewide_offer_coupon_code ] = sprintf( __( '%1$s (Type: %2$s)', 'woocommerce-smart-coupons' ), $storewide_offer_coupon_code, ( ( array_key_exists( $discount_type, $all_discount_types ) ) ? $all_discount_types[ $discount_type ] : $discount_type ) ); + } + + $valid_designs = $this->get_valid_coupon_designs(); + + $coupon_design = get_option( 'wc_sc_setting_coupon_design' ); + $default_coupon_design = 'basic'; + if ( ! empty( $coupon_design ) && 'custom-design' === $coupon_design ) { + $default_coupon_design = $coupon_design; + } + + $sc_settings = array( + array( + 'title' => __( 'Smart Coupons Settings', 'woocommerce-smart-coupons' ), + 'type' => 'title', + 'desc' => __( 'Set up Smart Coupons the way you like. Use these options to configure/change the way Smart Coupons works.', 'woocommerce-smart-coupons' ), + 'id' => 'sc_display_coupon_settings', + ), + array( + 'title' => __( 'Colors', 'woocommerce-smart-coupons' ), + 'id' => 'wc_sc_setting_coupon_design_colors', + 'default' => '2b2d42-edf2f4-d90429', + 'type' => 'wc_sc_radio_with_html', + 'desc_tip' => __( 'Choose a color scheme for coupons.', 'woocommerce-smart-coupons' ), + 'class' => 'wc_sc_setting_coupon_design_colors', + 'autoload' => false, + 'options' => array( + '2b2d42-edf2f4-d90429' => __( 'Amaranth red', 'woocommerce-smart-coupons' ), + '003459-ffffff-00a8e8' => __( 'Carolina Blue', 'woocommerce-smart-coupons' ), + '334752-fffdf5-46b39d' => __( 'Keppel', 'woocommerce-smart-coupons' ), + 'edf2f4-bb2538-fcbf49' => __( 'McDonald', 'woocommerce-smart-coupons' ), + 'd6b56d-231f20-ffe09c' => __( 'Gold', 'woocommerce-smart-coupons' ), + '362f78-f8f9fa-5950ec' => __( 'Majorelle Blue', 'woocommerce-smart-coupons' ), + 'a82f82-f5f8ff-f45dc4' => __( 'Rose Pink', 'woocommerce-smart-coupons' ), + '2c5f72-f3d2b3-f16a6c' => __( 'Vintage', 'woocommerce-smart-coupons' ), + 'e37332-fefefe-de4f3c' => __( 'Spanish Orange', 'woocommerce-smart-coupons' ), + '8e6e5d-f2f2f2-333333' => __( 'Chocolate', 'woocommerce-smart-coupons' ), + 'a7e7ff-418fde-ffffff' => __( 'Ocean', 'woocommerce-smart-coupons' ), + ), + 'args' => array( + 'html_callback' => array( $this, 'color_scheme_html' ), + ), + ), + array( + 'title' => __( 'Customize colors', 'woocommerce-smart-coupons' ), + 'id' => 'wc_sc_setting_coupon_design_colors', + 'default' => 'custom', + 'type' => 'wc_sc_radio_with_html', + 'desc_tip' => __( 'Customize color scheme for coupons.', 'woocommerce-smart-coupons' ), + 'class' => 'wc_sc_setting_coupon_design_colors custom', + 'autoload' => false, + 'options' => array( + 'custom' => __( 'Custom colors', 'woocommerce-smart-coupons' ), + ), + 'args' => array( + 'html_callback' => array( $this, 'color_scheme_html' ), + ), + ), + array( + 'title' => __( 'Styles', 'woocommerce-smart-coupons' ), + 'id' => 'wc_sc_setting_coupon_design', + 'default' => $default_coupon_design, + 'type' => 'wc_sc_radio_with_html', + 'desc_tip' => __( 'Choose a style for coupon on the website.', 'woocommerce-smart-coupons' ), + 'class' => 'sc-coupons-list wc_sc_setting_coupon_design', + 'autoload' => false, + 'options' => array( + 'flat' => __( 'Flat', 'woocommerce-smart-coupons' ), + 'promotion' => __( 'Promotion', 'woocommerce-smart-coupons' ), + 'ticket' => __( 'Ticket', 'woocommerce-smart-coupons' ), + 'festive' => __( 'Festive', 'woocommerce-smart-coupons' ), + 'special' => __( 'Special', 'woocommerce-smart-coupons' ), + 'shipment' => __( 'Shipment', 'woocommerce-smart-coupons' ), + 'cutout' => __( 'Cutout', 'woocommerce-smart-coupons' ), + 'deliver' => __( 'Deliver', 'woocommerce-smart-coupons' ), + 'clipper' => __( 'Clipper', 'woocommerce-smart-coupons' ), + 'basic' => __( 'Basic', 'woocommerce-smart-coupons' ), + 'deal' => __( 'Deal', 'woocommerce-smart-coupons' ), + ), + 'args' => array( + 'html_callback' => array( $this, 'coupon_design_html' ), + ), + ), + array( + 'title' => __( 'Style for email', 'woocommerce-smart-coupons' ), + 'id' => 'wc_sc_setting_coupon_design_for_email', + 'default' => 'email-coupon', + 'type' => 'wc_sc_radio_with_html', + 'desc_tip' => __( 'Style for coupon in email.', 'woocommerce-smart-coupons' ), + 'class' => 'sc-coupons-list wc_sc_setting_coupon_design', + 'autoload' => false, + 'options' => array( + 'email-coupon' => __( 'Email coupon', 'woocommerce-smart-coupons' ), + ), + 'args' => array( + 'html_callback' => array( $this, 'coupon_design_html' ), + ), + ), + array( + 'name' => __( 'Number of coupons to show', 'woocommerce-smart-coupons' ), + 'desc' => __( 'How many coupons (at max) should be shown on cart, checkout & my account page? If set to 0 (zero) then coupons will not be displayed at all on the website.', 'woocommerce-smart-coupons' ), + 'id' => 'wc_sc_setting_max_coupon_to_show', + 'type' => 'number', + 'desc_tip' => true, + 'css' => 'min-width:300px;', + 'autoload' => false, + ), + array( + 'name' => __( 'Number of characters in auto-generated coupon code', 'woocommerce-smart-coupons' ), + 'desc' => __( 'Number of characters in auto-generated coupon code will be restricted to this number excluding prefix and/or suffix. The default length will be 13. It is recommended to keep this number between 10 to 15 to avoid coupon code duplication.', 'woocommerce-smart-coupons' ), + 'id' => 'wc_sc_coupon_code_length', + 'type' => 'number', + 'desc_tip' => true, + 'placeholder' => '13', + 'css' => 'min-width:300px;', + 'custom_attributes' => array( + 'min' => 7, + 'step' => 1, + 'max' => 20, + ), + 'autoload' => false, + ), + array( + 'name' => __( 'Valid order status for auto-generating coupon', 'woocommerce-smart-coupons' ), + 'desc' => __( 'Choose order status which will trigger the auto-generation of coupon, if the order contains product which will generate the coupon.', 'woocommerce-smart-coupons' ), + 'id' => 'wc_sc_valid_order_statuses_for_coupon_auto_generation', + 'default' => $paid_statuses, + 'type' => 'multiselect', + 'class' => 'wc-enhanced-select', + 'css' => 'min-width: 350px;', + 'desc_tip' => true, + 'options' => $all_paid_order_statuses, + 'custom_attributes' => array( + 'data-placeholder' => __( 'Select order status…', 'woocommerce-smart-coupons' ), + ), + 'autoload' => false, + ), + array( + 'name' => __( 'Enable store notice for the coupon', 'woocommerce-smart-coupons' ), + 'id' => 'smart_coupons_storewide_offer_coupon_code', + 'type' => 'select', + 'default' => '', + 'desc' => __( 'Search & select a coupon which you want to display as store notice. The selected coupon\'s description will be displayed along with the coupon code (if it is set) otherwise, a description will be generated automatically. To disable the feature, keep this field empty.', 'woocommerce-smart-coupons' ), + 'desc_tip' => true, + 'class' => 'wc-sc-storewide-coupon-search', + 'css' => 'min-width:300px;', + 'autoload' => false, + 'custom_attributes' => array( + 'data-placeholder' => __( 'Search for a coupon...', 'woocommerce-smart-coupons' ), + 'data-action' => 'sc_json_search_storewide_coupons', + 'data-security' => wp_create_nonce( 'search-coupons' ), + 'data-allow_clear' => true, + ), + 'options' => $storewide_offer_coupon_option, + ), + array( + /* translators: %s: Label for store credit */ + 'name' => sprintf( __( 'Generated %s amount', 'woocommerce-smart-coupons' ), strtolower( $singular ) ), + /* translators: %s: Label for store credit */ + 'desc' => sprintf( __( 'Include tax in the amount of the generated %s', 'woocommerce-smart-coupons' ), strtolower( $singular ) ), + 'id' => 'wc_sc_generated_store_credit_includes_tax', + 'type' => 'checkbox', + 'default' => 'no', + 'checkboxgroup' => 'start', + 'autoload' => false, + ), + array( + 'name' => __( 'Displaying coupons', 'woocommerce-smart-coupons' ), + /* translators: %s: Preview link */ + 'desc' => sprintf( __( 'Include coupon details on product\'s page, for products that issue coupons %s', 'woocommerce-smart-coupons' ), '' . __( '[Preview]', 'woocommerce-smart-coupons' ) . '' ), + 'id' => 'smart_coupons_is_show_associated_coupons', + 'type' => 'checkbox', + 'default' => 'no', + 'checkboxgroup' => 'start', + 'autoload' => false, + ), + array( + /* translators: %s: Preview link */ + 'desc' => sprintf( __( 'Show coupons available to customers on their My Account > Coupons page %s', 'woocommerce-smart-coupons' ), '' . __( '[Preview]', 'woocommerce-smart-coupons' ) . '' ), + 'id' => 'woocommerce_smart_coupon_show_my_account', + 'type' => 'checkbox', + 'default' => 'yes', + 'checkboxgroup' => '', + 'autoload' => false, + ), + array( + /* translators: %s: Preview link */ + 'desc' => sprintf( __( 'Include coupons received from other people on My Account > Coupons page %s', 'woocommerce-smart-coupons' ), '' . __( '[Preview]', 'woocommerce-smart-coupons' ) . '' ), + 'id' => 'show_coupon_received_on_my_account', + 'type' => 'checkbox', + 'default' => 'no', + 'checkboxgroup' => '', + 'autoload' => false, + ), + array( + /* translators: %s: Preview link */ + 'desc' => sprintf( __( 'Show invalid or used coupons in My Account > Coupons %s', 'woocommerce-smart-coupons' ), '' . __( '[Preview]', 'woocommerce-smart-coupons' ) . '' ), + 'id' => 'smart_coupons_show_invalid_coupons_on_myaccount', + 'type' => 'checkbox', + 'default' => 'no', + 'checkboxgroup' => '', + 'autoload' => false, + ), + array( + /* translators: %s: Preview link */ + 'desc' => sprintf( __( 'Display coupon description along with coupon code (on site as well as in emails) %s', 'woocommerce-smart-coupons' ), '' . __( '[Preview]', 'woocommerce-smart-coupons' ) . '' ), + 'id' => 'smart_coupons_show_coupon_description', + 'type' => 'checkbox', + 'default' => 'no', + 'checkboxgroup' => 'end', + 'autoload' => false, + ), + array( + 'name' => __( 'Auto apply coupons', 'woocommerce-smart-coupons' ), + /* translators: %s: Explanation of the setting */ + 'desc' => sprintf( __( 'When enabled, each coupon will have the option to enable auto-apply for that coupon %s', 'woocommerce-smart-coupons' ), '
          ' . __( 'Disabling this, no coupons will be auto-applied - even if any coupon has "Auto apply?" enabled.', 'woocommerce-smart-coupons' ) . '' ), + 'id' => 'wc_sc_allow_auto_apply', + 'type' => 'checkbox', + 'default' => 'yes', + 'checkboxgroup' => 'start', + 'autoload' => false, + ), + array( + 'name' => __( 'Automatic deletion', 'woocommerce-smart-coupons' ), + /* translators: %s: Note for admin */ + 'desc' => sprintf( __( 'Delete the %1$s when entire credit amount is used up %2$s', 'woocommerce-smart-coupons' ), strtolower( $singular ), '' . __( '(Note: It\'s recommended to keep it Disabled)', 'woocommerce-smart-coupons' ) . '' ), + 'id' => 'woocommerce_delete_smart_coupon_after_usage', + 'type' => 'checkbox', + 'default' => 'no', + 'checkboxgroup' => 'start', + 'autoload' => false, + ), + array( + 'name' => __( 'Coupon emails', 'woocommerce-smart-coupons' ), + 'desc' => __( 'Email auto generated coupons to recipients', 'woocommerce-smart-coupons' ), + 'id' => 'smart_coupons_is_send_email', + 'type' => 'checkbox', + 'default' => 'yes', + 'checkboxgroup' => 'start', + 'autoload' => false, + ), + array( + 'name' => __( 'Printing coupons', 'woocommerce-smart-coupons' ), + 'desc' => __( 'Enable feature to allow printing of coupons', 'woocommerce-smart-coupons' ) . ' ' . __( '[Read More]', 'woocommerce-smart-coupons' ) . '', + 'id' => 'smart_coupons_is_print_coupon', + 'type' => 'checkbox', + 'default' => 'yes', + 'checkboxgroup' => 'start', + 'autoload' => false, + ), + array( + /* translators: %s: Label for store credit */ + 'name' => sprintf( __( 'Sell %s at less price?', 'woocommerce-smart-coupons' ), strtolower( $plural ) ), + /* translators: %s: Label for store credit, 1: : Label for store credit, 2: Label for store credit, 3: Label for store credit */ + 'desc' => sprintf( __( 'Allow selling %s at discounted price', 'woocommerce-smart-coupons' ), strtolower( $plural ) ) . ' ' . __( '[Read More]', 'woocommerce-smart-coupons' ) . '', + 'id' => 'smart_coupons_sell_store_credit_at_less_price', + 'type' => 'checkbox', + 'checkboxgroup' => 'start', + 'default' => 'no', + 'autoload' => false, + 'desc_tip' => '', + ), + array( + 'type' => 'sectionend', + 'id' => 'sc_display_coupon_settings', + ), + array( + 'title' => __( 'Labels', 'woocommerce-smart-coupons' ), + 'type' => 'title', + 'desc' => __( 'Call it something else! Use these to quickly change text labels through your store. Use translations for complete control.', 'woocommerce-smart-coupons' ), + 'id' => 'sc_setting_labels', + ), + array( + 'name' => __( 'Store Credit / Gift Certificate', 'woocommerce-smart-coupons' ), + 'desc' => '' . __( '[Read More]', 'woocommerce-smart-coupons' ) . '', + 'id' => 'sc_store_credit_singular_text', + 'type' => 'text', + 'placeholder' => __( 'Singular name', 'woocommerce-smart-coupons' ), + 'desc_tip' => __( 'Give alternate singular name to Store Credit / Gift Certificate. This label will only rename Store Credit / Gift Certificate used in the Smart Coupons plugin.', 'woocommerce-smart-coupons' ), + 'css' => 'min-width:300px;', + 'autoload' => false, + ), + array( + 'id' => 'sc_store_credit_plural_text', + 'type' => 'text', + 'desc_tip' => __( 'Give plural name for the above singular name.', 'woocommerce-smart-coupons' ), + 'placeholder' => __( 'Plural name', 'woocommerce-smart-coupons' ), + 'css' => 'min-width:300px;', + 'autoload' => false, + ), + array( + /* translators: %s: Label for store credit */ + 'name' => sprintf( __( '%s product CTA', 'woocommerce-smart-coupons' ), ucfirst( $singular ) ), + 'desc' => '' . __( '[Preview]', 'woocommerce-smart-coupons' ) . '', + 'id' => 'sc_gift_certificate_shop_loop_button_text', + 'type' => 'text', + /* translators: %s: Label for store credit */ + 'desc_tip' => sprintf( __( 'This is what will be shown instead of "Add to Cart" for products that sell %s.', 'woocommerce-smart-coupons' ), strtolower( $plural ) ), + 'placeholder' => __( 'Select options', 'woocommerce-smart-coupons' ), + 'css' => 'min-width:300px;', + 'autoload' => false, + ), + array( + /* translators: %s: Label for store credit */ + 'name' => sprintf( __( 'While purchasing %s', 'woocommerce-smart-coupons' ), strtolower( $plural ) ), + 'desc' => '' . __( '[Preview]', 'woocommerce-smart-coupons' ) . '', + 'id' => 'smart_coupon_store_gift_page_text', + 'type' => 'text', + /* translators: %s: Label for store credit */ + 'desc_tip' => sprintf( __( 'When you opt to allow people to buy %s of any amount, this label will be used.', 'woocommerce-smart-coupons' ), strtolower( $plural ) ), + 'placeholder' => __( 'Purchase credit worth', 'woocommerce-smart-coupons' ), + 'css' => 'min-width:300px;', + 'autoload' => false, + ), + array( + 'name' => __( '"Coupons with Product" description', 'woocommerce-smart-coupons' ), + 'desc' => '' . __( '[Preview]', 'woocommerce-smart-coupons' ) . '', + 'id' => 'smart_coupon_product_page_text', + 'type' => 'text', + 'desc_tip' => __( 'This is the heading above coupon details displayed on products that issue coupons.', 'woocommerce-smart-coupons' ), + 'placeholder' => __( 'You will get following coupon(s) when you buy this item', 'woocommerce-smart-coupons' ), + 'css' => 'min-width:300px;', + 'autoload' => false, + ), + array( + 'name' => __( 'On Cart/Checkout pages', 'woocommerce-smart-coupons' ), + 'desc' => '' . __( '[Preview]', 'woocommerce-smart-coupons' ) . '', + 'id' => 'smart_coupon_cart_page_text', + 'type' => 'text', + 'desc_tip' => __( 'This is the title for the list of available coupons, shown on Cart and Checkout pages.', 'woocommerce-smart-coupons' ), + 'placeholder' => __( 'Available Coupons (click on a coupon to use it)', 'woocommerce-smart-coupons' ), + 'css' => 'min-width:300px;', + 'autoload' => false, + ), + array( + 'name' => __( 'My Account page', 'woocommerce-smart-coupons' ), + 'desc' => '' . __( '[Preview]', 'woocommerce-smart-coupons' ) . '', + 'id' => 'smart_coupon_myaccount_page_text', + 'type' => 'text', + 'desc_tip' => __( 'Title of available coupons list on My Account page.', 'woocommerce-smart-coupons' ), + /* translators: %s: Label for store credit */ + 'placeholder' => sprintf( __( 'Available Coupons & %s', 'woocommerce-smart-coupons' ), ucwords( $plural ) ), + 'css' => 'min-width:300px;', + 'autoload' => false, + ), + array( + 'type' => 'sectionend', + 'id' => 'sc_setting_labels', + ), + array( + 'title' => __( 'Coupon Receiver Details during Checkout', 'woocommerce-smart-coupons' ), + 'type' => 'title', + 'desc' => __( 'Buyers can send purchased coupons to anyone – right while they\'re checking out.', 'woocommerce-smart-coupons' ), + 'id' => 'sc_coupon_receiver_settings', + ), + array( + 'name' => __( 'Allow sending of coupons to others', 'woocommerce-smart-coupons' ), + 'desc' => __( 'Allow the buyer to send coupons to someone else.', 'woocommerce-smart-coupons' ) . ' ' . __( '[Preview]', 'woocommerce-smart-coupons' ) . '', + 'id' => 'smart_coupons_display_coupon_receiver_details_form', + 'type' => 'checkbox', + 'default' => 'yes', + 'autoload' => false, + 'desc_tip' => '', + ), + array( + 'name' => __( 'Title', 'woocommerce-smart-coupons' ), + 'desc' => '' . __( '[Preview]', 'woocommerce-smart-coupons' ) . '', + 'id' => 'smart_coupon_gift_certificate_form_page_text', + 'type' => 'text', + 'desc_tip' => __( 'The title for coupon receiver details block.', 'woocommerce-smart-coupons' ), + 'placeholder' => __( 'Send Coupons to...', 'woocommerce-smart-coupons' ), + 'css' => 'min-width:300px;', + 'autoload' => false, + ), + array( + 'name' => __( 'Description', 'woocommerce-smart-coupons' ), + 'desc' => '' . __( '[Preview]', 'woocommerce-smart-coupons' ) . '', + 'id' => 'smart_coupon_gift_certificate_form_details_text', + 'type' => 'text', + 'desc_tip' => __( 'Additional text below the title.', 'woocommerce-smart-coupons' ), + 'css' => 'min-width:300px;', + 'autoload' => false, + ), + array( + 'name' => __( 'Allow schedule sending of coupons?', 'woocommerce-smart-coupons' ), + 'desc' => __( 'Enable this to allow buyers to select date & time for delivering the coupon.', 'woocommerce-smart-coupons' ) . ' ' . __( '[Preview]', 'woocommerce-smart-coupons' ) . '', + 'id' => 'smart_coupons_schedule_store_credit', + 'type' => 'checkbox', + 'checkboxgroup' => 'start', + 'default' => 'no', + 'autoload' => false, + 'desc_tip' => '', + ), + array( + 'name' => __( 'Combine emails', 'woocommerce-smart-coupons' ), + 'desc' => __( 'Send only one email instead of multiple emails when multiple coupons are generated for same recipient', 'woocommerce-smart-coupons' ), + 'id' => 'smart_coupons_combine_emails', + 'type' => 'checkbox', + 'default' => 'no', + 'autoload' => false, + ), + array( + 'type' => 'sectionend', + 'id' => 'sc_coupon_receiver_settings', + ), + ); + + if ( $this->is_wc_gte_30() && wc_tax_enabled() ) { + $before_tax_option[] = array( + 'name' => __( 'Apply before tax', 'woocommerce-smart-coupons' ), + 'desc' => __( 'Deduct credit/gift before doing tax calculations', 'woocommerce-smart-coupons' ), + 'id' => 'woocommerce_smart_coupon_apply_before_tax', + 'type' => 'checkbox', + 'default' => 'no', + 'checkboxgroup' => 'start', + 'autoload' => false, + 'show_if_checked' => 'option', + ); + + $prices_include_tax = wc_prices_include_tax(); + + if ( true === $prices_include_tax ) { + $before_tax_option[] = array( + /* translators: %s: Label for store credit */ + 'name' => sprintf( __( '%s include tax?', 'woocommerce-smart-coupons' ), ucfirst( $singular ) ), + /* translators: %s: Label for store credit */ + 'desc' => sprintf( __( '%s discount is inclusive of tax', 'woocommerce-smart-coupons' ), ucfirst( $singular ) ), + 'id' => 'woocommerce_smart_coupon_include_tax', + 'type' => 'checkbox', + 'default' => 'no', + 'checkboxgroup' => 'end', + 'autoload' => false, + 'show_if_checked' => 'yes', + ); + } + + array_splice( $sc_settings, 15, 0, $before_tax_option ); + } + + return apply_filters( 'wc_smart_coupons_settings', $sc_settings ); + + } + + /** + * Function for saving settings for Gift Certificate + */ + public function save_smart_coupon_admin_settings() { + if ( empty( $_POST['sc_security'] ) || ! wp_verify_nonce( wp_unslash( $_POST['sc_security'] ), 'wc_smart_coupons_settings' ) ) { // phpcs:ignore + return; + } + + $sc_settings = $this->get_settings(); + if ( ! is_array( $sc_settings ) || empty( $sc_settings ) ) { + return; + } + + woocommerce_update_options( $sc_settings ); + + // Update WC Email settings when SC admin settings are updated. + $is_send_email = get_option( 'smart_coupons_is_send_email', 'yes' ); + $combine_emails = get_option( 'smart_coupons_combine_emails', 'no' ); + + $email_settings = get_option( 'woocommerce_wc_sc_email_coupon_settings', array() ); + if ( is_array( $email_settings ) ) { + $email_settings['enabled'] = $is_send_email; + update_option( 'woocommerce_wc_sc_email_coupon_settings', $email_settings, 'no' ); + } + + $combine_email_settings = get_option( 'woocommerce_wc_sc_combined_email_coupon_settings', array() ); + if ( is_array( $combine_email_settings ) ) { + $combine_email_settings['enabled'] = $combine_emails; + update_option( 'woocommerce_wc_sc_combined_email_coupon_settings', $combine_email_settings, 'no' ); + } + + $predefined_colors = array( + '2b2d42-edf2f4-d90429', + '003459-ffffff-00a8e8', + '334752-fffdf5-46b39d', + 'edf2f4-bb2538-fcbf49', + 'd6b56d-231f20-ffe09c', + '362f78-f8f9fa-5950ec', + 'a82f82-f5f8ff-f45dc4', + '2c5f72-f3d2b3-f16a6c', + 'e37332-fefefe-de4f3c', + '8e6e5d-f2f2f2-333333', + 'a7e7ff-418fde-ffffff', + ); + + $color_options = array( + 'wc_sc_setting_coupon_background_color', + 'wc_sc_setting_coupon_foreground_color', + 'wc_sc_setting_coupon_third_color', + ); + $colors = array(); + foreach ( $color_options as $option ) { + $post_option = ( isset( $_POST[ $option ] ) ) ? wc_clean( wp_unslash( $_POST[ $option ] ) ) : ''; // phpcs:ignore + if ( ! empty( $post_option ) ) { + $colors[] = $post_option; + update_option( $option, $post_option, 'no' ); + } + } + $color_scheme = implode( '-', $colors ); + $color_scheme = str_replace( '#', '', $color_scheme ); + if ( in_array( $color_scheme, $predefined_colors, true ) ) { + update_option( 'wc_sc_setting_coupon_design_colors', $color_scheme, 'no' ); + } + + $old_storewide_offer_coupon_code = get_option( 'smart_coupons_storewide_offer_coupon_code' ); + $post_storewide_offer_coupon_code = ( ! empty( $_POST['smart_coupons_storewide_offer_coupon_code'] ) ) ? wc_clean( wp_unslash( $_POST['smart_coupons_storewide_offer_coupon_code'] ) ) : ''; // phpcs:ignore + if ( $old_storewide_offer_coupon_code !== $post_storewide_offer_coupon_code ) { + update_option( 'smart_coupons_storewide_offer_coupon_code', $post_storewide_offer_coupon_code, 'no' ); + if ( ! empty( $post_storewide_offer_coupon_code ) ) { + $coupon_id = wc_get_coupon_id_by_code( $post_storewide_offer_coupon_code ); + $coupon = new WC_Coupon( $coupon_id ); + $coupon_status = ( $this->is_wc_greater_than( '6.1.2' ) && $this->is_callable( $coupon, 'get_status' ) ) ? $coupon->get_status() : get_post_status( $coupon_id ); + if ( 'publish' === $coupon_status ) { + update_option( 'woocommerce_demo_store', 'yes' ); + } else { + update_option( 'woocommerce_demo_store', 'no' ); + } + update_option( 'woocommerce_demo_store_notice', '', 'no' ); + $notice = get_option( 'woocommerce_demo_store_notice' ); + if ( empty( $notice ) ) { + $coupon = new WC_Coupon( $post_storewide_offer_coupon_code ); + $notice = $this->generate_storewide_offer_coupon_description( array( 'coupon_object' => $coupon ) ); + update_option( 'woocommerce_demo_store_notice', wp_filter_post_kses( $notice ), 'no' ); + } + } else { + update_option( 'woocommerce_demo_store', 'no' ); + update_option( 'woocommerce_demo_store_notice', '', 'no' ); + } + } + + } + + /** + * Function to Add Delete Credit After Usage Notice + */ + public function add_delete_credit_after_usage_notice() { + + $is_delete_smart_coupon_after_usage = get_option( 'woocommerce_delete_smart_coupon_after_usage' ); + + if ( 'yes' !== $is_delete_smart_coupon_after_usage ) { + return; + } + + $admin_email = get_option( 'admin_email' ); + + $user = get_user_by( 'email', $admin_email ); + + $current_user_id = get_current_user_id(); + + if ( ! empty( $current_user_id ) && ! empty( $user->ID ) && $current_user_id === $user->ID ) { + add_action( 'admin_notices', array( $this, 'delete_credit_after_usage_notice' ) ); + add_action( 'admin_footer', array( $this, 'ignore_delete_credit_after_usage_notice' ) ); + } + + } + + /** + * Function to Delete Credit After Usage Notice + */ + public function delete_credit_after_usage_notice() { + global $store_credit_label; + $plural = ( ! empty( $store_credit_label['plural'] ) ) ? $store_credit_label['plural'] : __( 'store credits', 'woocommerce-smart-coupons' ); + $current_user_id = get_current_user_id(); + $is_hide_delete_after_usage_notice = get_user_meta( $current_user_id, 'hide_delete_credit_after_usage_notice', true ); // @codingStandardsIgnoreLine + if ( 'yes' !== $is_hide_delete_after_usage_notice ) { + echo '

          '; + if ( ! empty( $_GET['page'] ) && 'wc-settings' === $_GET['page'] && empty( $_GET['tab'] ) ) { // phpcs:ignore + /* translators: 1: plugin name 2: page based text 3: Label for store credit 4: Hide notice text */ + echo sprintf( esc_html__( '%1$s: %2$s to avoid issues related to missing data for %3$s. %4$s', 'woocommerce-smart-coupons' ), '' . esc_html__( 'WooCommerce Smart Coupons', 'woocommerce-smart-coupons' ) . '', esc_html__( 'Uncheck', 'woocommerce-smart-coupons' ) . ' "' . esc_html__( 'Delete Gift / Credit, when credit is used up', 'woocommerce-smart-coupons' ) . '"', esc_html( strtolower( $plural ) ), '' . esc_html__( 'Setting', 'woocommerce-smart-coupons' ) . '' ) . ' '; // phpcs ignore. + } else { + /* translators: 1: plugin name 2: page based text 3: Label for store credit 4: Hide notice text */ + echo sprintf( esc_html__( '%1$s: %2$s to avoid issues related to missing data for %3$s. %4$s', 'woocommerce-smart-coupons' ), '' . esc_html__( 'WooCommerce Smart Coupons', 'woocommerce-smart-coupons' ) . '', '' . esc_html__( 'Important setting', 'woocommerce-smart-coupons' ) . '', esc_html( strtolower( $plural ) ), '' . esc_html__( 'Setting', 'woocommerce-smart-coupons' ) . '' ) . ' '; // phpcs ignore. + } + echo '

          '; + } + + } + + /** + * Function to Ignore Delete Credit After Usage Notice + */ + public function ignore_delete_credit_after_usage_notice() { + + if ( ! wp_script_is( 'jquery' ) ) { + wp_enqueue_script( 'jquery' ); + } + + ?> + + $attribute_value ) { + $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"'; + } + } + + $field_description = WC_Admin_Settings::get_field_description( $value ); + $description = $field_description['description']; + $tooltip_html = $field_description['tooltip_html']; + + $option_value = $value['value']; + ?> + + + + + +
          + +
            + $val ) { + ?> +
          • + + + /> + +
          • + +
          +
          + + + '#39cccc', + 'wc_sc_setting_coupon_foreground_color' => '#30050b', + 'wc_sc_setting_coupon_third_color' => '#39cccc', + ); + foreach ( $color_options as $option => $default ) { + $color_code = get_option( $option, $default ); + ?> + + + + + + 10, + 'amount_symbol' => get_woocommerce_currency_symbol(), + 'discount_type' => __( 'Discount', 'woocommerce-smart-coupons' ), + 'coupon_description' => __( 'Hurry. Going fast! On the entire range of products.', 'woocommerce-smart-coupons' ), + 'coupon_code' => 'sample-code', + 'coupon_expiry' => $this->get_expiration_format( $this->strtotime( 'Dec 31' ) ), + 'thumbnail_src' => $this->get_coupon_design_thumbnail_src(), + 'classes' => '', + 'template_id' => $design, + 'is_percent' => false, + ); + ?> +
          + +
          + . + add_action( 'init', array( $this, 'register_smart_coupon_shortcode' ) ); + add_action( 'after_wp_tiny_mce', array( $this, 'smart_coupons_after_wp_tiny_mce' ) ); + add_filter( 'wc_sc_available_coupon_ids', array( $this, 'filter_coupon_ids' ), 10, 2 ); + + } + + /** + * Get single instance of WC_SC_Shortcode + * + * @return WC_SC_Shortcode Singleton object of WC_SC_Shortcode + */ + public static function get_instance() { + // Check if instance is already exists. + if ( is_null( self::$instance ) ) { + self::$instance = new self(); + } + + return self::$instance; + } + + /** + * Handle call to functions which is not available in this class + * + * @param string $function_name The function name. + * @param array $arguments Array of arguments passed while calling $function_name. + * @return result of function call + */ + public function __call( $function_name, $arguments = array() ) { + + global $woocommerce_smart_coupon; + + if ( ! is_callable( array( $woocommerce_smart_coupon, $function_name ) ) ) { + return; + } + + if ( ! empty( $arguments ) ) { + return call_user_func_array( array( $woocommerce_smart_coupon, $function_name ), $arguments ); + } else { + return call_user_func( array( $woocommerce_smart_coupon, $function_name ) ); + } + + } + + /** + * Add Smart Coupons shortcode button in WP editor + */ + public function smart_coupon_shortcode_button_init() { + + if ( get_user_option( 'rich_editing' ) === 'true' && ! current_user_can( 'manage_options' ) ) { // Add shortcode button to WP Editor only when the user is from the top level. + return; + } + + if ( ! wp_script_is( 'wpdialogs' ) ) { + wp_enqueue_script( 'wpdialogs' ); + } + + if ( ! wp_style_is( 'wp-jquery-ui-dialog' ) ) { + wp_enqueue_style( 'wp-jquery-ui-dialog' ); + } + + if ( ! wp_style_is( 'smart-coupon' ) ) { + wp_enqueue_style( 'smart-coupon' ); + } + + add_filter( 'mce_external_plugins', array( $this, 'smart_coupon_register_tinymce_plugin' ) ); + add_filter( 'mce_buttons', array( $this, 'smart_coupon_add_tinymce_button' ) ); + + } + + /** + * Add Smart Coupon short code button in TinyMCE + * + * @param array $plugin_array Existing plugin. + * @return array $plugin array with SMart Coupon shortcode + */ + public function smart_coupon_register_tinymce_plugin( $plugin_array ) { + $plugin_array['sc_shortcode_button'] = plugins_url( 'assets/js/sc-shortcode.js', WC_SC_PLUGIN_FILE ); + return $plugin_array; + } + + /** + * Add Smart coupon shortcode button in TinyMCE + * + * @param array $buttons Existing button. + * @return array $buttons With Smart Coupons shortcode button + */ + public function smart_coupon_add_tinymce_button( $buttons ) { + $buttons[] = 'sc_shortcode_button'; + return $buttons; + } + + /** + * Register shortcode for Smart Coupons + */ + public function register_smart_coupon_shortcode() { + add_shortcode( 'smart_coupons', array( $this, 'execute_smart_coupons_shortcode' ) ); + add_shortcode( 'wc_sc_available_coupons', array( $this, 'show_available_coupons_shortcode' ) ); + } + + /** + * Execute Smart Coupons shortcode + * + * @param array $atts Shortcode attributes. + * @return HTML code for coupon to be displayed + */ + public function execute_smart_coupons_shortcode( $atts ) { + + if ( is_admin() || wp_doing_ajax() || WC()->is_rest_api_request() ) { + return; + } + + ob_start(); + global $wpdb, $store_credit_label; + + $current_user = wp_get_current_user(); + $customer_id = $current_user->ID; + + $shortcode = shortcode_atts( + array( + 'coupon_code' => '', + 'discount_type' => 'smart_coupon', + 'coupon_amount' => '', + 'individual_use' => 'no', + 'product_ids' => '', + 'exclude_product_ids' => '', + 'usage_limit' => '', + 'usage_limit_per_user' => '', + 'limit_usage_to_x_items' => '', + 'expiry_date' => '', + 'apply_before_tax' => 'no', + 'free_shipping' => 'no', + 'product_categories' => '', + 'exclude_product_categories' => '', + 'minimum_amount' => '', + 'maximum_amount' => '', + 'exclude_sale_items' => 'no', + 'auto_generate' => 'no', + 'coupon_prefix' => '', + 'coupon_suffix' => '', + 'customer_email' => '', + 'coupon_style' => '', + 'disable_email' => 'no', + 'expiry_days' => '', + 'is_email' => 'no', + 'is_clickable' => 'no', + ), + $atts + ); + + $_coupon_code = $shortcode['coupon_code']; + $_discount_type = $shortcode['discount_type']; + $_coupon_amount = $shortcode['coupon_amount']; + $_expiry_date = $shortcode['expiry_date']; + $_free_shipping = $shortcode['free_shipping']; + $customer_email = $shortcode['customer_email']; + $coupon_prefix = $shortcode['coupon_prefix']; + $coupon_suffix = $shortcode['coupon_suffix']; + $individual_use = $shortcode['individual_use']; + $minimum_amount = $shortcode['minimum_amount']; + $maximum_amount = $shortcode['maximum_amount']; + $usage_limit = $shortcode['usage_limit']; + $apply_before_tax = $shortcode['apply_before_tax']; + $disable_email = $shortcode['disable_email']; + $expiry_days = $shortcode['expiry_days']; + $is_email = $shortcode['is_email']; + $is_clickable = $shortcode['is_clickable']; + + if ( empty( $_coupon_code ) && empty( $_coupon_amount ) ) { + return; // Minimum requirement for shortcode is either $_coupon_code or $_coupon_amount. + } + + if ( empty( $customer_email ) ) { + + if ( ! ( $current_user instanceof WP_User ) ) { + $current_user = wp_get_current_user(); + $customer_email = ( isset( $current_user->user_email ) ) ? $current_user->user_email : ''; + } else { + $customer_email = ( ! empty( $current_user->data->user_email ) ) ? $current_user->data->user_email : ''; + } + } + + if ( ! empty( $_coupon_code ) && ! empty( $customer_email ) ) { + $coupon_exists = wp_cache_get( 'wc_sc_shortcode_coupon_id_' . sanitize_key( $customer_email ), 'woocommerce_smart_coupons' ); + if ( false === $coupon_exists ) { + $coupon_exists = $wpdb->get_var( // phpcs:ignore + $wpdb->prepare( + "SELECT ID + FROM {$wpdb->prefix}posts AS posts + LEFT JOIN {$wpdb->prefix}postmeta AS postmeta + ON ( postmeta.post_id = posts.ID ) + WHERE posts.post_title = %s + AND posts.post_type = %s + AND posts.post_status = %s + AND postmeta.meta_key = %s + AND postmeta.meta_value LIKE %s", + strtolower( $_coupon_code ), + 'shop_coupon', + 'publish', + 'customer_email', + '%' . $wpdb->esc_like( '"' . $customer_email . '"' ) . '%' + ) + ); + wp_cache_set( 'wc_sc_shortcode_coupon_id_' . sanitize_key( $customer_email ), $coupon_exists, 'woocommerce_smart_coupons' ); + $this->maybe_add_cache_key( 'wc_sc_shortcode_coupon_id_' . sanitize_key( $customer_email ) ); + } + } else { + $coupon_exists = null; + } + + $is_generate = apply_filters( + 'wc_sc_shortcode_always_generate_coupon', + ( null === $coupon_exists ), + array( + 'source' => $this, + 'shortcode_attributes' => $shortcode, + ) + ); + + $_expiry_date = ''; + + if ( ! wp_style_is( 'smart-coupon' ) ) { + wp_enqueue_style( 'smart-coupon' ); + } + + $all_discount_types = wc_get_coupon_types(); + + if ( true === $is_generate ) { + + if ( ! empty( $_coupon_code ) ) { + $coupon = new WC_Coupon( $_coupon_code ); + $is_callable_coupon_update_meta = $this->is_callable( $coupon, 'update_meta_data' ); + + if ( $this->is_wc_gte_30() ) { + if ( ! is_object( $coupon ) || ! is_callable( array( $coupon, 'get_id' ) ) ) { + return; + } + $coupon_id = $coupon->get_id(); + if ( empty( $coupon_id ) ) { + return; + } + $is_free_shipping = ( $coupon->get_free_shipping() ) ? 'yes' : 'no'; + $discount_type = $coupon->get_discount_type(); + $expiry_date = $coupon->get_date_expires(); + $coupon_code = $coupon->get_code(); + } else { + $coupon_id = ( ! empty( $coupon->id ) ) ? $coupon->id : 0; + $is_free_shipping = ( ! empty( $coupon->free_shipping ) ) ? $coupon->free_shipping : ''; + $discount_type = ( ! empty( $coupon->discount_type ) ) ? $coupon->discount_type : ''; + $expiry_date = ( ! empty( $coupon->expiry_date ) ) ? $coupon->expiry_date : ''; + $coupon_code = ( ! empty( $coupon->code ) ) ? $coupon->code : ''; + } + + $coupon_amount = $this->get_amount( $coupon, true ); + + $is_callable_coupon_get_meta = $this->is_callable( $coupon, 'get_meta' ); + + if ( ! empty( $discount_type ) ) { + + $is_auto_generate = ( true === $is_callable_coupon_get_meta ) ? $coupon->get_meta( 'auto_generate_coupon' ) : get_post_meta( $coupon_id, 'auto_generate_coupon', true ); + $is_disable_email_restriction = ( true === $is_callable_coupon_get_meta ) ? $coupon->get_meta( 'sc_disable_email_restriction' ) : get_post_meta( $coupon_id, 'sc_disable_email_restriction', true ); + + if ( ( empty( $is_disable_email_restriction ) || 'no' === $is_disable_email_restriction ) && ( empty( $is_auto_generate ) || 'no' === $is_auto_generate ) ) { + $existing_customer_emails = ( $this->is_callable( $coupon, 'get_email_restrictions' ) ) ? $coupon->get_email_restrictions() : get_post_meta( $coupon_id, 'customer_email', true ); + if ( empty( $existing_customer_emails ) || ! is_array( $existing_customer_emails ) ) { + $existing_customer_emails = array(); + } + $existing_customer_emails[] = $customer_email; + if ( true === $is_callable_coupon_update_meta ) { + $coupon->set_email_restrictions( $existing_customer_emails ); + } else { + update_post_meta( $coupon_id, 'customer_email', $existing_customer_emails ); + } + } + + if ( ! empty( $is_auto_generate ) && 'yes' === $is_auto_generate ) { + + if ( 0 === $current_user->ID ) { + if ( 'smart_coupon' === $discount_type ) { + return; // Don't generate & don't show coupon if coupon of the shortcode is store credit & user is guest, otherwise it'll lead to unlimited generation of coupon. + } else { + $new_generated_coupon_code = $coupon_code; + } + } elseif ( true === $is_generate && 'yes' === $is_email ) { + $generated_coupon_details = $this->generate_smart_coupon_action( $customer_email, $coupon_amount, '', $coupon ); + $last_element = end( $generated_coupon_details[ $customer_email ] ); + $new_generated_coupon_code = $last_element['code']; + } else { + + $shortcode_generated_coupon = $this->get_shortcode_generated_coupon( $current_user, $coupon ); + + if ( empty( $shortcode_generated_coupon ) || ( true === $is_generate && 'yes' === $is_email ) ) { + $generated_coupon_details = $this->generate_smart_coupon_action( $customer_email, $coupon_amount, '', $coupon ); + $last_element = end( $generated_coupon_details[ $customer_email ] ); + $new_generated_coupon_code = $last_element['code']; + $this->save_shortcode_generated_coupon( $new_generated_coupon_code, $current_user, $coupon ); + } else { + $new_generated_coupon_code = $shortcode_generated_coupon; + } + } + } else { + + $new_generated_coupon_code = $_coupon_code; + + } + } + } + + if ( ( ! empty( $_coupon_code ) && empty( $discount_type ) ) || ( empty( $_coupon_code ) ) ) { + + if ( empty( $current_user->ID ) && ( 'smart_coupon' === $_discount_type || 'smart_coupon' === $discount_type ) ) { + return; // It'll prevent generation of unlimited coupons for guest. + } + + if ( empty( $coupon ) ) { + $coupon = null; + } + + $shortcode_generated_coupon = $this->get_shortcode_generated_coupon( $current_user, $coupon ); + + if ( empty( $shortcode_generated_coupon ) ) { + + if ( empty( $_coupon_code ) ) { + $_coupon_code = $this->generate_unique_code( $customer_email ); + $_coupon_code = $coupon_prefix . $_coupon_code . $coupon_suffix; + } + + $coupon_args = array( + 'post_title' => strtolower( $_coupon_code ), + 'post_content' => '', + 'post_status' => 'publish', + 'post_author' => 1, + 'post_type' => 'shop_coupon', + 'post_parent' => ! empty( $coupon_id ) ? absint( $coupon_id ) : 0, + ); + + $new_coupon = new WC_Coupon( $coupon_args['post_title'] ); + + if ( $this->is_wc_greater_than( '6.1.2' ) && $this->is_callable( $new_coupon, 'set_status' ) ) { + $new_coupon->set_status( $coupon_args['post_status'] ); + } + + $new_coupon_id = $new_coupon->save(); + + if ( ! empty( $new_coupon_id ) ) { + $coupon_args = array_diff_key( $coupon_args, array_flip( array( 'post_title', 'post_status', 'post_type' ) ) ); + $coupon_args['ID'] = $new_coupon_id; + wp_update_post( $coupon_args ); + } + + $new_coupon_id = absint( $new_coupon_id ); + + $new_coupon = new WC_Coupon( $new_coupon ); + + $is_callable_new_coupon_update_meta = $this->is_callable( $new_coupon, 'update_meta_data' ); + + if ( ! empty( $shortcode['expiry_date'] ) ) { + $timestamp = $this->strtotime( $shortcode['expiry_date'] ) + $this->wc_timezone_offset(); + $_expiry_date = gmdate( 'Y-m-d', $timestamp ); + } elseif ( ! empty( $expiry_days ) ) { + $timestamp = $this->strtotime( "+$expiry_days days" ) + $this->wc_timezone_offset(); + $_expiry_date = gmdate( 'Y-m-d', $timestamp ); + } + if ( $this->is_wc_gte_30() ) { + if ( ! empty( $_expiry_date ) ) { + $_expiry_date = $this->strtotime( $_expiry_date ) - $this->wc_timezone_offset(); + $_expiry_date = $this->get_date_expires_value( $_expiry_date ); + if ( true === $is_callable_new_coupon_update_meta ) { + $new_coupon->set_date_expires( $_expiry_date ); + } else { + update_post_meta( $new_coupon_id, 'date_expires', $_expiry_date ); + } + } + } else { + if ( true === $is_callable_new_coupon_update_meta ) { + $new_coupon->update_meta_data( 'expiry_date', $_expiry_date ); + } else { + update_post_meta( $new_coupon_id, 'expiry_date', $_expiry_date ); + } + } + + if ( 'smart_coupon' === $_discount_type ) { + $this->update_post_meta( $new_coupon_id, 'wc_sc_original_amount', $_coupon_amount, false ); + } + + if ( true === $is_callable_new_coupon_update_meta ) { + $new_coupon->set_discount_type( $_discount_type ); + $new_coupon->set_amount( $_coupon_amount ); + $new_coupon->set_individual_use( $this->wc_string_to_bool( $individual_use ) ); + $new_coupon->set_minimum_amount( $minimum_amount ); + $new_coupon->set_maximum_amount( $maximum_amount ); + $new_coupon->set_usage_limit( $usage_limit ); + $new_coupon->set_email_restrictions( array( $customer_email ) ); + $new_coupon->update_meta_data( 'apply_before_tax', $apply_before_tax ); + $new_coupon->set_free_shipping( $this->wc_string_to_bool( $_free_shipping ) ); + $new_coupon->set_product_categories( array() ); + $new_coupon->set_excluded_product_categories( array() ); + $new_coupon->update_meta_data( 'sc_disable_email_restriction', $disable_email ); + } else { + update_post_meta( $new_coupon_id, 'discount_type', $_discount_type ); + update_post_meta( $new_coupon_id, 'coupon_amount', $_coupon_amount ); + update_post_meta( $new_coupon_id, 'individual_use', $individual_use ); + update_post_meta( $new_coupon_id, 'minimum_amount', $minimum_amount ); + update_post_meta( $new_coupon_id, 'maximum_amount', $maximum_amount ); + update_post_meta( $new_coupon_id, 'usage_limit', $usage_limit ); + update_post_meta( $new_coupon_id, 'customer_email', array( $customer_email ) ); + update_post_meta( $new_coupon_id, 'apply_before_tax', $apply_before_tax ); + update_post_meta( $new_coupon_id, 'free_shipping', $_free_shipping ); + update_post_meta( $new_coupon_id, 'product_categories', array() ); + update_post_meta( $new_coupon_id, 'exclude_product_categories', array() ); + update_post_meta( $new_coupon_id, 'sc_disable_email_restriction', $disable_email ); + } + + if ( $this->is_callable( $new_coupon, 'save' ) ) { + $new_coupon->save(); + } + + $new_generated_coupon_code = $_coupon_code; + $this->save_shortcode_generated_coupon( $new_generated_coupon_code, $current_user, $coupon ); + + } else { + + $new_generated_coupon_code = $shortcode_generated_coupon; + + } + } + } else { + + $new_generated_coupon_code = $_coupon_code; + + } + + $new_coupon_generated = false; + if ( ! empty( $new_generated_coupon_code ) ) { + $coupon = new WC_Coupon( $new_generated_coupon_code ); + $new_coupon_generated = true; + } + + if ( $new_coupon_generated ) { + if ( $this->is_wc_gte_30() ) { + if ( ! is_object( $coupon ) || ! is_callable( array( $coupon, 'get_id' ) ) ) { + return; + } + $coupon_id = $coupon->get_id(); + if ( empty( $coupon_id ) ) { + return; + } + $is_free_shipping = ( $coupon->get_free_shipping() ) ? 'yes' : 'no'; + $discount_type = $coupon->get_discount_type(); + $expiry_date = $coupon->get_date_expires(); + $coupon_code = $coupon->get_code(); + } else { + $coupon_id = ( ! empty( $coupon->id ) ) ? $coupon->id : 0; + $is_free_shipping = ( ! empty( $coupon->free_shipping ) ) ? $coupon->free_shipping : ''; + $discount_type = ( ! empty( $coupon->discount_type ) ) ? $coupon->discount_type : ''; + $expiry_date = ( ! empty( $coupon->expiry_date ) ) ? $coupon->expiry_date : ''; + $coupon_code = ( ! empty( $coupon->code ) ) ? $coupon->code : ''; + } + } + + $coupon_amount = $this->get_amount( $coupon, true ); + + $coupon_post = get_post( $coupon_id ); + + $coupon_data = $this->get_coupon_meta_data( $coupon ); + + $design = get_option( 'wc_sc_setting_coupon_design', 'basic' ); + $background_color = get_option( 'wc_sc_setting_coupon_background_color', '#39cccc' ); + $foreground_color = get_option( 'wc_sc_setting_coupon_foreground_color', '#30050b' ); + $third_color = get_option( 'wc_sc_setting_coupon_third_color', '#39cccc' ); + + $show_coupon_description = get_option( 'smart_coupons_show_coupon_description', 'no' ); + + $valid_designs = $this->get_valid_coupon_designs(); + + if ( ! in_array( $design, $valid_designs, true ) ) { + $design = 'basic'; + } + + if ( 'yes' === $is_email ) { + $design = ( 'custom-design' !== $design ) ? 'email-coupon' : $design; + } + + ?> + + + + + + is_wc_gte_30() && $expiry_date instanceof WC_DateTime ) { + $expiry_date = ( is_callable( array( $expiry_date, 'getTimestamp' ) ) ) ? $expiry_date->getTimestamp() : null; + } elseif ( ! is_int( $expiry_date ) ) { + $expiry_date = $this->strtotime( $expiry_date ); + } + + if ( ! empty( $expiry_date ) && is_int( $expiry_date ) ) { + $expiry_time = ( $this->is_callable( $coupon, 'get_meta' ) ) ? (int) $coupon->get_meta( 'wc_sc_expiry_time' ) : (int) get_post_meta( $coupon_id, 'wc_sc_expiry_time', true ); + if ( ! empty( $expiry_time ) ) { + $expiry_date += $expiry_time; // Adding expiry time to expiry date. + } + } + + $coupon_description = ''; + if ( ! empty( $coupon_post->post_excerpt ) && 'yes' === $show_coupon_description ) { + $coupon_description = $coupon_post->post_excerpt; + } + + $is_percent = $this->is_percent_coupon( array( 'coupon_object' => $coupon ) ); + + $args = array( + 'coupon_object' => $coupon, + 'coupon_amount' => $coupon_amount, + 'amount_symbol' => ( true === $is_percent ) ? '%' : get_woocommerce_currency_symbol(), + 'discount_type' => wp_strip_all_tags( $coupon_type ), + 'coupon_description' => ( ! empty( $coupon_description ) ) ? $coupon_description : wp_strip_all_tags( $this->generate_coupon_description( array( 'coupon_object' => $coupon ) ) ), + 'coupon_code' => $new_generated_coupon_code, + 'coupon_expiry' => ( ! empty( $expiry_date ) ) ? $this->get_expiration_format( $expiry_date ) : __( 'Never expires', 'woocommerce-smart-coupons' ), + 'thumbnail_src' => $this->get_coupon_design_thumbnail_src( + array( + 'design' => $design, + 'coupon_object' => $coupon, + ) + ), + 'classes' => '', + 'template_id' => $design, + 'is_percent' => $is_percent, + ); + + $coupon_target = ''; + $wc_url_coupons_active_urls = get_option( 'wc_url_coupons_active_urls' ); // From plugin WooCommerce URL coupons. + if ( ! empty( $wc_url_coupons_active_urls ) ) { + $coupon_target = ( ! empty( $wc_url_coupons_active_urls[ $coupon_id ]['url'] ) ) ? $wc_url_coupons_active_urls[ $coupon_id ]['url'] : ''; + } + if ( ! empty( $coupon_target ) ) { + $coupon_target = home_url( '/' . $coupon_target ); + } else { + $coupon_target = home_url( '/?sc-page=shop&coupon-code=' . $coupon_code ); + } + + $coupon_target = apply_filters( 'sc_coupon_url_in_email', $coupon_target, $coupon ); + + do_action( + 'wc_sc_before_shortcode_smart_coupons_html_start', + array( + 'source' => $this, + 'shortcode_attributes' => $shortcode, + 'coupon_object' => $coupon, + ) + ); + + if ( 'yes' === $is_email ) { + echo ''; + } + + return ob_get_clean(); + } + + /** + * Show available coupons + * + * @param array $atts Shortcode attributes. + * @return HTML code for coupon to be displayed + */ + public function show_available_coupons_shortcode( $atts ) { + + if ( is_admin() || wp_doing_ajax() || WC()->is_rest_api_request() ) { + return; + } + + $shortcode = shortcode_atts( + array( + 'title' => get_option( 'smart_coupon_cart_page_text' ), + 'categories' => '', // expecting comma-separated term ids. + ), + $atts, + 'wc_sc_available_coupons' + ); + // To override shortcode attributes use filter 'shortcode_atts_wc_sc_available_coupons'. For more details refer this https://developer.wordpress.org/reference/functions/shortcode_atts/. + + $title = $shortcode['title']; + + $shortcode['categories'] = ( ! empty( $shortcode['categories'] ) && is_string( $shortcode['categories'] ) ) ? explode( ',', $shortcode['categories'] ) : array(); + + if ( ! class_exists( 'WC_SC_Display_Coupons' ) ) { + include_once 'class-wc-sc-display-coupons.php'; + } + $wc_sc_display_coupons = WC_SC_Display_Coupons::get_instance(); + + if ( ! is_object( $wc_sc_display_coupons ) || ! is_callable( array( $wc_sc_display_coupons, 'show_available_coupons' ) ) ) { + return ''; + } + + ob_start(); + $wc_sc_display_coupons->show_available_coupons( + $title, + get_the_title(), + array( + 'source' => $this, + 'shortcode_atts' => $shortcode, + ) + ); + $output = ob_get_clean(); + $stripped_output = wp_strip_all_tags( $output, true ); + if ( ( ! empty( $title ) && $stripped_output === $title ) || empty( $stripped_output ) ) { + $no_output_text = apply_filters( + 'wc_sc_shortcode_no_coupon_found_text', + $this->sc_get_option( 'wc_sc_shortcode_no_coupon_found_text', '' ), + array( + 'source' => $this, + 'shortcode_atts' => $shortcode, + ) + ); + return ( ! empty( $no_output_text ) ) ? '

          ' . wp_kses_post( $no_output_text ) . '

          ' : ''; + } + return $output; + } + + /** + * Function to check whether to generate a new coupon through shortcode for current user + * Don't create if it is already generated. + * + * @param WP_User $current_user The user object. + * @param WC_Coupon $coupon The coupon object. + * @return string $code + */ + public function get_shortcode_generated_coupon( $current_user = null, $coupon = null ) { + + $max_in_a_session = get_option( '_sc_max_coupon_generate_in_a_session', 1 ); + $max_per_coupon_per_user = get_option( '_sc_max_coupon_per_coupon_per_user', 1 ); + + if ( $this->is_wc_gte_30() ) { + $coupon_code = ( ! empty( $coupon ) && is_callable( array( $coupon, 'get_code' ) ) ) ? $coupon->get_code() : ''; + } else { + $coupon_code = ( ! empty( $coupon->code ) ) ? $coupon->code : ''; + } + + $code = ( ! empty( $coupon_code ) ) ? $coupon_code : ''; + + if ( ! empty( $current_user->ID ) ) { + + $generated_coupons = get_user_meta( $current_user->ID, '_sc_shortcode_generated_coupons', true ); + + if ( ! empty( $generated_coupons[ $code ] ) && count( $generated_coupons[ $code ] ) >= $max_per_coupon_per_user ) { + return end( $generated_coupons[ $code ] ); + } + } + + $session_shortcode_coupons = ( is_object( WC()->session ) && is_callable( array( WC()->session, 'get' ) ) ) ? WC()->session->get( '_sc_session_shortcode_generated_coupons' ) : array(); + + if ( ! empty( $session_shortcode_coupons[ $code ] ) && count( $session_shortcode_coupons[ $code ] ) >= $max_in_a_session ) { + return end( $session_shortcode_coupons[ $code ] ); + } + + return false; + + } + + /** + * Function to save shortcode generated coupon details + * + * @param string $new_code The coupon code. + * @param WP_User $current_user The user object. + * @param WC_Coupon $coupon The coupon object. + */ + public function save_shortcode_generated_coupon( $new_code, $current_user, $coupon ) { + + if ( $this->is_wc_gte_30() ) { + $coupon_code = ( ! empty( $coupon ) && is_callable( array( $coupon, 'get_code' ) ) ) ? $coupon->get_code() : ''; + } else { + $coupon_code = ( ! empty( $coupon->code ) ) ? $coupon->code : ''; + } + + $code = ( ! empty( $coupon_code ) ) ? $coupon_code : 0; + + $session_shortcode_coupons = ( is_object( WC()->session ) && is_callable( array( WC()->session, 'get' ) ) ) ? WC()->session->get( '_sc_session_shortcode_generated_coupons' ) : array(); + + if ( empty( $session_shortcode_coupons ) || ! is_array( $session_shortcode_coupons ) ) { + $session_shortcode_coupons = array(); + } + if ( empty( $session_shortcode_coupons[ $code ] ) ) { + $session_shortcode_coupons[ $code ] = array(); + } + if ( ! in_array( $new_code, $session_shortcode_coupons[ $code ], true ) ) { + $session_shortcode_coupons[ $code ][] = $new_code; + if ( is_object( WC()->session ) && is_callable( array( WC()->session, 'set' ) ) ) { + WC()->session->set( '_sc_session_shortcode_generated_coupons', $session_shortcode_coupons ); + } + } + + if ( ! empty( $current_user->ID ) ) { + $generated_coupons = get_user_meta( $current_user->ID, '_sc_shortcode_generated_coupons', true ); + if ( empty( $generated_coupons ) ) { + $generated_coupons = array(); + } + if ( empty( $generated_coupons[ $code ] ) ) { + $generated_coupons[ $code ] = array(); + } + if ( ! in_array( $new_code, $generated_coupons[ $code ], true ) ) { + $generated_coupons[ $code ][] = $new_code; + update_user_meta( $current_user->ID, '_sc_shortcode_generated_coupons', $generated_coupons ); + } + } + + } + + /** + * Smart coupon button after TinyMCE + * + * @param mixed $mce_settings The editor settings. + */ + public function smart_coupons_after_wp_tiny_mce( $mce_settings ) { + if ( ! is_admin() || ! current_user_can( 'manage_options' ) ) { // Show shortcode attribute dialog to only top level users. + return; + } + $this->sc_attributes_dialog(); + } + + /** + * Smart Coupons dialog content for shortcode + */ + public function sc_attributes_dialog() { + + ?> +
          +
          + + + + +
          +
          +
          + +
          +
          +
          +
          +
            +
            +
            +
            +
            +
            +
            +
            + +
            + get_valid_coupon_designs(); + + if ( ! in_array( $design, $valid_designs, true ) ) { + $design = 'basic'; + } + ?> + + + + + 'XX', + 'amount_symbol' => get_woocommerce_currency_symbol(), + 'discount_type' => 'Discount type', + 'coupon_description' => 'Description', + 'coupon_code' => 'coupon-code', + 'coupon_expiry' => 'Expires on xx date', + 'thumbnail_src' => '', + 'classes' => '', + 'template_id' => $design, + 'is_percent' => false, + ); + wc_get_template( 'coupon-design/' . $design . '.php', $args, '', plugin_dir_path( WC_SC_PLUGIN_FILE ) . 'templates/' ); + ?> +
            +
            +
            +
            + +
            +
            + +
            +
            +
            +
            + $this, + 'query_args' => $coupon_args, + ) + ); + + if ( is_array( $coupon_codes ) ) { + foreach ( $coupon_codes as $coupon_index => $coupon_code ) { + // Process only first five coupons to avoid GET request parameter limit. + if ( $max_url_coupons_limit === $coupon_index ) { + break; + } + + if ( empty( $coupon_code ) ) { + continue; + } + + $coupons_data[] = array( + 'coupon-code' => $coupon_code, + ); + } + } + + $cart = ( is_object( WC() ) && isset( WC()->cart ) ) ? WC()->cart : null; + $is_cart_empty = is_a( $cart, 'WC_Cart' ) && is_callable( array( $cart, 'is_empty' ) ) && $cart->is_empty(); + + if ( true === $is_cart_empty ) { + $is_hold = apply_filters( + 'wc_sc_hold_applied_coupons', + true, + array( + 'coupons_data' => $coupons_data, + 'source' => $this, + ) + ); + if ( true === $is_hold ) { + $this->hold_applied_coupon( $coupons_data ); + } + // Set a session cookie to persist the coupon in case the cart is empty. This code will persist the coupon even if the param sc-page is not supplied. + WC()->session->set_customer_session_cookie( true ); // Thanks to: Devon Godfrey. + } else { + foreach ( $coupons_data as $coupon_data ) { + $coupon_code = $coupon_data['coupon-code']; + $coupon = new WC_Coupon( $coupon_code ); + if ( ! WC()->cart->has_discount( $coupon_code ) && $this->is_valid( $coupon ) ) { + WC()->cart->add_discount( trim( $coupon_code ) ); + } + } + } + + if ( ! empty( $coupon_args['add-to-cart'] ) ) { + add_filter( 'woocommerce_add_to_cart_redirect', array( $this, 'add_to_cart_redirect' ), 20, 2 ); + return; // Redirection handed over to WooCommerce. + } + + if ( empty( $coupon_args['sc-page'] ) ) { + return; + } + + $redirect_url = $this->get_sc_redirect_url( $coupon_args ); + + wp_safe_redirect( $redirect_url ); + exit; + + } + + /** + * Get Smart Coupons redirect url. + * + * @param array $coupon_args Coupon args. + * @return string + */ + public function get_sc_redirect_url( $coupon_args = array() ) { + $redirect_url = ''; + + if ( empty( $coupon_args ) || ! is_array( $coupon_args ) ) { + return $redirect_url; + } + + if ( in_array( $coupon_args['sc-page'], array( 'shop', 'cart', 'checkout', 'myaccount' ), true ) ) { + $page_id = $this->is_wc_gte_30() ? wc_get_page_id( $coupon_args['sc-page'] ) : woocommerce_get_page_id( $coupon_args['sc-page'] ); + $redirect_url = get_permalink( $page_id ); + } elseif ( is_string( $coupon_args['sc-page'] ) ) { + if ( is_numeric( $coupon_args['sc-page'] ) && ! is_float( $coupon_args['sc-page'] ) ) { + $page = $coupon_args['sc-page']; + } else { + $page = ( function_exists( 'wpcom_vip_get_page_by_path' ) ) ? wpcom_vip_get_page_by_path( $coupon_args['sc-page'], OBJECT, get_post_types() ) : get_page_by_path( $coupon_args['sc-page'], OBJECT, get_post_types() ); // phpcs:ignore + } + $redirect_url = get_permalink( $page ); + } elseif ( is_numeric( $coupon_args['sc-page'] ) && ! is_float( $coupon_args['sc-page'] ) ) { + $redirect_url = get_permalink( $coupon_args['sc-page'] ); + } + + if ( empty( $redirect_url ) ) { + $redirect_url = home_url(); + } + + // unset known values in the array to re-build URL params below. + if ( isset( $coupon_args['coupon-code'] ) ) { + unset( $coupon_args['coupon-code'] ); + } + if ( isset( $coupon_args['sc-page'] ) ) { + unset( $coupon_args['sc-page'] ); + } + if ( isset( $coupon_args['add-to-cart'] ) ) { + unset( $coupon_args['add-to-cart'] ); + } + + // Not using WP's build_query due to performance. + $additional_url_params = http_build_query( $coupon_args ); + if ( ! empty( $additional_url_params ) ) { + $redirect_url .= ( ( false === strpos( $additional_url_params, '?' ) ) ? '?' : '&' ) . $additional_url_params; + } + + return $this->get_redirect_url_after_smart_coupons_process( $redirect_url ); + } + + /** + * WooCommerce handles add to cart redirect. + * + * @param string $url The redirect URL. + * @param WC_Product $product Product. + * @return string + */ + public function add_to_cart_redirect( $url = '', $product = null ) { + remove_filter( 'woocommerce_add_to_cart_redirect', array( $this, 'add_to_cart_redirect' ), 20 ); + + if ( empty( $_SERVER['QUERY_STRING'] ) ) { + return $url; + } + + parse_str( wp_unslash( $_SERVER['QUERY_STRING'] ), $coupon_args ); // phpcs:ignore + $coupon_args = wc_clean( $coupon_args ); + + $cart = ( is_object( WC() ) && isset( WC()->cart ) ) ? WC()->cart : null; + $is_cart_empty = is_a( $cart, 'WC_Cart' ) && is_callable( array( $cart, 'is_empty' ) ) && $cart->is_empty(); + + if ( false === $is_cart_empty && ! empty( $coupon_args['coupon-code'] ) ) { + $coupon_args['coupon-code'] = urldecode( $coupon_args['coupon-code'] ); + + $coupon_codes = explode( ',', $coupon_args['coupon-code'] ); + $coupon_codes = array_filter( $coupon_codes ); // Remove empty coupon codes if any. + + if ( ! empty( $coupon_codes ) ) { + $max_url_coupons_limit = apply_filters( 'wc_sc_max_url_coupons_limit', 5 ); + $coupon_codes = ( ! empty( $max_url_coupons_limit ) ) ? array_slice( $coupon_codes, 0, $max_url_coupons_limit ) : array(); + foreach ( $coupon_codes as $coupon_code ) { + $coupon = new WC_Coupon( $coupon_code ); + if ( ! WC()->cart->has_discount( $coupon_code ) && $this->is_valid( $coupon ) ) { + WC()->cart->add_discount( trim( $coupon_code ) ); + } + } + } + } + + if ( ! empty( $coupon_args['sc-page'] ) ) { + return $this->get_sc_redirect_url( $coupon_args ); + } + + return $url; + } + + /** + * Apply coupon code from session, if any. + */ + public function apply_coupon_from_session() { + + $cart = ( is_object( WC() ) && isset( WC()->cart ) ) ? WC()->cart : null; + if ( empty( $cart ) || WC()->cart->is_empty() ) { + return; + } + + $user_id = get_current_user_id(); + + if ( 0 === $user_id ) { + $unique_id = ( ! empty( $_COOKIE['sc_applied_coupon_profile_id'] ) ) ? wc_clean( wp_unslash( $_COOKIE['sc_applied_coupon_profile_id'] ) ) : ''; // phpcs:ignore + $applied_coupon_from_url = ( ! empty( $unique_id ) ) ? $this->get_applied_coupons_by_guest_user( $unique_id ) : array(); + } else { + $applied_coupon_from_url = get_user_meta( $user_id, 'sc_applied_coupon_from_url', true ); + } + + if ( empty( $applied_coupon_from_url ) || ! is_array( $applied_coupon_from_url ) ) { + return; + } + + foreach ( $applied_coupon_from_url as $index => $coupon_code ) { + $coupon = new WC_Coupon( $coupon_code ); + if ( $this->is_valid( $coupon ) && ! WC()->cart->has_discount( $coupon_code ) ) { + WC()->cart->add_discount( trim( $coupon_code ) ); + unset( $applied_coupon_from_url[ $index ] ); + } + } + + if ( 0 === $user_id ) { + $this->set_applied_coupon_for_guest_user( $unique_id, $applied_coupon_from_url ); + } else { + update_user_meta( $user_id, 'sc_applied_coupon_from_url', $applied_coupon_from_url ); + } + + } + + /** + * Apply coupon code from session, if any. + * + * @param array $coupons_args The coupon arguments. + */ + public function hold_applied_coupon( $coupons_args = array() ) { + + if ( empty( $coupons_args ) ) { + return; + } + + $user_id = get_current_user_id(); + + $saved_status = array(); + $saved_status = ( 0 === $user_id ) ? $this->save_applied_coupon_in_cookie( $coupons_args ) : $this->save_applied_coupon_in_account( $coupons_args, $user_id ); + if ( empty( $saved_status ) ) { + return; + } + + foreach ( $coupons_args as $coupon_args ) { + $coupon_code = $coupon_args['coupon-code']; + $save_status = isset( $saved_status[ $coupon_code ] ) ? $saved_status[ $coupon_code ] : ''; + if ( 'saved' === $save_status ) { + /* translators: %s: $coupon_code coupon code */ + $notice = sprintf( _x( 'Coupon code "%s" applied successfully. Please add some products to the cart to see the discount.', 'This notice will be shown on the cart or the checkout page if the coupon will be applied successfully.', 'woocommerce-smart-coupons' ), $coupon_code ); + wc_add_notice( $notice, 'success' ); + } elseif ( 'already_saved' === $save_status ) { + /* translators: %s: $coupon_code coupon code */ + $notice = sprintf( _x( 'Coupon code "%s" already applied! Please add some products to the cart to see the discount.', 'This notice will be shown on the cart or the checkout page if the coupon is already applied.', 'woocommerce-smart-coupons' ), $coupon_code ); + wc_add_notice( $notice, 'error' ); + } + } + + } + + /** + * Apply coupon code from session, if any. + * + * @param array $coupons_args The coupon arguments. + * @return array $saved_status + */ + public function save_applied_coupon_in_cookie( $coupons_args = array() ) { + + // Variable to store whether coupons saved/already saved in cookie. + $saved_status = array(); + + if ( empty( $coupons_args ) ) { + return $saved_status; + } + + if ( empty( $_COOKIE['sc_applied_coupon_profile_id'] ) ) { + $unique_id = $this->generate_unique_id(); + } else { + $unique_id = wc_clean( wp_unslash( $_COOKIE['sc_applied_coupon_profile_id'] ) ); // phpcs:ignore + } + + $applied_coupons = $this->get_applied_coupons_by_guest_user( $unique_id ); + + foreach ( $coupons_args as $coupon_args ) { + $coupon_code = isset( $coupon_args['coupon-code'] ) ? $coupon_args['coupon-code'] : ''; + if ( is_array( $applied_coupons ) && in_array( $coupon_code, $applied_coupons, true ) ) { + $saved_status[ $coupon_code ] = 'already_saved'; + } else { + $applied_coupons[] = $coupon_code; + $saved_status[ $coupon_code ] = 'saved'; + } + } + + $this->set_applied_coupon_for_guest_user( $unique_id, $applied_coupons ); + wc_setcookie( 'sc_applied_coupon_profile_id', $unique_id, $this->get_cookie_life() ); + + return $saved_status; + } + + /** + * Apply coupon code from session, if any. + * + * @param array $coupons_args The coupon arguments. + * @param int $user_id The user id. + * @return array $saved_status + */ + public function save_applied_coupon_in_account( $coupons_args = array(), $user_id = 0 ) { + + // Variable to store whether coupons saved/already saved in user meta. + $saved_status = array(); + + if ( ! empty( $coupons_args ) ) { + + $applied_coupons = get_user_meta( $user_id, 'sc_applied_coupon_from_url', true ); + + if ( empty( $applied_coupons ) ) { + $applied_coupons = array(); + } + + foreach ( $coupons_args as $coupon_args ) { + $coupon_code = $coupon_args['coupon-code']; + if ( ! in_array( $coupon_code, $applied_coupons, true ) ) { + $applied_coupons[] = $coupon_args['coupon-code']; + $saved_status[ $coupon_code ] = 'saved'; + } else { + $saved_status[ $coupon_code ] = 'already_saved'; + } + } + + update_user_meta( $user_id, 'sc_applied_coupon_from_url', $applied_coupons ); + } + + return $saved_status; + + } + + /** + * Apply coupon code from session, if any + */ + public function move_applied_coupon_from_cookies_to_account() { + + $user_id = get_current_user_id(); + + if ( $user_id > 0 && ! empty( $_COOKIE['sc_applied_coupon_profile_id'] ) ) { + + $unique_id = wc_clean( wp_unslash( $_COOKIE['sc_applied_coupon_profile_id'] ) ); // phpcs:ignore + + $applied_coupons = $this->get_applied_coupons_by_guest_user( $unique_id ); + + if ( false !== $applied_coupons && is_array( $applied_coupons ) && ! empty( $applied_coupons ) ) { + + $saved_coupons = get_user_meta( $user_id, 'sc_applied_coupon_from_url', true ); + if ( empty( $saved_coupons ) || ! is_array( $saved_coupons ) ) { + $saved_coupons = array(); + } + $saved_coupons = array_merge( $saved_coupons, $applied_coupons ); + update_user_meta( $user_id, 'sc_applied_coupon_from_url', $saved_coupons ); + wc_setcookie( 'sc_applied_coupon_profile_id', '' ); + $this->delete_applied_coupons_of_guest_user( $unique_id ); + delete_option( 'sc_applied_coupon_profile_' . $unique_id ); + } + } + + } + + /** + * Function to get redirect URL after processing Smart Coupons params + * + * @param string $url The URL. + * @return string $url + */ + public function get_redirect_url_after_smart_coupons_process( $url = '' ) { + + if ( empty( $url ) ) { + return $url; + } + + $query_string = ( ! empty( $_SERVER['QUERY_STRING'] ) ) ? wc_clean( wp_unslash( $_SERVER['QUERY_STRING'] ) ) : array(); // phpcs:ignore + + parse_str( $query_string, $url_args ); + + $sc_params = array( 'coupon-code', 'sc-page' ); + + $url_params = array_diff_key( $url_args, array_flip( $sc_params ) ); + + if ( empty( $url_params['add-to-cart'] ) ) { + $redirect_url = apply_filters( 'wc_sc_redirect_url_after_smart_coupons_process', add_query_arg( $url_params, $url ), array( 'source' => $this ) ); + } else { + $redirect_url = apply_filters( 'wc_sc_redirect_url_after_smart_coupons_process', $url, array( 'source' => $this ) ); + } + + return $redirect_url; + } + + /** + * Function to convert sc coupon notices to wc notices + */ + public function convert_sc_coupon_notices_to_wc_notices() { + $coupon_notices = $this->get_coupon_notices(); + // If we have coupon notices to be shown and we are on a woocommerce page then convert them to wc notices. + if ( count( $coupon_notices ) > 0 && ( is_woocommerce() || is_cart() || is_checkout() || is_account_page() ) ) { + foreach ( $coupon_notices as $notice_type => $notices ) { + if ( count( $notices ) > 0 ) { + foreach ( $notices as $notice ) { + wc_add_notice( $notice, $notice_type ); + } + } + } + $this->remove_coupon_notices(); + } + } + + /** + * Function to get sc coupon notices + */ + public function get_coupon_notices() { + return apply_filters( 'wc_sc_coupon_notices', $this->coupon_notices ); + } + + + /** + * Function to remove sc coupon notices + */ + public function remove_coupon_notices() { + $this->coupon_notices = array(); + } + + /** + * Function to add coupon notices to wp content + * + * @param string $content page content. + * @return string $content page content + */ + public function show_coupon_notices( $content = '' ) { + + $coupon_notices = $this->get_coupon_notices(); + + if ( count( $coupon_notices ) > 0 ) { + + // Buffer output. + ob_start(); + + foreach ( $coupon_notices as $notice_type => $notices ) { + if ( count( $coupon_notices[ $notice_type ] ) > 0 ) { + wc_get_template( + "notices/{$notice_type}.php", + array( + 'messages' => $coupon_notices[ $notice_type ], + ) + ); + } + } + + $notices = wc_kses_notice( ob_get_clean() ); + $content = $notices . $content; + $this->remove_coupon_notices(); // Empty out notice data. + } + + return $content; + + } + + /** + * Function to get coupon codes by guest user's unique ID. + * + * @param string $unique_id Unique ID for guest user. + * + * @return array. + */ + public function get_applied_coupons_by_guest_user( $unique_id = '' ) { + $key = sprintf( 'sc_applied_coupon_profile_%s', $unique_id ); + + // Get coupons from `transient`. + $coupons = get_transient( $key ); + if ( ! empty( $coupons ) && is_array( $coupons ) ) { + return $coupons; + } + // Get coupon from `wp_option`. + return get_option( $key, array() ); + } + + /** + * Function to set applied coupons for guest user. + * + * @param string $unique_id Unique id for guest user. + * @param array $coupons Array of coupon codes. + * + * @return bool. + */ + public function set_applied_coupon_for_guest_user( $unique_id = '', $coupons = array() ) { + + if ( ! empty( $unique_id ) && is_array( $coupons ) ) { + $key = sprintf( 'sc_applied_coupon_profile_%s', $unique_id ); + + if ( empty( $coupons ) ) { + return delete_transient( $key ); + } else { + return set_transient( + $key, + $coupons, + apply_filters( 'wc_sc_applied_coupon_by_url_expire_time', MONTH_IN_SECONDS ) + ); + } + } + + return false; + } + + /** + * Function to delete all applied coupons for a guest user. + * + * @param string $unique_id Unique id for guest user. + * + * @return bool. + */ + public function delete_applied_coupons_of_guest_user( $unique_id = '' ) { + + if ( ! empty( $unique_id ) ) { + $key = sprintf( 'sc_applied_coupon_profile_%s', $unique_id ); + return delete_transient( $key ); + } + + return false; + } + + } + +} + +WC_SC_URL_Coupon::get_instance(); diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-smart-coupons.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-smart-coupons.php new file mode 100644 index 00000000..c8e2ce2f --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-smart-coupons.php @@ -0,0 +1,7844 @@ +includes(); + + add_action( 'plugins_loaded', array( $this, 'load_action_scheduler' ), -1 ); + + add_action( 'init', array( $this, 'process_activation' ) ); + add_action( 'init', array( $this, 'add_sc_options' ) ); + add_action( 'init', array( $this, 'define_label_for_store_credit' ) ); + + add_filter( 'woocommerce_coupon_is_valid', array( $this, 'is_smart_coupon_valid' ), 10, 3 ); + add_filter( 'woocommerce_coupon_is_valid', array( $this, 'is_user_usage_limit_valid' ), 10, 3 ); + add_filter( 'woocommerce_coupon_is_valid_for_product', array( $this, 'smart_coupons_is_valid_for_product' ), 10, 4 ); + add_filter( 'woocommerce_coupon_validate_expiry_date', array( $this, 'validate_expiry_time' ), 999, 3 ); + add_filter( 'woocommerce_apply_individual_use_coupon', array( $this, 'smart_coupons_override_individual_use' ), 10, 3 ); + add_filter( 'woocommerce_apply_with_individual_use_coupon', array( $this, 'smart_coupons_override_with_individual_use' ), 10, 4 ); + + add_action( 'restrict_manage_posts', array( $this, 'woocommerce_restrict_manage_smart_coupons' ), 20 ); + add_action( 'admin_init', array( $this, 'woocommerce_export_coupons' ) ); + + add_action( 'personal_options_update', array( $this, 'my_profile_update' ) ); + add_action( 'edit_user_profile_update', array( $this, 'my_profile_update' ) ); + + add_filter( 'generate_smart_coupon_action', array( $this, 'generate_smart_coupon_action' ), 1, 10 ); + + add_action( 'wc_sc_new_coupon_generated', array( $this, 'smart_coupons_plugin_used' ) ); + + // Actions used to insert a new endpoint in the WordPress. + add_action( 'init', array( $this, 'sc_add_endpoints' ), 11 ); + + add_action( 'admin_enqueue_scripts', array( $this, 'smart_coupon_styles_and_scripts' ), 20 ); + add_action( 'admin_enqueue_scripts', array( $this, 'register_plugin_styles' ) ); + add_action( 'wp_enqueue_scripts', array( $this, 'register_plugin_styles' ) ); + + add_filter( 'wc_smart_coupons_export_headers', array( $this, 'wc_smart_coupons_export_headers' ) ); + add_filter( 'woocommerce_email_footer_text', array( $this, 'email_footer_replace_site_title' ) ); + + add_filter( 'is_protected_meta', array( $this, 'make_sc_meta_protected' ), 10, 3 ); + + add_action( 'admin_notices', array( $this, 'minimum_woocommerce_version_requirement' ) ); + + add_action( 'wp_loaded', array( $this, 'sc_handle_store_credit_application' ), 15 ); + + add_filter( 'woocommerce_debug_tools', array( $this, 'clear_cache_tool' ) ); + + add_action( 'woocommerce_checkout_update_order_review', array( $this, 'woocommerce_checkout_update_order_review' ) ); + + add_action( 'woocommerce_cart_reset', array( $this, 'woocommerce_cart_reset' ) ); + + // Actions used to schedule sending of coupons. + add_action( 'wc_sc_send_scheduled_coupon_email', array( $this, 'send_scheduled_coupon_email' ), 10, 7 ); + add_action( 'wc_sc_import_send_scheduled_coupon_email', array( $this, 'import_send_scheduled_coupon_email' ), 10, 5 ); + add_action( 'publish_future_post', array( $this, 'process_published_scheduled_coupon' ) ); + add_action( 'before_delete_post', array( $this, 'delete_scheduled_coupon_actions' ) ); + add_action( 'admin_footer', array( $this, 'enqueue_admin_footer_scripts' ) ); + add_action( 'wp_ajax_wc_sc_check_scheduled_coupon_actions', array( $this, 'check_scheduled_coupon_actions' ) ); + + // Filter to modify discount amount for percentage type coupon. + add_filter( 'woocommerce_coupon_get_discount_amount', array( $this, 'get_coupon_discount_amount' ), 10, 5 ); + + // Filter to add default values to coupon meta fields. + add_filter( 'smart_coupons_parser_postmeta_defaults', array( $this, 'postmeta_defaults' ) ); + + // Filter to register Smart Coupons' email classes. + add_filter( 'woocommerce_email_classes', array( $this, 'register_email_classes' ) ); + + add_filter( 'woocommerce_hold_stock_for_checkout', array( $this, 'hold_stock_for_checkout' ) ); + + add_action( 'wc_sc_generate_coupon', array( $this, 'generate_coupon' ) ); + add_action( 'wc_sc_paint_coupon', array( $this, 'paint_coupon' ) ); + + add_filter( 'woocommerce_rest_api_get_rest_namespaces', array( $this, 'rest_namespace' ) ); + + add_filter( 'woocommerce_shipping_free_shipping_is_available', array( $this, 'is_eligible_for_free_shipping' ), 10, 3 ); + + add_action( 'woocommerce_system_status_report', array( $this, 'smart_coupons_system_status_report' ), 11 ); + + add_action( 'woocommerce_rest_prepare_shop_order_object', array( $this, 'rest_api_prepare_shop_order_object' ), 10, 3 ); + + add_action( 'before_woocommerce_init', array( $this, 'hpos_compat_declaration' ) ); + add_action( 'before_woocommerce_init', array( $this, 'blocks_compat_declaration' ) ); + + add_filter( 'woocommerce_order_item_get_formatted_meta_data', array( $this, 'format_sc_meta_data' ), 99, 2 ); + add_filter( 'woocommerce_hidden_order_itemmeta', array( $this, 'hidden_order_itemmeta' ) ); + + add_filter( 'woocommerce_order_data_store_cpt_get_orders_query', array( $this, 'custom_meta_support_in_orders_query' ), 10, 2 ); + + add_action( 'upgrader_process_complete', array( $this, 'upgrader_process_complete' ), 10, 2 ); + + add_action( 'woocommerce_remove_cart_item', array( $this, 'sc_remove_coupon_with_cart_item' ), 10, 2 ); + + add_action( 'woocommerce_blocks_loaded', array( $this, 'register_endpoint_data' ) ); + add_action( 'woocommerce_store_api_checkout_update_order_from_request', array( $this, 'save_coupon_receiver_detail_in_order' ), 10, 2 ); + + add_action( 'woocommerce_order_after_calculate_totals', array( $this, 'update_smart_coupon_order_create_via_admin' ), 99, 2 ); + + } + + /** + * Function to handle WC compatibility related function call from appropriate class + * + * @param string $function_name Function to call. + * @param array $arguments Array of arguments passed while calling $function_name. + * @return mixed Result of function call. + */ + public function __call( $function_name, $arguments = array() ) { + + if ( ! is_callable( 'SA_WC_Compatibility_8_7', $function_name ) ) { + return; + } + + if ( ! empty( $arguments ) ) { + return call_user_func_array( 'SA_WC_Compatibility_8_7::' . $function_name, $arguments ); + } else { + return call_user_func( 'SA_WC_Compatibility_8_7::' . $function_name ); + } + + } + + /** + * Include files + */ + public function includes() { + + include_once 'compat/class-sa-wc-compatibility-4-4.php'; + include_once 'compat/class-sa-wc-compatibility-8-7.php'; + include_once 'compat/class-wc-sc-wpml-compatibility.php'; + include_once 'compat/class-wcopc-sc-compatibility.php'; + include_once 'compat/class-wcs-sc-compatibility.php'; + include_once 'compat/class-wc-sc-wmc-compatibility.php'; + include_once 'compat/class-wc-sc-aelia-cs-compatibility.php'; + include_once 'compat/class-wc-sc-kco-compatibility.php'; + include_once 'compat/class-wc-sc-pnr-compatibility.php'; + include_once 'compat/class-wc-sc-wscp-compatibility.php'; + + include_once 'class-wc-sc-admin-welcome.php'; + include_once 'class-wc-sc-background-coupon-importer.php'; + include_once 'class-wc-sc-admin-pages.php'; + include_once 'class-wc-sc-admin-notifications.php'; + + include_once 'class-wc-sc-ajax.php'; + include_once 'class-wc-sc-display-coupons.php'; + + include_once 'class-wc-sc-settings.php'; + include_once 'class-wc-sc-shortcode.php'; + include_once 'class-wc-sc-purchase-credit.php'; + include_once 'class-wc-sc-url-coupon.php'; + include_once 'class-wc-sc-print-coupon.php'; + include_once 'class-wc-sc-coupon-fields.php'; + include_once 'class-wc-sc-auto-apply-coupon.php'; + include_once 'class-wc-sc-product-fields.php'; + include_once 'class-wc-sc-order-fields.php'; + include_once 'class-wc-sc-coupon-process.php'; + include_once 'class-wc-sc-global-coupons.php'; + include_once 'class-wc-sc-admin-coupons-dashboard-actions.php'; + include_once 'class-wc-sc-privacy.php'; + include_once 'class-wc-sc-coupon-actions.php'; + include_once 'class-wc-sc-coupon-columns.php'; + include_once 'class-wc-sc-product-columns.php'; + include_once 'class-wc-sc-coupons-by-location.php'; + include_once 'class-wc-sc-coupons-by-payment-method.php'; + include_once 'class-wc-sc-coupons-by-shipping-method.php'; + include_once 'class-wc-sc-coupons-by-user-role.php'; + include_once 'class-wc-sc-coupons-by-product-attribute.php'; + include_once 'class-wc-sc-coupons-by-taxonomy.php'; + include_once 'class-wc-sc-coupons-by-excluded-email.php'; + include_once 'class-wc-sc-coupon-message.php'; + include_once 'class-wc-sc-coupon-categories.php'; + include_once 'class-wc-sc-coupons-by-product-quantity.php'; + include_once 'class-wc-sc-coupon-refund-process.php'; + include_once 'class-wc-sc-background-upgrade.php'; + include_once 'blocks/class-wc-sc-gutenberg-coupon-block.php'; + + } + + /** + * Process activation of the plugin + */ + public function process_activation() { + + if ( ! get_transient( '_smart_coupons_process_activation' ) ) { + return; + } + + delete_transient( '_smart_coupons_process_activation' ); + + include_once 'class-wc-sc-act-deact.php'; + + WC_SC_Act_Deact::process_activation(); + + } + + /** + * Load action scheduler + */ + public function load_action_scheduler() { + if ( ! class_exists( 'ActionScheduler' ) ) { + include_once 'libraries/action-scheduler/action-scheduler.php'; + } + } + + /** + * Set options + */ + public function add_sc_options() { + + $this->plugin_data = self::get_smart_coupons_plugin_data(); + + add_option( 'woocommerce_delete_smart_coupon_after_usage', 'no', '', 'no' ); + add_option( 'woocommerce_smart_coupon_apply_before_tax', 'no', '', 'no' ); + add_option( 'woocommerce_smart_coupon_include_tax', 'no', '', 'no' ); + add_option( 'woocommerce_smart_coupon_show_my_account', 'yes', '', 'no' ); + add_option( 'smart_coupons_is_show_associated_coupons', 'no', '', 'no' ); + add_option( 'smart_coupons_show_coupon_description', 'no', '', 'no' ); + add_option( 'smart_coupons_is_send_email', 'yes', '', 'no' ); + add_option( 'smart_coupons_is_print_coupon', 'yes', '', 'no' ); + add_option( 'show_coupon_received_on_my_account', 'no', '', 'no' ); + add_option( 'pay_from_smart_coupon_of_original_order', 'yes', '', 'no' ); + add_option( 'stop_recursive_coupon_generation', 'no', '', 'no' ); + add_option( 'sc_gift_certificate_shop_loop_button_text', __( 'Select options', 'woocommerce-smart-coupons' ), '', 'no' ); + add_option( 'wc_sc_setting_max_coupon_to_show', '5', '', 'no' ); + add_option( 'smart_coupons_show_invalid_coupons_on_myaccount', 'no', '', 'no' ); + add_option( 'smart_coupons_sell_store_credit_at_less_price', 'no', '', 'no' ); + add_option( 'smart_coupons_display_coupon_receiver_details_form', 'yes', '', 'no' ); + + // Convert SC admin email settings into WC email settings. + $is_send_email = get_option( 'smart_coupons_is_send_email' ); + if ( false !== $is_send_email ) { + $coupon_email_settings = get_option( 'woocommerce_wc_sc_email_coupon_settings' ); + if ( false === $coupon_email_settings ) { + $coupon_email_settings = array(); + $coupon_email_settings['enabled'] = $is_send_email; + update_option( 'woocommerce_wc_sc_email_coupon_settings', $coupon_email_settings, 'no' ); + } + } + + $is_combine_email = get_option( 'smart_coupons_combine_emails' ); + if ( false !== $is_combine_email ) { + $combine_email_settings = get_option( 'woocommerce_wc_sc_combined_email_coupon_settings' ); + if ( false === $combine_email_settings ) { + $combine_email_settings = array(); + $combine_email_settings['enabled'] = $is_combine_email; + update_option( 'woocommerce_wc_sc_combined_email_coupon_settings', $combine_email_settings, 'no' ); + } + } + + $valid_designs = $this->get_valid_coupon_designs(); + + $coupon_design = get_option( 'wc_sc_setting_coupon_design' ); + if ( false === $coupon_design ) { + add_option( 'wc_sc_setting_coupon_design', 'basic', '', 'no' ); + } else { + if ( 'custom-design' !== $coupon_design && ! in_array( $coupon_design, $valid_designs, true ) ) { + update_option( 'wc_sc_setting_coupon_design', 'basic', 'no' ); + } + } + + $coupon_background_color = get_option( 'wc_sc_setting_coupon_background_color' ); + if ( false === $coupon_background_color ) { + add_option( 'wc_sc_setting_coupon_background_color', '#2b2d42', '', 'no' ); + } else { + add_option( 'wc_sc_setting_coupon_third_color', $coupon_background_color, '', 'no' ); + } + + $coupon_foreground_color = get_option( 'wc_sc_setting_coupon_foreground_color' ); + if ( false === $coupon_foreground_color ) { + add_option( 'wc_sc_setting_coupon_foreground_color', '#edf2f4', '', 'no' ); + } + + $coupon_third_color = get_option( 'wc_sc_setting_coupon_third_color' ); + if ( false === $coupon_third_color ) { + add_option( 'wc_sc_setting_coupon_third_color', '#d90429', '', 'no' ); + } + + $coupon_design_colors = get_option( 'wc_sc_setting_coupon_design_colors' ); + if ( false === $coupon_design_colors ) { + if ( false !== $coupon_background_color && false !== $coupon_foreground_color ) { + add_option( 'wc_sc_setting_coupon_design_colors', 'custom', '', 'no' ); + } else { + add_option( 'wc_sc_setting_coupon_design_colors', '2b2d42-edf2f4-d90429', '', 'no' ); + } + } + + $coupon_design_for_email = get_option( 'wc_sc_setting_coupon_design_for_email' ); + if ( false === $coupon_design_for_email ) { + add_option( 'wc_sc_setting_coupon_design_for_email', 'email-coupon', '', 'no' ); + } + + $orders_prior_to_800 = $this->sc_get_option( 'wc_sc_old_orders_prior_to_800' ); + if ( false === $orders_prior_to_800 ) { + $this->maybe_sync_orders_prior_to_800(); + } + + } + + /** + * Function to log messages generated by Smart Coupons plugin + * + * @param string $level Message type. Valid values: debug, info, notice, warning, error, critical, alert, emergency. + * @param string $message The message to log. + */ + public function log( $level = 'notice', $message = '' ) { + + if ( empty( $message ) ) { + return; + } + + if ( function_exists( 'wc_get_logger' ) ) { + $logger = wc_get_logger(); + $context = array( 'source' => 'woocommerce-smart-coupons' ); + $logger->log( $level, $message, $context ); + } else { + include_once plugin_dir_path( WC_PLUGIN_FILE ) . 'includes/class-wc-logger.php'; + $logger = new WC_Logger(); + $logger->add( 'woocommerce-smart-coupons', $message ); + } + + } + + /** + * Coupon's expiration date (formatted) + * + * @param int $expiry_date Expiry date of coupon. + * @return string $expires_string Formatted expiry date + */ + public function get_expiration_format( $expiry_date ) { + + if ( $this->is_wc_gte_30() && $expiry_date instanceof WC_DateTime ) { + $expiry_date = ( is_callable( array( $expiry_date, 'getTimestamp' ) ) ) ? $expiry_date->getTimestamp() : null; + } elseif ( ! is_int( $expiry_date ) ) { + $expiry_date = $this->strtotime( $expiry_date ); + } + + $expiry_date += $this->wc_timezone_offset(); + + $expires_string = date_i18n( get_option( 'date_format', 'd-M-Y' ), $expiry_date ); + + return apply_filters( + 'wc_sc_formatted_coupon_expiry_date', + $expires_string, + array( + 'source' => $this, + 'expiry_date' => $expiry_date, + ) + ); + + } + + + /** + * Function to send e-mail containing coupon code to receiver + * + * @param array $coupon_title Associative array containing receiver's details. + * @param string $discount_type Type of coupon. + * @param int $order_id Associated order id. + * @param array $gift_certificate_receiver_name Array of receiver's name. + * @param string $message_from_sender Message added by sender. + * @param string $gift_certificate_sender_name Sender name. + * @param string $gift_certificate_sender_email Sender email. + * @param boolean $is_gift Whether it is a gift certificate or store credit. + */ + public function sa_email_coupon( $coupon_title, $discount_type, $order_id = '', $gift_certificate_receiver_name = '', $message_from_sender = '', $gift_certificate_sender_name = '', $gift_certificate_sender_email = '', $is_gift = '' ) { + + $is_send_email = $this->is_email_template_enabled(); + $combine_emails = $this->is_email_template_enabled( 'combine' ); + + if ( 'yes' === $is_send_email ) { + WC()->mailer(); + } + + $is_send_email = apply_filters( + 'wc_sc_is_send_coupon_email', + $is_send_email, + array( + 'source' => $this, + 'coupon_title' => $coupon_title, + 'discount_type' => $discount_type, + 'order_id' => $order_id, + 'gift_certificate_receiver_name' => $gift_certificate_receiver_name, + 'message_from_sender' => $message_from_sender, + 'gift_certificate_sender_name' => $gift_certificate_sender_name, + 'gift_certificate_sender_email' => $gift_certificate_sender_email, + 'is_gift' => $is_gift, + ) + ); + + $order = ( ! empty( $order_id ) ) ? wc_get_order( $order_id ) : null; + + foreach ( $coupon_title as $email => $coupon ) { + + if ( empty( $email ) ) { + $email = $gift_certificate_sender_email; + } + + $amount = $coupon['amount']; + $coupon_code = strtolower( $coupon['code'] ); + + if ( ! empty( $order_id ) ) { + $coupon_receiver_details = $this->get_post_meta( $order_id, 'sc_coupon_receiver_details', true, false, $order ); + if ( ! is_array( $coupon_receiver_details ) || empty( $coupon_receiver_details ) ) { + $coupon_receiver_details = array(); + } + $coupon_receiver_details[] = array( + 'code' => $coupon_code, + 'amount' => $amount, + 'email' => $email, + 'message' => $message_from_sender, + ); + $this->update_post_meta( $order_id, 'sc_coupon_receiver_details', $coupon_receiver_details, false, $order ); + } + + $action_args = apply_filters( + 'wc_sc_email_coupon_notification_args', + array( + 'order_id' => $order_id, + 'email' => $email, + 'coupon' => $coupon, + 'discount_type' => $discount_type, + 'receiver_name' => $gift_certificate_receiver_name, + 'message_from_sender' => $message_from_sender, + 'gift_certificate_sender_name' => $gift_certificate_sender_name, + 'gift_certificate_sender_email' => $gift_certificate_sender_email, + 'is_gift' => $is_gift, + ) + ); + + $schedule_gift_sending = 'no'; + if ( ! empty( $order_id ) ) { + $schedule_gift_sending = ( $this->is_callable( $order, 'get_meta' ) ) ? $order->get_meta( 'wc_sc_schedule_gift_sending' ) : $this->get_post_meta( $order_id, 'wc_sc_schedule_gift_sending', true ); + } + + $is_schedule_gift_sending = 'no'; + if ( 'yes' === $schedule_gift_sending ) { + $coupon_id = wc_get_coupon_id_by_code( $coupon_code ); + $coupon_receiver_details = $this->get_post_meta( $coupon_id, 'wc_sc_coupon_receiver_details', true ); + $scheduled_coupon_code = ( ! empty( $coupon_receiver_details['coupon_details']['code'] ) ) ? strtolower( $coupon_receiver_details['coupon_details']['code'] ) : ''; + if ( $scheduled_coupon_code === $coupon_code ) { + $is_schedule_gift_sending = 'yes'; + } + } + + if ( 'yes' === $is_send_email && ( 'no' === $combine_emails || 'yes' === $is_schedule_gift_sending ) ) { + $current_filter = current_filter(); + $order_actions_to_ignore_for_email = $this->order_actions_to_ignore_for_email(); + if ( ! in_array( $current_filter, $order_actions_to_ignore_for_email, true ) ) { + // Trigger email notification. + do_action( 'wc_sc_email_coupon_notification', $action_args ); + } + if ( 'yes' === $is_schedule_gift_sending ) { + // Delete receiver detail post meta as it is no longer necessary. + $this->delete_post_meta( $coupon_id, 'wc_sc_coupon_receiver_details' ); + } + } + } + + } + + /** + * Function to send combined e-mail containing coupon codes to receiver + * + * @param string $receiver_email receiver's email. + * @param array $receiver_details receiver details(code,message etc). + * @param int $order_id Associated order id. + * @param string $gift_certificate_sender_name Sender name. + * @param string $gift_certificate_sender_email Sender email. + */ + public function send_combined_coupon_email( $receiver_email = '', $receiver_details = array(), $order_id = 0, $gift_certificate_sender_name = '', $gift_certificate_sender_email = '' ) { + + $is_send_email = $this->is_email_template_enabled(); + $combine_emails = $this->is_email_template_enabled( 'combine' ); + + if ( 'yes' === $is_send_email && 'yes' === $combine_emails ) { + $current_filter = current_filter(); + $order_actions_to_ignore_for_email = $this->order_actions_to_ignore_for_email(); + if ( ! in_array( $current_filter, $order_actions_to_ignore_for_email, true ) ) { + WC()->mailer(); + + $order = ( ! empty( $order_id ) ) ? wc_get_order( $order_id ) : null; + + $is_gift = ''; + if ( ! empty( $order_id ) ) { + $is_gift = $this->get_post_meta( $order_id, 'is_gift', true ); + } + + if ( count( $receiver_details ) === 1 ) { + $coupon_code = ( ! empty( $receiver_details[0]['code'] ) ) ? $receiver_details[0]['code'] : ''; + $message_from_sender = ( ! empty( $receiver_details[0]['message'] ) ) ? $receiver_details[0]['message'] : ''; + + $coupon = new WC_Coupon( $coupon_code ); + $coupon_amount = $this->get_amount( $coupon, true, $order ); + $discount_type = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_discount_type' ) ) ) ? $coupon->get_discount_type() : ''; + $coupon_data = $this->get_coupon_meta_data( $coupon ); + + $coupon_detail = array( + 'amount' => $coupon_amount, + 'code' => $coupon_code, + ); + + $action_args = apply_filters( + 'wc_sc_email_coupon_notification_args', + array( + 'order_id' => $order_id, + 'email' => $receiver_email, + 'coupon' => $coupon_detail, + 'discount_type' => $discount_type, + 'receiver_name' => '', + 'message_from_sender' => $message_from_sender, + 'gift_certificate_sender_name' => $gift_certificate_sender_name, + 'gift_certificate_sender_email' => $gift_certificate_sender_email, + 'is_gift' => $is_gift, + ) + ); + // Trigger single email notification. + do_action( 'wc_sc_email_coupon_notification', $action_args ); + return; + } + } + + $action_args = apply_filters( + 'wc_sc_email_coupon_notification_args', + array( + 'order_id' => $order_id, + 'email' => $receiver_email, + 'receiver_details' => $receiver_details, + 'gift_certificate_sender_name' => $gift_certificate_sender_name, + 'gift_certificate_sender_email' => $gift_certificate_sender_email, + 'is_gift' => $is_gift, + ) + ); + + // Trigger combined email notification. + do_action( 'wc_sc_combined_email_coupon_notification', $action_args ); + } + } + + /** + * Function to schedule e-mail sending process containing coupon code to customer + * + * @param array $action_args arguments for Action Scheduler. + * @param string $sending_timestamp timestamp for scheduling email. + * @return boolean email sending scheduled or not. + */ + public function schedule_coupon_email( $action_args = array(), $sending_timestamp = '' ) { + + if ( empty( $action_args ) || empty( $sending_timestamp ) ) { + return false; + } + + $coupon_id = 0; + if ( isset( $action_args['coupon_id'] ) && ! empty( $action_args['coupon_id'] ) ) { + $coupon_id = $action_args['coupon_id']; + } + + $ref_key = ''; + if ( isset( $action_args['ref_key'] ) && ! empty( $action_args['ref_key'] ) ) { + $ref_key = $action_args['ref_key']; + } + + if ( ! empty( $coupon_id ) && ! empty( $ref_key ) && function_exists( 'as_schedule_single_action' ) ) { + if ( ! empty( $action_args['order_id'] ) ) { + $actions_id = as_schedule_single_action( $sending_timestamp, 'wc_sc_send_scheduled_coupon_email', $action_args ); + } else { + $actions_id = as_schedule_single_action( $sending_timestamp, 'wc_sc_import_send_scheduled_coupon_email', $action_args ); + } + if ( $actions_id ) { + $scheduled_actions_ids = $this->get_post_meta( $coupon_id, 'wc_sc_scheduled_actions_ids', true ); + if ( empty( $scheduled_actions_ids ) || ! is_array( $scheduled_actions_ids ) ) { + $scheduled_actions_ids = array(); + } + $scheduled_actions_ids[ $ref_key ] = $actions_id; + // Stored actions ids in coupons so that we can delete them when coupon gets deleted or email is sent successfully. + $this->update_post_meta( $coupon_id, 'wc_sc_scheduled_actions_ids', $scheduled_actions_ids ); + return true; + } + } + return false; + } + + /** + * Function to send scheduled coupon's e-mail containing coupon code to receiver. It is triggered through Action Scheduler + * + * @param string $auto_generate is auto generated coupon. + * @param int $coupon_id Associated coupon id. + * @param int $parent_id Associated parent coupon id. + * @param int $order_id Associated order id. + * @param string $receiver_email receiver email. + * @param string $sender_message_index_key key containing index of sender's message from gift_receiver_message meta in order. + * @param string $ref_key timestamp based reference key. + */ + public function send_scheduled_coupon_email( $auto_generate = '', $coupon_id = '', $parent_id = '', $order_id = '', $receiver_email = '', $sender_message_index_key = '', $ref_key = '' ) { + + if ( ! empty( $coupon_id ) && ! empty( $order_id ) && ! empty( $receiver_email ) ) { + + $coupon = new WC_Coupon( $coupon_id ); + + $coupon_status = ( $this->is_wc_greater_than( '6.1.2' ) && $this->is_callable( $coupon, 'get_status' ) ) ? $coupon->get_status() : get_post_status( $coupon_id ); + if ( 'publish' !== $coupon_status ) { + return; + } + + $order = wc_get_order( $order_id ); + if ( is_a( $coupon, 'WC_Coupon' ) && is_a( $order, 'WC_Order' ) ) { + $is_callable_order_get_meta = $this->is_callable( $order, 'get_meta' ); + $is_callable_coupon_get_meta = $this->is_callable( $coupon, 'get_meta' ); + $is_callable_coupon_update_meta_data = $this->is_callable( $coupon, 'update_meta_data' ); + $sc_disable_email_restriction = $this->get_post_meta( $parent_id, 'sc_disable_email_restriction', true ); + if ( $this->is_wc_gte_30() ) { + $discount_type = $coupon->get_discount_type(); + $coupon_code = $coupon->get_code(); + } else { + $discount_type = ( ! empty( $coupon->discount_type ) ) ? $coupon->discount_type : ''; + $coupon_code = ( ! empty( $coupon->code ) ) ? $coupon->code : ''; + } + + $coupon_amount = $this->get_amount( $coupon, true, $order ); + + $coupon_details = array( + $receiver_email => array( + 'parent' => $parent_id, + 'code' => $coupon_code, + 'amount' => $coupon_amount, + ), + ); + + $receiver_name = ''; + $message_from_sender = ''; + $gift_certificate_sender_name = ''; + $gift_certificate_sender_email = ''; + + $is_gift = ( true === $is_callable_order_get_meta ) ? $order->get_meta( 'is_gift' ) : $this->get_post_meta( $order_id, 'is_gift', true ); + + // In case of auto generated coupons receiver's details are saved in generated coupon. + if ( 'yes' === $auto_generate ) { + $coupon_receiver_details = ( true === $is_callable_coupon_get_meta ) ? $coupon->get_meta( 'wc_sc_coupon_receiver_details' ) : $this->get_post_meta( $coupon_id, 'wc_sc_coupon_receiver_details', true ); + if ( ! empty( $coupon_receiver_details ) && is_array( $coupon_receiver_details ) ) { + $message_from_sender = $coupon_receiver_details['message_from_sender']; + $gift_certificate_sender_name = $coupon_receiver_details['gift_certificate_sender_name']; + $gift_certificate_sender_email = $coupon_receiver_details['gift_certificate_sender_email']; + } + } else { + $receivers_messages = ( true === $is_callable_order_get_meta ) ? $order->get_meta( 'gift_receiver_message' ) : $this->get_post_meta( $order_id, 'gift_receiver_message', true ); + if ( strpos( $sender_message_index_key, ':' ) > 0 ) { + $index_keys = explode( ':', $sender_message_index_key ); + $coupon_index = $index_keys[0]; + $message_index = $index_keys[1]; + if ( isset( $receivers_messages[ $coupon_index ][ $message_index ] ) ) { + $message_from_sender = $receivers_messages[ $coupon_index ][ $message_index ]; + } + } + } + + $this->sa_email_coupon( $coupon_details, $discount_type, $order_id, $receiver_name, $message_from_sender, $gift_certificate_sender_name, $gift_certificate_sender_email, $is_gift ); + + if ( ( 'no' === $sc_disable_email_restriction || empty( $sc_disable_email_restriction ) ) ) { + $old_customers_email_ids = (array) maybe_unserialize( ( $this->is_callable( $coupon, 'get_email_restrictions' ) ) ? $coupon->get_email_restrictions() : $this->get_post_meta( $coupon_id, 'customer_email', true ) ); + $old_customers_email_ids[] = $receiver_email; + if ( true === $is_callable_coupon_update_meta_data ) { + $coupon->set_email_restrictions( $old_customers_email_ids ); + } else { + update_post_meta( $coupon_id, 'customer_email', $old_customers_email_ids ); + } + } + + if ( ! empty( $ref_key ) ) { + $scheduled_actions_ids = ( true === $is_callable_coupon_get_meta ) ? $coupon->get_meta( 'wc_sc_scheduled_actions_ids' ) : $this->get_post_meta( $coupon_id, 'wc_sc_scheduled_actions_ids', true ); + if ( isset( $scheduled_actions_ids[ $ref_key ] ) ) { + unset( $scheduled_actions_ids[ $ref_key ] ); + } + if ( ! empty( $scheduled_actions_ids ) ) { + if ( true === $is_callable_coupon_update_meta_data ) { + $coupon->update_meta_data( 'wc_sc_scheduled_actions_ids', $scheduled_actions_ids ); + } else { + update_post_meta( $coupon_id, 'wc_sc_scheduled_actions_ids', $scheduled_actions_ids ); + } + } else { + // Delete scheduled action ids meta since it is empty now. + $this->delete_post_meta( $coupon_id, 'wc_sc_scheduled_actions_ids', null, $coupon ); + } + } + if ( $this->is_callable( $coupon, 'save' ) ) { + $coupon->save(); + } + } + } + } + + /** + * Function to send scheduled coupon's e-mail containing coupon code to receiver. It is triggered through Action Scheduler + * + * @param string $auto_generate is auto generated coupon. + * @param int $coupon_id Associated coupon id. + * @param int $parent_id Associated parent coupon id. + * @param string $receiver_email receiver email. + * @param string $ref_key timestamp based reference key. + */ + public function import_send_scheduled_coupon_email( $auto_generate = '', $coupon_id = 0, $parent_id = 0, $receiver_email = '', $ref_key = '' ) { + + if ( ! empty( $coupon_id ) && ! empty( $receiver_email ) ) { + + $coupon = new WC_Coupon( $coupon_id ); + + $coupon_status = ( $this->is_wc_greater_than( '6.1.2' ) && $this->is_callable( $coupon, 'get_status' ) ) ? $coupon->get_status() : get_post_status( $coupon_id ); + if ( ! in_array( $coupon_status, array( 'publish', 'future' ), true ) ) { + return; + } + + if ( is_a( $coupon, 'WC_Coupon' ) ) { + $is_update_coupon = false; + $is_callable_coupon_get_meta = $this->is_callable( $coupon, 'get_meta' ); + $is_callable_coupon_update_meta_data = $this->is_callable( $coupon, 'update_meta_data' ); + if ( $this->is_wc_gte_30() ) { + $discount_type = $this->is_callable( $coupon, 'get_discount_type' ) ? $coupon->get_discount_type() : ''; + $coupon_code = $this->is_callable( $coupon, 'get_code' ) ? $coupon->get_code() : ''; + } else { + $discount_type = ( ! empty( $coupon->discount_type ) ) ? $coupon->discount_type : ''; + $coupon_code = ( ! empty( $coupon->code ) ) ? $coupon->code : ''; + } + + $coupon_amount = $this->get_amount( $coupon, true ); + + $coupon_details = array( + $receiver_email => array( + 'parent' => $parent_id, + 'code' => $coupon_code, + 'amount' => $coupon_amount, + ), + ); + + $this->sa_email_coupon( $coupon_details, $discount_type, 0 ); + + if ( ! empty( $ref_key ) ) { + $scheduled_actions_ids = ( true === $is_callable_coupon_get_meta ) ? $coupon->get_meta( 'wc_sc_scheduled_actions_ids' ) : $this->get_post_meta( $coupon_id, 'wc_sc_scheduled_actions_ids', true ); + if ( isset( $scheduled_actions_ids[ $ref_key ] ) ) { + unset( $scheduled_actions_ids[ $ref_key ] ); + } + if ( ! empty( $scheduled_actions_ids ) ) { + if ( true === $is_callable_coupon_update_meta_data ) { + $coupon->update_meta_data( 'wc_sc_scheduled_actions_ids', $scheduled_actions_ids ); + $is_update_coupon = true; + } else { + $this->update_post_meta( $coupon_id, 'wc_sc_scheduled_actions_ids', $scheduled_actions_ids ); + } + } else { + // Delete scheduled action ids meta since it is empty now. + $this->delete_post_meta( $coupon_id, 'wc_sc_scheduled_actions_ids', null, $coupon ); + } + } + if ( true === $is_update_coupon && $this->is_callable( $coupon, 'save' ) ) { + $coupon->save(); + } + } + } + } + + /** + * Function to process scheduled coupons. + * + * @param int $coupon_id published coupon's id. + */ + public function process_published_scheduled_coupon( $coupon_id = 0 ) { + + $post_type = $this->get_post_type( $coupon_id ); + if ( 'shop_coupon' !== $post_type ) { + return false; + } + + $coupon = new WC_Coupon( $coupon_id ); + if ( is_a( $coupon, 'WC_Coupon' ) ) { + $is_callable_coupon_get_meta = $this->is_callable( $coupon, 'get_meta' ); + $order_id = ( true === $is_callable_coupon_get_meta ) ? $coupon->get_meta( 'generated_from_order_id' ) : $this->get_post_meta( $coupon_id, 'generated_from_order_id', true ); + $order = wc_get_order( $order_id ); + if ( is_a( $order, 'WC_Order' ) ) { + $coupon_receiver_details = ( true === $is_callable_coupon_get_meta ) ? $coupon->get_meta( 'wc_sc_coupon_receiver_details' ) : $this->get_post_meta( $coupon_id, 'wc_sc_coupon_receiver_details', true ); + if ( ! empty( $coupon_receiver_details ) && is_array( $coupon_receiver_details ) ) { + $parent_id = $coupon_receiver_details['coupon_details']['parent']; + $receiver_email = $coupon_receiver_details['gift_certificate_receiver_email']; + $gift_certificate_sender_name = $coupon_receiver_details['gift_certificate_sender_name']; + $gift_certificate_sender_email = $coupon_receiver_details['gift_certificate_sender_email']; + $sending_timestamp = get_post_time( 'U', true, $coupon_id ); // Get coupon publish timestamp. + $action_args = array( + 'auto_generate' => 'yes', + 'coupon_id' => $coupon_id, + 'parent_id' => $parent_id, // Parent coupon id. + 'order_id' => $order_id, + 'receiver_email' => $receiver_email, + 'message_index_key' => '', + 'ref_key' => uniqid(), // A unique timestamp key to relate action schedulers with their coupons. + ); + $is_scheduled = $this->schedule_coupon_email( $action_args, $sending_timestamp ); + if ( ! $is_scheduled ) { + if ( $this->is_wc_gte_30() ) { + $coupon_code = $coupon->get_code(); + } else { + $coupon_code = ( ! empty( $coupon->code ) ) ? $coupon->code : ''; + } + /* translators: 1. Receiver email 2. Coupon code 3. Order id */ + $this->log( 'error', sprintf( __( 'Failed to schedule email to "%1$s" for coupon "%2$s" received from order #%3$s.', 'woocommerce-smart-coupons' ), $receiver_email, $coupon_code, $order_id ) ); + } + } + } + } + + } + + /** + * Function to delete action schedulers when associated coupon is deleted. + * + * @param int $coupon_id coupon id. + */ + public function delete_scheduled_coupon_actions( $coupon_id = 0 ) { + + global $post_type; + + if ( 'shop_coupon' !== $post_type ) { + return false; + } + + $coupon = new WC_Coupon( $coupon_id ); + + if ( is_a( $coupon, 'WC_Coupon' ) ) { + + $scheduled_actions_ids = ( $this->is_callable( $coupon, 'get_meta' ) ) ? $coupon->get_meta( 'wc_sc_scheduled_actions_ids' ) : $this->get_post_meta( $coupon_id, 'wc_sc_scheduled_actions_ids', true ); + + if ( ! empty( $scheduled_actions_ids ) && is_array( $scheduled_actions_ids ) ) { + + if ( ! class_exists( 'ActionScheduler' ) || ! is_callable( array( 'ActionScheduler', 'store' ) ) ) { + return false; + } + + foreach ( $scheduled_actions_ids as $ref_key => $action_id ) { + $action_scheduler = ActionScheduler::store()->fetch_action( $action_id ); + if ( is_a( $action_scheduler, 'ActionScheduler_Action' ) && is_callable( array( $action_scheduler, 'is_finished' ) ) ) { + $is_action_complete = $action_scheduler->is_finished(); + + // Delete only unfinished actions related to coupon. + if ( ! $is_action_complete ) { + ActionScheduler::store()->delete_action( $action_id ); + } + } + } + } + } + + } + + /** + * Function to check if passed timestamp is valid. + * + * @param string $timestamp timestamp. + * @return boolean is valid timestamp. + */ + public function is_valid_timestamp( $timestamp = '' ) { + + if ( empty( $timestamp ) || ! is_numeric( $timestamp ) ) { + return false; + } + + // Check if time is already passed. + if ( time() > $timestamp ) { + return false; + } + return true; + } + + + /** + * Function to enqueue scripts in footer. + */ + public function enqueue_admin_footer_scripts() { + + global $pagenow, $typenow; + + if ( empty( $pagenow ) || 'edit.php' !== $pagenow ) { + return; + } + + $coupon_status = ( ! empty( $_GET['post_status'] ) ) ? wc_clean( wp_unslash( $_GET['post_status'] ) ) : ''; // phpcs:ignore + if ( 'edit.php' === $pagenow && 'shop_coupon' === $typenow && 'trash' === $coupon_status ) { + if ( ! wp_script_is( 'jquery' ) ) { + wp_enqueue_script( 'jquery' ); + } + ?> + + 'no', + ); + + if ( ! empty( $coupon_id ) ) { + $coupon = new WC_Coupon( $coupon_id ); + if ( is_a( $coupon, 'WC_Coupon' ) ) { + $scheduled_actions_ids = ( $this->is_callable( $coupon, 'get_meta' ) ) ? $coupon->get_meta( 'wc_sc_scheduled_actions_ids' ) : $this->get_post_meta( $coupon_id, 'wc_sc_scheduled_actions_ids', true ); + if ( is_array( $scheduled_actions_ids ) && ! empty( $scheduled_actions_ids ) ) { + $response['has_scheduled_actions'] = 'yes'; + } + } + } + + wp_send_json( $response ); + } + + /** + * Register new endpoint to use inside My Account page. + */ + public function sc_add_endpoints() { + + if ( empty( WC_SC_Display_Coupons::$endpoint ) ) { + WC_SC_Display_Coupons::$endpoint = WC_SC_Display_Coupons::get_endpoint(); + } + + if ( $this->is_wc_gte_26() ) { + add_rewrite_endpoint( WC_SC_Display_Coupons::$endpoint, EP_ROOT | EP_PAGES ); + $this->sc_check_if_flushed_rules(); + } + + } + + /** + * To register Smart Coupons Endpoint after plugin is activated - Necessary + */ + public function sc_check_if_flushed_rules() { + $sc_check_flushed_rules = get_option( 'sc_flushed_rules', 'notfound' ); + if ( 'notfound' === $sc_check_flushed_rules ) { + flush_rewrite_rules(); // phpcs:ignore + update_option( 'sc_flushed_rules', 'found', 'no' ); + } + } + + /** + * Register & enqueue Smart Coupons CSS + */ + public function register_plugin_styles() { + global $pagenow; + + $is_frontend = ( ! is_admin() ) ? true : false; + $is_valid_post_page = ( ! empty( $pagenow ) && in_array( $pagenow, array( 'edit.php', 'post.php', 'post-new.php' ), true ) ) ? true : false; + $is_valid_admin_page = ( ( ! empty( $_GET['page'] ) && 'wc-smart-coupons' === wc_clean( wp_unslash( $_GET['page'] ) ) ) || ( ! empty( $_GET['tab'] ) && 'wc-smart-coupons' === wc_clean( wp_unslash( $_GET['tab'] ) ) ) ) ? true : false; // phpcs:ignore + + if ( $is_frontend || $is_valid_admin_page || $is_valid_post_page ) { + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; + wp_register_style( 'smart-coupon', untrailingslashit( plugins_url( '/', WC_SC_PLUGIN_FILE ) ) . '/assets/css/smart-coupon' . $suffix . '.css', array(), $this->plugin_data['Version'] ); + wp_register_style( 'smart-coupon-designs', untrailingslashit( plugins_url( '/', WC_SC_PLUGIN_FILE ) ) . '/assets/css/smart-coupon-designs.css', array(), $this->plugin_data['Version'] ); + } + } + + /** + * Get coupon style attributes + * + * @return string The coupon style attribute + */ + public function get_coupon_style_attributes() { + + $styles = array(); + + $coupon_design = get_option( 'wc_sc_setting_coupon_design', 'basic' ); + + if ( 'custom-design' !== $coupon_design ) { + $styles = array( + 'background-color: var(--sc-color1) !important;', + 'color: var(--sc-color2) !important;', + 'border-color: var(--sc-color3) !important;', + ); + } + + $styles = implode( ' ', $styles ); + + return apply_filters( 'wc_sc_coupon_style_attributes', $styles ); + + } + + /** + * Get coupon container classes + * + * @return string The coupon container classes + */ + public function get_coupon_container_classes() { + + return implode( ' ', apply_filters( 'wc_sc_coupon_container_classes', array( 'medium', get_option( 'wc_sc_setting_coupon_design', 'basic' ) ) ) ); + + } + + /** + * Get coupon content classes + * + * @return string The coupon content classes + */ + public function get_coupon_content_classes() { + + return implode( ' ', apply_filters( 'wc_sc_coupon_content_classes', array( 'dashed', 'small' ) ) ); + + } + + /** + * Formatted coupon data + * + * @param WC_Coupon $coupon Coupon object. + * @return array $coupon_data Associative array containing formatted coupon data. + */ + public function get_coupon_meta_data( $coupon ) { + global $store_credit_label, $post; + + $order = null; + + if ( ! empty( $post->ID ) && 'shop_order' === $this->get_post_type( $post->ID ) ) { + $order = wc_get_order( $post->ID ); + } + + $all_discount_types = wc_get_coupon_types(); + + if ( $this->is_wc_gte_30() ) { + $coupon_id = ( ! empty( $coupon ) && is_callable( array( $coupon, 'get_id' ) ) ) ? $coupon->get_id() : 0; + $discount_type = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_discount_type' ) ) ) ? $coupon->get_discount_type() : ''; + } else { + $coupon_id = ( ! empty( $coupon->id ) ) ? $coupon->id : 0; + $discount_type = ( ! empty( $coupon->discount_type ) ) ? $coupon->discount_type : ''; + } + + $coupon_amount = $this->get_amount( $coupon, true, $order ); + + $coupon_data = array(); + switch ( $discount_type ) { + case 'smart_coupon': + $coupon_data['coupon_type'] = ! empty( $store_credit_label['singular'] ) ? ucwords( $store_credit_label['singular'] ) : __( 'Store Credit', 'woocommerce-smart-coupons' ); + $coupon_data['coupon_amount'] = wc_price( $coupon_amount ); + break; + + case 'fixed_cart': + $coupon_data['coupon_type'] = __( 'Cart Discount', 'woocommerce-smart-coupons' ); + $coupon_data['coupon_amount'] = wc_price( $coupon_amount ); + break; + + case 'fixed_product': + $coupon_data['coupon_type'] = __( 'Product Discount', 'woocommerce-smart-coupons' ); + $coupon_data['coupon_amount'] = wc_price( $coupon_amount ); + break; + + case 'percent_product': + $coupon_data['coupon_type'] = __( 'Product Discount', 'woocommerce-smart-coupons' ); + $coupon_data['coupon_amount'] = $coupon_amount . '%'; + break; + + case 'percent': + $coupon_data['coupon_type'] = ( $this->is_wc_gte_30() ) ? __( 'Discount', 'woocommerce-smart-coupons' ) : __( 'Cart Discount', 'woocommerce-smart-coupons' ); + $coupon_data['coupon_amount'] = $coupon_amount . '%'; + $max_discount = $this->get_post_meta( $coupon_id, 'wc_sc_max_discount', true, true, $order ); + if ( ! empty( $max_discount ) && is_numeric( $max_discount ) ) { + /* translators: %s: Maximum coupon discount amount */ + $coupon_data['coupon_type'] .= ' ' . sprintf( __( ' upto %s', 'woocommerce-smart-coupons' ), wc_price( $max_discount ) ); + } + break; + + default: + $default_coupon_type = ( ! empty( $all_discount_types[ $discount_type ] ) ) ? $all_discount_types[ $discount_type ] : ucwords( str_replace( array( '_', '-' ), ' ', $discount_type ) ); + $coupon_data['coupon_type'] = apply_filters( 'wc_sc_coupon_type', $default_coupon_type, $coupon, $all_discount_types ); + $coupon_data['coupon_amount'] = apply_filters( 'wc_sc_coupon_amount', $coupon_amount, $coupon ); + break; + + } + return $coupon_data; + } + + /** + * Generate coupon description + * + * @param array $args The arguments. + * @return string + */ + public function generate_coupon_description( $args = array() ) { + $coupon = ( ! empty( $args['coupon_object'] ) ) ? $args['coupon_object'] : null; + $descriptions = array(); + $descriptions_data = array(); + if ( $this->is_wc_gte_30() && is_object( $coupon ) ) { + $discount_type = ( is_callable( array( $coupon, 'get_discount_type' ) ) ) ? $coupon->get_discount_type() : ''; + $expiry_time = ( is_callable( array( $coupon, 'get_meta' ) ) ) ? $coupon->get_meta( 'wc_sc_expiry_time' ) : ''; + + $expiry_needed_in_design = array( 'ticket', 'special' ); + $design = get_option( 'wc_sc_setting_coupon_design', 'basic' ); + + $descriptions_data['minimum_amount'] = ( is_callable( array( $coupon, 'get_minimum_amount' ) ) ) ? $coupon->get_minimum_amount() : ''; + $descriptions_data['maximum_amount'] = ( is_callable( array( $coupon, 'get_maximum_amount' ) ) ) ? $coupon->get_maximum_amount() : ''; + $descriptions_data['exclude_sale_items'] = ( is_callable( array( $coupon, 'get_exclude_sale_items' ) ) ) ? $coupon->get_exclude_sale_items() : ''; + $descriptions_data['product_ids'] = ( is_callable( array( $coupon, 'get_product_ids' ) ) ) ? $coupon->get_product_ids() : array(); + $descriptions_data['excluded_product_ids'] = ( is_callable( array( $coupon, 'get_excluded_product_ids' ) ) ) ? $coupon->get_excluded_product_ids() : array(); + $descriptions_data['product_categories'] = ( is_callable( array( $coupon, 'get_product_categories' ) ) ) ? $coupon->get_product_categories() : array(); + $descriptions_data['excluded_product_categories'] = ( is_callable( array( $coupon, 'get_excluded_product_categories' ) ) ) ? $coupon->get_excluded_product_categories() : array(); + + $check_descriptions_data = array_filter( $descriptions_data ); + + if ( in_array( $design, $expiry_needed_in_design, true ) || empty( $check_descriptions_data ) ) { + $descriptions_data['date_expires'] = ( is_callable( array( $coupon, 'get_date_expires' ) ) ) ? $coupon->get_date_expires() : ''; + } + + $max_fields = apply_filters( + 'wc_sc_max_fields_to_show_in_coupon_description', + 2, + array( + 'source' => $this, + 'coupon_object' => $coupon, + ) + ); + + if ( ! empty( $descriptions_data ) ) { + foreach ( $descriptions_data as $key => $data ) { + if ( count( $descriptions ) > $max_fields ) { + break; + } + if ( ! empty( $data ) ) { + switch ( $key ) { + case 'minimum_amount': + /* translators: Formatted minimum amount */ + $descriptions[] = sprintf( __( 'Spend at least %s', 'woocommerce-smart-coupons' ), wc_price( $data ) ); + break; + case 'maximum_amount': + /* translators: Formatted maximum amount */ + $descriptions[] = sprintf( __( 'Spend up to %s', 'woocommerce-smart-coupons' ), wc_price( $data ) ); + break; + case 'exclude_sale_items': + /* translators: Formatted maximum amount */ + $descriptions[] = sprintf( __( 'Not valid for sale items', 'woocommerce-smart-coupons' ), wc_price( $data ) ); + break; + case 'product_ids': + $get_product_names = $this->get_coupon_product_names( $data ); + $product_names = ( ! empty( $get_product_names ) && is_array( $get_product_names ) ) ? implode( ', ', $get_product_names ) : ''; + /* translators: Product names */ + $descriptions[] = sprintf( __( 'Valid for %s', 'woocommerce-smart-coupons' ), $product_names ); + break; + case 'excluded_product_ids': + $get_product_names = $this->get_coupon_product_names( $data ); + $product_names = ( ! empty( $get_product_names ) && is_array( $get_product_names ) ) ? implode( ', ', $get_product_names ) : ''; + /* translators: Excluded product names */ + $descriptions[] = sprintf( __( 'Not valid for %s', 'woocommerce-smart-coupons' ), $product_names ); + break; + case 'product_categories': + $get_product_categories = $this->get_coupon_category_names( $data ); + $product_categories = ( ! empty( $get_product_categories ) ) ? implode( ', ', $get_product_categories ) : ''; + $count_product_categories = ( ! empty( $get_product_categories ) ) ? count( $get_product_categories ) : 1; + /* translators: 1: The category names */ + $descriptions[] = sprintf( esc_html( _n( 'Valid for category %s', 'Valid for categories %s', $count_product_categories, 'woocommerce-smart-coupons' ) ), $product_categories ); + break; + case 'excluded_product_categories': + $get_product_categories = $this->get_coupon_category_names( $data ); + $product_categories = ( ! empty( $get_product_categories ) ) ? implode( ', ', $get_product_categories ) : ''; + $count_product_categories = ( ! empty( $get_product_categories ) ) ? count( $get_product_categories ) : 1; + /* translators: 1: The category names excluded */ + $descriptions[] = sprintf( esc_html( _n( 'Not valid for category %s', 'Not valid for categories %s', $count_product_categories, 'woocommerce-smart-coupons' ) ), $product_categories ); + break; + case 'date_expires': + if ( $data instanceof WC_DateTime ) { + $expiry_date = ( is_object( $data ) && is_callable( array( $data, 'getTimestamp' ) ) ) ? $data->getTimestamp() : null; + } elseif ( ! is_int( $expiry_date ) ) { + $expiry_date = $this->strtotime( $expiry_date ); + } + if ( ! empty( $expiry_date ) && is_int( $expiry_date ) && ! empty( $expiry_time ) ) { + $expiry_date += $expiry_time; // Adding expiry time to expiry date. + } + if ( ! empty( $expiry_date ) ) { + /* translators: 1: The expiry date */ + $descriptions[] = sprintf( __( 'Expiry: %s', 'woocommerce-smart-coupons' ), $this->get_expiration_format( $expiry_date ) ); + } + break; + } + } + } + } + } + if ( empty( $descriptions ) ) { + $descriptions[] = __( 'Valid on entire range of products. Buy anything in the store.', 'woocommerce-smart-coupons' ); + } + return apply_filters( + 'wc_sc_generated_coupon_description', + implode( '. ', $descriptions ), + array( + 'source' => $this, + 'coupon_object' => $coupon, + ) + ); + } + + /** + * Get coupon category names. + * + * @since 5.7.0 + * + * @param array $category_ids Category IDs. + * @return array + */ + public function get_coupon_category_names( $category_ids = array() ) { + $category_names = array(); + + if ( empty( $category_ids ) || ! is_array( $category_ids ) ) { + return $category_names; + } + + $category_name_count_restriction = (int) apply_filters( + 'wc_sc_max_restricted_category_names', + 2, + array( + 'source' => $this, + 'data' => $category_ids, + ) + ); + + if ( count( $category_ids ) > $category_name_count_restriction ) { + $category_ids = array_slice( $category_ids, 0, $category_name_count_restriction ); + } + $category_names = get_terms( + array( + 'taxonomy' => 'product_cat', + 'include' => $category_ids, + 'fields' => 'id=>name', + 'get' => 'all', + ) + ); + + return array_filter( $category_names ); + } + + /** + * Get coupon product's names. + * + * @since 5.7.0 + * + * @param array $product_ids Product IDs. + * @return array + */ + public function get_coupon_product_names( $product_ids = array() ) { + $product_names = array(); + + if ( empty( $product_ids ) || ! is_array( $product_ids ) ) { + return $product_names; + } + + $data_count = count( $product_ids ); + $product_name_count = 0; + + $product_name_count_restriction = (int) apply_filters( + 'wc_sc_max_restricted_product_names', + 2, + array( + 'source' => $this, + 'data' => $product_ids, + ) + ); + + for ( $i = 0; $i < $data_count && $product_name_count < $product_name_count_restriction; $i++ ) { + $product = wc_get_product( $product_ids[ $i ] ); + if ( is_object( $product ) && is_callable( array( $product, 'get_name' ) ) ) { + $product_names[] = $product->get_name(); + $product_name_count++; + } + } + + return array_filter( $product_names ); + + } + + /** + * Get valid coupon designs + * + * @return array + */ + public function get_valid_coupon_designs() { + $valid_designs = array( + 'flat', + 'promotion', + 'ticket', + 'festive', + 'special', + 'shipment', + 'cutout', + 'deliver', + 'clipper', + 'basic', + 'deal', + 'custom-design', + ); + return $valid_designs; + } + + /** + * Get coupon design thumbnail src + * + * @param array $args The arguments. + * @return string + */ + public function get_coupon_design_thumbnail_src( $args = array() ) { + $coupon = ( ! empty( $args['coupon_object'] ) ) ? $args['coupon_object'] : null; + $src = ''; + $src_selected = ''; + $placeholder = wc_placeholder_img_src(); + if ( is_object( $coupon ) ) { + $coupon_product_ids = ( is_callable( array( $coupon, 'get_product_ids' ) ) ) ? $coupon->get_product_ids() : array(); + if ( ! empty( $coupon_product_ids ) ) { + $product_id = current( $coupon_product_ids ); + $product = wc_get_product( $product_id ); + $thumbnail_id = ( is_object( $product ) && is_callable( array( $product, 'get_image_id' ) ) ) ? $product->get_image_id() : ''; + } else { + $coupon_product_category_ids = ( is_callable( array( $coupon, 'get_product_categories' ) ) ) ? $coupon->get_product_categories() : array(); + if ( ! empty( $coupon_product_category_ids ) ) { + $category_id = current( $coupon_product_category_ids ); + $thumbnail_id = get_term_meta( $category_id, 'thumbnail_id', true ); + } + } + $src_array = ( ! empty( $thumbnail_id ) ) ? wp_get_attachment_image_src( $thumbnail_id, 'woocommerce_thumbnail' ) : array(); + $src = ( ! empty( $src_array[0] ) ) ? $src_array[0] : wc_placeholder_img_src(); + if ( ! empty( $src ) && strpos( $src, $placeholder ) !== false ) { + $src = ''; + } + } + if ( empty( $src ) ) { + $src_set = array(); + if ( $this->is_wc_gte_30() ) { + $discount_type = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_discount_type' ) ) ) ? $coupon->get_discount_type() : ''; + $is_free_shipping = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_free_shipping' ) ) ) ? ( ( $coupon->get_free_shipping() ) ? 'yes' : 'no' ) : ''; + } else { + $discount_type = ( ! empty( $coupon->discount_type ) ) ? $coupon->discount_type : ''; + $is_free_shipping = ( ! empty( $coupon->free_shipping ) ) ? $coupon->free_shipping : ''; + } + + if ( 'yes' === $is_free_shipping ) { + $src_set = array( + 'delivery-motorcyle.svg', + ); + } else { + switch ( $discount_type ) { + case 'smart_coupon': + $src_set = array( + 'giftbox-color.svg', + ); + break; + + case 'fixed_cart': + $src_set = array( + 'sale-splash-tag.svg', + ); + break; + + case 'fixed_product': + $src_set = array( + 'product-package-box.svg', + ); + break; + + case 'percent_product': + $src_set = array( + 'cart-discount.svg', + ); + break; + + case 'percent': + $src_set = array( + 'cart-discount.svg', + ); + break; + + default: + $src_set = apply_filters( + 'wc_sc_coupon_design_thumbnail_src_set', + array( 'discount-coupon.svg' ), + array( + 'source' => $this, + 'coupon_object' => $coupon, + ) + ); + break; + + } + } + if ( ! empty( $src_set ) ) { + $src_index = array_rand( $src_set ); + $src_selected = $src_set[ $src_index ]; + $file = trailingslashit( plugins_url( '/', WC_SC_PLUGIN_FILE ) ) . 'assets/images/' . $src_selected; + $src = apply_filters( + 'wc_sc_coupon_design_thumbnail_src', + $file, + array( + 'source' => $this, + 'selected' => $src_selected, + 'coupon_object' => $coupon, + ) + ); + } + } + if ( empty( $src ) ) { + $design = ( ! empty( $args['design'] ) ) ? $args['design'] : ''; + if ( ! empty( $design ) ) { + switch ( $design ) { + case 'special': + $src_selected = 'giftbox-color.svg'; + break; + case 'shipment': + $src_selected = 'product-package-box.svg'; + break; + case 'cutout': + $src_selected = 'cart-discount.svg'; + break; + case 'deliver': + $src_selected = 'delivery-motorcyle.svg'; + break; + case 'deal': + $src_selected = 'discount-coupon.svg'; + break; + case 'flat': + case 'promotion': + case 'ticket': + case 'festive': + case 'clipper': + case 'basic': + default: + $src_selected = 'discount-coupon.svg'; + break; + } + if ( ! empty( $src_selected ) ) { + $file = trailingslashit( plugins_url( '/', WC_SC_PLUGIN_FILE ) ) . 'assets/images/' . $src_selected; + $src = apply_filters( + 'wc_sc_coupon_design_thumbnail_src', + $file, + array( + 'source' => $this, + 'selected' => $src_selected, + 'coupon_object' => $coupon, + ) + ); + } else { + $src = ''; + } + } + } + return $src; + } + + /** + * Find if the discount type is percent + * + * @param array $args The arguments. + * @return boolean + */ + public function is_percent_coupon( $args = array() ) { + $is_percent = false; + $coupon = ( ! empty( $args['coupon_object'] ) ) ? $args['coupon_object'] : null; + $percent_discount_types = apply_filters( + 'wc_sc_percent_discount_types', + array( 'percent_product', 'percent' ), + array( + 'source' => $this, + 'coupon_object' => $coupon, + ) + ); + if ( $this->is_wc_gte_30() ) { + $discount_type = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_discount_type' ) ) ) ? $coupon->get_discount_type() : ''; + } else { + $discount_type = ( ! empty( $coupon->discount_type ) ) ? $coupon->discount_type : ''; + } + if ( in_array( $discount_type, $percent_discount_types, true ) ) { + $is_percent = true; + } + return $is_percent; + } + + /** + * Generate storewide offer coupon description + * + * @param array $args Arguments. + * @return string + */ + public function generate_storewide_offer_coupon_description( $args = array() ) { + $coupon = ( ! empty( $args['coupon_object'] ) ) ? $args['coupon_object'] : false; + $coupon_amount = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_amount' ) ) ) ? $coupon->get_amount( 'edit' ) : 0; + $coupon_code = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_code' ) ) ) ? $coupon->get_code() : ''; + + if ( empty( $coupon_amount ) || empty( $coupon_code ) ) { + return ''; + } + + $description = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_description' ) ) ) ? $coupon->get_description() : ''; + + if ( empty( $description ) ) { + + $is_percent = $this->is_percent_coupon( array( 'coupon_object' => $coupon ) ); + $currency_symbol = get_woocommerce_currency_symbol(); + + $before_heading = array( + __( 'Great News!', 'woocommerce-smart-coupons' ), + __( 'Super Savings!', 'woocommerce-smart-coupons' ), + __( 'Ending Soon!', 'woocommerce-smart-coupons' ), + __( 'Limited Time Offer!', 'woocommerce-smart-coupons' ), + __( 'This Week Only!', 'woocommerce-smart-coupons' ), + __( 'Attention!', 'woocommerce-smart-coupons' ), + __( 'You don\'t want to miss this...', 'woocommerce-smart-coupons' ), + __( 'This will be over soon! Hurry.', 'woocommerce-smart-coupons' ), + __( 'Act before the offer expires.', 'woocommerce-smart-coupons' ), + __( 'Don't Miss Out.', 'woocommerce-smart-coupons' ), + ); + + $heading = array( + /* translators: 1. The discount text */ + __( '%s discount on anything you want.', 'woocommerce-smart-coupons' ), + /* translators: 1. The discount text */ + __( '%s discount on entire store.', 'woocommerce-smart-coupons' ), + /* translators: 1. The discount text */ + __( 'Pick any item today for %s off.', 'woocommerce-smart-coupons' ), + /* translators: 1. The discount text */ + __( 'Buy as much as you want. Flat %s off everything.', 'woocommerce-smart-coupons' ), + /* translators: 1. The discount text */ + __( 'Flat %s discount on everything today.', 'woocommerce-smart-coupons' ), + ); + + $before_heading_index = array_rand( $before_heading ); + $heading_index = array_rand( $heading ); + + if ( true === $is_percent ) { + $discount_text = $coupon_amount . '%'; + } else { + $discount_text = $currency_symbol . $coupon_amount; + } + + $description = sprintf( '%s ' . $heading[ $heading_index ] . ' %s: %s', $before_heading[ $before_heading_index ], '' . $discount_text . '', __( 'Use code', 'woocommerce-smart-coupons' ), '' . $coupon_code . '' ); + + $description = apply_filters( + 'wc_sc_storewide_offer_coupon_description', + $description, + array_merge( + $args, + array( + 'before_heading' => $before_heading[ $before_heading_index ], + 'heading' => $heading, + 'discount_text' => $discount_text, + ) + ) + ); + + } else { + /* translators: 1. The coupon code */ + $description .= ' ' . sprintf( __( 'Use code: %s', 'woocommerce-smart-coupons' ), '' . $coupon_code . '' ); + } + + return $description; + + } + + /** + * Update coupon's email id with the updation of customer profile + * + * @param int $user_id User ID of the user being saved. + */ + public function my_profile_update( $user_id ) { + + global $wpdb; + + if ( current_user_can( 'edit_user', $user_id ) ) { + + $current_user = get_userdata( $user_id ); + + $old_customers_email_id = $current_user->data->user_email; + + $post_email = ( isset( $_POST['email'] ) ) ? wc_clean( wp_unslash( $_POST['email'] ) ) : ''; // phpcs:ignore + + if ( ! empty( $post_email ) && $post_email !== $old_customers_email_id ) { + + $result = wp_cache_get( 'wc_sc_customers_coupon_ids_' . sanitize_key( $old_customers_email_id ), 'woocommerce_smart_coupons' ); + + if ( false === $result ) { + $result = $wpdb->get_col( // phpcs:ignore + $wpdb->prepare( + "SELECT post_id + FROM $wpdb->postmeta + WHERE meta_key = %s + AND meta_value LIKE %s + AND post_id IN ( SELECT ID + FROM $wpdb->posts + WHERE post_type = %s)", + 'customer_email', + '%' . $wpdb->esc_like( '"' . $old_customers_email_id . '"' ) . '%', + 'shop_coupon' + ) + ); + wp_cache_set( 'wc_sc_customers_coupon_ids_' . sanitize_key( $old_customers_email_id ), $result, 'woocommerce_smart_coupons' ); + $this->maybe_add_cache_key( 'wc_sc_customers_coupon_ids_' . sanitize_key( $old_customers_email_id ) ); + } + + if ( ! empty( $result ) ) { + + foreach ( $result as $post_id ) { + + $coupon_meta = $this->get_post_meta( $post_id, 'customer_email', true ); + $is_update_coupon_meta = false; + + if ( ! empty( $coupon_meta ) ) { + foreach ( $coupon_meta as $key => $email_id ) { + if ( $email_id === $old_customers_email_id ) { + $coupon_meta[ $key ] = $post_email; + $is_update_coupon_meta = true; + } + } + } + + if ( true === $is_update_coupon_meta ) { + $this->update_post_meta( $post_id, 'customer_email', $coupon_meta ); + } + } //end foreach + } + } + } + } + + /** + * Method to check whether 'pick_price_from_product' is set or not + * + * @param array $coupons Array of coupon codes. + * @return boolean + */ + public function is_coupon_amount_pick_from_product_price( $coupons ) { + + if ( empty( $coupons ) ) { + return false; + } + + if ( ! is_array( $coupons ) && is_scalar( $coupons ) ) { + $coupons = array( $coupons ); + } + + foreach ( $coupons as $coupon_code ) { + $coupon = new WC_Coupon( $coupon_code ); + if ( $this->is_wc_gte_30() ) { + if ( ! is_object( $coupon ) || ! is_callable( array( $coupon, 'get_id' ) ) ) { + continue; + } + $coupon_id = $coupon->get_id(); + if ( empty( $coupon_id ) ) { + continue; + } + $discount_type = $coupon->get_discount_type(); + $is_pick_price_of_product = ( $this->is_callable( $coupon, 'get_meta' ) ) ? $coupon->get_meta( 'is_pick_price_of_product' ) : $this->get_post_meta( $coupon_id, 'is_pick_price_of_product', true ); + } else { + $coupon_id = ( ! empty( $coupon->id ) ) ? $coupon->id : 0; + $discount_type = ( ! empty( $coupon->discount_type ) ) ? $coupon->discount_type : ''; + $is_pick_price_of_product = get_post_meta( $coupon_id, 'is_pick_price_of_product', true ); + } + if ( 'smart_coupon' === $discount_type && 'yes' === $is_pick_price_of_product ) { + return true; + } + } + return false; + } + + /** + * Function to find if order is discounted with store credit + * + * @param WC_Order $order Order object. + * @return boolean + */ + public function is_order_contains_store_credit( $order = null ) { + + if ( empty( $order ) ) { + return false; + } + + $coupons = $order->get_items( 'coupon' ); + + foreach ( $coupons as $item_id => $item ) { + $code = ( is_object( $item ) && is_callable( array( $item, 'get_name' ) ) ) ? $item->get_name() : trim( $item['name'] ); + $coupon = new WC_Coupon( $code ); + if ( $this->is_wc_gte_30() ) { + $discount_type = $coupon->get_discount_type(); + } else { + $discount_type = ( ! empty( $coupon->discount_type ) ) ? $coupon->discount_type : ''; + } + if ( 'smart_coupon' === $discount_type ) { + return true; + } + } + + return false; + + } + + /** + * Function to validate smart coupon for product + * + * @param bool $valid Coupon validity. + * @param WC_Product|null $product Product object. + * @param WC_Coupon|null $coupon Coupon object. + * @param array|null $values Values. + * @return bool $valid + */ + public function smart_coupons_is_valid_for_product( $valid, $product = null, $coupon = null, $values = null ) { + + if ( empty( $product ) || empty( $coupon ) ) { + return $valid; + } + + if ( $this->is_wc_gte_30() ) { + $product_id = ( is_object( $product ) && is_callable( array( $product, 'get_id' ) ) ) ? $product->get_id() : 0; + $product_parent_id = ( is_object( $product ) && is_callable( array( $product, 'get_parent_id' ) ) ) ? $product->get_parent_id() : 0; + $product_variation_id = ( is_object( $product ) && is_callable( array( $product, 'get_id' ) ) ) ? $product->get_id() : 0; + $discount_type = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_discount_type' ) ) ) ? $coupon->get_discount_type() : ''; + $coupon_product_ids = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_product_ids' ) ) ) ? $coupon->get_product_ids() : ''; + $coupon_product_categories = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_product_categories' ) ) ) ? $coupon->get_product_categories() : ''; + $coupon_excluded_product_ids = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_excluded_product_ids' ) ) ) ? $coupon->get_excluded_product_ids() : ''; + $coupon_excluded_product_categories = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_excluded_product_categories' ) ) ) ? $coupon->get_excluded_product_categories() : ''; + $is_exclude_sale_items = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_exclude_sale_items' ) ) ) ? ( ( $coupon->get_exclude_sale_items() ) ? 'yes' : 'no' ) : ''; + } else { + $product_id = ( ! empty( $product->id ) ) ? $product->id : 0; + $product_parent_id = ( ! empty( $product ) && is_callable( array( $product, 'get_parent' ) ) ) ? $product->get_parent() : 0; + $product_variation_id = ( ! empty( $product->variation_id ) ) ? $product->variation_id : 0; + $discount_type = ( ! empty( $coupon->discount_type ) ) ? $coupon->discount_type : ''; + $coupon_product_ids = ( ! empty( $coupon->product_ids ) ) ? $coupon->product_ids : array(); + $coupon_product_categories = ( ! empty( $coupon->product_categories ) ) ? $coupon->product_categories : array(); + $coupon_excluded_product_ids = ( ! empty( $coupon->exclude_product_ids ) ) ? $coupon->exclude_product_ids : array(); + $coupon_excluded_product_categories = ( ! empty( $coupon->exclude_product_categories ) ) ? $coupon->exclude_product_categories : array(); + $is_exclude_sale_items = ( ! empty( $coupon->exclude_sale_items ) ) ? $coupon->exclude_sale_items : ''; + } + + if ( 'smart_coupon' === $discount_type ) { + + $product_cats = wc_get_product_cat_ids( $product_id ); + + // Specific products get the discount. + if ( count( $coupon_product_ids ) > 0 ) { + + if ( in_array( $product_id, $coupon_product_ids, true ) || ( isset( $product_variation_id ) && in_array( $product_variation_id, $coupon_product_ids, true ) ) || in_array( $product_parent_id, $coupon_product_ids, true ) ) { + $valid = true; + } + + // Category discounts. + } elseif ( count( $coupon_product_categories ) > 0 ) { + + if ( count( array_intersect( $product_cats, $coupon_product_categories ) ) > 0 ) { + $valid = true; + } + } else { + // No product ids - all items discounted. + $valid = true; + } + + // Specific product ID's excluded from the discount. + if ( count( $coupon_excluded_product_ids ) > 0 ) { + if ( in_array( $product_id, $coupon_excluded_product_ids, true ) || ( isset( $product_variation_id ) && in_array( $product_variation_id, $coupon_excluded_product_ids, true ) ) || in_array( $product_parent_id, $coupon_excluded_product_ids, true ) ) { + $valid = false; + } + } + + // Specific categories excluded from the discount. + if ( count( $coupon_excluded_product_categories ) > 0 ) { + if ( count( array_intersect( $product_cats, $coupon_excluded_product_categories ) ) > 0 ) { + $valid = false; + } + } + + // Sale Items excluded from discount. + if ( 'yes' === $is_exclude_sale_items ) { + $product_ids_on_sale = wc_get_product_ids_on_sale(); + + if ( in_array( $product_id, $product_ids_on_sale, true ) || ( isset( $product_variation_id ) && in_array( $product_variation_id, $product_ids_on_sale, true ) ) || in_array( $product_parent_id, $product_ids_on_sale, true ) ) { + $valid = false; + } + } + } + + return $valid; + } + + /** + * Validate expiry time + * + * @param boolean $expired Whether the coupon is expired or not. + * @param WC_Coupon $coupon The coupon object. + * @param WC_Discounts $discounts The discount object. + * @return boolean + */ + public function validate_expiry_time( $expired = false, $coupon = null, $discounts = null ) { + + if ( ! $this->is_wc_gte_30() ) { + return $expired; // Expiry time feature is not supported for lower version of WooCommerce. + } + + $expiry_time = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_meta' ) ) ) ? (int) $coupon->get_meta( 'wc_sc_expiry_time' ) : 0; + + if ( ! empty( $expiry_time ) ) { + $expiry_date = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_date_expires' ) ) ) ? $coupon->get_date_expires() : ''; + if ( ! empty( $expiry_date ) ) { + if ( $expiry_date instanceof WC_DateTime ) { + $expiry_date = ( is_callable( array( $expiry_date, 'getTimestamp' ) ) ) ? $expiry_date->getTimestamp() : null; + } elseif ( ! is_int( $expiry_date ) ) { + $expiry_date = $this->strtotime( $expiry_date ); + } + if ( is_int( $expiry_date ) ) { + $expiry_date += $expiry_time; // Adding expiry time to expiry date. + if ( time() <= $expiry_date ) { + $expired = false; + } else { + $expired = true; + } + } + } + } + + return $expired; + } + + /** + * Wrapper function for strtotime + * + * @param string $date_time The date time. + * @return int + */ + public function strtotime( $date_time = '' ) { + $parsed_date = ( is_string( $date_time ) ) ? date_parse( $date_time ) : array( 'warning_count' => 1 ); + if ( ! empty( $parsed_date['warning_count'] ) ) { + return 0; + } + return strtotime( $date_time ); + } + + /** + * Function to keep valid coupons when individual use coupon is applied + * + * @param array $coupons_to_keep Coupons to keep. + * @param WC_Coupon|boolean $the_coupon Coupon object. + * @param array $applied_coupons Array of applied coupons. + * @return array $coupons_to_keep + */ + public function smart_coupons_override_individual_use( $coupons_to_keep = array(), $the_coupon = false, $applied_coupons = array() ) { + + if ( $this->is_wc_gte_30() ) { + foreach ( $applied_coupons as $code ) { + $coupon = new WC_Coupon( $code ); + if ( 'smart_coupon' === $coupon->get_discount_type() && ! $coupon->get_individual_use() && ! in_array( $code, $coupons_to_keep, true ) ) { + $coupons_to_keep[] = $code; + } + } + } + + return $coupons_to_keep; + } + + /** + * Force apply store credit even if the individual coupon already exists in cart + * + * @param boolean $is_apply Apply with individual use coupon. + * @param WC_Coupon|boolean $the_coupon Coupon object. + * @param WC_Coupon|boolean $applied_coupon Coupon object. + * @param array $applied_coupons Array of applied coupons. + * @return boolean + */ + public function smart_coupons_override_with_individual_use( $is_apply = false, $the_coupon = false, $applied_coupon = false, $applied_coupons = array() ) { + + if ( $this->is_wc_gte_30() ) { + if ( ! $is_apply && 'smart_coupon' === $the_coupon->get_discount_type() && ! $the_coupon->get_individual_use() ) { + $is_apply = true; + } + } + + return $is_apply; + } + + /** + * Function to add appropriate discount total filter + */ + public function smart_coupons_discount_total_filters() { + if ( WCS_SC_Compatibility::is_cart_contains_subscription() && WCS_SC_Compatibility::is_wcs_gte( '2.0.0' ) ) { + add_action( 'woocommerce_after_calculate_totals', array( $this, 'smart_coupons_after_calculate_totals' ), 9999 ); + } else { + add_action( 'woocommerce_after_calculate_totals', array( $this, 'smart_coupons_after_calculate_totals' ), 9999 ); + global $current_screen; + if ( ! empty( $current_screen ) && 'edit-shop_order' !== $current_screen ) { + add_filter( 'woocommerce_order_get_total', array( $this, 'smart_coupons_order_discounted_total' ), 10, 2 ); + } + } + } + + /** + * Function to handle store credit application + */ + public function sc_handle_store_credit_application() { + $apply_before_tax = get_option( 'woocommerce_smart_coupon_apply_before_tax', 'no' ); + + if ( $this->is_wc_gte_30() && 'yes' === $apply_before_tax ) { + include_once 'class-wc-sc-apply-before-tax.php'; + } else { + add_action( 'wp_loaded', array( $this, 'smart_coupons_discount_total_filters' ), 20 ); + add_action( 'woocommerce_order_after_calculate_totals', array( $this, 'order_calculate_discount_amount' ), 10, 2 ); + add_action( 'woocommerce_order_after_calculate_totals', array( $this, 'order_calculate_discount_amount_rest_api' ), 10, 2 ); + add_filter( 'woocommerce_cart_totals_coupon_html', array( $this, 'cart_totals_coupon_html' ), 99, 3 ); + } + } + + + /** + * Function calculate actual order total without discount + * + * @param WC_Order $order Order object. + * @return float $order_total + */ + public function get_original_order_total_before_discount( $order = null ) { + $order_total = 0; + if ( ! is_object( $order ) || ! $order instanceof WC_Order ) { + return $order_total; + } + $line_items = $order->get_items( 'line_item' ); + $fee_items = $order->get_items( 'fee' ); + + if ( is_array( $line_items ) && ! empty( $line_items ) ) { + foreach ( $line_items as $order_item ) { + if ( ! $order_item instanceof WC_Order_Item_Product ) { + continue; + } + $order_total += $order->get_line_subtotal( $order_item, true ); + } + } + if ( $this->is_callable( $order, 'get_shipping_total' ) && $this->is_callable( $order, 'get_shipping_tax' ) ) { + $order_total += ( (float) $order->get_shipping_total() + (float) $order->get_shipping_tax() ); + } + + if ( is_array( $fee_items ) && ! empty( $fee_items ) ) { + foreach ( $fee_items as $fee_item ) { + if ( ! $fee_item instanceof WC_Order_Item_Fee ) { + continue; + } + $order_total += $order->get_item_total( $fee_item, true ); + } + } + return $order_total; + } + + /** + * Function to update smart coupon balance that are created manually. This method will call apply before tax enable/disable. + * + * @param bool $and_taxes Calc taxes if true. + * @param WC_Order $order Order object. + */ + public function update_smart_coupon_order_create_via_admin( $and_taxes = false, $order = null ) { + if ( ! is_object( $order ) || ! $order instanceof WC_Order ) { + return; + } + if ( isset( $order->sc_total_credit_used ) && is_array( $order->sc_total_credit_used ) && count( $order->sc_total_credit_used ) > 0 ) { + // phpcs:disable WordPress.Security.NonceVerification.Missing + $post_action = ! empty( $_POST['action'] ) ? sanitize_text_field( wp_unslash( $_POST['action'] ) ) : ''; + // Note*: Deduct Smart Coupon when publish a new order. + if ( in_array( $post_action, array( 'edit_order', 'editpost' ), true ) ) { + $status_exceptions = array( 'auto-draft', 'trash' ); + $new_status = ''; + $post_status = ! empty( $_POST['post_status'] ) ? sanitize_text_field( wp_unslash( $_POST['post_status'] ) ) : ''; + + if ( ! empty( $_POST['order_status'] ) ) { + + $order_status = sanitize_text_field( wp_unslash( $_POST['order_status'] ?? '' ) ); + + $new_status = 'wc-' === substr( $order_status, 0, 3 ) ? substr( $order_status, 3 ) : $order_status; + } + if ( 'auto-' === substr( $post_status, 0, 5 ) ) { + $post_status = substr( $post_status, 5 ); + } + + if ( in_array( 'auto-' === substr( $order->get_status(), 0, 5 ) ? substr( $order->get_status(), 5 ) : $order->get_status(), array( 'draft' ), true ) && in_array( 'auto-' === substr( $post_status, 0, 5 ) ? substr( $post_status, 5 ) : $post_status, array( 'draft' ), true ) && in_array( 'wc-' . $new_status, array_keys( wc_get_order_statuses() ), true ) && ! in_array( $new_status, $status_exceptions, true ) && did_action( 'sc_after_order_calculate_discount_amount' ) <= 0 ) { + do_action( 'sc_after_order_calculate_discount_amount', $order->get_id() ); + } + } + $pending_statuses = $this->get_pending_statuses(); + $current_applied_code = ( ! empty( $_POST['coupon'] ) ) ? strtolower( wc_clean( wp_unslash( $_POST['coupon'] ) ) ) : ''; // phpcs:ignore + + if ( 'woocommerce_add_coupon_discount' === $post_action && $order->has_status( $pending_statuses ) && !empty( $order->get_coupon_codes() ) && in_array( $current_applied_code , array_map( 'strtolower', $order->get_coupon_codes() ) ) && did_action( 'sc_after_order_calculate_discount_amount' ) <= 0 ) { // phpcs:ignore + do_action( 'sc_after_order_calculate_discount_amount', $order->get_id() ); + } + // phpcs:enable + } + } + + /** + * Function to set store credit amount for orders that are manually created and updated from backend + * + * @param bool $and_taxes Calc taxes if true. + * @param WC_Order $order Order object. + */ + public function order_calculate_discount_amount( $and_taxes = false, $order = null ) { + if ( ! is_object( $order ) || ! $order instanceof WC_Order ) { + return; + } + $order_actions = array( 'woocommerce_add_coupon_discount', 'woocommerce_calc_line_taxes', 'woocommerce_save_order_items', 'woocommerce_remove_order_coupon' ); + + $order_id = ( $this->is_callable( $order, 'get_id' ) ) ? $order->get_id() : 0; + + $post_action = ( ! empty( $_POST['action'] ) ) ? wc_clean( wp_unslash( $_POST['action'] ) ) : ''; // phpcs:ignore + $post_post_type = ( $this->is_hpos() ) ? $this->get_post_type( $order_id ) : ( ( ! empty( $_POST['post_type'] ) ) ? wc_clean( wp_unslash( $_POST['post_type'] ) ) : '' ); // phpcs:ignore + $order_created_via_admin = ! empty( $post_action ) && ( in_array( $post_action, $order_actions, true ) ) || 'admin' === $order->get_created_via() ? true : false; + $discount_total = 0; + $discount_tax = 0; + if ( ( ! empty( $post_action ) && ( in_array( $post_action, $order_actions, true ) || ( ! empty( $post_post_type ) && 'shop_order' === $post_post_type && in_array( $post_action, array( 'edit_order', 'editpost' ), true ) ) ) ) ) { + if ( ! is_callable( array( $order, 'get_id' ) ) ) { + return; + } + + if ( empty( $order_id ) ) { + return; + } + + $coupons = $order->get_items( 'coupon' ); + $total = $this->get_original_order_total_before_discount( $order ); + + if ( ! empty( $coupons ) ) { + foreach ( $coupons as $item_id => $item ) { + $coupon_code = ( is_object( $item ) && is_callable( array( $item, 'get_name' ) ) ) ? $item->get_name() : trim( $item['name'] ); + + if ( empty( $coupon_code ) ) { + continue; + } + + $coupon = new WC_Coupon( $coupon_code ); + $discount_type = $coupon->get_discount_type(); + $discount_amount = ( is_object( $item ) && is_callable( array( $item, 'get_discount' ) ) ) ? $item->get_discount() : $this->get_order_item_meta( $item_id, 'discount_amount', true, true ); + $discount_amount_tax = ( is_object( $item ) && is_callable( array( $item, 'get_discount_tax' ) ) ) ? $item->get_discount_tax() : $this->get_order_item_meta( $item_id, 'discount_tax', true, true ); + + if ( 'smart_coupon' === $discount_type ) { + + $smart_coupons_contribution = $this->get_post_meta( $order_id, 'smart_coupons_contribution', true, true ); + $smart_coupons_contribution = ! empty( $smart_coupons_contribution ) ? $smart_coupons_contribution : array(); + + if ( ! empty( $smart_coupons_contribution ) && count( $smart_coupons_contribution ) > 0 && array_key_exists( $coupon_code, $smart_coupons_contribution ) ) { + $discount = $smart_coupons_contribution[ $coupon_code ]; + if ( $order_created_via_admin ) { + $discount_amount = $discount; + } + } else { + $discount_data = $this->sc_order_get_discount_amount( $total, $coupon, $order ); + $discount_amount = isset( $discount_data['discount_total'] ) ? $discount_data['discount_total'] : 0; + $discount_amount_tax = isset( $discount_data['discount_tax'] ) ? $discount_data['discount_tax'] : 0; + $discount = $discount_amount + $discount_amount_tax; + $smart_coupons_contribution[ $coupon_code ] = $discount; + + // check if store credit discount does not cross max discount. It is only applicable for manual order creation. + if ( $order_created_via_admin && count( $smart_coupons_contribution ) > 0 && (float) array_sum( $smart_coupons_contribution ) > (float) $order->get_total() ) { + $ignore_discount_amount = (float) array_sum( $smart_coupons_contribution ) - (float) $order->get_total(); + $discount -= $ignore_discount_amount; + if ( $discount < 1 ) { + $discount_amount = 0; + $discount_amount_tax = 0; + $discount = 0; + } else { + $discount_amount = $discount; + } + $smart_coupons_contribution[ $coupon_code ] = $discount; + } + + $this->update_post_meta( $order_id, 'smart_coupons_contribution', $smart_coupons_contribution, true, $order ); + } + + if ( is_object( $item ) && is_callable( array( $item, 'set_discount' ) ) && isset( $discount_amount ) ) { + $item->set_discount( $discount_amount ); + } + if ( is_object( $item ) && is_callable( array( $item, 'set_discount_tax' ) ) && isset( $discount_amount_tax ) ) { + $item->set_discount_tax( $discount_amount_tax ); + } + } + + $discount_total += $discount_amount; + $discount_tax += $discount_amount_tax; + } + + $order->sc_total_credit_used = isset( $smart_coupons_contribution ) ? $smart_coupons_contribution : array(); + $order->set_discount_total( $discount_total ); + $order->set_discount_tax( $discount_tax ); + $order->set_total( $total - ( $discount_total + $discount_tax ) ); + } + } + } + + /** + * Function to set store credit amount for orders that are manually created and updated from REST API + * + * @param bool $and_taxes Calc taxes if true. + * @param WC_Order $order Order object. + */ + public function order_calculate_discount_amount_rest_api( $and_taxes, $order = null ) { + + if ( ! is_object( $order ) || ! $order instanceof WC_Order ) { + return; + } + $is_rest_api_request = WC()->is_rest_api_request(); + $order_id = ( $this->is_callable( $order, 'get_id' ) ) ? $order->get_id() : 0; + $post_post_type = $this->get_post_type( $order_id ); // phpcs:ignore + + if ( 'shop_order' === $post_post_type && ( $is_rest_api_request ) ) { + if ( ! is_callable( array( $order, 'get_id' ) ) ) { + return; + } + + if ( empty( $order_id ) ) { + return; + } + $coupons = $order->get_items( 'coupon' ); + $woocommerce_discount_total = $order->get_total_discount( false ); + $actual_discount_total = 0; + $order_discount_total = 0; + $order_discount_tax = 0; + $cart_tax = (float) $order->get_cart_tax(); + $cart_discount_tax = (float) $order->get_discount_tax(); + + if ( ( empty( $cart_tax ) || $cart_tax < 1 ) && $cart_discount_tax > 0 ) { // when coupon fully cover order subtotal. + $cart_tax = $cart_discount_tax; + } elseif ( $cart_discount_tax > 0 && $cart_tax > 0 ) { // when coupon not fully cover order subtotal. + $cart_tax += $cart_discount_tax; + } + + $smart_coupons_contribution = $this->get_post_meta( $order_id, 'smart_coupons_contribution', true, true ); + $smart_coupons_contribution = ! empty( $smart_coupons_contribution ) ? $smart_coupons_contribution : array(); + + if ( ! empty( $coupons ) ) { + foreach ( $coupons as $item_id => $item ) { + $coupon_code = ( is_object( $item ) && is_callable( array( $item, 'get_name' ) ) ) ? $item->get_name() : trim( $item['name'] ); + + if ( empty( $coupon_code ) ) { + continue; + } + + $coupon = new WC_Coupon( $coupon_code ); + $discount_type = $coupon->get_discount_type(); + + $discount_amount = ( is_object( $item ) && is_callable( array( $item, 'get_discount' ) ) ) ? $item->get_discount() : $this->get_order_item_meta( $item_id, 'discount_amount', true, true ); + $discount_amount_tax = ( is_object( $item ) && is_callable( array( $item, 'get_discount_tax' ) ) ) ? $item->get_discount_tax() : $this->get_order_item_meta( $item_id, 'discount_amount_tax', true, true ); + + $discount_of_individual_coupon = (float) $discount_amount + (float) $discount_amount_tax; + $actual_discount_total += $discount_of_individual_coupon; + $order_discount_total += $discount_amount; + $order_discount_tax += $discount_amount_tax; + + if ( ! $coupon->is_type( array( 'smart_coupon' ) ) && ( $cart_tax >= $discount_amount_tax ) ) { + $cart_tax -= $discount_amount_tax; + } + if ( 'smart_coupon' === $discount_type && empty( $smart_coupons_contribution ) && ! array_key_exists( $coupon_code, $smart_coupons_contribution ) ) { + $smart_coupons_contribution[ $coupon_code ] = $discount_of_individual_coupon; + $this->update_post_meta( $order_id, 'smart_coupons_contribution', $smart_coupons_contribution, true, $order ); + } + } + + $woocomerce_order_total = (float) $order->get_total(); + $diff_discount = 0; + if ( $actual_discount_total > $woocommerce_discount_total ) { + $diff_discount = (float) $actual_discount_total - (float) $woocommerce_discount_total; + } elseif ( $woocommerce_discount_total > $actual_discount_total ) { + $woocomerce_order_total += $woocommerce_discount_total - $actual_discount_total; + } + + $order->set_cart_tax( $cart_tax ); + $order->set_discount_total( $order_discount_total ); + $order->set_discount_tax( $order_discount_tax ); + $order->set_total( $woocomerce_order_total - $diff_discount ); + } + } + + } + + + /** + * Function to get discount amount for orders + * + * @param float $total Order total. + * @param WC_Coupon $coupon Coupon object. + * @param WC_Order $order Order object. + * @return array $discount_total and $discount_tax + */ + public function sc_order_get_discount_amount( $total = 0, $coupon = null, $order = null ) { + + if ( is_a( $coupon, 'WC_Coupon' ) && is_a( $order, 'WC_Order' ) ) { + $discount_line_totals = 0; + $discount_line_taxes = 0; + $discount_type = $coupon->get_discount_type(); + $coupon_product_ids = $coupon->get_product_ids(); + $coupon_product_categories = $coupon->get_product_categories(); + $order_items = $order->get_items( 'line_item' ); + $shipping_items = $order->get_items( 'shipping' ); + $fee_items = $order->get_items( 'fee' ); + + if ( 'smart_coupon' === $discount_type ) { + + $coupon_amount = $this->get_amount( $coupon, true, $order ); + + $calculated_total = $total; + + if ( count( $coupon_product_ids ) > 0 || count( $coupon_product_categories ) > 0 ) { + + $discount = 0; + $discounted_products = array(); + + foreach ( $order_items as $order_item_id => $order_item ) { + if ( $discount >= $coupon_amount ) { + break; + } + + $product_id = ( is_object( $order_item ) && is_callable( array( $order_item, 'get_product_id' ) ) ) ? $order_item->get_product_id() : $order_item['product_id']; + $variation_id = ( is_object( $order_item ) && is_callable( array( $order_item, 'get_variation_id' ) ) ) ? $order_item->get_variation_id() : $order_item['variation_id']; + $line_total = ( is_object( $order_item ) && is_callable( array( $order_item, 'get_total' ) ) ) ? $order_item->get_total() : $order_item['line_total']; + $line_tax = ( is_object( $order_item ) && is_callable( array( $order_item, 'get_total_tax' ) ) ) ? $order_item->get_total_tax() : $order_item['line_tax']; + + $product_cats = wc_get_product_cat_ids( $product_id ); + + if ( count( $coupon_product_categories ) > 0 ) { + + $continue = false; + + if ( ! empty( $order_item_id ) && ! empty( $discounted_products ) && is_array( $discounted_products ) && in_array( $order_item_id, $discounted_products, true ) ) { + $continue = true; + } + + if ( ! $continue && count( array_intersect( $product_cats, $coupon_product_categories ) ) > 0 ) { + + $discounted_products[] = ( ! empty( $order_item_id ) ) ? $order_item_id : ''; + + $discount_line_totals += $line_total; + $discount_line_taxes += $line_tax; + + } + } + + if ( count( $coupon_product_ids ) > 0 ) { + + $continue = false; + + if ( ! empty( $order_item_id ) && ! empty( $discounted_products ) && is_array( $discounted_products ) && in_array( $order_item_id, $discounted_products, true ) ) { + $continue = true; + } + + if ( ! $continue && in_array( $product_id, $coupon_product_ids, true ) || in_array( $variation_id, $coupon_product_ids, true ) ) { + + $discounted_products[] = ( ! empty( $order_item_id ) ) ? $order_item_id : ''; + + $discount_line_totals += $line_total; + $discount_line_taxes += $line_tax; + + } + } + } + + $calculated_total = round( ( $discount_line_totals + $discount_line_taxes ), wc_get_price_decimals() ); + + } else { + + if ( ! empty( $order_items ) && is_array( $order_items ) && $coupon_amount > 0 ) { + foreach ( $order_items as $order_item ) { + if ( ! $order_item instanceof WC_Order_Item_Product ) { + continue; + } + if ( $coupon_amount <= 0 ) { + break; + } + $line_total = (float) ( is_object( $order_item ) && is_callable( array( $order_item, 'get_subtotal' ) ) ) ? $order_item->get_subtotal() : $order_item['subtotal']; + $discount_line_total = min( $coupon_amount, $line_total ); + $discount_line_totals += $discount_line_total; + $coupon_amount -= $discount_line_total; + if ( ! $discount_line_total > $line_total ) { + $order_item->set_total( $line_total - $discount_line_total ); + } + } + + foreach ( $order_items as $order_item ) { + if ( ! $order_item instanceof WC_Order_Item_Product ) { + continue; + } + if ( $coupon_amount <= 0 ) { + break; + } + $line_tax = (float) ( is_object( $order_item ) && is_callable( array( $order_item, 'get_subtotal_tax' ) ) ) ? $order_item->get_subtotal_tax() : $order_item['subtotal_tax']; + $discount_line_tax = min( $coupon_amount, $line_tax ); + $discount_line_taxes += $discount_line_tax; + $coupon_amount -= $discount_line_tax; + if ( ! $discount_line_tax > $line_tax ) { + $order_item->set_total_tax( $line_tax - $discount_line_tax ); + } + } + } + if ( ! empty( $shipping_items ) && is_array( $shipping_items ) && $coupon_amount > 0 ) { + + foreach ( $shipping_items as $shipping_item ) { + if ( ! $shipping_item instanceof WC_Order_Item_Shipping ) { + continue; + } + if ( $coupon_amount <= 0 ) { + break; + } + $shipping_total = (float) ( is_object( $shipping_item ) && is_callable( array( $shipping_item, 'get_total' ) ) ) ? $shipping_item->get_total() : $shipping_item['total']; + $shipping_discount_total = min( $coupon_amount, $shipping_total ); + $discount_line_totals += $shipping_discount_total; + $coupon_amount -= $shipping_discount_total; + if ( $coupon_amount <= 0 ) { + break; + } + + $shipping_tax = (float) ( is_object( $shipping_item ) && is_callable( array( $shipping_item, 'get_total_tax' ) ) ) ? $shipping_item->get_total_tax() : $shipping_item['total_tax']; + $shipping_discount_tax = min( $coupon_amount, $shipping_tax ); + $discount_line_taxes += $shipping_discount_tax; + $coupon_amount -= $shipping_discount_tax; + } + } + + if ( ! empty( $fee_items ) && is_array( $fee_items ) && $coupon_amount > 0 ) { + foreach ( $fee_items as $fee_item ) { + if ( ! $fee_item instanceof WC_Order_Item_Fee || $coupon_amount < 1 ) { + continue; + } + + $fee_total = (float) ( is_object( $fee_item ) && is_callable( array( $fee_item, 'get_total' ) ) ) ? $fee_item->get_total() : $fee_item['total']; + $fee_discount_total = min( $coupon_amount, $fee_total ); + $discount_line_totals += $fee_discount_total; + $coupon_amount -= $fee_discount_total; + + // cover fee tax. + if ( $coupon_amount <= 0 ) { + break; + } + $fee_tax = (float) ( is_object( $fee_item ) && is_callable( array( $fee_item, 'get_total_tax' ) ) ) ? $fee_item->get_total_tax() : $fee_item['total_tax']; + $fee_discount_tax = min( $coupon_amount, $fee_tax ); + $discount_line_taxes += $fee_discount_tax; + $coupon_amount -= $fee_discount_tax; + + } + } + } + } + } + + return array( + 'discount_total' => (float) $discount_line_totals, + 'discount_tax' => (float) $discount_line_taxes, + ); + } + + /** + * Function to apply Smart Coupons discount + * + * @param float $total Cart total. + * @param WC_Cart $cart Cart object. + * @param boolean $cart_contains_subscription Is cart contains subscription. + * @param string $calculation_type The calculation type. + * @return float $total + */ + public function smart_coupons_discounted_totals( $total = 0, $cart = null, $cart_contains_subscription = false, $calculation_type = '' ) { + + if ( empty( $total ) ) { + return $total; + } + + $applied_coupons = ( is_object( WC()->cart ) && is_callable( array( WC()->cart, 'get_applied_coupons' ) ) ) ? WC()->cart->get_applied_coupons() : array(); + + $smart_coupon_credit_used = ( is_object( WC()->cart ) && isset( WC()->cart->smart_coupon_credit_used ) ) ? WC()->cart->smart_coupon_credit_used : array(); + + if ( ! empty( $applied_coupons ) ) { + $request_wc_ajax = ( ! empty( $_REQUEST['wc-ajax'] ) ) ? wc_clean( wp_unslash( $_REQUEST['wc-ajax'] ) ) : ''; // phpcs:ignore + $ignore_ajax_action = array( 'update_order_review', 'checkout' ); + foreach ( $applied_coupons as $code ) { + if ( ! empty( $request_wc_ajax ) && in_array( $request_wc_ajax, $ignore_ajax_action, true ) && array_key_exists( $code, $smart_coupon_credit_used ) && true !== $cart_contains_subscription && ! isset( WC()->session->reload_checkout ) ) { + continue; + } + $coupon = new WC_Coupon( $code ); + $discount = $this->sc_cart_get_discount_amount( $total, $coupon ); + + if ( ! empty( $discount ) ) { + $discount = min( $total, $discount ); + $total = $total - $discount; + $this->manage_smart_coupon_credit_used( $coupon, $discount, $cart_contains_subscription, $calculation_type ); + } + } + } + + return $total; + } + + /** + * Function to apply Smart Coupons discount after calculating tax + * + * @param WC_Cart $cart Cart object. + */ + public function smart_coupons_after_calculate_totals( $cart = null ) { + + if ( empty( $cart ) || ! ( $cart instanceof WC_Cart ) ) { + return; + } + + $debug_backtrace = debug_backtrace(); // phpcs:ignore + $discount_type = ''; + $route = ''; + if ( ! empty( $debug_backtrace ) ) { + foreach ( $debug_backtrace as $backtrace ) { + $function = ( ! empty( $backtrace['function'] ) ) ? $backtrace['function'] : ''; + $class = ( ! empty( $backtrace['class'] ) ) ? $backtrace['class'] : ''; + if ( 'Automattic\WooCommerce\StoreApi\Routes\V1\AbstractCartRoute' === $class && 'get_response' === $function ) { + $args = ( ! empty( $backtrace['args'] ) ) ? $backtrace['args'] : ''; + if ( ! empty( $args[0] ) && is_a( $args[0], 'WP_REST_Request' ) ) { + $request = $args[0]; + $route = ( $this->is_callable( $request, 'get_route' ) ) ? $request->get_route() : ''; + if ( '/wc/store/v1/cart/remove-coupon' === $route ) { + $params = ( $this->is_callable( $request, 'get_params' ) ) ? $request->get_params() : array(); + if ( ! empty( $params['code'] ) ) { + $coupon = new WC_Coupon( $params['code'] ); + $discount_type = ( $this->is_callable( $coupon, 'get_discount_type' ) ) ? $coupon->get_discount_type() : ''; + } + } + break; + } + } + } + } + + $is_rest_request = ( function_exists( 'WC' ) && is_object( WC() ) && $this->is_callable( WC(), 'is_rest_api_request' ) ) ? WC()->is_rest_api_request() : null; + if ( true === $is_rest_request && '/wc/store/v1/cart/remove-coupon' === $route && 'smart_coupon' === $discount_type ) { + return; + } + + // Check if AvaTax is active by checking for its main function. + if ( function_exists( 'wc_avatax' ) ) { + $wc_avatax = wc_avatax(); + if ( is_callable( array( $wc_avatax, 'get_tax_handler' ) ) ) { + $ava_tax_handler = $wc_avatax->get_tax_handler(); + // Check if AvaTax is doing tax calculation. + if ( is_callable( array( $ava_tax_handler, 'is_available' ) ) && true === $ava_tax_handler->is_available() ) { + // Stop discount calculation till taxes from AvaTax have been calculated. + if ( is_checkout() && ! did_action( 'wc_avatax_after_checkout_tax_calculated' ) ) { + return; + } + } + } + } + + $cart_total = ( $this->is_wc_greater_than( '3.1.2' ) ) ? $cart->get_total( 'edit' ) : $cart->total; + + if ( ! empty( $cart_total ) ) { + + $stop_at = did_action( 'woocommerce_cart_reset' ); + + $stop_at = apply_filters( 'wc_sc_calculate_totals_stop_at', $stop_at, $cart ); + + if ( empty( $stop_at ) ) { + $stop_at = 1; + } + + $cart_contains_subscription = WCS_SC_Compatibility::is_cart_contains_subscription(); + $calculation_type = ''; + + if ( $cart_contains_subscription ) { + $stop_at++; + $calculation_type = WC_Subscriptions_Cart::get_calculation_type(); + } + + if ( did_action( 'smart_coupons_after_calculate_totals' ) > $stop_at ) { + return; + } + + if ( 'recurring_total' === $calculation_type ) { + $total = $cart_total; + } else { + $total = $this->smart_coupons_discounted_totals( $cart_total, $cart, $cart_contains_subscription, $calculation_type ); + } + + if ( $this->is_wc_greater_than( '3.1.2' ) ) { + $cart_contents_total = $this->is_callable( $cart, 'get_cart_contents_total' ) ? $cart->get_cart_contents_total() : 0; + $cart_contents_tax = $this->is_callable( $cart, 'get_cart_contents_tax' ) ? $cart->get_cart_contents_tax() : 0; + $cart_contents_taxes = $this->is_callable( $cart, 'get_cart_contents_taxes' ) ? $cart->get_cart_contents_taxes() : array(); + $coupon_discount_totals = $this->is_callable( $cart, 'get_coupon_discount_totals' ) ? $cart->get_coupon_discount_totals() : array(); + $coupon_discount_tax_totals = $this->is_callable( $cart, 'get_coupon_discount_tax_totals' ) ? $cart->get_coupon_discount_tax_totals() : array(); + $discount_total = $this->is_callable( $cart, 'get_discount_total' ) ? $cart->get_discount_total() : 0; + $discount_tax = $this->is_callable( $cart, 'get_discount_tax' ) ? $cart->get_discount_tax() : 0; + $shipping_total = $this->is_callable( $cart, 'get_shipping_total' ) ? $cart->get_shipping_total() : 0; + $shipping_tax = $this->is_callable( $cart, 'get_shipping_tax' ) ? $cart->get_shipping_tax() : 0; + $shipping_taxes = $this->is_callable( $cart, 'get_shipping_taxes' ) ? $cart->get_shipping_taxes() : array(); + $fees = $this->is_callable( $cart, 'fees_api' ) && $this->is_callable( $cart->fees_api(), 'get_fees' ) ? $cart->fees_api()->get_fees() : array(); + $coupon_discount = 0; + $coupon_discount_total = $discount_total; + $coupon_discount_tax = $discount_tax; + $coupon_discount_taxes = $coupon_discount_tax_totals; + $new_coupon_discount_tax = 0; + $fee_totals = array(); + $fee_taxes = array(); + $fee = 0; + $fee_tax = 0; + $fee_discount_total = 0; + $new_fee_discount = 0; + $shipping_discount = 0; + $shipping_discount_total = 0; + $shipping_discount_tax = 0; + $shipping_discount_taxes = array(); + $credit_discount_tax = 0; + $credit_discount_taxes = array(); + + if ( ! empty( $fees ) ) { + foreach ( $fees as $fee_id => $fee_data ) { + $fee_totals[ $fee_id ] = ( ! empty( $fee_data->total ) ) ? $fee_data->total : 0; + $fee_taxes[ $fee_id ] = ( ! empty( $fee_data->tax ) ) ? $fee_data->tax : 0; + } + $fee = ( ! empty( $fee_totals ) ) ? array_sum( $fee_totals ) : 0; + $fee_tax = ( ! empty( $fee_taxes ) ) ? array_sum( $fee_taxes ) : 0; + } + + $smart_coupon_credit_used = ( ! empty( $cart->smart_coupon_credit_used ) ) ? $cart->smart_coupon_credit_used : array(); + + if ( is_array( $smart_coupon_credit_used ) && ! empty( $smart_coupon_credit_used ) ) { + $total = $this->is_callable( $cart, 'get_total' ) ? $cart->get_total( 'edit' ) : $total; + + $total_credit_used = array_sum( $smart_coupon_credit_used ); + $cart_items = $this->is_callable( $cart, 'get_cart' ) ? $cart->get_cart() : array(); + + if ( is_array( $cart_items ) && ! empty( $cart_items ) ) { + + // Apply discount on line total of every item. + foreach ( $cart_items as $cart_key => $item ) { + if ( $total_credit_used < 1 ) { + continue; + } + $discount_line_total = min( $item['line_total'], $total_credit_used ); + $item['line_total'] -= $discount_line_total; + $total_credit_used -= $discount_line_total; + $cart_items[ $cart_key ] = $item; + } + // Apply discount on line tax of every item. + foreach ( $cart_items as $cart_key => $item ) { + if ( $total_credit_used < 1 ) { + continue; + } + if ( isset( $item['line_tax_data']['total'] ) && is_array( $item['line_tax_data']['total'] ) && ! empty( $item['line_tax_data']['total'] ) ) { + foreach ( $item['line_tax_data']['total'] as $key => $tax_item ) { + if ( $total_credit_used < 1 ) { + continue; + } + $discount_line_tax = min( $tax_item, $total_credit_used ); + $item['line_tax_data']['total'][ $key ] -= $discount_line_tax; + $total_credit_used -= $discount_line_tax; + } + } + + $item['line_tax'] = array_sum( $item['line_tax_data']['total'] ); + $cart_items[ $cart_key ] = $item; + } + } + + $cart->cart_contents = $cart_items; + + foreach ( $smart_coupon_credit_used as $code => $coupon_credit ) { + if ( $coupon_credit > 0 ) { + $coupon_discount = min( $cart_contents_total, $coupon_credit ); + $coupon_discount_total += $coupon_discount; + $cart_contents_total -= $coupon_discount; + $coupon_discount_totals[ $code ] = $coupon_discount; + $cart->set_cart_contents_total( $cart_contents_total ); + $cart->set_coupon_discount_totals( $coupon_discount_totals ); + $coupon_credit -= $coupon_discount; + if ( $coupon_credit > 0 ) { + if ( is_array( $cart_contents_taxes ) && ! empty( $cart_contents_taxes ) ) { + if ( empty( $coupon_discount_taxes[ $code ] ) ) { + $coupon_discount_taxes[ $code ] = 0; + } + if ( empty( $credit_discount_taxes[ $code ] ) ) { + $credit_discount_taxes[ $code ] = 0; + } + foreach ( $cart_contents_taxes as $index => $tax ) { + $new_coupon_discount_tax = min( $tax, $coupon_credit ); + $coupon_credit -= $new_coupon_discount_tax; + $coupon_discount_taxes[ $code ] += $new_coupon_discount_tax; + $credit_discount_taxes[ $code ] += $new_coupon_discount_tax; + } + $credit_discount_tax = array_sum( $credit_discount_taxes ); + $coupon_discount_tax = array_sum( $coupon_discount_taxes ) - $credit_discount_tax; + $coupon_discount_tax_totals[ $code ] = $coupon_discount_taxes[ $code ]; + $cart->set_coupon_discount_tax_totals( $coupon_discount_tax_totals ); + } + } + if ( $coupon_credit > 0 ) { + $shipping_discount = min( $shipping_total, $coupon_credit ); + $shipping_discount_total += $shipping_discount; + $coupon_discount_totals[ $code ] += $shipping_discount; + $cart->set_coupon_discount_totals( $coupon_discount_totals ); + $coupon_credit -= $shipping_discount; + } + if ( $coupon_credit > 0 ) { + if ( is_array( $shipping_taxes ) && ! empty( $shipping_taxes ) ) { + foreach ( $shipping_taxes as $index => $s_tax ) { + $shipping_discount_taxes[ $index ] = min( $s_tax, $coupon_credit ); + $coupon_credit -= $shipping_discount_taxes[ $index ]; + } + $shipping_discount_tax = array_sum( $shipping_discount_taxes ); + $coupon_discount_tax_totals[ $code ] += $shipping_discount_tax; + $cart->set_coupon_discount_tax_totals( $coupon_discount_tax_totals ); + } + } + if ( $coupon_credit > 0 && ! empty( $fee_totals ) ) { + if ( is_array( $fee_totals ) && ! empty( $fee_totals ) ) { + if ( empty( $coupon_discount_totals[ $code ] ) ) { + $coupon_discount_totals[ $code ] = 0; + } + foreach ( $fee_totals as $fee_id => $f ) { + $new_fee_discount = min( $f, $coupon_credit ); + $coupon_credit -= $new_fee_discount; + $fee -= $new_fee_discount; + $fee_discount_total += $new_fee_discount; + $coupon_discount_totals[ $code ] += $new_fee_discount; + } + $cart->set_coupon_discount_totals( $coupon_discount_totals ); + } + } + if ( $coupon_credit > 0 && ! empty( $fee_taxes ) ) { + if ( is_array( $fee_taxes ) && ! empty( $fee_taxes ) ) { + if ( empty( $coupon_discount_taxes[ $code ] ) ) { + $coupon_discount_taxes[ $code ] = 0; + } + if ( empty( $credit_discount_taxes[ $code ] ) ) { + $credit_discount_taxes[ $code ] = 0; + } + foreach ( $fee_taxes as $fee_id => $f_tax ) { + $new_coupon_discount_tax = min( $f_tax, $coupon_credit ); + $coupon_credit -= $new_coupon_discount_tax; + $coupon_discount_taxes[ $code ] += $new_coupon_discount_tax; + $credit_discount_taxes[ $code ] += $new_coupon_discount_tax; + $coupon_discount_tax_totals[ $code ] += $new_coupon_discount_tax; + } + $credit_discount_tax = array_sum( $credit_discount_taxes ); + $coupon_discount_tax = array_sum( $coupon_discount_taxes ) - $credit_discount_tax; + $cart->set_coupon_discount_tax_totals( $coupon_discount_tax_totals ); + } + } + } + } + $discount_total = $coupon_discount_total + $shipping_discount_total + $fee_discount_total; + $cart->set_discount_total( $discount_total ); + $discount_tax = array_sum( $coupon_discount_tax_totals ); + $cart->set_discount_tax( $discount_tax ); + $total_tax = $cart_contents_tax + $shipping_tax + $fee_tax; + $cart->set_total_tax( $total_tax ); + $total = $cart_contents_total + array_sum( $cart_contents_taxes ) + $shipping_total + array_sum( $shipping_taxes ) + $fee + $fee_tax - array_sum( $credit_discount_taxes ) - $shipping_discount_total - $shipping_discount_tax; + } + $cart->set_total( $total ); + $cart->set_session(); + } else { + $cart->total = $total; + } + + do_action( 'smart_coupons_after_calculate_totals' ); + + } + + } + + /** + * Function to show the discount amount applied by the store credit on the tax. + * + * @param string $coupon_html The current HTML. + * @param WC_Coupon $coupon The coupon object. + * @param string $discount_amount_html The discount amount HTML. + * @return string + */ + public function cart_totals_coupon_html( $coupon_html = '', $coupon = null, $discount_amount_html = '' ) { + $cart = ( function_exists( 'WC' ) && isset( WC()->cart ) ) ? WC()->cart : null; + if ( is_a( $cart, 'WC_Cart' ) ) { + $tax_price_display_mode = $cart->get_tax_price_display_mode(); + $smart_coupon_credit_used = ( isset( $cart->smart_coupon_credit_used ) ) ? $cart->smart_coupon_credit_used : array(); + $coupon_code = ( $this->is_callable( $coupon, 'get_code' ) ) ? $coupon->get_code() : ''; + if ( ! empty( $coupon_code ) && array_key_exists( $coupon_code, $smart_coupon_credit_used ) ) { + $coupon_discount_tax_totals = $this->is_callable( $cart, 'get_coupon_discount_tax_totals' ) ? $cart->get_coupon_discount_tax_totals() : array(); + if ( ! empty( $coupon_discount_tax_totals[ $coupon_code ] ) ) { + if ( 'excl' === $tax_price_display_mode ) { + /* translators: Discount amount applied on tax */ + $coupon_html = $coupon_html . ' (' . sprintf( __( 'excludes -%s on tax', 'woocommerce-smart-coupons' ), wc_price( $coupon_discount_tax_totals[ $coupon_code ] ) ) . ')'; + } else { + /* translators: Discount amount applied on tax */ + $coupon_html = $coupon_html . ' (' . sprintf( __( 'includes -%s on tax', 'woocommerce-smart-coupons' ), wc_price( $coupon_discount_tax_totals[ $coupon_code ] ) ) . ')'; + } + } + } + } + return $coupon_html; + } + + /** + * Function to do action 'smart_coupons_after_calculate_totals' since WooCommerce Services plugin triggers 'woocommerce_cart_reset' in its function for 'woocommerce_after_calculate_totals' action causing miscalculation in did_action( 'smart_coupons_after_calculate_totals' ) hook. + */ + public function woocommerce_cart_reset() { + + $cart_reset_action_count = did_action( 'woocommerce_cart_reset' ); + $sc_after_calculate_action_count = did_action( 'smart_coupons_after_calculate_totals' ); + + // This is to match counter for 'smart_coupons_after_calculate_totals' hook with 'woocommerce_cart_reset' counter since we are using these two counters to prevent store credit being applied multiple times. + if ( $sc_after_calculate_action_count < $cart_reset_action_count ) { + do_action( 'smart_coupons_after_calculate_totals' ); + } + + } + + /** + * Function to calculate total cart contents. + * skip the product if the product is a bundled product. + * + * @since 4.32.0 + * @return int + */ + public function get_cart_contents_count() { + $total_product = 0; + $cart_data = ( isset( WC()->cart ) && is_callable( array( WC()->cart, 'get_cart' ) ) ) ? WC()->cart->get_cart() : array(); + if ( ! empty( $cart_data ) ) { + foreach ( $cart_data as $data ) { + // Skip bundled products. + if ( isset( $data['stamp'] ) && isset( $data['bundled_by'] ) ) { + continue; + } + $total_product++; + } + } + return $total_product; + } + + /** + * Get coupon discount amount for percentage type coupon. + * + * @param float $discount Amount this coupon has discounted. + * @param float $discounting_amount Amount the coupon is being applied to. + * @param array|null $cart_item Cart item being discounted if applicable. + * @param bool $single True if discounting a single qty item, false if its the line. + * @param WC_Coupon $coupon Coupon object. + * @return float $discount + */ + public function get_coupon_discount_amount( $discount = 0, $discounting_amount = 0, $cart_item = array(), $single = false, $coupon = object ) { + + if ( is_a( $coupon, 'WC_Coupon' ) ) { + + $order = ( is_a( $cart_item, 'WC_Order_Item' ) && is_callable( array( $cart_item, 'get_order' ) ) ) ? $cart_item->get_order() : null; + + if ( $this->is_valid( $coupon, $order ) && is_object( $coupon ) && is_callable( array( $coupon, 'is_type' ) ) && $coupon->is_type( 'percent' ) ) { + if ( $this->is_wc_gte_30() ) { + $coupon_id = ( is_callable( array( $coupon, 'get_id' ) ) ) ? $coupon->get_id() : 0; + } else { + $coupon_id = ( ! empty( $coupon->id ) ) ? $coupon->id : 0; + } + + if ( empty( $coupon_id ) ) { + return $discount; + } + + $max_discount = $this->get_post_meta( $coupon_id, 'wc_sc_max_discount', true, true, $order ); + + if ( ! empty( $max_discount ) && is_numeric( $max_discount ) ) { + + $coupon_product_ids = ( is_callable( array( $coupon, 'get_product_ids' ) ) ) ? $coupon->get_product_ids() : array(); + $coupon_excluded_product_ids = ( is_callable( array( $coupon, 'get_excluded_product_ids' ) ) ) ? $coupon->get_excluded_product_ids() : array(); + $coupon_category_ids = ( is_callable( array( $coupon, 'get_product_categories' ) ) ) ? $coupon->get_product_categories() : array(); + $coupon_excluded_category_ids = ( is_callable( array( $coupon, 'get_excluded_product_categories' ) ) ) ? $coupon->get_excluded_product_categories() : array(); + $cart_items_subtotal = 0; + $cart_contents_count = 0; + $max_discount_name = 'wc_sc_max_discount_data'; + $inc_tax = wc_prices_include_tax(); + $is_restricted = count( $coupon_product_ids ) > 0 || count( $coupon_excluded_product_ids ) > 0 || count( $coupon_category_ids ) > 0 || count( $coupon_excluded_category_ids ) > 0; + $is_restricted = apply_filters( + 'wc_sc_is_coupon_restriction_available', + $is_restricted, + array( + 'source' => $this, + 'discount' => $discount, + 'discounting_amount' => $discounting_amount, + 'cart_item' => $cart_item, + 'single' => $single, + 'coupon_object' => $coupon, + ) + ); + + if ( is_a( $cart_item, 'WC_Order_Item_Product' ) ) { + $order = $wc_cart_or_order_object = ( is_callable( array( $cart_item, 'get_order' ) ) ) ? $cart_item->get_order() : null; // phpcs:ignore + $wc_order_id = ( is_callable( array( $cart_item, 'get_order_id' ) ) ) ? $cart_item->get_order_id() : 0; + if ( empty( $wc_order_id ) ) { + return $discount; + } + $order_line_items = array(); + if ( is_a( $order, 'WC_Order' ) ) { + $cart_items_subtotal = ( is_callable( array( $order, 'get_subtotal' ) ) ) ? $order->get_subtotal() : 0; + $order_line_items = ( is_callable( array( $order, 'get_items' ) ) ) ? $order->get_items() : array(); + } + + $max_discount_name = 'wc_sc_max_discount_data_for_' . $wc_order_id; + if ( ! empty( $order_line_items ) ) { + foreach ( $order_line_items as $order_line_item ) { + $cart_contents_count++; + } + } + + $max_discount_data = function_exists( 'get_transient' ) ? get_transient( $max_discount_name ) : array(); + } else { + $wc_cart = $wc_cart_or_order_object = ! empty( WC()->cart ) ? WC()->cart : null; // phpcs:ignore + $wc_session = ! empty( WC()->session ) ? WC()->session : null; + if ( ! is_a( $wc_cart, 'WC_Cart' ) ) { + return $discount; + } + if ( true === $inc_tax ) { + $cart_items_subtotal = ! empty( $wc_cart->subtotal ) ? $wc_cart->subtotal : 0; + } else { + $cart_items_subtotal = ! empty( $wc_cart->subtotal_ex_tax ) ? $wc_cart->subtotal_ex_tax : 0; + } + + $max_discount_data = ( ! empty( $wc_session ) && is_a( $wc_session, 'WC_Session' ) && is_callable( array( $wc_session, 'get' ) ) ) ? $wc_session->get( $max_discount_name ) : array(); + + $cart_contents_count = $this->get_cart_contents_count(); + } + + $is_update_valid_item_count = false; + + if ( empty( $max_discount_data ) || ! is_array( $max_discount_data ) ) { + $max_discount_data = array(); + } + + if ( empty( $max_discount_data[ $coupon_id ] ) || ! is_array( $max_discount_data[ $coupon_id ] ) ) { + $max_discount_data[ $coupon_id ] = array(); + $is_update_valid_item_count = true; + $max_discount_data[ $coupon_id ]['amount'] = $max_discount; + $max_discount_data[ $coupon_id ]['count'] = $cart_contents_count; + } + + if ( true === $is_restricted && class_exists( 'WC_Discounts' ) && ! empty( $wc_cart_or_order_object ) ) { + + $wc_discounts = new WC_Discounts( $wc_cart_or_order_object ); + $items_to_validate = array(); + + if ( is_callable( array( $wc_discounts, 'get_items_to_validate' ) ) ) { + $items_to_validate = $wc_discounts->get_items_to_validate(); + } elseif ( is_callable( array( $wc_discounts, 'get_items' ) ) ) { + $items_to_validate = $wc_discounts->get_items(); + } elseif ( ! empty( $wc_discounts->items ) && is_array( $wc_discounts->items ) ) { + $items_to_validate = $wc_discounts->items; + } + + if ( is_array( $items_to_validate ) ) { + $valid_product_count = 0; + foreach ( $items_to_validate as $item ) { + $item_to_apply = clone $item; // Clone the item so changes to wc_discounts item do not affect the originals. + $valid_product_quantity = ( ! empty( $item_to_apply->quantity ) ) ? intval( $item_to_apply->quantity ) : 0; + $product = ( ! empty( $item_to_apply->product ) ) ? $item_to_apply->product : null; + $item_to_apply_object = ( ! empty( $item_to_apply->object ) ) ? $item_to_apply->object : null; + + if ( 0 === $wc_discounts->get_discounted_price_in_cents( $item_to_apply ) || 0 >= $valid_product_quantity ) { + continue; + } + + if ( ! $coupon->is_valid_for_product( $product, $item_to_apply_object ) && ! $coupon->is_valid_for_cart() ) { + continue; + } + + // Increment if the product is not a bundled product. + $valid_product_count = ( isset( $item_to_apply_object['stamp'] ) && isset( $item_to_apply_object['bundled_by'] ) ) ? $valid_product_count : $valid_product_count + 1; + $line_subtotal = ! empty( $item_to_apply_object['line_subtotal'] ) ? intval( $item_to_apply_object['line_subtotal'] ) : 0; + if ( true === $inc_tax ) { + $line_subtotal_tax = ! empty( $item_to_apply_object['line_subtotal_tax'] ) ? intval( $item_to_apply_object['line_subtotal_tax'] ) : 0; + $cart_items_subtotal += $line_subtotal + $line_subtotal_tax; + } else { + $cart_items_subtotal += $line_subtotal; + } + } + + if ( true === $is_update_valid_item_count ) { + $max_discount_data[ $coupon_id ]['count'] = $valid_product_count; + } + } + } + + if ( 0 !== $cart_items_subtotal ) { + + $max_discount = ! empty( $max_discount_data[ $coupon_id ]['amount'] ) ? $max_discount_data[ $coupon_id ]['amount'] : 0; + if ( $max_discount < 0 ) { + $max_discount = 0; + } + + $discount = min( $max_discount, $discount ); + + if ( ! empty( $max_discount ) ) { + $max_discount_data[ $coupon_id ]['amount'] -= $discount; + } + + $max_discount_data[ $coupon_id ]['count']--; + + if ( 0 >= $max_discount_data[ $coupon_id ]['count'] ) { + unset( $max_discount_data[ $coupon_id ] ); + } + if ( 'wc_sc_max_discount_data' === $max_discount_name ) { + if ( ! empty( $wc_session ) && is_a( $wc_session, 'WC_Session' ) && is_callable( array( $wc_session, 'set' ) ) ) { + $wc_session->set( $max_discount_name, $max_discount_data ); + } + } elseif ( function_exists( 'set_transient' ) ) { + set_transient( $max_discount_name, $max_discount_data, DAY_IN_SECONDS ); + } + } + } + } + } + return $discount; + } + + /** + * Function to set default values to postmeta fields + * + * @param array $defaults Existing postmeta defaults. + * @return array + */ + public function postmeta_defaults( $defaults = array() ) { + + if ( $this->is_wc_gte_32() ) { + $defaults['wc_sc_expiry_time'] = ''; + } + + return $defaults; + } + + /** + * Function to get discount amount + * + * @param float $total The total. + * @param WC_Coupon $coupon The coupon object. + * @return float $discount + */ + public function sc_cart_get_discount_amount( $total = 0, $coupon = '' ) { + + $discount = 0; + + if ( is_a( $coupon, 'WC_Coupon' ) ) { + + if ( $this->is_valid( $coupon ) && $coupon->is_type( 'smart_coupon' ) ) { + + if ( $this->is_wc_gte_30() ) { + $coupon_code = $coupon->get_code(); + $coupon_product_ids = $coupon->get_product_ids(); + $coupon_product_categories = $coupon->get_product_categories(); + } else { + $coupon_code = ( ! empty( $coupon->code ) ) ? $coupon->code : ''; + $coupon_product_ids = ( ! empty( $coupon->product_ids ) ) ? $coupon->product_ids : array(); + $coupon_product_categories = ( ! empty( $coupon->product_categories ) ) ? $coupon->product_categories : array(); + } + + $coupon_amount = $this->get_amount( $coupon, true ); + + $calculated_total = $total; + + if ( count( $coupon_product_ids ) > 0 || count( $coupon_product_categories ) > 0 ) { + + $discount = 0; + $line_totals = 0; + $line_taxes = 0; + $discounted_products = array(); + + foreach ( WC()->cart->cart_contents as $cart_item_key => $product ) { + + if ( $discount >= $coupon_amount ) { + break; + } + + $product_cats = wc_get_product_cat_ids( $product['product_id'] ); + + if ( count( $coupon_product_categories ) > 0 ) { + + $continue = false; + + if ( ! empty( $cart_item_key ) && ! empty( $discounted_products ) && is_array( $discounted_products ) && in_array( $cart_item_key, $discounted_products, true ) ) { + $continue = true; + } + + if ( ! $continue && count( array_intersect( $product_cats, $coupon_product_categories ) ) > 0 ) { + + $discounted_products[] = ( ! empty( $cart_item_key ) ) ? $cart_item_key : ''; + + $line_totals += $product['line_total']; + $line_taxes += $product['line_tax']; + + } + } + + if ( count( $coupon_product_ids ) > 0 ) { + + $continue = false; + + if ( ! empty( $cart_item_key ) && ! empty( $discounted_products ) && is_array( $discounted_products ) && in_array( $cart_item_key, $discounted_products, true ) ) { + $continue = true; + } + + $parent_id = ( $this->is_wc_gte_30() ) ? $product['data']->get_parent_id() : $product['data']->get_parent(); + + if ( ! $continue && in_array( $product['product_id'], $coupon_product_ids, true ) || in_array( $product['variation_id'], $coupon_product_ids, true ) || in_array( $parent_id, $coupon_product_ids, true ) ) { + + $discounted_products[] = ( ! empty( $cart_item_key ) ) ? $cart_item_key : ''; + + $line_totals += $product['line_total']; + $line_taxes += $product['line_tax']; + + } + } + } + + $calculated_total = round( ( $line_totals + $line_taxes ), wc_get_price_decimals() ); + + } + + $discount = min( $calculated_total, $coupon_amount ); + } + } + + return $discount; + } + + /** + * Function to manage store credit used + * + * @param WC_Coupon $coupon The coupon object. + * @param float $discount The discount. + * @param bool $cart_contains_subscription Is cart contains subscription. + * @param string $calculation_type Calculation type. + */ + public function manage_smart_coupon_credit_used( $coupon = '', $discount = 0, $cart_contains_subscription = false, $calculation_type = '' ) { + if ( is_object( $coupon ) && $coupon instanceof WC_Coupon ) { + + if ( $this->is_wc_gte_30() ) { + $coupon_code = ( is_callable( array( $coupon, 'get_code' ) ) ) ? $coupon->get_code() : ''; + } else { + $coupon_code = ( ! empty( $coupon->code ) ) ? $coupon->code : ''; + } + + $coupon_amount = $this->get_amount( $coupon, true ); + + if ( $cart_contains_subscription ) { + if ( WCS_SC_Compatibility::is_wcs_gte( '2.0.10' ) ) { + if ( $this->is_wc_greater_than( '3.1.2' ) ) { + $coupon_discount_totals = ( is_object( WC()->cart ) && is_callable( array( WC()->cart, 'get_coupon_discount_totals' ) ) ) ? WC()->cart->get_coupon_discount_totals() : array(); + if ( ! is_array( $coupon_discount_totals ) ) { + $coupon_discount_totals = array(); + } + if ( empty( $coupon_discount_totals[ $coupon_code ] ) ) { + $coupon_discount_totals[ $coupon_code ] = $discount; + } else { + $coupon_discount_totals[ $coupon_code ] += $discount; + } + ( is_object( WC()->cart ) && is_callable( array( WC()->cart, 'set_coupon_discount_totals' ) ) ) ? WC()->cart->set_coupon_discount_totals( $coupon_discount_totals ) : ''; + } else { + $coupon_discount_amounts = ( is_object( WC()->cart ) && isset( WC()->cart->coupon_discount_amounts ) ) ? WC()->cart->coupon_discount_amounts : array(); + if ( ! is_array( $coupon_discount_amounts ) ) { + $coupon_discount_amounts = array(); + } + if ( empty( $coupon_discount_amounts[ $coupon_code ] ) ) { + $coupon_discount_amounts[ $coupon_code ] = $discount; + } else { + $coupon_discount_amounts[ $coupon_code ] += $discount; + } + WC()->cart->coupon_discount_amounts = $coupon_discount_amounts; + } + } elseif ( WCS_SC_Compatibility::is_wcs_gte( '2.0.0' ) ) { + WC_Subscriptions_Coupon::increase_coupon_discount_amount( WC()->cart, $coupon_code, $discount ); + } else { + WC_Subscriptions_Cart::increase_coupon_discount_amount( $coupon_code, $discount ); + } + } else { + if ( $this->is_wc_greater_than( '3.1.2' ) ) { + $coupon_discount_totals = ( is_object( WC()->cart ) && is_callable( array( WC()->cart, 'get_coupon_discount_totals' ) ) ) ? WC()->cart->get_coupon_discount_totals() : array(); + if ( ! is_array( $coupon_discount_totals ) ) { + $coupon_discount_totals = array(); + } + if ( empty( $coupon_discount_totals[ $coupon_code ] ) ) { + $coupon_discount_totals[ $coupon_code ] = $discount; + } else { + $coupon_discount_totals[ $coupon_code ] += $discount; + } + ( is_object( WC()->cart ) && is_callable( array( WC()->cart, 'set_coupon_discount_totals' ) ) ) ? WC()->cart->set_coupon_discount_totals( $coupon_discount_totals ) : ''; + } else { + $coupon_discount_amounts = ( is_object( WC()->cart ) && isset( WC()->cart->coupon_discount_amounts ) ) ? WC()->cart->coupon_discount_amounts : array(); + if ( ! is_array( $coupon_discount_amounts ) ) { + $coupon_discount_amounts = array(); + } + if ( empty( $coupon_discount_amounts[ $coupon_code ] ) ) { + $coupon_discount_amounts[ $coupon_code ] = $discount; + } else { + $coupon_discount_amounts[ $coupon_code ] += $discount; + } + WC()->cart->coupon_discount_amounts = $coupon_discount_amounts; + } + } + + if ( isset( WC()->session->reload_checkout ) ) { // reload_checkout is triggered when customer is registered from checkout. + unset( WC()->cart->smart_coupon_credit_used ); // reset store credit used data for re-calculation. + } + + $smart_coupon_credit_used = ( is_object( WC()->cart ) && isset( WC()->cart->smart_coupon_credit_used ) ) ? WC()->cart->smart_coupon_credit_used : array(); + + if ( ! is_array( $smart_coupon_credit_used ) ) { + $smart_coupon_credit_used = array(); + } + if ( empty( $smart_coupon_credit_used[ $coupon_code ] ) || ( $cart_contains_subscription && ( 'combined_total' === $calculation_type || 'sign_up_fee_total' === $calculation_type ) ) ) { + $smart_coupon_credit_used[ $coupon_code ] = $discount; + } else { + $smart_coupon_credit_used[ $coupon_code ] += $discount; + } + if ( floatval( $smart_coupon_credit_used[ $coupon_code ] ) > floatval( $coupon_amount ) ) { + $smart_coupon_credit_used[ $coupon_code ] = $coupon_amount; + } + WC()->cart->smart_coupon_credit_used = $smart_coupon_credit_used; + + } + } + + /** + * Apply store credit discount in order during recalculation + * + * @param float $total The total. + * @param WC_Order $order The order object. + * @return float $total + */ + public function smart_coupons_order_discounted_total( $total = 0, $order = null ) { + + if ( ! $this->is_wc_gte_30() ) { + + $is_proceed = check_ajax_referer( 'calc-totals', 'security', false ); + + if ( ! $is_proceed ) { + return $total; + } + + $called_by = ( ! empty( $_POST['action'] ) ) ? wc_clean( wp_unslash( $_POST['action'] ) ) : ''; // phpcs:ignore + + if ( 'woocommerce_calc_line_taxes' !== $called_by ) { + return $total; + } + } + + if ( empty( $order ) ) { + return $total; + } + + $coupons = ( is_object( $order ) && is_callable( array( $order, 'get_items' ) ) ) ? $order->get_items( 'coupon' ) : array(); + + if ( ! empty( $coupons ) ) { + foreach ( $coupons as $coupon ) { + $code = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_code' ) ) ) ? $coupon->get_code() : ''; + if ( empty( $code ) ) { + continue; + } + $_coupon = new WC_Coupon( $code ); + $discount_type = ( is_object( $_coupon ) && is_callable( array( $_coupon, 'get_discount_type' ) ) ) ? $_coupon->get_discount_type() : ''; + if ( ! empty( $discount_type ) && 'smart_coupon' === $discount_type ) { + $discount = $this->get_amount( $_coupon, true, $order ); + $applied_discount = min( $total, $discount ); + if ( $this->is_wc_gte_30() ) { + $coupon->set_discount( $applied_discount ); + $coupon->save(); + } + $total = $total - $applied_discount; + } + } + } + + return $total; + } + + /** + * Add tool for clearing cache + * + * @param array $tools Existing tools. + * @return array $tools + */ + public function clear_cache_tool( $tools = array() ) { + + $tools['wc_sc_clear_cache'] = array( + 'name' => __( 'WooCommerce Smart Coupons Cache', 'woocommerce-smart-coupons' ), + 'button' => __( 'Clear Smart Coupons Cache', 'woocommerce-smart-coupons' ), + 'desc' => __( 'This tool will clear the cache created by WooCommerce Smart Coupons.', 'woocommerce-smart-coupons' ), + 'callback' => array( + $this, + 'clear_cache', + ), + ); + + return $tools; + } + + /** + * Clear cache + * + * @return string $message + */ + public function clear_cache() { + + $message = ( is_callable( array( 'WC_SC_Act_Deact', 'clear_cache' ) ) ) ? WC_SC_Act_Deact::clear_cache() : ''; + + return $message; + } + + /** + * WooCommerce Checkout Update Order Review + * + * @param array $post_data The post data. + */ + public function woocommerce_checkout_update_order_review( $post_data = array() ) { + + wp_parse_str( $post_data, $posted_data ); + + if ( ! empty( $posted_data['billing_email'] ) ) { + $applied_coupons = ( is_object( WC()->cart ) && is_callable( array( WC()->cart, 'get_applied_coupons' ) ) ) ? WC()->cart->get_applied_coupons() : array(); + if ( ! empty( $applied_coupons ) ) { + if ( empty( $_REQUEST['billing_email'] ) ) { // phpcs:ignore + $_REQUEST['billing_email'] = $posted_data['billing_email']; + } + foreach ( $applied_coupons as $coupon_code ) { + $coupon = new WC_Coupon( $coupon_code ); + $is_valid = $this->is_user_usage_limit_valid( true, $coupon ); + if ( true !== $is_valid ) { + WC()->cart->remove_coupon( $coupon_code ); + /* translators: The coupon code */ + wc_add_notice( sprintf( __( 'Coupon %s is valid for a new user only, hence removed.', 'woocommerce-smart-coupons' ), '' . $coupon_code . '' ), 'error' ); + } + } + } + } + + } + + /** + * Function to return validity of Store Credit / Gift Certificate + * + * @param boolean $valid Coupon validity. + * @param WC_Coupon $coupon Coupon object. + * @param WC_Discounts $discounts Discounts object. + * @return boolean $valid TRUE if smart coupon valid, FALSE otherwise + */ + public function is_smart_coupon_valid( $valid, $coupon, $discounts = null ) { + + if ( $this->is_wc_gte_30() ) { + $discount_type = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_discount_type' ) ) ) ? $coupon->get_discount_type() : ''; + $coupon_code = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_code' ) ) ) ? $coupon->get_code() : ''; + } else { + $discount_type = ( ! empty( $coupon->discount_type ) ) ? $coupon->discount_type : ''; + $coupon_code = ( ! empty( $coupon->code ) ) ? $coupon->code : ''; + } + + $coupon_amount = $this->get_amount( $coupon, true ); + + if ( 'smart_coupon' !== $discount_type ) { + return $valid; + } + + $applied_coupons = ( is_object( WC()->cart ) && is_callable( array( WC()->cart, 'get_applied_coupons' ) ) ) ? WC()->cart->get_applied_coupons() : array(); + + if ( empty( $applied_coupons ) || ( ! empty( $applied_coupons ) && ! in_array( $coupon_code, $applied_coupons, true ) ) ) { + return $valid; + } + + if ( is_wc_endpoint_url( 'order-received' ) ) { + return $valid; + } + + $is_valid_coupon_amount = ( $coupon_amount <= 0 ) ? false : true; + + $is_valid_coupon_amount = apply_filters( + 'wc_sc_validate_coupon_amount', + $is_valid_coupon_amount, + array( + 'coupon' => $coupon, + 'discounts' => $discounts, + 'coupon_amount' => $coupon_amount, + 'discount_type' => $discount_type, + 'coupon_code' => $coupon_code, + ) + ); + + if ( $valid && ! $is_valid_coupon_amount ) { + WC()->cart->remove_coupon( $coupon_code ); + /* translators: The coupon code */ + wc_add_notice( sprintf( __( 'Coupon removed. There is no credit remaining in %s.', 'woocommerce-smart-coupons' ), '' . $coupon_code . '' ), 'error' ); + return false; + } + + return $valid; + } + + /** + * Strict check if user is valid as per usage limit + * + * @param boolean $is_valid Is valid. + * @param WC_Coupon $coupon The coupon object. + * @param WC_Discounts $discounts The discounts object. + * @return boolean + * @throws Exception When coupon is not valid as per the usage limit. + */ + public function is_user_usage_limit_valid( $is_valid = false, $coupon = null, $discounts = null ) { + + if ( is_admin() && ( ! defined( 'DOING_AJAX' ) || DOING_AJAX !== true ) ) { + return $is_valid; + } + + if ( true !== $is_valid ) { + return $is_valid; + } + + global $wpdb; + + if ( $this->is_wc_gte_30() ) { + $coupon_id = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_id' ) ) ) ? $coupon->get_id() : 0; + } else { + $coupon_id = ( ! empty( $coupon->id ) ) ? $coupon->id : 0; + } + + $for_new_user = ( $this->is_callable( $coupon, 'get_meta' ) ) ? $coupon->get_meta( 'sc_restrict_to_new_user' ) : get_post_meta( $coupon_id, 'sc_restrict_to_new_user', true ); + + if ( 'yes' === $for_new_user ) { + + $failed_notice = __( 'This coupon is valid for the first order only.', 'woocommerce-smart-coupons' ); + + $user_id_1 = 0; + $user_id_2 = 0; + $user_id_3 = 0; + + $current_user = wp_get_current_user(); + + $email = ( ! empty( $current_user->data->user_email ) ) ? $current_user->data->user_email : ''; + + $email = ( ! empty( $_REQUEST['billing_email'] ) ) ? sanitize_email( wp_unslash( $_REQUEST['billing_email'] ) ) : $email; // phpcs:ignore + + $valid_order_statuses = get_option( 'wc_sc_valid_order_statuses_for_coupon_auto_generation', array() ); + $statuses_placeholder = array(); + if ( ! empty( $valid_order_statuses ) ) { + $valid_order_statuses = array_map( + function( $status ) { + return 'wc-' . $status; + }, + $valid_order_statuses + ); + $how_many_statuses = count( $valid_order_statuses ); + $statuses_placeholder = array_fill( 0, $how_many_statuses, '%s' ); + } + + if ( ! empty( $email ) && is_email( $email ) ) { + + $order_id = wp_cache_get( 'wc_sc_order_id_by_billing_email_' . sanitize_key( $email ), 'woocommerce_smart_coupons' ); + + if ( false === $order_id ) { + if ( $this->is_hpos() ) { + $query = $wpdb->prepare( + "SELECT id + FROM {$wpdb->prefix}wc_orders + WHERE billing_email = %s", + $email + ); + } else { + $query = $wpdb->prepare( + "SELECT ID + FROM $wpdb->posts AS p + LEFT JOIN $wpdb->postmeta AS pm + ON ( p.ID = pm.post_id AND pm.meta_key = %s ) + WHERE p.post_type = %s + AND pm.meta_value = %s", + '_billing_email', + 'shop_order', + $email + ); + } + + if ( ! empty( $valid_order_statuses ) && ! empty( $statuses_placeholder ) ) { + // phpcs:disable + if ( $this->is_hpos() ) { + $query .= $wpdb->prepare( + ' AND status IN (' . implode( ',', $statuses_placeholder ) . ')', + $valid_order_statuses + ); + } else { + $query .= $wpdb->prepare( + ' AND p.post_status IN (' . implode( ',', $statuses_placeholder ) . ')', + $valid_order_statuses + ); + } + // phpcs:enable + } + + $order_id = $wpdb->get_var( $query ); // phpcs:ignore + + wp_cache_set( 'wc_sc_order_id_by_billing_email_' . sanitize_key( $email ), $order_id, 'woocommerce_smart_coupons' ); + $this->maybe_add_cache_key( 'wc_sc_order_id_by_billing_email_' . sanitize_key( $email ) ); + } + + if ( ! empty( $order_id ) ) { + if ( defined( 'WC_DOING_AJAX' ) && WC_DOING_AJAX === true ) { + $is_valid = false; + } else { + throw new Exception( $failed_notice ); + } + } + + $user_id_1 = wp_cache_get( 'wc_sc_user_id_by_user_email_' . sanitize_key( $email ), 'woocommerce_smart_coupons' ); + if ( false === $user_id_1 ) { + $user_id_1 = $wpdb->get_var( // phpcs:ignore + $wpdb->prepare( + "SELECT ID + FROM {$wpdb->base_prefix}users + WHERE user_email = %s", + $email + ) + ); + wp_cache_set( 'wc_sc_user_id_by_user_email_' . sanitize_key( $email ), $user_id_1, 'woocommerce_smart_coupons' ); + $this->maybe_add_cache_key( 'wc_sc_user_id_by_user_email_' . sanitize_key( $email ) ); + } + + $user_id_2 = wp_cache_get( 'wc_sc_user_id_by_billing_email_' . sanitize_key( $email ), 'woocommerce_smart_coupons' ); + if ( false === $user_id_2 ) { + $user_id_2 = $wpdb->get_var( // phpcs:ignore + $wpdb->prepare( + "SELECT user_id + FROM {$wpdb->base_prefix}usermeta + WHERE meta_key = %s + AND meta_value = %s", + 'billing_email', + $email + ) + ); + wp_cache_set( 'wc_sc_user_id_by_billing_email_' . sanitize_key( $email ), $user_id_2, 'woocommerce_smart_coupons' ); + $this->maybe_add_cache_key( 'wc_sc_user_id_by_billing_email_' . sanitize_key( $email ) ); + } + } + + $user_id_3 = get_current_user_id(); + + $user_ids = array( $user_id_1, $user_id_2, $user_id_3 ); + $user_ids = array_unique( array_filter( $user_ids ) ); + + if ( ! empty( $user_ids ) ) { + + $unique_user_ids = array_unique( $user_ids ); + + $order_id = wp_cache_get( 'wc_sc_order_for_user_id_' . implode( '_', $unique_user_ids ), 'woocommerce_smart_coupons' ); + + if ( false === $order_id ) { + if ( $this->is_hpos() ) { + $query = $wpdb->prepare( + "SELECT id + FROM {$wpdb->prefix}wc_orders + WHERE %d", + 1 + ); + } else { + $query = $wpdb->prepare( + "SELECT ID + FROM $wpdb->posts AS p + LEFT JOIN $wpdb->postmeta AS pm + ON ( p.ID = pm.post_id AND pm.meta_key = %s ) + WHERE p.post_type = %s", + '_customer_user', + 'shop_order' + ); + } + + if ( ! empty( $valid_order_statuses ) && ! empty( $statuses_placeholder ) ) { + // phpcs:disable + if ( $this->is_hpos() ) { + $query .= $wpdb->prepare( + ' AND status IN (' . implode( ',', $statuses_placeholder ) . ')', + $valid_order_statuses + ); + } else { + $query .= $wpdb->prepare( + ' AND p.post_status IN (' . implode( ',', $statuses_placeholder ) . ')', + $valid_order_statuses + ); + } + // phpcs:enable + } + + $how_many_user_ids = count( $user_ids ); + + // phpcs:disable + if ( $this->is_hpos() ) { + $id_placeholder = array_fill( 0, $how_many_user_ids, '%d' ); + $query .= $wpdb->prepare( + ' AND customer_id IN (' . implode( ',', $id_placeholder ) . ')', + $user_ids + ); + } else { + $id_placeholder = array_fill( 0, $how_many_user_ids, '%s' ); + $query .= $wpdb->prepare( + ' AND pm.meta_value IN (' . implode( ',', $id_placeholder ) . ')', + $user_ids + ); + } + // phpcs:enable + + $order_id = $wpdb->get_var( $query ); // phpcs:ignore + + wp_cache_set( 'wc_sc_order_for_user_id_' . implode( '_', $unique_user_ids ), $order_id, 'woocommerce_smart_coupons' ); + $this->maybe_add_cache_key( 'wc_sc_order_for_user_id_' . implode( '_', $unique_user_ids ) ); + } + + if ( ! empty( $order_id ) ) { + if ( defined( 'WC_DOING_AJAX' ) && WC_DOING_AJAX === true ) { + $is_valid = false; + } else { + throw new Exception( $failed_notice ); + } + } + } + } + + return $is_valid; + } + + /** + * Locate template for Smart Coupons + * + * @param string $template_name The template name. + * @param mixed $template Default template. + * @return mixed $template + */ + public function locate_template_for_smart_coupons( $template_name = '', $template = '' ) { + + $default_path = untrailingslashit( plugin_dir_path( WC_SC_PLUGIN_FILE ) ) . '/templates/'; + + $plugin_base_dir = substr( plugin_basename( WC_SC_PLUGIN_FILE ), 0, strpos( plugin_basename( WC_SC_PLUGIN_FILE ), '/' ) + 1 ); + + // Look within passed path within the theme - this is priority. + $template = locate_template( + array( + 'woocommerce/' . $plugin_base_dir . $template_name, + $plugin_base_dir . $template_name, + $template_name, + ) + ); + + // Get default template. + if ( ! $template ) { + $template = $default_path . $template_name; + } + + return $template; + } + + /** + * Function to get template base directory for Smart Coupons' email templates + * + * @param string $template_name Template name. + * @return string $template_base_dir Base directory for Smart Coupons' email templates. + */ + public function get_template_base_dir( $template_name = '' ) { + + $template_base_dir = ''; + $plugin_base_dir = substr( plugin_basename( WC_SC_PLUGIN_FILE ), 0, strpos( plugin_basename( WC_SC_PLUGIN_FILE ), '/' ) + 1 ); + $wc_sc_base_dir = 'woocommerce/' . $plugin_base_dir; + + // First locate the template in woocommerce/woocommerce-smart-coupons folder of active theme. + $template = locate_template( + array( + $wc_sc_base_dir . $template_name, + ) + ); + + if ( ! empty( $template ) ) { + $template_base_dir = $wc_sc_base_dir; + } else { + // If not found then locate the template in woocommerce-smart-coupons folder of active theme. + $template = locate_template( + array( + $plugin_base_dir . $template_name, + ) + ); + if ( ! empty( $template ) ) { + $template_base_dir = $plugin_base_dir; + } + } + + $template_base_dir = apply_filters( 'wc_sc_template_base_dir', $template_base_dir, $template_name ); + + return $template_base_dir; + } + + /** + * Check whether credit is sent or not + * + * @param string $email_id The email address. + * @param WC_Coupon $coupon The coupon object. + * @return boolean + */ + public function is_credit_sent( $email_id, $coupon ) { + + global $smart_coupon_codes; + + if ( isset( $smart_coupon_codes[ $email_id ] ) && count( $smart_coupon_codes[ $email_id ] ) > 0 ) { + if ( $this->is_wc_gte_30() ) { + $coupon_id = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_id' ) ) ) ? $coupon->get_id() : 0; + } else { + $coupon_id = ( ! empty( $coupon->id ) ) ? $coupon->id : 0; + } + foreach ( $smart_coupon_codes[ $email_id ] as $generated_coupon_details ) { + if ( $generated_coupon_details['parent'] === $coupon_id ) { + return true; + } + } + } + + return false; + + } + + /** + * Generate unique string to be used as coupon code. Also add prefix or suffix if already set + * + * @param string $email The email address. + * @param WC_Coupon $coupon The coupon object. + * @return string $unique_code + */ + public function generate_unique_code( $email = '', $coupon = '' ) { + $unique_code = ''; + srand( (double) microtime( true ) * 1000000 ); // phpcs:ignore + + $coupon_code_length = $this->get_coupon_code_length(); + + $chars = array_diff( array_merge( range( 'a', 'z' ), range( '0', '9' ) ), array( 'a', 'e', 'i', 'o', 'u' ) ); + $chars = apply_filters( + 'wc_sc_coupon_code_allowed_characters', + array_values( $chars ), + array( + 'source' => $this, + 'email' => $email, + 'coupon_object' => $coupon, + 'coupon_code_length' => $coupon_code_length, + ) + ); + + $numbers = array_values( array_filter( $chars, 'is_numeric' ) ); + $alphabets = ( count( $chars ) !== count( $numbers ) ) ? array_values( array_diff( $chars, $numbers ) ) : array(); + + if ( empty( $numbers ) || empty( $alphabets ) ) { + $chars = array_values( array_merge( $alphabets, $numbers ) ); + for ( $rand = 1; $rand <= $coupon_code_length; $rand++ ) { + $random = rand( 0, count( $chars ) - 1 ); // phpcs:ignore + $unique_code .= $chars[ $random ]; + } + } else { + for ( $rand = 1, $char_count = 0, $num_count = 0; $rand <= $coupon_code_length; $rand++ ) { + if ( $char_count >= 2 ) { + $random = rand( 0, count( $numbers ) - 1 ); // phpcs:ignore + $unique_code .= $numbers[ $random ]; + $char_count = 0; + $num_count++; + } elseif ( $num_count >= 1 ) { + $random = rand( 0, count( $alphabets ) - 1 ); // phpcs:ignore + $unique_code .= $alphabets[ $random ]; + $num_count = 0; + $char_count++; + } else { + $random = rand( 0, count( $chars ) - 1 ); // phpcs:ignore + $selected_char = $chars[ $random ]; + $unique_code .= $selected_char; + if ( is_numeric( $selected_char ) ) { + $num_count++; + } else { + $char_count++; + } + } + } + } + + if ( $this->is_wc_gte_30() ) { + $coupon_id = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_id' ) ) ) ? $coupon->get_id() : 0; + } else { + $coupon_id = ( ! empty( $coupon->id ) ) ? $coupon->id : 0; + } + + if ( $this->is_callable( $coupon, 'get_meta' ) ) { + if ( 'yes' === $coupon->get_meta( 'auto_generate_coupon' ) ) { + $prefix = $coupon->get_meta( 'coupon_title_prefix' ); + $suffix = $coupon->get_meta( 'coupon_title_suffix' ); + $unique_code = $prefix . $unique_code . $suffix; + } + } else { + if ( ! empty( $coupon_id ) && get_post_meta( $coupon_id, 'auto_generate_coupon', true ) === 'yes' ) { + $prefix = get_post_meta( $coupon_id, 'coupon_title_prefix', true ); + $suffix = get_post_meta( $coupon_id, 'coupon_title_suffix', true ); + $unique_code = $prefix . $unique_code . $suffix; + } + } + + return apply_filters( + 'wc_sc_generate_unique_coupon_code', + $unique_code, + array( + 'email' => $email, + 'coupon' => $coupon, + ) + ); + } + + /** + * Function for generating Gift Certificate + * + * @param mixed $email The email address. + * @param float $amount The amount. + * @param int $order_id The order id. + * @param WC_Coupon $coupon The coupon object. + * @param string $discount_type The discount type. + * @param array $gift_certificate_receiver_name Receiver name. + * @param string $message_from_sender Message from sender. + * @param string $gift_certificate_sender_name Sender name. + * @param string $gift_certificate_sender_email Sender email. + * @param string $sending_timestamp timestamp for scheduled sending. + * @return array of generated coupon details + */ + public function generate_smart_coupon( $email, $amount, $order_id = '', $coupon = '', $discount_type = 'smart_coupon', $gift_certificate_receiver_name = '', $message_from_sender = '', $gift_certificate_sender_name = '', $gift_certificate_sender_email = '', $sending_timestamp = '' ) { + return $this->generate_smart_coupon_action( $email, $amount, $order_id, $coupon, $discount_type, $gift_certificate_receiver_name, $message_from_sender, $gift_certificate_sender_name, $gift_certificate_sender_email, $sending_timestamp ); + } + + /** + * Function for generating Gift Certificate + * + * @param mixed $email The email address. + * @param float $amount The amount. + * @param int $order_id The order id. + * @param WC_Coupon $coupon The coupon object. + * @param string $discount_type The discount type. + * @param array $gift_certificate_receiver_name Receiver name. + * @param string $message_from_sender Message from sender. + * @param string $gift_certificate_sender_name Sender name. + * @param string $gift_certificate_sender_email Sender email. + * @param string $sending_timestamp timestamp for scheduled sending. + * @return array $smart_coupon_codes associative array containing generated coupon details + */ + public function generate_smart_coupon_action( $email, $amount, $order_id = '', $coupon = '', $discount_type = 'smart_coupon', $gift_certificate_receiver_name = '', $message_from_sender = '', $gift_certificate_sender_name = '', $gift_certificate_sender_email = '', $sending_timestamp = '' ) { + + if ( '' === $email ) { + return false; + } + + global $smart_coupon_codes; + + $order_id = ( ! empty( $order_id ) ) ? absint( $order_id ) : 0; + $order = ( function_exists( 'wc_get_order' ) && ! empty( $order_id ) ) ? wc_get_order( $order_id ) : null; + + $is_callable_order_get_meta = $this->is_callable( $order, 'get_meta' ); + $is_callable_coupon_get_meta = $this->is_callable( $coupon, 'get_meta' ); + + if ( $this->is_wc_gte_30() ) { + $coupon_id = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_id' ) ) ) ? $coupon->get_id() : 0; + $is_free_shipping = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_free_shipping' ) ) ) ? ( ( $coupon->get_free_shipping() ) ? 'yes' : 'no' ) : ''; + $discount_type = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_discount_type' ) ) ) ? $coupon->get_discount_type() : ''; + $expiry_date = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_date_expires' ) ) ) ? $coupon->get_date_expires() : ''; + $coupon_product_ids = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_product_ids' ) ) ) ? $coupon->get_product_ids() : ''; + $coupon_product_categories = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_product_categories' ) ) ) ? $coupon->get_product_categories() : ''; + $coupon_excluded_product_ids = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_excluded_product_ids' ) ) ) ? $coupon->get_excluded_product_ids() : ''; + $coupon_excluded_product_categories = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_excluded_product_categories' ) ) ) ? $coupon->get_excluded_product_categories() : ''; + $coupon_minimum_amount = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_minimum_amount' ) ) ) ? $coupon->get_minimum_amount() : ''; + $coupon_maximum_amount = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_maximum_amount' ) ) ) ? $coupon->get_maximum_amount() : ''; + $coupon_usage_limit = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_usage_limit' ) ) ) ? $coupon->get_usage_limit() : ''; + $coupon_usage_limit_per_user = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_usage_limit_per_user' ) ) ) ? $coupon->get_usage_limit_per_user() : ''; + $coupon_limit_usage_to_x_items = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_limit_usage_to_x_items' ) ) ) ? $coupon->get_limit_usage_to_x_items() : ''; + $is_exclude_sale_items = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_exclude_sale_items' ) ) ) ? ( ( $coupon->get_exclude_sale_items() ) ? 'yes' : 'no' ) : ''; + $is_individual_use = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_individual_use' ) ) ) ? ( ( $coupon->get_individual_use() ) ? 'yes' : 'no' ) : ''; + } else { + $coupon_id = ( ! empty( $coupon->id ) ) ? $coupon->id : 0; + $is_free_shipping = ( ! empty( $coupon->free_shipping ) ) ? $coupon->free_shipping : ''; + $discount_type = ( ! empty( $coupon->discount_type ) ) ? $coupon->discount_type : ''; + $expiry_date = ( ! empty( $coupon->expiry_date ) ) ? $coupon->expiry_date : ''; + $coupon_product_ids = ( ! empty( $coupon->product_ids ) ) ? $coupon->product_ids : ''; + $coupon_product_categories = ( ! empty( $coupon->product_categories ) ) ? $coupon->product_categories : ''; + $coupon_excluded_product_ids = ( ! empty( $coupon->exclude_product_ids ) ) ? $coupon->exclude_product_ids : ''; + $coupon_excluded_product_categories = ( ! empty( $coupon->exclude_product_categories ) ) ? $coupon->exclude_product_categories : ''; + $coupon_minimum_amount = ( ! empty( $coupon->minimum_amount ) ) ? $coupon->minimum_amount : ''; + $coupon_maximum_amount = ( ! empty( $coupon->maximum_amount ) ) ? $coupon->maximum_amount : ''; + $coupon_usage_limit = ( ! empty( $coupon->usage_limit ) ) ? $coupon->usage_limit : ''; + $coupon_usage_limit_per_user = ( ! empty( $coupon->usage_limit_per_user ) ) ? $coupon->usage_limit_per_user : ''; + $coupon_limit_usage_to_x_items = ( ! empty( $coupon->limit_usage_to_x_items ) ) ? $coupon->limit_usage_to_x_items : ''; + $is_exclude_sale_items = ( ! empty( $coupon->exclude_sale_items ) ) ? $coupon->exclude_sale_items : ''; + $is_individual_use = ( ! empty( $coupon->individual_use ) ) ? $coupon->individual_use : ''; + } + + if ( ! is_array( $email ) ) { + $emails = array( $email => 1 ); + } else { + $temp_email = ( true === $is_callable_order_get_meta ) ? $order->get_meta( 'temp_gift_card_receivers_emails' ) : get_post_meta( $order_id, 'temp_gift_card_receivers_emails', true ); + if ( ! empty( $temp_email ) && count( $temp_email ) > 0 ) { + $email = $temp_email; + } + $emails = ( ! empty( $coupon_id ) ) ? array_count_values( $email[ $coupon_id ] ) : array(); + } + + if ( ! empty( $order_id ) ) { + $receivers_messages = ( true === $is_callable_order_get_meta ) ? $order->get_meta( 'gift_receiver_message' ) : get_post_meta( $order_id, 'gift_receiver_message', true ); + $schedule_gift_sending = ( true === $is_callable_order_get_meta ) ? $order->get_meta( 'wc_sc_schedule_gift_sending' ) : get_post_meta( $order_id, 'wc_sc_schedule_gift_sending', true ); + $sending_timestamps = ( true === $is_callable_order_get_meta ) ? $order->get_meta( 'gift_sending_timestamp' ) : get_post_meta( $order_id, 'gift_sending_timestamp', true ); + } + + foreach ( $emails as $email_id => $qty ) { + + if ( $this->is_credit_sent( $email_id, $coupon ) ) { + continue; + } + + $smart_coupon_code = $this->generate_unique_code( $email_id, $coupon ); + + $coupon_post = ( ! empty( $coupon_id ) ) ? get_post( $coupon_id ) : new stdClass(); + + $smart_coupon_args = array( + 'post_title' => strtolower( $smart_coupon_code ), + 'post_excerpt' => ( ! empty( $coupon_post->post_excerpt ) ) ? $coupon_post->post_excerpt : '', + 'post_content' => '', + 'post_status' => 'publish', + 'post_author' => 1, + 'post_type' => 'shop_coupon', + 'post_parent' => ! empty( $coupon_id ) ? absint( $coupon_id ) : 0, + ); + + $should_schedule = isset( $schedule_gift_sending ) && 'yes' === $schedule_gift_sending && $this->is_valid_timestamp( $sending_timestamp ) ? true : false; + + if ( $should_schedule ) { + $smart_coupon_args['post_date_gmt'] = gmdate( 'Y-m-d H:i:s', $sending_timestamp ); + $smart_coupon_args['post_date'] = gmdate( 'Y-m-d H:i:s', ( $sending_timestamp + $this->wc_timezone_offset() ) ); + } + + $smart_coupon = new WC_Coupon( $smart_coupon_args['post_title'] ); + $smart_coupon->set_description( $smart_coupon_args['post_excerpt'] ); + + if ( $this->is_wc_greater_than( '6.1.2' ) && $this->is_callable( $smart_coupon, 'set_status' ) ) { + $smart_coupon->set_status( $smart_coupon_args['post_status'] ); + } + + $smart_coupon_id = $smart_coupon->save(); + + if ( ! empty( $smart_coupon_id ) ) { + $smart_coupon_args = array_diff_key( $smart_coupon_args, array_flip( array( 'post_excerpt', 'post_title', 'post_status', 'post_type' ) ) ); + $smart_coupon_args['ID'] = $smart_coupon_id; + wp_update_post( $smart_coupon_args ); + } + + $smart_coupon_id = absint( $smart_coupon_id ); + + $smart_coupon = new WC_Coupon( $smart_coupon ); + + $is_callable_smart_coupon_update_meta = $this->is_callable( $smart_coupon, 'update_meta_data' ); + + $type = ( ! empty( $discount_type ) ) ? $discount_type : 'smart_coupon'; + $individual_use = ( ! empty( $is_individual_use ) ) ? $is_individual_use : 'no'; + $minimum_amount = ( ! empty( $coupon_minimum_amount ) ) ? $coupon_minimum_amount : ''; + $maximum_amount = ( ! empty( $coupon_maximum_amount ) ) ? $coupon_maximum_amount : ''; + $product_ids = ( ! empty( $coupon_product_ids ) ) ? implode( ',', $coupon_product_ids ) : ''; + $exclude_product_ids = ( ! empty( $coupon_excluded_product_ids ) ) ? implode( ',', $coupon_excluded_product_ids ) : ''; + $usage_limit = ( ! empty( $coupon_usage_limit ) ) ? $coupon_usage_limit : ''; + $usage_limit_per_user = ( ! empty( $coupon_usage_limit_per_user ) ) ? $coupon_usage_limit_per_user : ''; + $limit_usage_to_x_items = ( ! empty( $coupon_limit_usage_to_x_items ) ) ? $coupon_limit_usage_to_x_items : ''; + $free_shipping = ( ! empty( $is_free_shipping ) ) ? $is_free_shipping : 'no'; + $product_categories = ( ! empty( $coupon_product_categories ) ) ? $coupon_product_categories : array(); + $exclude_product_categories = ( ! empty( $coupon_excluded_product_categories ) ) ? $coupon_excluded_product_categories : array(); + $sc_coupon_validity = ( true === $is_callable_coupon_get_meta ) ? $coupon->get_meta( 'sc_coupon_validity' ) : ( ( ! empty( $coupon_id ) ) ? get_post_meta( $coupon_id, 'sc_coupon_validity', true ) : '' ); + $is_disable_email_restriction = ( true === $is_callable_coupon_get_meta ) ? $coupon->get_meta( 'sc_disable_email_restriction' ) : ( ( ! empty( $coupon_id ) ) ? get_post_meta( $coupon_id, 'sc_disable_email_restriction', true ) : '' ); + $sc_restrict_to_new_user = ( true === $is_callable_coupon_get_meta ) ? $coupon->get_meta( 'sc_restrict_to_new_user' ) : get_post_meta( $coupon_id, 'sc_restrict_to_new_user', true ); + $wc_sc_max_discount = $this->get_post_meta( $coupon_id, 'wc_sc_max_discount', true, true, $order ); + + if ( $this->is_wc_gte_30() && $expiry_date instanceof WC_DateTime ) { + $expiry_date = ( is_callable( array( $expiry_date, 'getTimestamp' ) ) ) ? $expiry_date->getTimestamp() : null; + } elseif ( ! is_int( $expiry_date ) ) { + $expiry_date = $this->strtotime( $expiry_date ); + } + + if ( ! empty( $coupon_id ) && ! empty( $sc_coupon_validity ) ) { + $is_parent_coupon_expired = ( ! empty( $expiry_date ) && ( $expiry_date < time() ) ) ? true : false; + if ( ! $is_parent_coupon_expired ) { + $validity_suffix = ( true === $is_callable_coupon_get_meta ) ? $coupon->get_meta( 'validity_suffix' ) : get_post_meta( $coupon_id, 'validity_suffix', true ); + // In case of scheduled coupon, expiry date is calculated from scheduled publish date. + if ( isset( $smart_coupon_args['post_date_gmt'] ) ) { + $expiry_date = $this->strtotime( $smart_coupon_args['post_date_gmt'] . "+$sc_coupon_validity $validity_suffix" ); + } else { + $expiry_date = $this->strtotime( "+$sc_coupon_validity $validity_suffix" ); + } + } + } + + if ( $this->is_wc_gte_30() ) { + $expiry_date = $this->get_date_expires_value( $expiry_date ); + if ( true === $is_callable_smart_coupon_update_meta ) { + $smart_coupon->set_date_expires( $expiry_date ); + } else { + update_post_meta( $smart_coupon_id, 'date_expires', $expiry_date ); + } + } else { + $expiry_date = ( ! empty( $expiry_date ) ) ? gmdate( 'Y-m-d', intval( $expiry_date ) + $this->wc_timezone_offset() ) : ''; + if ( true === $is_callable_smart_coupon_update_meta ) { + $smart_coupon->update_meta_data( 'expiry_date', $expiry_date ); + } else { + update_post_meta( $smart_coupon_id, 'expiry_date', $expiry_date ); + } + } + + if ( 'smart_coupon' === $type ) { + $this->update_post_meta( $smart_coupon_id, 'wc_sc_original_amount', $amount, false, $order ); + } + + if ( true === $is_callable_smart_coupon_update_meta ) { + $product_ids = ( ! is_array( $product_ids ) ) ? explode( ',', $product_ids ) : $product_ids; // set_product_ids expects an array. + $exclude_product_ids = ( ! is_array( $exclude_product_ids ) ) ? explode( ',', $exclude_product_ids ) : $exclude_product_ids; // set_excluded_product_ids expects an array. + + $smart_coupon->set_amount( $amount ); + $smart_coupon->set_excluded_product_ids( $exclude_product_ids ); + $smart_coupon->set_excluded_product_categories( $exclude_product_categories ); + $smart_coupon->set_discount_type( $type ); + $smart_coupon->set_individual_use( $this->wc_string_to_bool( $individual_use ) ); + $smart_coupon->set_minimum_amount( $minimum_amount ); + $smart_coupon->set_maximum_amount( $maximum_amount ); + $smart_coupon->set_product_ids( $product_ids ); + $smart_coupon->set_usage_limit( $usage_limit ); + $smart_coupon->set_usage_limit_per_user( $usage_limit_per_user ); + $smart_coupon->set_limit_usage_to_x_items( $limit_usage_to_x_items ); + $smart_coupon->set_free_shipping( $this->wc_string_to_bool( $free_shipping ) ); + $smart_coupon->set_product_categories( $product_categories ); + $smart_coupon->set_exclude_sale_items( $this->wc_string_to_bool( $is_exclude_sale_items ) ); + $smart_coupon->update_meta_data( 'sc_restrict_to_new_user', $sc_restrict_to_new_user ); + if ( ! empty( $order_id ) ) { + $smart_coupon->update_meta_data( 'generated_from_order_id', $order_id ); + } + if ( empty( $is_disable_email_restriction ) || 'no' === $is_disable_email_restriction ) { + // Update customer_email now if coupon is not scheduled otherwise it would be updated by action scheduler later on. + if ( ! $should_schedule ) { + $smart_coupon->set_email_restrictions( array( $email_id ) ); + } + } + } else { + update_post_meta( $smart_coupon_id, 'discount_type', $type ); + update_post_meta( $smart_coupon_id, 'coupon_amount', $amount ); + update_post_meta( $smart_coupon_id, 'individual_use', $individual_use ); + update_post_meta( $smart_coupon_id, 'minimum_amount', $minimum_amount ); + update_post_meta( $smart_coupon_id, 'maximum_amount', $maximum_amount ); + update_post_meta( $smart_coupon_id, 'product_ids', $product_ids ); + update_post_meta( $smart_coupon_id, 'exclude_product_ids', $exclude_product_ids ); + update_post_meta( $smart_coupon_id, 'usage_limit', $usage_limit ); + update_post_meta( $smart_coupon_id, 'usage_limit_per_user', $usage_limit_per_user ); + update_post_meta( $smart_coupon_id, 'limit_usage_to_x_items', $limit_usage_to_x_items ); + update_post_meta( $smart_coupon_id, 'free_shipping', $free_shipping ); + update_post_meta( $smart_coupon_id, 'product_categories', $product_categories ); + update_post_meta( $smart_coupon_id, 'exclude_product_categories', $exclude_product_categories ); + update_post_meta( $smart_coupon_id, 'exclude_sale_items', $is_exclude_sale_items ); + update_post_meta( $smart_coupon_id, 'sc_restrict_to_new_user', $sc_restrict_to_new_user ); + if ( ! empty( $order_id ) ) { + update_post_meta( $smart_coupon_id, 'generated_from_order_id', $order_id ); + } + if ( empty( $is_disable_email_restriction ) || 'no' === $is_disable_email_restriction ) { + // Update customer_email now if coupon is not scheduled otherwise it would be updated by action scheduler later on. + if ( ! $should_schedule ) { + update_post_meta( $smart_coupon_id, 'customer_email', array( $email_id ) ); + } + } + } + + if ( ! $this->is_wc_gte_30() ) { + $apply_before_tax = ( ! empty( $coupon->apply_before_tax ) ) ? $coupon->apply_before_tax : 'no'; + if ( true === $is_callable_smart_coupon_update_meta ) { + $smart_coupon->update_meta_data( 'apply_before_tax', $apply_before_tax ); + } else { + update_post_meta( $smart_coupon_id, 'apply_before_tax', $apply_before_tax ); + } + } + + // Add terms to auto-generated if found in parent coupon. + $coupon_terms = get_the_terms( $coupon_id, 'sc_coupon_category' ); + if ( ! empty( $coupon_terms ) ) { + $term_ids = array_column( $coupon_terms, 'term_id' ); + wp_set_object_terms( $smart_coupon_id, $term_ids, 'sc_coupon_category', false ); + } + + if ( ! empty( $wc_sc_max_discount ) ) { + $this->update_post_meta( $smart_coupon_id, 'wc_sc_max_discount', $wc_sc_max_discount, true, $order ); + } + + if ( $this->is_wc_gte_32() ) { + $wc_sc_expiry_time = ( true === $is_callable_coupon_get_meta ) ? (int) $coupon->get_meta( 'wc_sc_expiry_time' ) : (int) get_post_meta( $coupon_id, 'wc_sc_expiry_time', true ); + if ( ! empty( $wc_sc_expiry_time ) ) { + if ( true === $is_callable_smart_coupon_update_meta ) { + $smart_coupon->update_meta_data( 'wc_sc_expiry_time', $wc_sc_expiry_time ); + } else { + update_post_meta( $smart_coupon_id, 'wc_sc_expiry_time', $wc_sc_expiry_time ); + } + } + } + + if ( $this->is_callable( $smart_coupon, 'save' ) ) { + $smart_coupon->save(); + } + + /** + * Hook for 3rd party developers to add data in generated coupon + * + * New coupon id new_coupon_id Newly generated coupon post id + * Reference coupon ref_coupon This is the coupon from which meta will be copied to newly created coupon + */ + do_action( + 'wc_sc_new_coupon_generated', + array( + 'new_coupon_id' => $smart_coupon_id, + 'ref_coupon' => $coupon, + ) + ); + + $generated_coupon_details = array( + 'parent' => ( ! empty( $coupon_id ) ) ? $coupon_id : 0, + 'code' => $smart_coupon_code, + 'amount' => $amount, + ); + + $smart_coupon_codes[ $email_id ][] = $generated_coupon_details; + + if ( ! empty( $order_id ) ) { + $is_gift = ( true === $is_callable_order_get_meta ) ? $order->get_meta( 'is_gift' ) : get_post_meta( $order_id, 'is_gift', true ); + } else { + $is_gift = 'no'; + } + + if ( is_array( $email ) && ! empty( $coupon_id ) && isset( $email[ $coupon_id ] ) ) { + $message_index = array_search( $email_id, $email[ $coupon_id ], true ); + if ( false !== $message_index && isset( $receivers_messages[ $coupon_id ][ $message_index ] ) && ! empty( $receivers_messages[ $coupon_id ][ $message_index ] ) ) { + $message_from_sender = $receivers_messages[ $coupon_id ][ $message_index ]; + unset( $email[ $coupon_id ][ $message_index ] ); + $this->update_post_meta( $order_id, 'temp_gift_card_receivers_emails', $email, false, $order ); + } + } + + if ( ( isset( $schedule_gift_sending ) && 'yes' === $schedule_gift_sending && $this->is_valid_timestamp( $sending_timestamp ) ) ) { + $wc_sc_coupon_receiver_details = array( + 'coupon_details' => $generated_coupon_details, + 'gift_certificate_receiver_email' => $email_id, + 'gift_certificate_receiver_name' => $gift_certificate_receiver_name, + 'message_from_sender' => $message_from_sender, + 'gift_certificate_sender_name' => $gift_certificate_sender_name, + 'gift_certificate_sender_email' => $gift_certificate_sender_email, + ); + if ( true === $is_callable_smart_coupon_update_meta ) { + $smart_coupon->update_meta_data( 'wc_sc_coupon_receiver_details', $wc_sc_coupon_receiver_details ); + } else { + update_post_meta( $smart_coupon_id, 'wc_sc_coupon_receiver_details', $wc_sc_coupon_receiver_details ); + } + } else { + $is_send_email = $this->is_email_template_enabled(); + $combine_emails = $this->is_email_template_enabled( 'combine' ); + if ( 'yes' === $is_send_email ) { + if ( 'yes' === $combine_emails ) { + $coupon_receiver_details = ( true === $is_callable_order_get_meta ) ? $order->get_meta( 'sc_coupon_receiver_details' ) : get_post_meta( $order_id, 'sc_coupon_receiver_details', true ); + if ( empty( $coupon_receiver_details ) || ! is_array( $coupon_receiver_details ) ) { + $coupon_receiver_details = array(); + } + $coupon_receiver_details[] = array( + 'code' => $generated_coupon_details['code'], + 'amount' => $amount, + 'email' => $email_id, + 'message' => $message_from_sender, + ); + $this->update_post_meta( $order_id, 'sc_coupon_receiver_details', $coupon_receiver_details, false, $order ); + } else { + $this->sa_email_coupon( array( $email_id => $generated_coupon_details ), $type, $order_id, $gift_certificate_receiver_name, $message_from_sender, $gift_certificate_sender_name, $gift_certificate_sender_email, $is_gift ); + } + } else { + if ( ! empty( $order_id ) ) { + $coupon_receiver_details = ( true === $is_callable_order_get_meta ) ? $order->get_meta( 'sc_coupon_receiver_details' ) : get_post_meta( $order_id, 'sc_coupon_receiver_details', true ); + if ( empty( $coupon_receiver_details ) || ! is_array( $coupon_receiver_details ) ) { + $coupon_receiver_details = array(); + } + $coupon_receiver_details[] = array( + 'code' => $generated_coupon_details['code'], + 'amount' => $amount, + 'email' => $email_id, + 'message' => $message_from_sender, + ); + $this->update_post_meta( $order_id, 'sc_coupon_receiver_details', $coupon_receiver_details, false, $order ); + } + } + } + if ( $this->is_callable( $smart_coupon, 'save' ) ) { + $smart_coupon->save(); + } + } + + return $smart_coupon_codes; + + } + + /** + * Function to set that Smart Coupons plugin is used to auto generate a coupon + * + * @param array $args Data. + */ + public function smart_coupons_plugin_used( $args = array() ) { + + $is_show_review_notice = get_option( 'wc_sc_is_show_review_notice' ); + + if ( false === $is_show_review_notice ) { + update_option( 'wc_sc_is_show_review_notice', time(), 'no' ); + } + + } + + /** + * Add button to export coupons on Coupons admin page + */ + public function woocommerce_restrict_manage_smart_coupons() { + global $typenow, $wp_query, $wp, $woocommerce_smart_coupon; + + if ( 'shop_coupon' !== $typenow ) { + return; + } + + $is_print = get_option( 'smart_coupons_is_print_coupon', 'yes' ); + $is_print = apply_filters( 'wc_sc_admin_show_print_button', wc_string_to_bool( $is_print ), array( 'source' => $woocommerce_smart_coupon ) ); + $print_url = add_query_arg( + array( + 'print-coupons' => 'yes', + 'source' => 'wc-smart-coupons', + 'coupon-codes' => '', + ), + home_url() + ); + wc_product_dropdown_categories( + array( + 'selected' => isset( $wp_query->query_vars['sc_coupon_category'] ) ? $wp_query->query_vars['sc_coupon_category'] : '', + 'taxonomy' => 'sc_coupon_category', + 'name' => 'sc_coupon_category', + 'option_select_text' => __( 'Filter by category', 'woocommerce-smart-coupons' ), + 'hide_empty' => 0, + ) + ); + + ?> + +
            + '; // phpcs:ignore + } + ?> + + + + + +
            + '', + 'post_type' => '', + 'm' => '', + 'posts_per_page' => -1, + 'fields' => 'ids', + ); + + if ( ! empty( $_REQUEST['sc_export_query_args'] ) ) { // phpcs:ignore + parse_str( wc_clean( wp_unslash( $_REQUEST['sc_export_query_args'] ) ), $sc_args ); // phpcs:ignore + } + $args = array_merge( $args, $sc_args ); + + $get_coupon_type = ( ! empty( $_GET['coupon_type'] ) ) ? wc_clean( wp_unslash( $_GET['coupon_type'] ) ) : ''; // phpcs:ignore + $get_post = ( ! empty( $_GET['post'] ) ) ? wc_clean( wp_unslash( $_GET['post'] ) ) : ''; // phpcs:ignore + + if ( isset( $get_coupon_type ) && '' !== $get_coupon_type ) { + $args['meta_query'] = array( // phpcs:ignore + array( + 'key' => 'discount_type', + 'value' => $get_coupon_type, + ), + ); + } + + if ( ! empty( $get_post ) ) { + $args['post__in'] = $get_post; + } + + foreach ( $args as $key => $value ) { + if ( array_key_exists( $key, wc_clean( wp_unslash( $_GET ) ) ) ) { // phpcs:ignore + $args[ $key ] = wc_clean( wp_unslash( $_GET[ $key ] ) ); // phpcs:ignore + } + } + + if ( 'all' === $args['post_status'] ) { + $args['post_status'] = array( 'publish', 'draft', 'pending', 'private', 'future' ); + + } + + $query = new WP_Query( $args ); + + $post_ids = $query->posts; + + $this->export_coupon( '', wc_clean( wp_unslash( $_GET ) ), $post_ids ); // phpcs:ignore + } + } + + /** + * Generate coupon code + * + * @param array $post POST. + * @param array $get GET. + * @param array $post_ids Post ids. + * @param array $coupon_postmeta_headers Coupon postmeta headers. + * @return array $data associative array of generated coupon + */ + public function generate_coupons_code( $post = array(), $get = array(), $post_ids = array(), $coupon_postmeta_headers = array() ) { + global $wpdb, $wp, $wp_query; + + if ( ! empty( $post_ids ) ) { + if ( ! is_array( $post_ids ) ) { + $post_ids = array( $post_ids ); + } + $post_ids = array_map( 'absint', $post_ids ); + } + + $data = array(); + if ( ! empty( $post ) && isset( $post['generate_and_import'] ) ) { + + $customer_emails = array(); + $unique_code = ''; + if ( ! empty( $post['customer_email'] ) ) { + $emails = explode( ',', $post['customer_email'] ); + if ( is_array( $emails ) && count( $emails ) > 0 ) { + for ( $j = 1; $j <= $post['no_of_coupons_to_generate']; $j++ ) { + $email = ( ! empty( $emails[ $j - 1 ] ) ) ? sanitize_email( $emails[ $j - 1 ] ) : ''; + $customer_emails[ $j ] = ( ! empty( $email ) && is_email( $email ) ) ? $email : ''; + } + } + } + + $all_discount_types = wc_get_coupon_types(); + $generated_codes = array(); + $refresh_global_coupons = false; + + for ( $i = 1; $i <= $post['no_of_coupons_to_generate']; $i++ ) { + $customer_email = ( ! empty( $customer_emails[ $i ] ) ) ? $customer_emails[ $i ] : ''; + $unique_code = $this->generate_unique_code( $customer_email ); + if ( ! empty( $generated_codes ) && in_array( $unique_code, $generated_codes, true ) ) { + $max = ( $post['no_of_coupons_to_generate'] * 10 ) - 1; + do { + $unique_code_temp = $unique_code . wp_rand( 0, $max ); + } while ( in_array( $unique_code_temp, $generated_codes, true ) ); + $unique_code = $unique_code_temp; + } + $generated_codes[] = $unique_code; + $post['coupon_title_prefix'] = ( ! empty( $post['coupon_title_prefix'] ) ) ? $post['coupon_title_prefix'] : ''; + $post['coupon_title_suffix'] = ( ! empty( $post['coupon_title_suffix'] ) ) ? $post['coupon_title_suffix'] : ''; + $code = $post['coupon_title_prefix'] . $unique_code . $post['coupon_title_suffix']; + + $data[ $i ]['post_title'] = strtolower( $code ); + + $discount_type = ( ! empty( $post['discount_type'] ) ) ? $post['discount_type'] : 'percent'; + + if ( ! empty( $all_discount_types[ $discount_type ] ) ) { + $data[ $i ]['discount_type'] = $all_discount_types[ $discount_type ]; + } else { + if ( $this->is_wc_gte_30() ) { + $data[ $i ]['discount_type'] = 'Percentage discount'; + } else { + $data[ $i ]['discount_type'] = 'Cart % Discount'; + } + } + + if ( $this->is_wc_gte_30() ) { + $post['product_ids'] = ( ! empty( $post['product_ids'] ) ) ? ( ( is_array( $post['product_ids'] ) ) ? implode( ',', $post['product_ids'] ) : $post['product_ids'] ) : ''; + $post['exclude_product_ids'] = ( ! empty( $post['exclude_product_ids'] ) ) ? ( ( is_array( $post['exclude_product_ids'] ) ) ? implode( ',', $post['exclude_product_ids'] ) : $post['exclude_product_ids'] ) : ''; + } + + $data[ $i ]['coupon_amount'] = $post['coupon_amount']; + $data[ $i ]['individual_use'] = ( isset( $post['individual_use'] ) ) ? 'yes' : 'no'; + $data[ $i ]['product_ids'] = ( isset( $post['product_ids'] ) ) ? str_replace( array( ',', ' ' ), array( '|', '' ), $post['product_ids'] ) : ''; + $data[ $i ]['exclude_product_ids'] = ( isset( $post['exclude_product_ids'] ) ) ? str_replace( array( ',', ' ' ), array( '|', '' ), $post['exclude_product_ids'] ) : ''; + $data[ $i ]['usage_limit'] = ( isset( $post['usage_limit'] ) ) ? $post['usage_limit'] : ''; + $data[ $i ]['usage_limit_per_user'] = ( isset( $post['usage_limit_per_user'] ) ) ? $post['usage_limit_per_user'] : ''; + $data[ $i ]['limit_usage_to_x_items'] = ( isset( $post['limit_usage_to_x_items'] ) ) ? $post['limit_usage_to_x_items'] : ''; + if ( empty( $post['expiry_date'] ) && ! empty( $post['sc_coupon_validity'] ) && ! empty( $post['validity_suffix'] ) ) { + $data[ $i ]['expiry_date'] = gmdate( 'Y-m-d', $this->strtotime( '+' . $post['sc_coupon_validity'] . ' ' . $post['validity_suffix'] ) + $this->wc_timezone_offset() ); + } else { + $data[ $i ]['expiry_date'] = $post['expiry_date']; + } + $data[ $i ]['free_shipping'] = ( isset( $post['free_shipping'] ) ) ? 'yes' : 'no'; + $data[ $i ]['product_categories'] = ( isset( $post['product_categories'] ) ) ? implode( '|', $post['product_categories'] ) : ''; + $data[ $i ]['exclude_product_categories'] = ( isset( $post['exclude_product_categories'] ) ) ? implode( '|', $post['exclude_product_categories'] ) : ''; + $data[ $i ]['exclude_sale_items'] = ( isset( $post['exclude_sale_items'] ) ) ? 'yes' : 'no'; + $data[ $i ]['minimum_amount'] = ( isset( $post['minimum_amount'] ) ) ? $post['minimum_amount'] : ''; + $data[ $i ]['maximum_amount'] = ( isset( $post['maximum_amount'] ) ) ? $post['maximum_amount'] : ''; + $data[ $i ]['customer_email'] = ( ! empty( $customer_emails ) ) ? $customer_emails[ $i ] : ''; + $data[ $i ]['sc_coupon_validity'] = ( isset( $post['sc_coupon_validity'] ) ) ? $post['sc_coupon_validity'] : ''; + $data[ $i ]['validity_suffix'] = ( isset( $post['validity_suffix'] ) ) ? $post['validity_suffix'] : ''; + $data[ $i ]['is_pick_price_of_product'] = ( isset( $post['is_pick_price_of_product'] ) ) ? 'yes' : 'no'; + $data[ $i ]['sc_disable_email_restriction'] = ( isset( $post['sc_disable_email_restriction'] ) ) ? 'yes' : 'no'; + $data[ $i ]['sc_is_visible_storewide'] = ( isset( $post['sc_is_visible_storewide'] ) ) ? 'yes' : 'no'; + $data[ $i ]['coupon_title_prefix'] = ( isset( $post['coupon_title_prefix'] ) ) ? $post['coupon_title_prefix'] : ''; + $data[ $i ]['coupon_title_suffix'] = ( isset( $post['coupon_title_suffix'] ) ) ? $post['coupon_title_suffix'] : ''; + $data[ $i ]['sc_restrict_to_new_user'] = ( isset( $post['sc_restrict_to_new_user'] ) ) ? $post['sc_restrict_to_new_user'] : ''; + $data[ $i ]['post_status'] = 'publish'; + $data[ $i ]['post_excerpt'] = ( isset( $post['excerpt'] ) ) ? $post['excerpt'] : ''; + $data[ $i ]['wc_sc_max_discount'] = ( isset( $post['wc_sc_max_discount'] ) ) ? $post['wc_sc_max_discount'] : ''; + $data[ $i ]['wc_sc_expiry_time'] = ( isset( $post['wc_sc_expiry_time'] ) ) ? $post['wc_sc_expiry_time'] : ''; + $data[ $i ]['wc_sc_product_attribute_ids'] = ( isset( $post['wc_sc_product_attribute_ids'] ) ) ? implode( '|', $post['wc_sc_product_attribute_ids'] ) : ''; + $data[ $i ]['wc_sc_exclude_product_attribute_ids'] = ( isset( $post['wc_sc_exclude_product_attribute_ids'] ) ) ? implode( '|', $post['wc_sc_exclude_product_attribute_ids'] ) : ''; + $data[ $i ]['sc_coupon_category'] = ( isset( $post['tax_input']['sc_coupon_category'] ) ) ? implode( '|', $post['tax_input']['sc_coupon_category'] ) : ''; + + $data[ $i ] = apply_filters( 'sc_generate_coupon_meta', $data[ $i ], $post ); + + if ( false === $refresh_global_coupons && 'yes' === $data[ $i ]['sc_is_visible_storewide'] ) { + $refresh_global_coupons = true; + } + } + + if ( true === $refresh_global_coupons ) { + delete_option( 'sc_display_global_coupons' ); // Since there's an update in storewide coupon, refresh the global coupon's list. + } + } + + if ( ! empty( $get ) && isset( $get['export_coupons'] ) ) { + + $headers = array_keys( $coupon_postmeta_headers ); + if ( $this->is_wc_gte_30() ) { + $headers[] = 'date_expires'; + } + $headers = esc_sql( $headers ); + $how_many_headers = count( $headers ); + $header_placeholder = array_fill( 0, $how_many_headers, '%s' ); + + $how_many_ids = count( $post_ids ); + $id_placeholder = array_fill( 0, $how_many_ids, '%d' ); + + $wpdb->query( $wpdb->prepare( 'SET SESSION group_concat_max_len=%d', 999999 ) ); // phpcs:ignore + + $unique_post_ids = array_unique( $post_ids ); + + $results = wp_cache_get( 'wc_sc_exported_coupon_data_' . implode( '_', $unique_post_ids ), 'woocommerce_smart_coupons' ); + + if ( false === $results ) { + $results = $wpdb->get_results( // phpcs:ignore + // phpcs:disable + $wpdb->prepare( + "SELECT p.ID, + p.post_title, + p.post_excerpt, + p.post_status, + p.post_parent, + p.menu_order, + DATE_FORMAT(p.post_date,'%%d-%%m-%%Y %%H:%%i:%%s') AS post_date, + GROUP_CONCAT(pm.meta_key order by pm.meta_id SEPARATOR '###') AS coupon_meta_key, + GROUP_CONCAT(pm.meta_value order by pm.meta_id SEPARATOR '###') AS coupon_meta_value + FROM {$wpdb->prefix}posts as p JOIN {$wpdb->prefix}postmeta as pm ON (p.ID = pm.post_id + AND pm.meta_key IN (" . implode( ',', $header_placeholder ) . ') ) + WHERE p.ID IN (' . implode( ',', $id_placeholder ) . ') AND pm.meta_value IS NOT NULL + GROUP BY p.id ORDER BY p.id', + array_merge( $headers, $post_ids ) + ), + // phpcs:enable + ARRAY_A + ); + wp_cache_set( 'wc_sc_exported_coupon_data_' . implode( '_', $unique_post_ids ), $results, 'woocommerce_smart_coupons' ); + $this->maybe_add_cache_key( 'wc_sc_exported_coupon_data_' . implode( '_', $unique_post_ids ) ); + } + + foreach ( $results as $result ) { + + $coupon_meta_key = explode( '###', $result['coupon_meta_key'] ); + $coupon_meta_value = explode( '###', $result['coupon_meta_value'] ); + + unset( $result['coupon_meta_key'] ); + unset( $result['coupon_meta_value'] ); + + if ( ! empty( $result['post_date'] ) ) { + $timestamp = $this->strtotime( $result['post_date'] ) + 1; + $result['post_date'] = gmdate( 'd-m-Y H:i:s', $timestamp ); + } + + $id = $result['ID']; + $data[ $id ] = $result; + + foreach ( $coupon_meta_key as $index => $key ) { + if ( 'product_ids' === $key || 'exclude_product_ids' === $key ) { + $data[ $id ][ $key ] = ( isset( $coupon_meta_value[ $index ] ) ) ? str_replace( array( ',', ' ' ), array( '|', '' ), $coupon_meta_value[ $index ] ) : ''; + } elseif ( 'product_categories' === $key || 'exclude_product_categories' === $key ) { + $data[ $id ][ $key ] = ( ! empty( $coupon_meta_value[ $index ] ) ) ? implode( '|', maybe_unserialize( stripslashes( $coupon_meta_value[ $index ] ) ) ) : ''; + } elseif ( '_used_by' === $key ) { + if ( ! isset( $data[ $id ][ $key ] ) ) { + $data[ $id ][ $key ] = ''; + } + $data[ $id ][ $key ] .= '|' . $coupon_meta_value[ $index ]; + $data[ $id ][ $key ] = trim( $data[ $id ][ $key ], '|' ); + } elseif ( 'date_expires' === $key && $this->is_wc_gte_30() ) { + if ( ! empty( $coupon_meta_value[ $index ] ) ) { + $data[ $id ]['expiry_date'] = gmdate( 'Y-m-d', intval( $coupon_meta_value[ $index ] ) + $this->wc_timezone_offset() ); + } + } elseif ( 'ID' !== $key ) { + if ( ! empty( $coupon_meta_value[ $index ] ) ) { + if ( is_serialized( $coupon_meta_value[ $index ] ) ) { + $temp_data = maybe_unserialize( stripslashes( $coupon_meta_value[ $index ] ) ); + $current_temp_data = current( $temp_data ); + if ( ! is_array( $current_temp_data ) && ( count( array_filter( array_keys( $temp_data ), 'is_string' ) ) < 1 ) ) { + $temp_data = implode( ',', $temp_data ); + } else { + $temp_data = apply_filters( + 'wc_sc_export_coupon_meta_data', + $temp_data, + array( + 'coupon_id' => $id, + 'index' => $index, + 'meta_key' => $key, // phpcs:ignore + 'meta_keys' => $coupon_meta_key, + 'meta_values' => $coupon_meta_value, + ) + ); + } + } else { + $temp_data = $coupon_meta_value[ $index ]; + } + $data[ $id ][ $key ] = apply_filters( + 'wc_sc_export_coupon_meta', + $temp_data, + array( + 'coupon_id' => $id, + 'index' => $index, + 'meta_key' => $key, // phpcs:ignore + 'meta_value' => $coupon_meta_value[ $index ], // phpcs:ignore + 'meta_keys' => $coupon_meta_key, + 'meta_values' => $coupon_meta_value, + ) + ); + } + } + } + } + } + + return $data; + + } + + /** + * Export coupon CSV data + * + * @param array $columns_header Column header. + * @param array $data The data. + * @return array $file_data + */ + public function export_coupon_csv( $columns_header, $data ) { + + $getfield = ''; + + foreach ( $columns_header as $key => $value ) { + $getfield .= $key . ','; + } + + $fields = substr_replace( $getfield, '', -1 ); + + $csv_file_name = get_bloginfo( 'name' ) . gmdate( 'd-M-Y_H_i_s' ) . '.csv'; + + $fields .= $this->get_coupon_csv_data( $columns_header, $data ); + + $upload_dir = wp_get_upload_dir(); + + $file_data = array(); + $file_data['wp_upload_dir'] = $upload_dir['basedir'] . '/woocommerce_uploads/'; + $file_data['file_name'] = $csv_file_name; + $file_data['file_content'] = $fields; + + if ( isset( $upload_dir['error'] ) && ! empty( $upload_dir['error'] ) ) { + $file_data['error'] = $upload_dir['error']; + } + + return $file_data; + } + + /** + * Export coupon CSV data + * + * @param array $columns_header Column header. + * @param array $data The data. + * @return array $file_data + */ + public function get_coupon_csv_data( $columns_header, $data ) { + + $each_field = array_keys( $columns_header ); + + $csv_data = ''; + + foreach ( (array) $data as $row ) { + $count_columns_header = count( $columns_header ); + for ( $i = 0; $i < $count_columns_header; $i++ ) { + if ( 0 === $i ) { + $csv_data .= "\n"; + } + + if ( array_key_exists( $each_field[ $i ], $row ) ) { + $row_each_field = $row[ $each_field[ $i ] ]; + } else { + $row_each_field = ''; + } + + $array = str_replace( array( "\n", "\n\r", "\r\n", "\r" ), "\t", $row_each_field ); + + $array = ( is_string( $array ) ) ? str_getcsv( $array, ',', '"', '\\' ) : array(); + + $str = ( $array && is_array( $array ) ) ? implode( ', ', $array ) : ''; + + $str = addslashes( $str ); + + $csv_data .= '"' . $str . '",'; + } + $csv_data = substr_replace( $csv_data, '', -1 ); + } + + return $csv_data; + } + + /** + * Smart Coupons export headers + * + * @param array $coupon_postmeta_headers Existing. + * @return array $coupon_postmeta_headers Including additional headers. + */ + public function wc_smart_coupons_export_headers( $coupon_postmeta_headers = array() ) { + + $sc_postmeta_headers = array( + 'sc_coupon_validity' => __( 'Coupon Validity', 'woocommerce-smart-coupons' ), + 'validity_suffix' => __( 'Validity Suffix', 'woocommerce-smart-coupons' ), + 'auto_generate_coupon' => __( 'Auto Generate Coupon', 'woocommerce-smart-coupons' ), + 'coupon_title_prefix' => __( 'Coupon Title Prefix', 'woocommerce-smart-coupons' ), + 'coupon_title_suffix' => __( 'Coupon Title Suffix', 'woocommerce-smart-coupons' ), + 'is_pick_price_of_product' => __( 'Is Pick Price of Product', 'woocommerce-smart-coupons' ), + 'sc_disable_email_restriction' => __( 'Disable Email Restriction', 'woocommerce-smart-coupons' ), + 'sc_is_visible_storewide' => __( 'Coupon Is Visible Storewide', 'woocommerce-smart-coupons' ), + 'sc_restrict_to_new_user' => __( 'For new user only?', 'woocommerce-smart-coupons' ), + 'wc_sc_max_discount' => __( 'Max discount', 'woocommerce-smart-coupons' ), + ); + + if ( $this->is_wc_gte_32() ) { + $sc_postmeta_headers['wc_sc_expiry_time'] = __( 'Coupon expiry time', 'woocommerce-smart-coupons' ); + } + + return array_merge( $coupon_postmeta_headers, $sc_postmeta_headers ); + + } + + /** + * Filter callback to replace {site_title} in email footer + * + * @param string $string Email footer text. + * @return string Email footer text with any replacements done. + */ + public function email_footer_replace_site_title( $string ) { + $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); + return str_replace( '{site_title}', $blogname, $string ); + } + + /** + * Register Smart Coupons' email classes to WooCommerce's emails class list + * + * @param array $email_classes available email classes list. + * @return array $email_classes modified email classes list + */ + public function register_email_classes( $email_classes = array() ) { + + include_once 'emails/class-wc-sc-email.php'; + include_once 'emails/class-wc-sc-email-coupon.php'; + include_once 'emails/class-wc-sc-combined-email-coupon.php'; + include_once 'emails/class-wc-sc-acknowledgement-email.php'; + + // Add the email class to the list of email classes that WooCommerce loads. + $email_classes['WC_SC_Email_Coupon'] = new WC_SC_Email_Coupon(); + $email_classes['WC_SC_Combined_Email_Coupon'] = new WC_SC_Combined_Email_Coupon(); + $email_classes['WC_SC_Acknowledgement_Email'] = new WC_SC_Acknowledgement_Email(); + + return $email_classes; + } + + /** + * Whether to hold stock for checkout or not + * + * TODO: Rework to find perfect solution + * + * @param boolean $is_hold Whether to hold or not. + * @return boolean + */ + public function hold_stock_for_checkout( $is_hold = true ) { + $is_ignore = get_option( 'wc_sc_ignore_coupon_used_warning' ); + if ( 'yes' === $is_ignore ) { + return false; + } + return $is_hold; + } + + /** + * Function to generate a coupon + * + * @param array $args Additional data. + * @return string|WC_Coupon + */ + public function generate_coupon( $args = array() ) { + if ( ! $this->is_wc_gte_30() ) { + return; + } + + $args = array_filter( $args ); + + $return_type = ( ! empty( $args['return'] ) && in_array( $args['return'], array( 'code', 'object' ), true ) ) ? $args['return'] : 'object'; + + $coupon = null; + if ( ! empty( $args['coupon'] ) ) { + if ( is_numeric( $args['coupon'] ) || is_string( $args['coupon'] ) ) { + $coupon = new WC_Coupon( $args['coupon'] ); + } elseif ( $args['coupon'] instanceof WC_Coupon ) { + $coupon = $args['coupon']; + } + } elseif ( ! empty( $args['id'] ) ) { + $coupon = new WC_Coupon( $args['id'] ); + } elseif ( ! empty( $args['code'] ) ) { + $coupon = new WC_Coupon( $args['code'] ); + } + + $internal_keys = array( + 'code', + 'amount', + 'discount_type', + 'description', + 'date_expires', + 'individual_use', + 'product_ids', + 'excluded_product_ids', + 'usage_limit', + 'usage_limit_per_user', + 'limit_usage_to_x_items', + 'free_shipping', + 'product_categories', + 'excluded_product_categories', + 'exclude_sale_items', + 'minimum_amount', + 'maximum_amount', + 'email_restrictions', + 'meta_data', + ); + + $email_restrictions = ( ! empty( $args['email_restrictions'] ) && count( $args['email_restrictions'] ) === 1 ) ? $args['email_restrictions'] : ''; + + $new_code = ''; + if ( is_null( $coupon ) ) { + if ( ! empty( $args['discount_type'] ) && ! empty( $args['amount'] ) ) { + $new_code = $this->generate_unique_code( $email_restrictions ); + $new_coupon = new WC_Coupon( $new_code ); + foreach ( $args as $key => $value ) { + switch ( $key ) { + case 'code': + // do nothing. + break; + case 'meta_data': + if ( is_array( $value ) && is_callable( array( $new_coupon, 'update_meta_data' ) ) ) { + foreach ( $value as $meta ) { + $new_coupon->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' ); + } + } + break; + case 'description': + $new_coupon->set_description( wp_filter_post_kses( $value ) ); + break; + default: + if ( is_callable( array( $new_coupon, "set_{$key}" ) ) ) { + $new_coupon->{"set_{$key}"}( $value ); + } + break; + } + } + $new_coupon->save(); + return ( 'code' === $return_type ) ? $new_code : $new_coupon; + } else { + return; + } + } else { + $is_auto_generate = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_meta' ) ) ) ? $coupon->get_meta( 'auto_generate_coupon' ) : 'no'; + if ( 'yes' !== $is_auto_generate ) { + $code = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_code' ) ) ) ? $coupon->get_code() : ''; + return ( 'code' === $return_type ) ? $code : $coupon; + } else { + $new_code = $this->generate_unique_code( $email_restrictions ); + $new_coupon = new WC_Coupon( $new_code ); + foreach ( $internal_keys as $key ) { + if ( ! is_object( $coupon ) ) { + continue; + } + switch ( $key ) { + case 'code': + // do nothing. + break; + case 'meta_data': + $meta_data = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_meta_data' ) ) ) ? $coupon->get_meta_data() : null; + if ( ! empty( $meta_data ) ) { + foreach ( $meta_data as $meta ) { + if ( is_object( $meta ) && is_callable( array( $meta, 'get_data' ) ) ) { + $data = $meta->get_data(); + if ( is_callable( array( $new_coupon, 'update_meta_data' ) ) ) { + $new_coupon->update_meta_data( $data['key'], $data['value'] ); + } + } + } + } + break; + case 'description': + $description = ( is_callable( array( $coupon, 'get_description' ) ) ) ? $coupon->get_description() : ''; + if ( ! empty( $description ) && is_callable( array( $new_coupon, 'set_description' ) ) ) { + $new_coupon->set_description( wp_filter_post_kses( $description ) ); + } + break; + default: + $value = ( is_callable( array( $coupon, "get_{$key}" ) ) ) ? $coupon->{"get_{$key}"}() : ''; + if ( ! empty( $value ) && is_callable( array( $new_coupon, "set_{$key}" ) ) ) { + $new_coupon->{"set_{$key}"}( $value ); + } + break; + } + } + $new_coupon->save(); + return ( 'code' === $return_type ) ? $new_code : $new_coupon; + } + } + } + + /** + * Function to paint/draw coupon on a page in HTML format + * + * @param array $args Additional data including coupon info. + */ + public function paint_coupon( $args = array() ) { + if ( ! $this->is_wc_gte_30() ) { + return ''; + } + if ( empty( $args['coupon'] ) ) { + return ''; + } + ob_start(); + + if ( is_numeric( $args['coupon'] ) || is_string( $args['coupon'] ) ) { + $coupon = new WC_Coupon( $args['coupon'] ); + } elseif ( $args['coupon'] instanceof WC_Coupon ) { + $coupon = $args['coupon']; + } else { + return ''; + } + + $with_container = ( ! empty( $args['with_container'] ) ) ? $args['with_container'] : 'no'; + $with_css = ( ! empty( $args['with_css'] ) ) ? $args['with_css'] : 'no'; + + $design = get_option( 'wc_sc_setting_coupon_design', 'basic' ); + $background_color = get_option( 'wc_sc_setting_coupon_background_color', '#39cccc' ); + $foreground_color = get_option( 'wc_sc_setting_coupon_foreground_color', '#30050b' ); + $third_color = get_option( 'wc_sc_setting_coupon_third_color', '#39cccc' ); + $show_coupon_description = get_option( 'smart_coupons_show_coupon_description', 'no' ); + $coupon_id = ( is_callable( array( $coupon, 'get_id' ) ) ) ? $coupon->get_id() : 0; + $coupon_code = ( is_callable( array( $coupon, 'get_code' ) ) ) ? $coupon->get_code() : ''; + $coupon_description = ( is_callable( array( $coupon, 'description' ) ) ) ? $coupon->get_description() : ''; + $coupon_amount = ( is_callable( array( $coupon, 'get_amount' ) ) ) ? $coupon->get_amount() : 0; + $is_free_shipping = ( is_callable( array( $coupon, 'get_free_shipping' ) ) ) ? wc_bool_to_string( $coupon->get_free_shipping() ) : 'no'; + $expiry_date = ( is_callable( array( $coupon, 'get_date_expires' ) ) ) ? $coupon->get_date_expires() : null; + + $is_callable_coupon_get_meta = $this->is_callable( $coupon, 'get_meta' ); + + $coupon_data = $this->get_coupon_meta_data( $coupon ); + $coupon_type = ( ! empty( $coupon_data['coupon_type'] ) ) ? $coupon_data['coupon_type'] : ''; + + if ( 'yes' === $is_free_shipping ) { + if ( ! empty( $coupon_type ) ) { + $coupon_type .= __( ' & ', 'woocommerce-smart-coupons' ); + } + $coupon_type .= __( 'Free Shipping', 'woocommerce-smart-coupons' ); + } + + $coupon_description = ( 'yes' === $show_coupon_description ) ? $coupon_description : ''; + + $is_percent = $this->is_percent_coupon( array( 'coupon_object' => $coupon ) ); + + if ( $expiry_date instanceof WC_DateTime ) { + $expiry_date = ( is_callable( array( $expiry_date, 'getTimestamp' ) ) ) ? $expiry_date->getTimestamp() : null; + } elseif ( ! is_int( $expiry_date ) ) { + $expiry_date = $this->strtotime( $expiry_date ); + } + + if ( ! empty( $expiry_date ) && is_int( $expiry_date ) ) { + $expiry_time = ( $this->is_callable( $coupon, 'get_meta' ) ) ? (int) $coupon->get_meta( 'wc_sc_expiry_time' ) : (int) get_post_meta( $coupon_id, 'wc_sc_expiry_time', true ); + if ( ! empty( $expiry_time ) ) { + $expiry_date += $expiry_time; // Adding expiry time to expiry date. + } + } + + $args = array( + 'coupon_object' => $coupon, + 'coupon_amount' => $coupon_amount, + 'amount_symbol' => ( true === $is_percent ) ? '%' : get_woocommerce_currency_symbol(), + 'discount_type' => wp_strip_all_tags( $coupon_type ), + 'coupon_description' => ( ! empty( $coupon_description ) ) ? $coupon_description : wp_strip_all_tags( $this->generate_coupon_description( array( 'coupon_object' => $coupon ) ) ), + 'coupon_code' => $coupon_code, + 'coupon_expiry' => ( ! empty( $expiry_date ) ) ? $this->get_expiration_format( $expiry_date ) : __( 'Never expires', 'woocommerce-smart-coupons' ), + 'thumbnail_src' => $this->get_coupon_design_thumbnail_src( + array( + 'design' => $design, + 'coupon_object' => $coupon, + ) + ), + 'classes' => 'apply_coupons_credits', + 'template_id' => $design, + 'is_percent' => $is_percent, + ); + + if ( 'yes' === $with_css ) { + ?> +
            + + + +
            +
            + +
            +
            + +
            + $this ) ) ); + + echo $html; // phpcs:ignore + } + + /** + * Add Smart Coupons' REST API Controllers + * + * @param array $namespaces Existing namespaces. + * @return array + */ + public function rest_namespace( $namespaces = array() ) { + include_once 'class-wc-sc-rest-coupons-controller.php'; + $namespaces['wc/v3/sc'] = array( + 'coupons' => 'WC_SC_REST_Coupons_Controller', + ); + return $namespaces; + } + + /** + * Get coupon column headers + * + * @return array + */ + public function get_coupon_column_headers() { + + $coupon_posts_headers = array( + 'post_title' => __( 'Coupon Code', 'woocommerce-smart-coupons' ), + 'post_excerpt' => __( 'Post Excerpt', 'woocommerce-smart-coupons' ), + 'post_status' => __( 'Post Status', 'woocommerce-smart-coupons' ), + 'post_parent' => __( 'Post Parent', 'woocommerce-smart-coupons' ), + 'menu_order' => __( 'Menu Order', 'woocommerce-smart-coupons' ), + 'post_date' => __( 'Post Date', 'woocommerce-smart-coupons' ), + ); + + $coupon_postmeta_headers = apply_filters( + 'wc_smart_coupons_export_headers', + array( + 'discount_type' => __( 'Discount Type', 'woocommerce-smart-coupons' ), + 'coupon_amount' => __( 'Coupon Amount', 'woocommerce-smart-coupons' ), + 'free_shipping' => __( 'Free shipping', 'woocommerce-smart-coupons' ), + 'expiry_date' => __( 'Expiry date', 'woocommerce-smart-coupons' ), + 'minimum_amount' => __( 'Minimum Spend', 'woocommerce-smart-coupons' ), + 'maximum_amount' => __( 'Maximum Spend', 'woocommerce-smart-coupons' ), + 'individual_use' => __( 'Individual USe', 'woocommerce-smart-coupons' ), + 'exclude_sale_items' => __( 'Exclude Sale Items', 'woocommerce-smart-coupons' ), + 'product_ids' => __( 'Product IDs', 'woocommerce-smart-coupons' ), + 'exclude_product_ids' => __( 'Exclude product IDs', 'woocommerce-smart-coupons' ), + 'product_categories' => __( 'Product categories', 'woocommerce-smart-coupons' ), + 'exclude_product_categories' => __( 'Exclude Product categories', 'woocommerce-smart-coupons' ), + 'customer_email' => __( 'Customer Email', 'woocommerce-smart-coupons' ), + 'usage_limit' => __( 'Usage Limit', 'woocommerce-smart-coupons' ), + 'usage_limit_per_user' => __( 'Usage Limit Per User', 'woocommerce-smart-coupons' ), + 'limit_usage_to_x_items' => __( 'Limit Usage to X Items', 'woocommerce-smart-coupons' ), + 'usage_count' => __( 'Usage Count', 'woocommerce-smart-coupons' ), + '_used_by' => __( 'Used By', 'woocommerce-smart-coupons' ), + 'sc_restrict_to_new_user' => __( 'For new user only?', 'woocommerce-smart-coupons' ), + ) + ); + + $coupon_term_headers = array( + 'sc_coupon_category' => __( 'Coupon Category', 'woocommerce-smart-coupons' ), + ); + + return array( + 'posts_headers' => $coupon_posts_headers, + 'postmeta_headers' => $coupon_postmeta_headers, + 'term_headers' => $coupon_term_headers, + ); + } + + /** + * Write to file after exporting + * + * @param array $post POST. + * @param array $get GET. + * @param array $post_ids Post ids. + */ + public function export_coupon( $post = array(), $get = array(), $post_ids = array() ) { + // Run a capability check before attempting to export coupons. + if ( ! is_admin() && ! current_user_can( 'manage_woocommerce' ) ) { + return; + } + + $coupon_column_headers = $this->get_coupon_column_headers(); + $coupon_posts_headers = $coupon_column_headers['posts_headers']; + $coupon_postmeta_headers = $coupon_column_headers['postmeta_headers']; + + $column_headers = array_merge( $coupon_posts_headers, $coupon_postmeta_headers ); + + if ( ! empty( $post ) ) { + $data = $this->generate_coupons_code( $post, '', '', array() ); + } elseif ( ! empty( $get ) ) { + $data = $this->generate_coupons_code( '', $get, $post_ids, $coupon_postmeta_headers ); + } + + $file_data = $this->export_coupon_csv( $column_headers, $data ); + + if ( ( isset( $post['generate_and_import'] ) && ! empty( $post['smart_coupons_generate_action'] ) && 'sc_export_and_import' === $post['smart_coupons_generate_action'] ) || isset( $get['export_coupons'] ) ) { + + if ( ob_get_level() ) { + $levels = ob_get_level(); + for ( $i = 0; $i < $levels; $i++ ) { + ob_end_clean(); + } + } else { + ob_end_clean(); + } + nocache_headers(); + header( 'X-Robots-Tag: noindex, nofollow', true ); + header( 'Content-Type: text/x-csv; charset=UTF-8' ); + header( 'Content-Description: File Transfer' ); + header( 'Content-Transfer-Encoding: binary' ); + header( 'Content-Disposition: attachment; filename="' . sanitize_file_name( $file_data['file_name'] ) . '";' ); + + echo $file_data['file_content']; // phpcs:ignore + exit; + } else { + + // Proceed only if there is no directory permission related issue. + if ( ! isset( $file_data['error'] ) ) { + // Create CSV file. + $csv_folder = $file_data['wp_upload_dir']; + $filename = str_replace( array( '\'', '"', ',', ';', '<', '>', '/', ':' ), '', $file_data['file_name'] ); + $csvfilename = $csv_folder . $filename; + $fp = fopen( $csvfilename, 'w' ); // phpcs:ignore + if ( false !== $fp ) { + fwrite( $fp , $file_data['file_content'] ); // phpcs:ignore + fclose( $fp ); // phpcs:ignore + } + + return $csvfilename; + } + } + + } + + /** + * Function to enqueue additional styles & scripts for Smart Coupons in admin + */ + public function smart_coupon_styles_and_scripts() { + global $post, $pagenow; + + if ( ! empty( $pagenow ) ) { + $show_css_for_smart_coupon_tab = false; + $get_post_type = ( ! empty( $post->ID ) ) ? $this->get_post_type( $post->ID ) : ( ( ! empty( $_GET['post_type'] ) ) ? wc_clean( wp_unslash( $_GET['post_type'] ) ) : '' ); // phpcs:ignore + $get_page = ( ! empty( $_GET['page'] ) ) ? wc_clean( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore + if ( ( 'edit.php' === $pagenow || 'post.php' === $pagenow || 'post-new.php' === $pagenow ) && in_array( $get_post_type, array( 'shop_coupon', 'product', 'product-variation' ), true ) ) { + $show_css_for_smart_coupon_tab = true; + } + if ( 'admin.php' === $pagenow && in_array( $get_page, array( 'wc-smart-coupons', 'wc-orders' ), true ) ) { + $show_css_for_smart_coupon_tab = true; + } + if ( $show_css_for_smart_coupon_tab ) { + if ( ! wp_style_is( 'smart-coupon' ) ) { + wp_enqueue_style( 'smart-coupon' ); + } + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; + wp_register_style( 'smart-coupons-admin', untrailingslashit( plugins_url( '/', WC_SC_PLUGIN_FILE ) ) . '/assets/css/smart-coupons-admin' . $suffix . '.css', array(), $this->plugin_data['Version'] ); + wp_enqueue_style( 'smart-coupons-admin' ); + } + } + + if ( ! empty( $post->post_type ) && 'product' === $post->post_type ) { + if ( wp_script_is( 'select2' ) ) { + wp_localize_script( + 'select2', + 'smart_coupons_select_params', + array( + 'i18n_matches_1' => _x( 'One result is available, press enter to select it.', 'enhanced select', 'woocommerce-smart-coupons' ), + 'i18n_matches_n' => _x( '%qty% results are available, use up and down arrow keys to navigate.', 'enhanced select', 'woocommerce-smart-coupons' ), + 'i18n_no_matches' => _x( 'No matches found', 'enhanced select', 'woocommerce-smart-coupons' ), + 'i18n_ajax_error' => _x( 'Loading failed', 'enhanced select', 'woocommerce-smart-coupons' ), + 'i18n_input_too_short_1' => _x( 'Please enter 1 or more characters', 'enhanced select', 'woocommerce-smart-coupons' ), + 'i18n_input_too_short_n' => _x( 'Please enter %qty% or more characters', 'enhanced select', 'woocommerce-smart-coupons' ), + 'i18n_input_too_long_1' => _x( 'Please delete 1 character', 'enhanced select', 'woocommerce-smart-coupons' ), + 'i18n_input_too_long_n' => _x( 'Please delete %qty% characters', 'enhanced select', 'woocommerce-smart-coupons' ), + 'i18n_selection_too_long_1' => _x( 'You can only select 1 item', 'enhanced select', 'woocommerce-smart-coupons' ), + 'i18n_selection_too_long_n' => _x( 'You can only select %qty% items', 'enhanced select', 'woocommerce-smart-coupons' ), + 'i18n_load_more' => _x( 'Loading more results…', 'enhanced select', 'woocommerce-smart-coupons' ), + 'i18n_searching' => _x( 'Searching…', 'enhanced select', 'woocommerce-smart-coupons' ), + 'ajax_url' => admin_url( 'admin-ajax.php' ), + 'search_products_nonce' => wp_create_nonce( 'search-products' ), + 'search_customers_nonce' => wp_create_nonce( 'search-customers' ), + ) + ); + } + } + + } + + /** + * Add if cache key doesn't exists + * + * @param string $key The cache key. + */ + public function maybe_add_cache_key( $key = '' ) { + if ( ! empty( $key ) ) { + $all_cache_key = get_option( 'wc_sc_all_cache_key' ); + if ( false !== $all_cache_key ) { + if ( empty( $all_cache_key ) || ! is_array( $all_cache_key ) ) { + $all_cache_key = array(); + } + if ( ! in_array( $key, $all_cache_key, true ) ) { + $all_cache_key[] = $key; + update_option( 'wc_sc_all_cache_key', $all_cache_key, 'no' ); + } + } + } + } + + /** + * Make meta data of this plugin, protected + * + * @param bool $protected Is protected. + * @param string $meta_key the meta key. + * @param string $meta_type The meta type. + * @return bool $protected + */ + public function make_sc_meta_protected( $protected, $meta_key, $meta_type ) { + $sc_meta = array( + 'auto_generate_coupon', + 'coupon_sent', + 'coupon_title_prefix', + 'coupon_title_suffix', + 'generated_from_order_id', + 'gift_receiver_email', + 'gift_receiver_message', + 'gift_sending_timestamp', + 'is_gift', + 'is_pick_price_of_product', + 'sc_called_credit_details', + 'sc_coupon_receiver_details', + 'sc_coupon_validity', + 'sc_disable_email_restriction', + 'sc_is_visible_storewide', + 'send_coupons_on_renewals', + 'smart_coupons_contribution', + 'temp_gift_card_receivers_emails', + 'validity_suffix', + 'sc_restrict_to_new_user', + 'wc_sc_schedule_gift_sending', + 'wc_sc_max_discount', + 'wc_sc_expiry_time', + 'wc_sc_product_attribute_ids', + 'wc_sc_exclude_product_attribute_ids', + ); + if ( in_array( $meta_key, $sc_meta, true ) ) { + return true; + } + return $protected; + } + + /** + * Get the order from the PayPal 'Custom' variable. + * + * Credit: WooCommerce + * + * @param string $raw_custom JSON Data passed back by PayPal. + * @return bool|WC_Order object + */ + public function get_paypal_order( $raw_custom ) { + + if ( ! class_exists( 'WC_Gateway_Paypal' ) ) { + include_once WC()->plugin_path() . '/includes/gateways/paypal/class-wc-gateway-paypal.php'; + } + // We have the data in the correct format, so get the order. + if ( ( $custom = json_decode( $raw_custom ) ) && is_object( $custom ) ) { // phpcs:ignore + $order_id = $custom->order_id; + $order_key = $custom->order_key; + + // Fallback to serialized data if safe. This is @deprecated in 2.3.11. + } elseif ( preg_match( '/^a:2:{/', $raw_custom ) && ! preg_match( '/[CO]:\+?[0-9]+:"/', $raw_custom ) && ( $custom = maybe_unserialize( $raw_custom ) ) ) { // phpcs:ignore + $order_id = $custom[0]; + $order_key = $custom[1]; + + // Nothing was found. + } else { + WC_Gateway_Paypal::log( 'Error: Order ID and key were not found in "custom".' ); + return false; + } + + if ( ! $order = wc_get_order( $order_id ) ) { // phpcs:ignore + // We have an invalid $order_id, probably because invoice_prefix has changed. + $order_id = wc_get_order_id_by_order_key( $order_key ); + $order = wc_get_order( $order_id ); + } + + if ( $this->is_wc_gte_30() ) { + $_order_key = ( ! empty( $order ) && is_callable( array( $order, 'get_order_key' ) ) ) ? $order->get_order_key() : ''; + } else { + $_order_key = ( ! empty( $order->order_key ) ) ? $order->order_key : ''; + } + + if ( ! $order || $_order_key !== $order_key ) { + WC_Gateway_Paypal::log( 'Error: Order Keys do not match.' ); + return false; + } + + return $order; + } + + /** + * Get all coupon styles + * + * @return array + */ + public function get_wc_sc_coupon_styles() { + + $all_styles = array( + 'inner' => __( 'Style 1', 'woocommerce-smart-coupons' ), + 'round-corner' => __( 'Style 2', 'woocommerce-smart-coupons' ), + 'round-dashed' => __( 'Style 3', 'woocommerce-smart-coupons' ), + 'outer-dashed' => __( 'Style 4', 'woocommerce-smart-coupons' ), + 'left' => __( 'Style 5', 'woocommerce-smart-coupons' ), + 'bottom' => __( 'Style 6', 'woocommerce-smart-coupons' ), + 'custom-design' => __( 'Custom Style', 'woocommerce-smart-coupons' ), + ); + + return apply_filters( 'wc_sc_get_wc_sc_coupon_styles', $all_styles ); + + } + + /** + * Get coupon display styles + * + * @param string $style_name The style name. + * @param array $args Additional arguments. + * @return string + */ + public function get_coupon_styles( $style_name = '', $args = array() ) { + + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; + + $is_email = ( ! empty( $args['is_email'] ) ) ? $args['is_email'] : 'no'; + + ob_start(); + + if ( 'custom-design' === $style_name ) { + $custom_design_css = get_option( 'wc_sc_custom_design_css', '' ); + echo $custom_design_css; // phpcs:ignore + } elseif ( 'email-coupon' === $style_name ) { + $file = trailingslashit( WP_PLUGIN_DIR . '/' . WC_SC_PLUGIN_DIRNAME ) . 'assets/css/wc-sc-style-' . $style_name . $suffix . '.css'; + if ( file_exists( $file ) ) { + include $file; + } else { + /* translators: File path */ + $this->log( 'error', sprintf( __( 'File not found %s', 'woocommerce-smart-coupons' ), '' . $file . '' ) . ' ' . __FILE__ . ' ' . __LINE__ ); + } + } else { + $file = trailingslashit( WP_PLUGIN_DIR . '/' . WC_SC_PLUGIN_DIRNAME ) . 'assets/css/smart-coupon-designs.css'; + if ( file_exists( $file ) ) { + include $file; + } else { + /* translators: File path */ + $this->log( 'error', sprintf( __( 'File not found %s', 'woocommerce-smart-coupons' ), '' . $file . '' ) . ' ' . __FILE__ . ' ' . __LINE__ ); + } + } + + $styles = ob_get_clean(); + + if ( 'yes' === $is_email ) { + $styles = str_replace( array( ':before', ':hover', ':focus', ':active' ), array( '-pseudo-before', '-pseudo-hover', '-pseudo-focus', '-pseudo-active' ), $styles ); + } + + return apply_filters( 'wc_sc_get_coupon_styles', $styles, $style_name, $args ); + + } + + /** + * Insert a setting or an array of settings after another specific setting by its ID. + * + * @since 1.2.1 + * @param array $settings The original list of settings. + * @param string $insert_after_setting_id The setting id to insert the new setting after. + * @param array $new_setting The new setting to insert. Can be a single setting or an array of settings. + * @param string $insert_type The type of insert to perform. Can be 'single_setting' or 'multiple_settings'. Optional. Defaults to a single setting insert. + * + * @credit: WooCommerce Subscriptions + */ + public static function insert_setting_after( &$settings, $insert_after_setting_id, $new_setting, $insert_type = 'single_setting' ) { + if ( ! is_array( $settings ) ) { + return; + } + + $original_settings = $settings; + $settings = array(); + + foreach ( $original_settings as $setting ) { + $settings[] = $setting; + + if ( isset( $setting['id'] ) && $insert_after_setting_id === $setting['id'] ) { + if ( 'single_setting' === $insert_type ) { + $settings[] = $new_setting; + } else { + $settings = array_merge( $settings, $new_setting ); + } + } + } + } + + /** + * To generate unique id + * + * Credit: WooCommerce + */ + public function generate_unique_id() { + + require_once ABSPATH . 'wp-includes/class-phpass.php'; + $hasher = new PasswordHash( 8, false ); + return md5( $hasher->get_random_bytes( 32 ) ); + + } + + /** + * To get cookie life + */ + public function get_cookie_life() { + + $life = get_option( 'wc_sc_coupon_cookie_life', 180 ); + + return apply_filters( 'wc_sc_coupon_cookie_life', time() + ( 60 * 60 * 24 * $life ) ); + + } + + /** + * Show notice on admin panel about minimum required version of WooCommerce + */ + public function minimum_woocommerce_version_requirement() { + if ( $this->is_wc_gte_30() ) { + return; + } + + $plugin_data = self::get_smart_coupons_plugin_data(); + $plugin_name = $plugin_data['Name']; + ?> +
            +

            + ' . esc_html__( 'Important', 'woocommerce-smart-coupons' ) . ': ' . esc_html( $plugin_name ) . ' ' . esc_html__( 'is active but it will only work with WooCommerce 3.0.0+.', 'woocommerce-smart-coupons' ) . ' ' . esc_html__( 'Please update WooCommerce to the latest version', 'woocommerce-smart-coupons' ) . '.'; + ?> +

            +
            + is_wc_gte_37() ) { + $coupon_codes = is_callable( array( $order, 'get_coupon_codes' ) ) ? $order->get_coupon_codes() : array(); + } else { + $coupon_codes = is_callable( array( $order, 'get_used_coupons' ) ) ? $order->get_used_coupons() : array(); + } + } + } + return $coupon_codes; + } + + /** + * Function to get default CSS for custom coupon design + * + * @return string $default_css Default custom CSS. + */ + public function get_custom_design_default_css() { + $default_css = '/* Coupon style for custom-design */ +.coupon-container.custom-design { + background: #39cccc; +} + +.coupon-container.custom-design .coupon-content { + border: solid 1px lightgrey; + color: #30050b; +}'; + return apply_filters( 'wc_sc_coupon_custom_design_default_css', $default_css ); + } + + /** + * Function to check if coupon email is enabled or not + * + * TODO: Can be removed in future + * + * @param string $template The template's setting to check for. + * @return boolean $is_email_enabled Is email enabled + */ + public function is_email_template_enabled( $template = 'send' ) { + + if ( 'combine' === $template ) { + $wc_email_settings_key = 'woocommerce_wc_sc_combined_email_coupon_settings'; + $sc_email_setting_key = 'smart_coupons_combine_emails'; + $default = 'no'; + } else { + $wc_email_settings_key = 'woocommerce_wc_sc_email_coupon_settings'; + $sc_email_setting_key = 'smart_coupons_is_send_email'; + $default = 'yes'; + } + + $is_email_enabled = ''; + + $wc_email_settings = get_option( $wc_email_settings_key ); + + // If setting is not found in WC Email settings fetch it from SC admin settings. + if ( false === $wc_email_settings ) { + $is_email_enabled = get_option( $sc_email_setting_key, $default ); + } elseif ( is_array( $wc_email_settings ) && ! empty( $wc_email_settings ) ) { + $is_email_enabled = ( isset( $wc_email_settings['enabled'] ) && ! empty( $wc_email_settings['enabled'] ) ) ? $wc_email_settings['enabled'] : $default; + } + + return $is_email_enabled; + } + + /** + * Function to check if store credit discount is inclusive of tax. + * + * @return string $sc_include_tax Is store credit includes tax + */ + public function is_store_credit_include_tax() { + + $sc_include_tax = 'no'; + $prices_include_tax = wc_prices_include_tax(); + + // Discount can only be inclusive of tax if prices are inclusive of tax and apply before tax is enabled. + if ( true === $prices_include_tax ) { + $apply_before_tax = get_option( 'woocommerce_smart_coupon_apply_before_tax', 'no' ); + if ( 'yes' === $apply_before_tax ) { + // Get SC setting for include tax. + $sc_include_tax = get_option( 'woocommerce_smart_coupon_include_tax', 'no' ); + } + } + return $sc_include_tax; + } + + /** + * Whether to generate store credit including tax amount or not + * + * @return boolean + */ + public function is_generated_store_credit_includes_tax() { + $is_include_tax = get_option( 'wc_sc_generated_store_credit_includes_tax', 'no' ); + return apply_filters( 'wc_sc_is_generated_store_credit_includes_tax', wc_string_to_bool( $is_include_tax ), array( 'source' => $this ) ); + } + + /** + * Get emoji + * + * @return string + */ + public function get_emoji() { + $emojis = array( + 11088 => '⭐', + 127775 => '🌟', + 127873 => '🎁', + 127881 => '🎉', + 127882 => '🎊', + 127941 => '🏅', + 127942 => '🏆', + 127991 => '🏷', + 128075 => '👋', + 128076 => '👌', + 128077 => '👍', + 128079 => '👏', + 128081 => '👑', + 128142 => '💎', + 128165 => '💥', + 128276 => '🔔', + 128293 => '🔥', + 128640 => '🚀', + 129311 => '🤟', + 129321 => '🤩', + ); + $key = array_rand( $emojis ); + return $emojis[ $key ]; + } + + /** + * Get coupon titles for product + * + * @param array $args Additional data. + * @return array + */ + public function get_coupon_titles( $args = array() ) { + $coupon_titles = array(); + if ( empty( $args ) ) { + return $coupon_titles; + } + $product = ( ! empty( $args['product_object'] ) && is_a( $args['product_object'], 'WC_Product' ) ) ? $args['product_object'] : null; + if ( is_null( $product ) ) { + return $coupon_titles; + } + $coupon_titles = ( is_callable( array( $product, 'get_meta' ) ) ) ? $product->get_meta( '_coupon_title' ) : array(); + if ( empty( $coupon_titles ) ) { + $parent_id = ( is_callable( array( $product, 'get_parent_id' ) ) ) ? $product->get_parent_id() : 0; + if ( empty( $parent_id ) ) { + return array(); + } + $parent_product = ( function_exists( 'wc_get_product' ) ) ? wc_get_product( $parent_id ) : null; + $coupon_titles = ( $this->is_callable( $parent_product, 'get_meta' ) ) ? $parent_product->get_meta( '_coupon_title' ) : $this->get_post_meta( $parent_id, '_coupon_title', true ); + } + if ( empty( $coupon_titles ) && ! is_array( $coupon_titles ) ) { + return array(); + } + return $coupon_titles; + } + + /** + * Function to copy coupon meta data and save to new coupon. + * + * @param array $coupon_data Array of new coupon id and old coupon object. + * @param array $meta_keys Meta keys. + */ + public function copy_coupon_meta_data( $coupon_data = array(), $meta_keys = array() ) { + + $new_coupon_id = ( ! empty( $coupon_data['new_coupon_id'] ) ) ? absint( $coupon_data['new_coupon_id'] ) : 0; + $coupon = ( ! empty( $coupon_data['ref_coupon'] ) ) ? $coupon_data['ref_coupon'] : false; + + if ( empty( $new_coupon_id ) || empty( $coupon ) ) { + return; + } + + if ( ! empty( $new_coupon_id ) && is_array( $meta_keys ) && ! empty( $meta_keys ) ) { + $new_coupon = new WC_Coupon( $new_coupon_id ); + $is_callable_new_coupon_update_meta = $this->is_callable( $new_coupon, 'update_meta_data' ); + $is_callable_coupon_get_meta = $this->is_callable( $coupon, 'get_meta' ); + // Save each meta to new coupon. + foreach ( $meta_keys as $meta_key ) { + $update = false; + if ( $this->is_wc_gte_30() ) { + $meta_value = ( true === $is_callable_coupon_get_meta ) ? $coupon->get_meta( $meta_key ) : ''; + $update = true; + } else { + $old_coupon_id = ( ! empty( $coupon->id ) ) ? $coupon->id : 0; + if ( ! empty( $old_coupon_id ) ) { // This will confirm that the coupon exists. + $meta_value = get_post_meta( $old_coupon_id, $meta_key, true ); + $update = true; + } + } + if ( true === $update ) { + if ( true === $is_callable_new_coupon_update_meta ) { + $new_coupon->update_meta_data( $meta_key, $meta_value ); + } else { + update_post_meta( $new_coupon_id, $meta_key, $meta_value ); + } + } + } + if ( $this->is_callable( $new_coupon, 'save' ) ) { + $new_coupon->save(); + } + } + } + + /** + * Check given coupon exists. + * + * @param string $coupon_code Coupon code. + * @return bool + * + * Credit: WooCommerce + */ + public function sc_coupon_exists( $coupon_code = '' ) { + if ( empty( $coupon_code ) ) { + return false; + } + $coupon = new WC_Coupon( $coupon_code ); + return (bool) $coupon->get_id() || $coupon->get_virtual(); + } + + /** + * Function to get pending order statuses + * + * @return array + */ + public function get_pending_statuses() { + // removed auto-draft status as we don't need to do any action on this status. + return apply_filters( 'wc_sc_pending_order_statuses', array( 'on-hold', 'pending' ), array( 'source' => $this ) ); + } + + /** + * Checking subtotal is eligible for free shipping method + * + * @param bool $is_available true/false. + * @param array $package Shipping package. + * @param object $free_shipping free shipping object. + * @return mixed|void + */ + public function is_eligible_for_free_shipping( $is_available = false, $package = array(), $free_shipping = null ) { + + // If free shipping is invalid already, no need for further checks. + if ( false === $is_available || ! is_object( $free_shipping ) ) { + return $is_available; + } + + $apply_before_tax = get_option( 'woocommerce_smart_coupon_apply_before_tax', 'no' ); + + if ( $this->is_wc_gte_30() && 'yes' === $apply_before_tax ) { + return $is_available; + } + + $has_coupon = false; + $has_met_min_amount = false; + $has_smart_coupon = false; + $coupon_usable_amount = 0; + $coupons = ( is_object( WC()->cart ) && is_callable( array( WC()->cart, 'get_coupons' ) ) ) ? WC()->cart->get_coupons() : array(); + $free_shipping_condition = ! empty( $free_shipping->requires ) ? $free_shipping->requires : ''; + $free_shipping_ignore_discounts = ! empty( $free_shipping->ignore_discounts ) ? $free_shipping->ignore_discounts : ''; + $free_shipping_min_amount = ! empty( $free_shipping->min_amount ) ? $free_shipping->min_amount : 0; + + if ( ! empty( $coupons ) ) { + + foreach ( $coupons as $coupon_code => $coupon ) { + $discount_type = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_discount_type' ) ) ) ? $coupon->get_discount_type() : ''; + if ( 'smart_coupon' === $discount_type ) { + $has_smart_coupon = true; + $coupon_usable_amount += $this->get_amount( $coupon, true ); + } + if ( in_array( $free_shipping_condition, array( 'coupon', 'either', 'both' ), true ) ) { + $coupon_is_valid = $this->is_valid( $coupon ); + $coupon_get_free_shipping = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_free_shipping' ) ) ) ? $coupon->get_free_shipping() : false; + if ( true === $coupon_is_valid && true === $coupon_get_free_shipping ) { + $has_coupon = true; + } + } + } + } + + if ( false === $has_smart_coupon ) { + return $is_available; + } + + if ( in_array( $free_shipping_condition, array( 'min_amount', 'either', 'both' ), true ) ) { + + $total = ( is_object( WC()->cart ) && is_callable( array( WC()->cart, 'get_displayed_subtotal' ) ) ) ? WC()->cart->get_displayed_subtotal() : 0; + $display_prices_including_tax = ( is_object( WC()->cart ) && is_callable( array( WC()->cart, 'display_prices_including_tax' ) ) ) ? WC()->cart->display_prices_including_tax() : false; + + if ( $display_prices_including_tax ) { + $get_discount_tax = ( is_object( WC()->cart ) && is_callable( array( WC()->cart, 'get_discount_tax' ) ) ) ? WC()->cart->get_discount_tax() : 0; + $total = $total - $get_discount_tax; + } + + if ( 'no' === $free_shipping_ignore_discounts ) { + $get_discount_total = ( is_object( WC()->cart ) && is_callable( array( WC()->cart, 'get_discount_total' ) ) ) ? WC()->cart->get_discount_total() : 0; + $total = $total - $get_discount_total; + $total = $total - $coupon_usable_amount; + } + + $total = round( ( $total ), get_option( 'woocommerce_price_num_decimals', 2 ) ); + + if ( $total >= $free_shipping_min_amount ) { + $has_met_min_amount = true; + } + } + + switch ( $free_shipping->requires ) { + case 'min_amount': + $is_available = $has_met_min_amount; + break; + case 'coupon': + $is_available = $has_coupon; + break; + case 'both': + $is_available = $has_met_min_amount && $has_coupon; + break; + case 'either': + $is_available = $has_met_min_amount || $has_coupon; + break; + default: + $is_available = true; + break; + } + + return $is_available; + } + + /** + * Smart coupon system status section in wc system status. + * + * @return void + */ + public function smart_coupons_system_status_report() { + $smart_coupons_settings = array(); + + $max_coupon_to_show = get_option( 'wc_sc_setting_max_coupon_to_show' ); + $coupon_code_length = get_option( 'wc_sc_coupon_code_length' ); + $valid_order_statuses = get_option( 'wc_sc_valid_order_statuses_for_coupon_auto_generation' ); + $is_include_tax = get_option( 'wc_sc_generated_store_credit_includes_tax' ); + $apply_before_tax = get_option( 'woocommerce_smart_coupon_apply_before_tax' ); + $sc_include_tax = get_option( 'woocommerce_smart_coupon_include_tax' ); + $is_delete_smart_coupon_after_usage = get_option( 'woocommerce_delete_smart_coupon_after_usage' ); + $is_send_email = get_option( 'smart_coupons_is_send_email' ); + $is_print = get_option( 'smart_coupons_is_print_coupon' ); + $sell_sc_at_less_price = get_option( 'smart_coupons_sell_store_credit_at_less_price' ); + $pay_from_credit_of_original_order = get_option( 'pay_from_smart_coupon_of_original_order' ); + $stop_recursive_coupon_generation = get_option( 'stop_recursive_coupon_generation' ); + $is_show_coupon_receiver_form = get_option( 'smart_coupons_display_coupon_receiver_details_form' ); + $schedule_store_credit = get_option( 'smart_coupons_schedule_store_credit' ); + $combine_emails = get_option( 'smart_coupons_combine_emails' ); + $enable_taxes = get_option( 'woocommerce_calc_taxes' ); + $price_entered_with_tax_type = get_option( 'woocommerce_prices_include_tax' ); + $round_at_subtotal = get_option( 'woocommerce_tax_round_at_subtotal' ); + $tax_display_shop = get_option( 'woocommerce_tax_display_shop' ); + $tax_display_cart = get_option( 'woocommerce_tax_display_cart' ); + $tax_total_display = get_option( 'woocommerce_tax_total_display' ); + $wc_enable_coupons = get_option( 'woocommerce_enable_coupons' ); + $calc_discounts_sequentially = get_option( 'woocommerce_calc_discounts_sequentially' ); + $wc_sc_dashboard_endpoint = get_option( 'woocommerce_myaccount_wc_sc_dashboard_endpoint', 'wc-smart-coupons' ); + + if ( is_array( $valid_order_statuses ) && ! empty( $valid_order_statuses ) ) { + $valid_order_statuses = implode( ' | ', array_map( 'ucwords', $valid_order_statuses ) ); + } + + $auto_generated_coupon_email = $this->is_email_template_enabled(); + $combined_email_coupon_enabled = $this->is_email_template_enabled( 'combine' ); + + $cart_page_id = absint( get_option( 'woocommerce_cart_page_id' ) ); + $checkout_page_id = absint( get_option( 'woocommerce_checkout_page_id' ) ); + $is_block_enabled_cart = ( has_block( 'woocommerce/cart', $cart_page_id ) ) ? 'yes' : 'no'; + $is_block_enabled_checkout = ( has_block( 'woocommerce/checkout', $checkout_page_id ) ) ? 'yes' : 'no'; + + $woocommerce_account_auth = ( class_exists( 'WC_Helper_Options' ) && is_callable( array( 'WC_Helper_Options', 'get' ) ) ) ? WC_Helper_Options::get( 'auth' ) : null; + $woocommerce_account_connected = ( ! empty( $woocommerce_account_auth ) ) ? 'yes' : 'no'; + + $smart_coupons_settings = array( + __( 'Number of coupons to show', 'woocommerce-smart-coupons' ) => $max_coupon_to_show, + __( 'Number of characters in auto-generated coupon code', 'woocommerce-smart-coupons' ) => $coupon_code_length, + __( 'Valid order status for auto-generating coupon', 'woocommerce-smart-coupons' ) => $valid_order_statuses, + __( 'Include tax in the amount of the generated gift card', 'woocommerce-smart-coupons' ) => $this->iconify( $is_include_tax ), + __( 'Deduct credit/gift before doing tax calculations', 'woocommerce-smart-coupons' ) => $this->iconify( $apply_before_tax ), + __( 'Gift Card discount is inclusive of tax', 'woocommerce-smart-coupons' ) => $this->iconify( $sc_include_tax ), + __( 'Automatic deletion', 'woocommerce-smart-coupons' ) => $this->iconify( $is_delete_smart_coupon_after_usage, true ), + __( 'Coupon emails', 'woocommerce-smart-coupons' ) => $this->iconify( $is_send_email ), + __( 'Printing coupons', 'woocommerce-smart-coupons' ) => $this->iconify( $is_print ), + __( 'Sell gift cards at less price?', 'woocommerce-smart-coupons' ) => $this->iconify( $sell_sc_at_less_price ), + __( 'Use gift card applied in first subscription order for subsequent renewals until credit reaches zero', 'woocommerce-smart-coupons' ) => $this->iconify( $pay_from_credit_of_original_order ), + __( 'Renewal orders should not generate coupons even when they include a product that issues coupons', 'woocommerce-smart-coupons' ) => $this->iconify( $stop_recursive_coupon_generation ), + __( 'Allow sending of coupons to others', 'woocommerce-smart-coupons' ) => $this->iconify( $is_show_coupon_receiver_form ), + __( 'Allow schedule sending of coupons?', 'woocommerce-smart-coupons' ) => $this->iconify( $schedule_store_credit ), + __( 'Combine emails', 'woocommerce-smart-coupons' ) => $this->iconify( $combine_emails ), + __( 'Auto generated coupon email', 'woocommerce-smart-coupons' ) => $this->iconify( $auto_generated_coupon_email ), + __( 'Combined auto generated coupons email', 'woocommerce-smart-coupons' ) => $this->iconify( $combined_email_coupon_enabled ), + __( 'Acknowledgement email', 'woocommerce-smart-coupons' ) => $this->iconify( $auto_generated_coupon_email ), + __( 'Enable taxes', 'woocommerce-smart-coupons' ) => $this->iconify( $enable_taxes ), + __( 'Prices entered with tax', 'woocommerce-smart-coupons' ) => $this->iconify( $price_entered_with_tax_type ), + __( 'Display prices in the shop', 'woocommerce-smart-coupons' ) => $this->iconify( $tax_display_shop ), + __( 'Display prices during cart and checkout', 'woocommerce-smart-coupons' ) => $this->iconify( $tax_display_cart ), + __( 'Rounding', 'woocommerce-smart-coupons' ) => $this->iconify( $round_at_subtotal ), + __( 'Display tax totals', 'woocommerce-smart-coupons' ) => ucwords( $tax_total_display ), + __( 'Enable the use of coupon codes', 'woocommerce-smart-coupons' ) => $this->iconify( $wc_enable_coupons ), + __( 'Calculate coupon discounts sequentially', 'woocommerce-smart-coupons' ) => $this->iconify( $calc_discounts_sequentially ), + __( 'Account endpoints > Coupons', 'woocommerce-smart-coupons' ) => '' . $wc_sc_dashboard_endpoint . '', + __( 'Block-enabled Cart', 'woocommerce-smart-coupons' ) => $this->iconify( $is_block_enabled_cart ), + __( 'Block-enabled Checkout', 'woocommerce-smart-coupons' ) => $this->iconify( $is_block_enabled_checkout ), + __( 'WooCommerce Account Connected', 'woocommerce-smart-coupons' ) => $this->iconify( $woocommerce_account_connected ), + ); + + ?> + + + + + + + + $value ) { + ?> + + + + + + + +

            : + +   
            + ' . ucwords( $original_text ) . ''; + } elseif ( in_array( $text, array( 'no', 'excl' ), true ) ) { + return ' ' . ucwords( $original_text ) . ''; + } + break; + case false: + default: + if ( in_array( $text, array( 'yes', 'incl' ), true ) ) { + return ' ' . ucwords( $original_text ) . ''; + } elseif ( in_array( $text, array( 'no', 'excl' ), true ) ) { + return ' ' . ucwords( $original_text ) . ''; + } + break; + } + } + + /** + * An alternate(get_option()) way of fetching any option using query. + * + * @param string $option_name Option name. + * @param string $default Default value. + * @return string|null + */ + public function sc_get_option( $option_name = '', $default = 'no_default' ) { + global $wpdb; + + if ( empty( $option_name ) ) { + return false; + } + + if ( 'no_default' === $default ) { + $row = $wpdb->get_row( // phpcs:ignore + $wpdb->prepare( + "SELECT option_value + FROM {$wpdb->prefix}options + WHERE option_name = %s + LIMIT %d", + $option_name, + 1 + ) + ); + } else { + $row = $wpdb->get_row( // phpcs:ignore + $wpdb->prepare( + "SELECT option_value + FROM {$wpdb->prefix}options + WHERE option_name = %s + UNION SELECT %s + LIMIT %d", + $option_name, + $default, + 1 + ) + ); + } + + return is_null( $row ) ? false : ( ( ! empty( $row->option_value ) ) ? maybe_unserialize( $row->option_value ) : '' ); + + } + + /** + * Add total SC used in REST API shop order object. + * + * @since 5.7.0 + * + * @param WP_REST_Response $response WP_REST_Response object. + * @param WC_Order $order WC_Order object. + * @param WP_REST_Request $request WP_REST_Response object. + * @return WP_REST_Response + */ + public function rest_api_prepare_shop_order_object( $response = null, $order = null, $request = null ) { + if ( empty( $response ) || empty( $order ) ) { + return $response; + } + + $sc_order_fields = WC_SC_Order_Fields::get_instance(); + + $total_credit_used = $sc_order_fields->get_total_credit_used_in_order( $order ); + + if ( is_object( $response ) && ! empty( $response->data ) && is_array( $response->data ) ) { + $response->data['store_credit_used'] = round( $total_credit_used, get_option( 'woocommerce_price_num_decimals', 2 ) ); + } + + return $response; + } + + /** + * Function to get coupon amount considering currency + * + * @param WC_Coupon $coupon The coupon object. + * @param boolean $convert Whether to convert or not. + * @param WC_Order $order The order object. + * + * @throws Exception If $coupon is not an object of WC_Coupon. + * @return float + */ + public function get_amount( $coupon = null, $convert = false, $order = null ) { + if ( ! is_a( $coupon, 'WC_Coupon' ) ) { + $error = __( '$coupon is not an object of WC_Coupon', 'woocommerce-smart-coupons' ); + ob_start(); + esc_html_e( '$coupon is: ', 'woocommerce-smart-coupons' ) . ( is_scalar( $coupon ) ) ? var_dump( $coupon ) : print_r( gettype( $coupon ) ) . print_r( "\r\n" ); // phpcs:ignore + $this->log( 'notice', print_r( $error, true ) . ' ' . __FILE__ . ' ' . __LINE__ . print_r( "\r\n" . ob_get_clean(), true ) ); // phpcs:ignore + return floatval( 0 ); + } + if ( $this->is_wc_gte_30() ) { + $coupon_amount = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_amount' ) ) ) ? $coupon->get_amount() : 0; + } else { + $coupon_amount = ( ! empty( $coupon->amount ) ) ? $coupon->amount : 0; + } + return $coupon_amount; + } + + /** + * Maybe convert price read from database to current currency + * + * @param integer $price The price to be converted. + * @param boolean $convert Whether to convert or not. + * @param WC_Order $order The order object. + * @return float $price The converted price. + */ + public function read_price( $price = 0, $convert = false, $order = null ) { + if ( true === $convert ) { + $order_currency = ''; + if ( is_a( $order, 'WC_Order' ) ) { + if ( $this->is_wc_gte_30() ) { + $order_currency = ( is_callable( array( $order, 'get_currency' ) ) ) ? $order->get_currency() : ''; // phpcs:ignore + } else { + $order_currency = ( is_callable( array( $order, 'get_order_currency' ) ) ) ? $order->get_order_currency() : ''; // phpcs:ignore + } + } + $current_currency = ( ! empty( $order_currency ) ) ? $order_currency : get_woocommerce_currency(); + $base_currency = get_option( 'woocommerce_currency' ); + if ( $base_currency !== $current_currency ) { + $price = $this->convert_price( $price, $current_currency, $base_currency ); + } + $price = apply_filters( + 'wc_sc_read_price', + $price, + array( + 'source' => $this, + 'currency_conversion' => $convert, + 'order_obj' => $order, + ) + ); + } + return $price; + } + + /** + * Maybe convert price to base currency before saving to the database + * + * @param integer $price The price to be converted. + * @param boolean $convert Whether to convert or not. + * @param WC_Order $order The order object. + * @return float $price The converted price. + */ + public function write_price( $price = 0, $convert = false, $order = null ) { + if ( true === $convert ) { + $order_currency = ''; + if ( is_a( $order, 'WC_Order' ) ) { + if ( $this->is_wc_gte_30() ) { + $order_currency = ( is_callable( array( $order, 'get_currency' ) ) ) ? $order->get_currency() : ''; // phpcs:ignore + } else { + $order_currency = ( is_callable( array( $order, 'get_order_currency' ) ) ) ? $order->get_order_currency() : ''; // phpcs:ignore + } + } + $current_currency = ( ! empty( $order_currency ) ) ? $order_currency : get_woocommerce_currency(); + $base_currency = get_option( 'woocommerce_currency' ); + if ( $base_currency !== $current_currency ) { + $price = $this->convert_price( $price, $base_currency, $current_currency ); + } + $price = apply_filters( + 'wc_sc_write_price', + $price, + array( + 'source' => $this, + 'currency_conversion' => $convert, + 'order_obj' => $order, + ) + ); + } + return $price; + } + + /** + * Get post meta considering currency + * + * @param integer $post_id The post id. + * @param string $meta_key The meta key. + * @param boolean $single Whether to get single value or not. + * @param boolean $convert Whether to convert or not. + * @param WC_Order $order The order object. + * + * @throws Exception If Some values not passed for $post_id & $meta_key. + * @return mixed + */ + public function get_post_meta( $post_id = 0, $meta_key = '', $single = false, $convert = false, $order = null ) { + if ( empty( $post_id ) || empty( $meta_key ) ) { + $error = __( 'Some values required for $post_id & $meta_key', 'woocommerce-smart-coupons' ); + ob_start(); + esc_html_e( '$post_id is: ', 'woocommerce-smart-coupons' ) . ( is_scalar( $post_id ) ) ? var_dump( $post_id ) : print_r( gettype( $post_id ) ) . print_r( "\r\n" ); // phpcs:ignore + esc_html_e( '$meta_key is: ', 'woocommerce-smart-coupons' ) . ( is_scalar( $meta_key ) ) ? var_dump( $meta_key ) : print_r( gettype( $meta_key ) ) . print_r( "\r\n" ); // phpcs:ignore + $this->log( 'notice', print_r( $error, true ) . ' ' . __FILE__ . ' ' . __LINE__ . print_r( "\r\n" . ob_get_clean(), true ) ); // phpcs:ignore + return null; + } + $meta_value = ''; + $post_type = ( $this->is_callable( $this, 'get_post_type' ) ) ? $this->get_post_type( $post_id ) : ''; + if ( in_array( $post_type, array( 'product', 'product_variation', 'shop_coupon', 'shop_order' ), true ) ) { + $object = null; + $use_getter = false; + $post_id = absint( $post_id ); + switch ( $post_type ) { + case 'product': + case 'product_variation': + $object = ( function_exists( 'wc_get_product' ) ) ? wc_get_product( $post_id ) : null; + break; + case 'shop_coupon': + $object = new WC_Coupon( $post_id ); + $meta_key_to_props = array( + 'coupon_amount' => 'amount', + 'customer_email' => 'email_restrictions', + 'date_expires' => 'date_expires', + 'discount_type' => 'discount_type', + 'expiry_date' => 'date_expires', + ); + if ( array_key_exists( $meta_key, $meta_key_to_props ) ) { + $function = 'get_' . $meta_key_to_props[ $meta_key ]; + if ( $this->is_callable( $object, $function ) ) { + $use_getter = true; + } + } + break; + case 'shop_order': + $object = ( is_object( $order ) && is_a( $order, 'WC_Order' ) ) ? $order : ( function_exists( 'wc_get_order' ) ? wc_get_order( $post_id ) : null ); + $order = $object; + $meta_key_to_props = array( + '_order_total' => 'total', + '_billing_email' => 'billing_email', + ); + if ( array_key_exists( $meta_key, $meta_key_to_props ) ) { + $function = 'get_' . $meta_key_to_props[ $meta_key ]; + if ( $this->is_callable( $object, $function ) ) { + $use_getter = true; + } + } + break; + } + if ( true === $use_getter ) { + $meta_value = $object->{$function}(); + } elseif ( $this->is_callable( $object, 'get_meta' ) ) { + $meta_value = $object->get_meta( $meta_key ); + } else { + $meta_value = get_post_meta( $post_id, $meta_key, $single ); + } + if ( in_array( $meta_key, array( 'coupon_amount', 'smart_coupons_contribution', 'wc_sc_max_discount', 'wc_sc_original_amount', 'sc_called_credit_details', '_order_discount', '_order_total' ), true ) ) { + $order_currency = null; + if ( ! is_a( $order, 'WC_Order' ) && ! empty( $post_type ) && 'shop_order' === $post_type ) { + $order = ( ! empty( $post_id ) ) ? wc_get_order( $post_id ) : null; + } + if ( is_a( $order, 'WC_Order' ) ) { + if ( $this->is_wc_gte_30() ) { + $order_currency = ( is_callable( array( $order, 'get_currency' ) ) ) ? $order->get_currency() : ''; // phpcs:ignore + } else { + $order_currency = ( is_callable( array( $order, 'get_order_currency' ) ) ) ? $order->get_order_currency() : ''; // phpcs:ignore + } + } + if ( true === $convert ) { + $current_currency = ( ! is_null( $order_currency ) ) ? $order_currency : get_woocommerce_currency(); + $base_currency = get_option( 'woocommerce_currency' ); + if ( $base_currency !== $current_currency ) { + if ( is_scalar( $meta_value ) ) { + $meta_value = $this->convert_price( $meta_value, $current_currency, $base_currency ); + } elseif ( is_array( $meta_value ) ) { + array_walk( + $meta_value, + array( $this, 'array_convert_price' ), + array( + 'to_currency' => $current_currency, + 'from_currency' => $base_currency, + ) + ); + } + } + } + return apply_filters( + 'wc_sc_after_get_post_meta', + $meta_value, + array( + 'source' => $this, + 'currency_conversion' => $convert, + 'post_id' => $post_id, + 'meta_key' => $meta_key, // phpcs:ignore + 'order_obj' => $order, + ) + ); + } + } + return $meta_value; + } + + /** + * Update post meta considering currency + * + * @param integer $post_id The post id. + * @param string $meta_key The meta key. + * @param string $meta_value The meta value. + * @param boolean $convert Whether to convert or not. + * @param WC_Order $order The order object. + * + * @throws Exception If Some values not passed for $post_id & $meta_key. + */ + public function update_post_meta( $post_id = 0, $meta_key = '', $meta_value = '', $convert = false, $order = null ) { + if ( empty( $post_id ) || empty( $meta_key ) ) { + $error = __( 'Some values required for $post_id & $meta_key', 'woocommerce-smart-coupons' ); + ob_start(); + esc_html_e( '$post_id is: ', 'woocommerce-smart-coupons' ) . ( is_scalar( $post_id ) ) ? var_dump( $post_id ) : print_r( gettype( $post_id ) ) . print_r( "\r\n" ); // phpcs:ignore + esc_html_e( '$meta_key is: ', 'woocommerce-smart-coupons' ) . ( is_scalar( $meta_key ) ) ? var_dump( $meta_key ) : print_r( gettype( $meta_key ) ) . print_r( "\r\n" ); // phpcs:ignore + $this->log( 'notice', print_r( $error, true ) . ' ' . __FILE__ . ' ' . __LINE__ . print_r( "\r\n" . ob_get_clean(), true ) ); // phpcs:ignore + return false; + } + $post_type = ( $this->is_callable( $this, 'get_post_type' ) ) ? $this->get_post_type( $post_id ) : ''; + if ( in_array( $meta_key, array( 'coupon_amount', 'smart_coupons_contribution', 'wc_sc_max_discount', 'wc_sc_original_amount', 'sc_called_credit_details', '_order_discount', '_order_total' ), true ) ) { + $order_currency = null; + + if ( ! is_a( $order, 'WC_Order' ) && ! empty( $post_type ) && 'shop_order' === $post_type ) { + $order = ( ! empty( $post_id ) ) ? wc_get_order( $post_id ) : null; + } + if ( is_a( $order, 'WC_Order' ) ) { + if ( $this->is_wc_gte_30() ) { + $order_currency = ( is_callable( array( $order, 'get_currency' ) ) ) ? $order->get_currency() : ''; // phpcs:ignore + } else { + $order_currency = ( is_callable( array( $order, 'get_order_currency' ) ) ) ? $order->get_order_currency() : ''; // phpcs:ignore + } + } + if ( true === $convert ) { + $current_currency = ( ! is_null( $order_currency ) ) ? $order_currency : get_woocommerce_currency(); + $base_currency = get_option( 'woocommerce_currency' ); + if ( $base_currency !== $current_currency ) { + if ( is_scalar( $meta_value ) ) { + $meta_value = $this->convert_price( $meta_value, $base_currency, $current_currency ); + } elseif ( is_array( $meta_value ) ) { + array_walk( + $meta_value, + array( $this, 'array_convert_price' ), + array( + 'to_currency' => $base_currency, + 'from_currency' => $current_currency, + ) + ); + } + } + } + $meta_value = apply_filters( + 'wc_sc_before_update_post_meta', + $meta_value, + array( + 'source' => $this, + 'currency_conversion' => $convert, + 'post_id' => $post_id, + 'meta_key' => $meta_key, // phpcs:ignore + 'order_obj' => $order, + ) + ); + } + if ( in_array( $post_type, array( 'product', 'product_variation', 'shop_coupon', 'shop_order' ), true ) ) { + $object = null; + $use_setter = false; + $post_id = absint( $post_id ); + switch ( $post_type ) { + case 'product': + case 'product_variation': + $object = ( function_exists( 'wc_get_product' ) ) ? wc_get_product( $post_id ) : null; + break; + case 'shop_coupon': + $object = new WC_Coupon( $post_id ); + $meta_key_to_props = array( + 'coupon_amount' => 'amount', + 'customer_email' => 'email_restrictions', + 'date_expires' => 'date_expires', + 'discount_type' => 'discount_type', + 'expiry_date' => 'date_expires', + ); + if ( array_key_exists( $meta_key, $meta_key_to_props ) ) { + $function = 'set_' . $meta_key_to_props[ $meta_key ]; + if ( $this->is_callable( $object, $function ) && $this->is_callable( $object, 'save' ) ) { + $use_setter = true; + } + } + break; + case 'shop_order': + $object = ( is_object( $order ) && is_a( $order, 'WC_Order' ) ) ? $order : ( function_exists( 'wc_get_order' ) ? wc_get_order( $post_id ) : null ); + $meta_key_to_props = array( + '_order_total' => 'total', + '_billing_email' => 'billing_email', + ); + if ( array_key_exists( $meta_key, $meta_key_to_props ) ) { + $function = 'set_' . $meta_key_to_props[ $meta_key ]; + if ( $this->is_callable( $object, $function ) && $this->is_callable( $object, 'save' ) ) { + $use_setter = true; + } + } + break; + } + if ( true === $use_setter ) { + $object->{$function}( $meta_value ); + $object->save(); + } elseif ( $this->is_callable( $object, 'update_meta_data' ) && $this->is_callable( $object, 'save' ) ) { + $object->update_meta_data( $meta_key, $meta_value ); + $object->save(); + } else { + update_post_meta( $post_id, $meta_key, $meta_value ); + } + } + } + + /** + * Wrapper function for deleting post meta + * + * @param integer $post_id The post id. + * @param string $meta_key The meta key to delete. + * @param string $meta_value The meta value to delete. + * @param mixed $object The object. + * + * @throws Exception If Some values not passed for $post_id & $meta_key. + */ + public function delete_post_meta( $post_id = 0, $meta_key = '', $meta_value = '', $object = null ) { + if ( empty( $post_id ) || empty( $meta_key ) ) { + $error = __( 'Some values required for $post_id & $meta_key', 'woocommerce-smart-coupons' ); + ob_start(); + esc_html_e( '$post_id is: ', 'woocommerce-smart-coupons' ) . ( is_scalar( $post_id ) ) ? var_dump( $post_id ) : print_r( gettype( $post_id ) ) . print_r( "\r\n" ); // phpcs:ignore + esc_html_e( '$meta_key is: ', 'woocommerce-smart-coupons' ) . ( is_scalar( $meta_key ) ) ? var_dump( $meta_key ) : print_r( gettype( $meta_key ) ) . print_r( "\r\n" ); // phpcs:ignore + $this->log( 'notice', print_r( $error, true ) . ' ' . __FILE__ . ' ' . __LINE__ . print_r( "\r\n" . ob_get_clean(), true ) ); // phpcs:ignore + return false; + } + if ( is_null( $object ) || ! ( $this->is_callable( $object, 'delete_meta_data' ) && $this->is_callable( $object, 'save' ) ) ) { + $post_type = ( $this->is_callable( $this, 'get_post_type' ) ) ? $this->get_post_type( $post_id ) : ''; + if ( in_array( $post_type, array( 'product', 'product_variation', 'shop_coupon', 'shop_order' ), true ) ) { + $post_id = absint( $post_id ); + switch ( $post_type ) { + case 'product': + case 'product_variation': + $object = ( function_exists( 'wc_get_product' ) ) ? wc_get_product( $post_id ) : null; + break; + case 'shop_coupon': + $object = new WC_Coupon( $post_id ); + break; + case 'shop_order': + $object = ( is_object( $order ) && is_a( $order, 'WC_Order' ) ) ? $order : ( function_exists( 'wc_get_order' ) ? wc_get_order( $post_id ) : null ); + break; + } + } + } + if ( $this->is_callable( $object, 'delete_meta_data' ) && $this->is_callable( $object, 'save' ) ) { + $object->delete_meta_data( $meta_key ); + $object->save(); + } else { + delete_post_meta( $post_id, $meta_key ); + } + } + + /** + * Get value from WooCommerce session + * + * @param string $key The key. + * @param boolean $convert Whether to convert or not. + * + * @throws Exception If $key is not passed. + * @return mixed + */ + public function get_session( $key = '', $convert = false ) { + if ( empty( $key ) ) { + $error = __( '$key is required', 'woocommerce-smart-coupons' ); + ob_start(); + esc_html_e( '$key is: ', 'woocommerce-smart-coupons' ) . ( is_scalar( $key ) ) ? var_dump( $key ) : print_r( gettype( $key ) ) . print_r( "\r\n" ); // phpcs:ignore + $this->log( 'notice', print_r( $error, true ) . ' ' . __FILE__ . ' ' . __LINE__ . print_r( "\r\n" . ob_get_clean(), true ) ); // phpcs:ignore + return null; + } + if ( ! is_callable( 'WC' ) || ! is_object( WC() ) || ! is_object( WC()->session ) || ! is_callable( array( WC()->session, 'get' ) ) ) { + return null; + } + $value = WC()->session->get( $key ); + if ( 'credit_called' !== $key ) { + return $value; + } + if ( true === $convert ) { + $current_currency = get_woocommerce_currency(); + $base_currency = get_option( 'woocommerce_currency' ); + if ( $base_currency !== $current_currency ) { + if ( ! empty( $value ) ) { + if ( is_scalar( $value ) ) { + $value = $this->convert_price( $value, $current_currency, $base_currency ); + } elseif ( is_array( $value ) ) { + array_walk( + $value, + array( $this, 'array_convert_price' ), + array( + 'to_currency' => $current_currency, + 'from_currency' => $base_currency, + ) + ); + } + } + } + } + return apply_filters( + 'wc_sc_after_get_session', + $value, + array( + 'source' => $this, + 'currency_conversion' => $convert, + 'key' => $key, + ) + ); + } + + /** + * Save a value in WooCommerce session + * + * @param string $key The key. + * @param string $value The value. + * @param boolean $convert Whether to convert or not. + * + * @throws Exception If $key is not passed. + */ + public function set_session( $key = '', $value = '', $convert = false ) { + if ( empty( $key ) ) { + $error = __( '$key is required', 'woocommerce-smart-coupons' ); + ob_start(); + esc_html_e( '$key is: ', 'woocommerce-smart-coupons' ) . ( is_scalar( $key ) ) ? var_dump( $key ) : print_r( gettype( $key ) ) . print_r( "\r\n" ); // phpcs:ignore + $this->log( 'notice', print_r( $error, true ) . ' ' . __FILE__ . ' ' . __LINE__ . print_r( "\r\n" . ob_get_clean(), true ) ); // phpcs:ignore + return false; + } + if ( ! is_callable( 'WC' ) || ! is_object( WC() ) || ! is_object( WC()->session ) || ! is_callable( array( WC()->session, 'set' ) ) ) { + return; + } + if ( 'credit_called' !== $key ) { + return; + } + if ( true === $convert ) { + $current_currency = get_woocommerce_currency(); + $base_currency = get_option( 'woocommerce_currency' ); + if ( $base_currency !== $current_currency ) { + if ( ! empty( $value ) ) { + if ( is_scalar( $value ) ) { + $value = $this->convert_price( $value, $base_currency, $current_currency ); + } elseif ( is_array( $value ) ) { + array_walk( + $value, + array( $this, 'array_convert_price' ), + array( + 'to_currency' => $base_currency, + 'from_currency' => $current_currency, + ) + ); + } + } + } + } + $value = apply_filters( + 'wc_sc_before_set_session', + $value, + array( + 'source' => $this, + 'currency_conversion' => $convert, + 'key' => $key, + ) + ); + WC()->session->set( $key, $value ); + } + + /** + * Get order item meta considering currency + * + * @param integer $item_id The order item id. + * @param string $item_key The order item key. + * @param boolean $single Whether to get single value or not. + * @param boolean $convert Whether to convert or not. + * + * @throws Exception If Some values not passed for $item_id & $item_key. + * @return mixed + */ + public function get_order_item_meta( $item_id = 0, $item_key = '', $single = false, $convert = false ) { + if ( empty( $item_id ) || empty( $item_key ) ) { + $error = __( 'Some values required for $item_id & $item_key', 'woocommerce-smart-coupons' ); + ob_start(); + esc_html_e( '$item_id is: ', 'woocommerce-smart-coupons' ) . ( is_scalar( $item_id ) ) ? var_dump( $item_id ) : print_r( gettype( $item_id ) ) . print_r( "\r\n" ); // phpcs:ignore + esc_html_e( '$item_key is: ', 'woocommerce-smart-coupons' ) . ( is_scalar( $item_key ) ) ? var_dump( $item_key ) : print_r( gettype( $item_key ) ) . print_r( "\r\n" ); // phpcs:ignore + $this->log( 'notice', print_r( $error, true ) . ' ' . __FILE__ . ' ' . __LINE__ . print_r( "\r\n" . ob_get_clean(), true ) ); // phpcs:ignore + return null; + } + $item_value = wc_get_order_item_meta( $item_id, $item_key, $single ); + if ( in_array( $item_key, array( 'discount', 'discount_amount', 'discount_amount_tax', 'sc_refunded_discount', 'sc_refunded_discount_tax', 'sc_called_credit' ), true ) ) { + if ( $this->is_wc_gte_30() ) { + $order_id = ( ! empty( $item_id ) ) ? wc_get_order_id_by_order_item_id( $item_id ) : 0; + } else { + $order_id = ( ! empty( $item_id ) ) ? $this->get_order_id_by_order_item_id_wclt30( $item_id ) : 0; + } + $order = ( ! empty( $order_id ) ) ? wc_get_order( $order_id ) : null; + $item = ( is_object( $order ) && is_callable( array( $order, 'get_item' ) ) ) ? $order->get_item( $item_id ) : null; + if ( true === $convert ) { + if ( $this->is_wc_gte_30() ) { + $order_currency = ( is_object( $order ) && is_callable( array( $order, 'get_currency' ) ) ) ? $order->get_currency() : ''; // phpcs:ignore + } else { + $order_currency = ( is_object( $order ) && is_callable( array( $order, 'get_order_currency' ) ) ) ? $order->get_order_currency() : ''; // phpcs:ignore + } + if ( ! empty( $order_currency ) ) { + $base_currency = get_option( 'woocommerce_currency' ); + $item_value = $this->convert_price( $item_value, $order_currency, $base_currency ); + } + } + return apply_filters( + 'wc_sc_after_get_order_item_meta', + $item_value, + array( + 'source' => $this, + 'currency_conversion' => $convert, + 'order_item_obj' => $item, + 'order_item_id' => $item_id, + 'order_item_key' => $item_key, + ) + ); + } + return $item_value; + } + + /** + * Add order item meta considering currency + * + * @param integer $item_id The order item id. + * @param string $item_key The order item key. + * @param string $item_value The order item value. + * @param boolean $convert Whether to convert or not. + * + * @throws Exception If Some values not passed for $item_id & $item_key. + */ + public function add_order_item_meta( $item_id = 0, $item_key = '', $item_value = '', $convert = false ) { + if ( empty( $item_id ) || empty( $item_key ) ) { + $error = __( 'Some values required for $item_id & $item_key', 'woocommerce-smart-coupons' ); + ob_start(); + esc_html_e( '$item_id is: ', 'woocommerce-smart-coupons' ) . ( is_scalar( $item_id ) ) ? var_dump( $item_id ) : print_r( gettype( $item_id ) ) . print_r( "\r\n" ); // phpcs:ignore + esc_html_e( '$item_key is: ', 'woocommerce-smart-coupons' ) . ( is_scalar( $item_key ) ) ? var_dump( $item_key ) : print_r( gettype( $item_key ) ) . print_r( "\r\n" ); // phpcs:ignore + $this->log( 'notice', print_r( $error, true ) . ' ' . __FILE__ . ' ' . __LINE__ . print_r( "\r\n" . ob_get_clean(), true ) ); // phpcs:ignore + return 0; + } + if ( in_array( $item_key, array( 'discount', 'discount_amount', 'discount_amount_tax', 'sc_refunded_discount', 'sc_refunded_discount_tax', 'sc_called_credit' ), true ) ) { + $item_value = $this->get_item_value( $item_id, $item_value, $convert ); + } + if ( $this->is_wc_gte_30() ) { + wc_add_order_item_meta( $item_id, $item_key, $item_value ); + } else { + woocommerce_add_order_item_meta( $item_id, $item_key, $item_value ); + } + } + + /** + * Update order item meta considering currency + * + * @param integer $item_id The order item id. + * @param string $item_key The order item key. + * @param string $item_value The order item value. + * @param boolean $convert Whether to convert or not. + * + * @throws Exception If Some values not passed for $item_id & $item_key. + */ + public function update_order_item_meta( $item_id = 0, $item_key = '', $item_value = '', $convert = false ) { + if ( empty( $item_id ) || empty( $item_key ) ) { + $error = __( 'Some values required for $item_id & $item_key', 'woocommerce-smart-coupons' ); + ob_start(); + esc_html_e( '$item_id is: ', 'woocommerce-smart-coupons' ) . ( is_scalar( $item_id ) ) ? var_dump( $item_id ) : print_r( gettype( $item_id ) ) . print_r( "\r\n" ); // phpcs:ignore + esc_html_e( '$item_key is: ', 'woocommerce-smart-coupons' ) . ( is_scalar( $item_key ) ) ? var_dump( $item_key ) : print_r( gettype( $item_key ) ) . print_r( "\r\n" ); // phpcs:ignore + $this->log( 'notice', print_r( $error, true ) . ' ' . __FILE__ . ' ' . __LINE__ . print_r( "\r\n" . ob_get_clean(), true ) ); // phpcs:ignore + return false; + } + if ( in_array( $item_key, array( 'discount', 'discount_amount', 'discount_amount_tax', 'sc_refunded_discount', 'sc_refunded_discount_tax', 'sc_called_credit' ), true ) ) { + $item_value = $this->get_item_value( $item_id, $item_value, $convert ); + } + wc_update_order_item_meta( $item_id, $item_key, $item_value ); + } + + /** + * Delete order item meta + * + * @param integer $item_id The order item id. + * @param string $item_key The order item key. + * @param boolean $convert Whether to convert or not. + * + * @throws Exception If Some values not passed for $item_id & $item_key. + */ + public function delete_order_item_meta( $item_id = 0, $item_key = '', $convert = false ) { + if ( empty( $item_id ) || empty( $item_key ) ) { + $error = __( 'Some values required for $item_id & $item_key', 'woocommerce-smart-coupons' ); + ob_start(); + esc_html_e( '$item_id is: ', 'woocommerce-smart-coupons' ) . ( is_scalar( $item_id ) ) ? var_dump( $item_id ) : print_r( gettype( $item_id ) ) . print_r( "\r\n" ); // phpcs:ignore + esc_html_e( '$item_key is: ', 'woocommerce-smart-coupons' ) . ( is_scalar( $item_key ) ) ? var_dump( $item_key ) : print_r( gettype( $item_key ) ) . print_r( "\r\n" ); // phpcs:ignore + $this->log( 'notice', print_r( $error, true ) . ' ' . __FILE__ . ' ' . __LINE__ . print_r( "\r\n" . ob_get_clean(), true ) ); // phpcs:ignore + return false; + } + if ( in_array( $item_key, array( 'discount', 'discount_amount', 'discount_amount_tax', 'sc_refunded_discount', 'sc_refunded_discount_tax', 'sc_called_credit' ), true ) ) { + if ( $this->is_wc_gte_30() ) { + wc_delete_order_item_meta( $item_id, $item_key ); + } else { + woocommerce_delete_order_item_meta( $item_id, $item_key ); + } + } + } + + /** + * Get order item meta + * + * @param WC_Order_item $item The order item object. + * @param string $item_key The order item meta key. + * @param boolean $convert Whether to convert or not. + * + * @throws Exception If $item is not an object of WC_Order_Item. + * @return mixed + */ + public function get_meta( $item = null, $item_key = '', $convert = false ) { + if ( ! is_a( $item, 'WC_Order_Item' ) ) { + $error = __( '$item is not an object of WC_Order_Item', 'woocommerce-smart-coupons' ); + ob_start(); + esc_html_e( '$item is: ', 'woocommerce-smart-coupons' ) . ( is_scalar( $item ) ) ? var_dump( $item ) : print_r( gettype( $item ) ) . print_r( "\r\n" ); // phpcs:ignore + $this->log( 'notice', print_r( $error, true ) . ' ' . __FILE__ . ' ' . __LINE__ . print_r( "\r\n" . ob_get_clean(), true ) ); // phpcs:ignore + return null; + } + $item_value = ( is_callable( array( $item, 'get_meta' ) ) ) ? $item->get_meta( $item_key ) : ( ( ! empty( $item[ $item_key ] ) ) ? $item[ $item_key ] : '' ); + if ( in_array( $item_key, array( 'discount', 'discount_amount', 'discount_amount_tax', 'sc_refunded_discount', 'sc_refunded_discount_tax', 'sc_called_credit' ), true ) ) { + $item_id = ( is_callable( array( $item, 'get_id' ) ) ) ? $item->get_id() : 0; + if ( true === $convert ) { + $order = ( is_callable( array( $item, 'get_order' ) ) ) ? $item->get_order() : null; + if ( $this->is_wc_gte_30() ) { + $order_currency = ( is_object( $order ) && is_callable( array( $order, 'get_currency' ) ) ) ? $order->get_currency() : ''; // phpcs:ignore + } else { + $order_currency = ( is_object( $order ) && is_callable( array( $order, 'get_order_currency' ) ) ) ? $order->get_order_currency() : ''; // phpcs:ignore + } + if ( ! empty( $order_currency ) ) { + $base_currency = get_option( 'woocommerce_currency' ); + $item_value = $this->convert_price( $item_value, $order_currency, $base_currency ); + } + } + return apply_filters( + 'wc_sc_after_get_order_item_meta', + $item_value, + array( + 'source' => $this, + 'currency_conversion' => $convert, + 'order_item_obj' => $item, + 'order_item_id' => $item_id, + 'order_item_key' => $item_key, + ) + ); + } + return $item_value; + } + + /** + * Update order item meta considering currency + * + * @param WC_Order_item $item The order item object. + * @param string $item_key The order item meta key. + * @param string $item_value The order item value. + * @param boolean $convert Whether to convert or not. + * + * @throws Exception If $item is not an object of WC_Order_Item. + */ + public function update_meta_data( &$item = null, $item_key = '', $item_value = '', $convert = false ) { + if ( ! is_a( $item, 'WC_Order_Item' ) ) { + $error = __( '$item is not an object of WC_Order_Item', 'woocommerce-smart-coupons' ); + ob_start(); + esc_html_e( '$item is: ', 'woocommerce-smart-coupons' ) . ( is_scalar( $item ) ) ? var_dump( $item ) : print_r( gettype( $item ) ) . print_r( "\r\n" ); // phpcs:ignore + $this->log( 'notice', print_r( $error, true ) . ' ' . __FILE__ . ' ' . __LINE__ . print_r( "\r\n" . ob_get_clean(), true ) ); // phpcs:ignore + return false; + } + if ( in_array( $item_key, array( 'discount', 'discount_amount', 'discount_amount_tax', 'sc_refunded_discount', 'sc_refunded_discount_tax', 'sc_called_credit' ), true ) ) { + $item_id = ( is_callable( array( $item, 'get_id' ) ) ) ? $item->get_id() : 0; + $item_value = $this->get_item_value( $item_id, $item_value, $convert ); + if ( is_callable( array( $item, 'update_meta_data' ) ) ) { + $item->update_meta_data( $item_key, $item_value ); + } else { + $item[ $item_key ] = $item_value; + } + } + } + + /** + * Check & convert price + * + * @since 6.0.0 + * + * @param float $price The price need to be converted. + * @param string $to_currency The price will be converted to this currency. + * @param string $from_currency The price will be converted from this currency. + * @return float + */ + public function convert_price( $price = 0, $to_currency = null, $from_currency = null ) { + if ( ! function_exists( 'is_plugin_active' ) ) { + require_once ABSPATH . 'wp-admin/includes/plugin.php'; + } + if ( is_plugin_active( 'woocommerce-aelia-currencyswitcher/woocommerce-aelia-currencyswitcher.php' ) ) { + if ( ! class_exists( 'WC_SC_Aelia_CS_Compatibility' ) ) { + include_once 'compat/class-wc-sc-aelia-cs-compatibility.php'; + } + return WC_SC_Aelia_CS_Compatibility::get_instance()->convert_price( $price, $to_currency, $from_currency ); + } + + if ( is_plugin_active( 'woocommerce-payments/woocommerce-payments.php' ) ) { + + if ( ! class_exists( 'WC_SC_WooPayments_Compatibility' ) ) { + include_once 'compat/class-wc-sc-woopayments-compatibility.php'; + } + + return WC_SC_WooPayments_Compatibility::get_instance()->convert_price( $price, $to_currency, $from_currency ); + } + return $price; + } + + /** + * Callback function for array_walk to apply convert price on each element of array + * + * @param mixed $value The array element. + * @param mixed $key The array key. + * @param array $args The additional arguments. + */ + public function array_convert_price( &$value = null, $key = null, $args = null ) { + if ( ! is_null( $value ) && ! is_null( $key ) && ! is_null( $args ) ) { + $to_currency = ( ! empty( $args['to_currency'] ) ) ? $args['to_currency'] : ''; + $from_currency = ( ! empty( $args['from_currency'] ) ) ? $args['from_currency'] : ''; + if ( ! empty( $to_currency ) && ! empty( $from_currency ) ) { + $value = $this->convert_price( $value, $to_currency, $from_currency ); + } + } + } + + /** + * Get item value for saving/updating in DB considering currency + * + * @param integer $item_id The order item id. + * @param string $item_value The item value. + * @param boolean $convert Whether to convert or not. + * + * @throws Exception If $item is not passed. + * @return mixed + */ + public function get_item_value( $item_id = 0, $item_value = '', $convert = false ) { + if ( empty( $item_id ) ) { + $error = __( '$item_id is required', 'woocommerce-smart-coupons' ); + ob_start(); + esc_html_e( '$item_id is: ', 'woocommerce-smart-coupons' ) . ( is_scalar( $item_id ) ) ? var_dump( $item_id ) : print_r( gettype( $item_id ) ) . print_r( "\r\n" ); // phpcs:ignore + $this->log( 'notice', print_r( $error, true ) . ' ' . __FILE__ . ' ' . __LINE__ . print_r( "\r\n" . ob_get_clean(), true ) ); // phpcs:ignore + return null; + } + if ( $this->is_wc_gte_30() ) { + $order_id = ( ! empty( $item_id ) ) ? wc_get_order_id_by_order_item_id( $item_id ) : 0; + } else { + $order_id = ( ! empty( $item_id ) ) ? $this->get_order_id_by_order_item_id_wclt30( $item_id ) : 0; + } + $order = ( ! empty( $order_id ) ) ? wc_get_order( $order_id ) : null; + if ( true === $convert ) { + if ( $this->is_wc_gte_30() ) { + $order_currency = ( is_object( $order ) && is_callable( array( $order, 'get_currency' ) ) ) ? $order->get_currency() : ''; // phpcs:ignore + } else { + $order_currency = ( is_object( $order ) && is_callable( array( $order, 'get_order_currency' ) ) ) ? $order->get_order_currency() : ''; // phpcs:ignore + } + if ( ! empty( $order_currency ) ) { + $base_currency = get_option( 'woocommerce_currency' ); + if ( $base_currency !== $order_currency ) { + $item_value = $this->convert_price( $item_value, $base_currency, $order_currency ); + } + } + } + return apply_filters( + 'wc_sc_before_update_order_item_meta', + $item_value, + array( + 'source' => $this, + 'currency_conversion' => $convert, + 'order_obj' => $order, + 'order_item_id' => $item_id, + ) + ); + + } + + /** + * Get order id by order item id for WooCommerce version lower than 3.0.0 + * + * @param integer $item_id The order item id. + * @return mixed + */ + public function get_order_id_by_order_item_id_wclt30( $item_id = 0 ) { + global $wpdb; + return $wpdb->get_var( // phpcs:ignore + $wpdb->prepare( + "SELECT order_id + FROM {$wpdb->prefix}woocommerce_order_items + WHERE order_item_id = %d", + absint( $item_id ) + ) + ); + } + + /** + * Convert a date string to a WC_DateTime. + * + * Wrapper function to give support for store running WooCommerce 3.0.0. + * + * Credit: WooCommerce + * + * @since 6.3.0 + * @param string $time_string Time string. + * @return WC_DateTime + */ + public function wc_string_to_datetime( $time_string ) { + + if ( function_exists( 'wc_string_to_datetime' ) ) { + return wc_string_to_datetime( $time_string ); + } + + // Strings are defined in local WP timezone. Convert to UTC. + if ( 1 === preg_match( '/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(Z|((-|\+)\d{2}:\d{2}))$/', $time_string, $date_bits ) ) { + $offset = ! empty( $date_bits[7] ) ? iso8601_timezone_to_offset( $date_bits[7] ) : $this->wc_timezone_offset(); + $timestamp = gmmktime( $date_bits[4], $date_bits[5], $date_bits[6], $date_bits[2], $date_bits[3], $date_bits[1] ) - $offset; + } else { + $timestamp = wc_string_to_timestamp( get_gmt_from_date( gmdate( 'Y-m-d H:i:s', wc_string_to_timestamp( $time_string ) ) ) ); + } + $datetime = new WC_DateTime( "@{$timestamp}", new DateTimeZone( 'UTC' ) ); + + // Set local timezone or offset. + if ( get_option( 'timezone_string' ) ) { + $datetime->setTimezone( new DateTimeZone( wc_timezone_string() ) ); + } else { + $datetime->set_utc_offset( $this->wc_timezone_offset() ); + } + + return $datetime; + } + + /** + * Get timezone offset in seconds. + * + * Wrapper function for giving support to lower version of WooCommerce + * + * Credit: WooCommerce + * + * @since 6.3.0 + * @return float + */ + public function wc_timezone_offset() { + + if ( function_exists( 'wc_timezone_offset' ) ) { + return wc_timezone_offset(); + } + + $timezone = get_option( 'timezone_string' ); + + if ( $timezone ) { + $timezone_object = new DateTimeZone( $timezone ); + return $timezone_object->getOffset( new DateTime( 'now' ) ); + } else { + return floatval( get_option( 'gmt_offset', 0 ) ) * HOUR_IN_SECONDS; + } + } + + /** + * Get timestamp from date string + * + * @param string $date_string The date in string format. + * @return int + */ + public function wc_string_to_datetime_to_timestamp( $date_string = '' ) { + $timestamp = null; + if ( ! empty( $date_string ) ) { + $datetime = $this->wc_string_to_datetime( $date_string ); + $timestamp = ( is_object( $datetime ) && is_callable( array( $datetime, 'getTimestamp' ) ) ) ? $datetime->getTimestamp() : null; + } + return $timestamp; + } + + /** + * Maybe convert to correct value for meta 'date_expires' + * + * @param mixed $date_expires The current date_expires value. + * @return mixed + */ + public function get_date_expires_value( $date_expires = null ) { + $date_expires = intval( $date_expires ); + $date_expires = ( ! empty( $date_expires ) ) ? $date_expires : null; + return $date_expires; + } + + /** + * Converts a string (e.g. 'yes' or 'no') to a bool. + * + * Credit: WooCommerce + * + * @since 7.2.0 + * @param string|bool $string String to convert. If a bool is passed it will be returned as-is. + * @return bool + */ + public function wc_string_to_bool( $string ) { + + if ( function_exists( 'wc_string_to_bool' ) ) { + return wc_string_to_bool( $string ); + } + + return is_bool( $string ) ? $string : ( 'yes' === strtolower( $string ) || 1 === $string || 'true' === strtolower( $string ) || '1' === $string ); + } + + /** + * Converts a bool to a 'yes' or 'no'. + * + * Credit: WooCommerce + * + * @since 7.2.0 + * @param bool|string $bool Bool to convert. If a string is passed it will first be converted to a bool. + * @return string + */ + public function wc_bool_to_string( $bool ) { + + if ( function_exists( 'wc_bool_to_string' ) ) { + return wc_bool_to_string( $bool ); + } + + if ( ! is_bool( $bool ) ) { + $bool = $this->wc_string_to_bool( $bool ); + } + return true === $bool ? 'yes' : 'no'; + } + + /** + * Compatible function for mb_detect_encoding. + * + * (c) Fabien Potencier + * + * @author Nicolas Grekas + * + * @param string $string The string to be checked. + * @param mixed $encodings List of encoding. + * @param boolean $strict Strict checking or not. + * @return mixed + */ + public function mb_detect_encoding( $string, $encodings = null, $strict = false ) { + + if ( function_exists( 'mb_detect_encoding' ) ) { + return mb_detect_encoding( $string, $encodings, $strict ); + } + + if ( null === $encodings ) { + $encodings = array( 'ASCII', 'UTF-8' ); + } else { + if ( ! is_array( $encodings ) ) { + $encodings = array_map( 'trim', explode( ',', $encodings ) ); + } + $encodings = array_map( 'strtoupper', $encodings ); + } + + foreach ( $encodings as $enc ) { + switch ( $enc ) { + case 'ASCII': + if ( ! preg_match( '/[\x80-\xFF]/', $string ) ) { + return $enc; + } + break; + + case 'UTF8': + case 'UTF-8': + if ( preg_match( '//u', $string ) ) { + return 'UTF-8'; + } + break; + + default: + if ( 0 === strncmp( $enc, 'ISO-8859-', 9 ) ) { + return $enc; + } + } + } + + return false; + } + + /** + * Check if a method is callable w.r.t. given object or not + * + * @param mixed $object The object. + * @param string $method The method name. + * @return boolean + */ + public function is_callable( $object = null, $method = '' ) { + if ( empty( $object ) || empty( $method ) ) { + return false; + } + $type = gettype( $object ); + if ( ! in_array( $type, array( 'string', 'object' ), true ) ) { + return false; + } + if ( 'string' === $type && ! class_exists( $object ) ) { + return false; + } + return is_callable( array( $object, $method ) ); + } + + /** + * Wrapper function for checking if a coupon is valid for the cart. + * + * @param WC_Coupon $coupon The coupon object. + * @param WC_Cart|WC_Order $cart_or_order Cart or order object. + * @return bool + */ + public function is_valid( $coupon = null, $cart_or_order = null ) { + if ( is_null( $coupon ) ) { + return false; + } + if ( is_null( $cart_or_order ) ) { + $cart_or_order = WC()->cart; + } + $discounts = new WC_Discounts( $cart_or_order ); + $valid = $discounts->is_coupon_valid( $coupon ); + + if ( is_wp_error( $valid ) ) { + if ( $this->is_wc_greater_than( '8.8.1' ) && $this->is_callable( $coupon, 'set_error_message' ) && $this->is_callable( $valid, 'get_error_message' ) ) { + $coupon->set_error_message( $valid->get_error_message() ); + } + return false; + } + + return $valid; + } + + /** + * Generate link for filter by passed email + * + * @param string $email The email address. + * @return string $link + */ + public function filter_by_email_link( $email = '' ) { + $html = ''; + if ( ! empty( $email ) && is_email( $email ) ) { + $link = add_query_arg( + array( + 'post_type' => 'shop_coupon', + 'post_status' => 'all', + 's' => 'email:' . $email, + ), + admin_url( 'edit.php' ) + ); + /* translators: Email address of users */ + $html = '' . esc_html( $email ) . ''; + } + return $html; + } + + /** + * Get post by post_title + * + * @param array $titles The titles to be searched. + * @param constant $return_type The return type. + * @param array $post_types The post types to be considered for searching. + * @return array $posts Found posts + */ + public function get_post_by_title( $titles = array(), $return_type = OBJECT, $post_types = array() ) { + global $wpdb; + + $query = $wpdb->prepare( + "SELECT ID, post_title + FROM $wpdb->posts + WHERE %d", + 1 + ); + + if ( ! is_array( $titles ) ) { + $titles = array( $titles ); + } + + $how_many = count( $titles ); + $placeholders = array_fill( 0, $how_many, '%s' ); + + if ( ! empty( $how_many ) ) { + if ( $how_many > 1 ) { + $query .= $wpdb->prepare( + ' AND post_title IN (' . implode( ',', $placeholders ) . ')', // phpcs:ignore + $titles + ); + } else { + if ( is_array( $titles ) ) { + $titles = current( $titles ); + } + $query .= $wpdb->prepare( + ' AND post_title = %s', + $titles + ); + } + } + + if ( ! is_array( $post_types ) ) { + $post_types = array( $post_types ); + } + + $how_many = count( $post_types ); + $placeholders = array_fill( 0, $how_many, '%s' ); + + if ( ! empty( $how_many ) ) { + if ( $how_many > 1 ) { + $query .= $wpdb->prepare( + ' AND post_type IN (' . implode( ',', $placeholders ) . ')', // phpcs:ignore + $post_types + ); + } else { + if ( is_array( $post_types ) ) { + $post_types = current( $post_types ); + } + $query .= $wpdb->prepare( + ' AND post_type = %s', + $post_types + ); + } + } + + $results = $wpdb->get_results( $query, ARRAY_A ); // phpcs:ignore + + if ( ! is_wp_error( $results ) && ! empty( $results ) ) { + $id_to_post_titles = wp_list_pluck( $results, 'post_title', 'ID' ); + $id_to_title_slug = array_map( 'sanitize_title', $id_to_post_titles ); + $title_slug_to_id = array_flip( $id_to_title_slug ); + $title_slug_to_post = array(); + foreach ( $title_slug_to_id as $slug => $id ) { + if ( ! empty( $slug ) && ! empty( $id ) ) { + $title_slug_to_post[ $slug ] = get_post( $id, $return_type ); + } + } + return $title_slug_to_post; + } + + return null; + + } + + /** + * Wrapper function to get post type + * + * @param integer $post_id The post id. + * @return string|boolean + */ + public function get_post_type( $post_id = null ) { + if ( ! empty( $post_id ) && $this->is_hpos_order( $post_id ) ) { + return 'shop_order'; + } + return get_post_type( $post_id ); + } + + /** + * Function to check whether the order was created prior to version 8.0.0 or not. + * + * @param WC_Order|int $order The order to be checked. + * @return boolean + */ + public function is_old_sc_order( $order = null ) { + + if ( empty( $order ) || is_array( $order ) ) { + return false; + } + + $orders_prior_to_800 = $this->sc_get_option( 'wc_sc_old_orders_prior_to_800' ); + + if ( empty( $orders_prior_to_800 ) || 'no' === $orders_prior_to_800 ) { + return false; + } + + if ( is_a( $order, 'WC_Order' ) ) { + $order_id = $this->is_callable( $order, 'get_id' ) ? $order->get_id() : 0; + } else { + $order_id = $order; + } + $order_id = absint( $order_id ); + + $from_to_groups = array_chunk( $orders_prior_to_800, 2, true ); + + foreach ( $from_to_groups as $group ) { + $group = array_flip( $group ); + $from = ( ! empty( $group['from'] ) ) ? absint( $group['from'] ) : 0; + $to = ( ! empty( $group['to'] ) ) ? absint( $group['to'] ) : 0; + if ( $from <= $to && $order_id >= $from && $order_id <= $to ) { + return true; + } + } + + return false; + } + + /** + * Function to find & record orders that were created when Smart Coupons older than 8.0.0 was active & in which store credit was applied + */ + public function maybe_sync_orders_prior_to_800() { + $orders_prior_to_800 = $this->sc_get_option( 'wc_sc_old_orders_prior_to_800' ); + + if ( 'no' === $orders_prior_to_800 ) { + return; + } + + $args = array( + 'return' => 'ids', + 'orderby' => 'ID', + 'order' => 'ASC', + 'limit' => -1, + 'smart_coupons_contribution' => array( + 'value' => array( '', 'a:0:{}' ), + 'compare' => 'NOT IN', + ), + ); + $order_ids = wc_get_orders( $args ); + + if ( empty( $order_ids ) ) { + return; + } + + if ( ! is_array( $orders_prior_to_800 ) || empty( $orders_prior_to_800 ) ) { + $orders_prior_to_800 = array(); + if ( ! empty( $order_ids ) ) { + $from = min( $order_ids ); + $to = max( $order_ids ); + $orders_prior_to_800[ absint( $from ) ] = 'from'; + $orders_prior_to_800[ absint( $to ) ] = 'to'; + update_option( 'wc_sc_old_orders_prior_to_800', $orders_prior_to_800, 'no' ); + } + return; + } + + if ( ! empty( $orders_prior_to_800 ) ) { + krsort( $orders_prior_to_800, SORT_NUMERIC ); + } + + $last_800_order = array_search( '8.0.0', $orders_prior_to_800, true ); + $last_from_order = array_search( 'from', $orders_prior_to_800, true ); + $last_to_order = array_search( 'to', $orders_prior_to_800, true ); + $max = max( $last_800_order, $last_from_order, $last_to_order ); + + if ( ! array_key_exists( $max, $orders_prior_to_800 ) ) { + return; + } + + $status = $orders_prior_to_800[ $max ]; + $remaining = array_slice( $order_ids, ( array_search( $max, $order_ids, true ) + 1 ) ); + + if ( empty( $remaining ) ) { + return; + } + + switch ( $status ) { + case '8.0.0': + $from = min( $remaining ); + $to = max( $remaining ); + $orders_prior_to_800[ absint( $from ) ] = 'from'; + $orders_prior_to_800[ absint( $to ) ] = 'to'; + break; + case 'from': + $to = max( $remaining ); + $orders_prior_to_800[ absint( $to ) ] = 'to'; + break; + case 'to': + $to = max( $remaining ); + unset( $orders_prior_to_800[ $max ] ); + $orders_prior_to_800[ absint( $to ) ] = 'to'; + break; + } + + $orders_prior_to_800 = array_diff( $orders_prior_to_800, array( '8.0.0' ) ); + + ksort( $orders_prior_to_800, SORT_NUMERIC ); + + update_option( 'wc_sc_old_orders_prior_to_800', $orders_prior_to_800, 'no' ); + + } + + /** + * Function to be executed after the plugin is upgraded. + * + * @param object $upgrader The upgrader object. + * @param array $hook_extra Additional params. + */ + public function upgrader_process_complete( $upgrader = null, $hook_extra = array() ) { + if ( ! empty( $hook_extra['type'] ) && 'plugin' === $hook_extra['type'] + && ! empty( $upgrader->result['destination_name'] ) && 'woocommerce-smart-coupons' === $upgrader->result['destination_name'] + && isset( $upgrader->new_plugin_data['Woo'] ) && ! empty( $upgrader->new_plugin_data['Woo'] && '18729:05c45f2aa466106a466de4402fff9dde' === $upgrader->new_plugin_data['Woo'] ) + ) { + if ( $this->is_sc_gte( '8.0.0' ) ) { + $this->maybe_sync_orders_prior_to_800(); + } else { + $this->record_latest_800_order(); + } + } + } + + /** + * Add support for custom meta from Smart Coupons to search for Orders + * + * @param array $query The query. + * @param array $query_vars The query vars. + * @return array + */ + public function custom_meta_support_in_orders_query( $query = array(), $query_vars = array() ) { + if ( ! empty( $query_vars['smart_coupons_contribution'] ) ) { + $query['meta_query'][] = array( + 'key' => 'smart_coupons_contribution', + 'value' => array_map( 'esc_attr', $query_vars['smart_coupons_contribution']['value'] ), + 'compare' => esc_attr( $query_vars['smart_coupons_contribution']['compare'] ), + ); + } + return $query; + } + + /** + * Function to record latest order which was created when Smart Coupons 8.0.0+ was active & store credit was applied to the order. + */ + public function record_latest_800_order() { + $orders_prior_to_800 = $this->sc_get_option( 'wc_sc_old_orders_prior_to_800' ); + + if ( false !== $orders_prior_to_800 && 'no' !== $orders_prior_to_800 ) { + $args = array( + 'return' => 'ids', + 'orderby' => 'ID', + 'order' => 'DESC', + 'limit' => 1, + 'smart_coupons_contribution' => array( + 'value' => array( '', 'a:0:{}' ), + 'compare' => 'NOT IN', + ), + ); + if ( function_exists( 'wc_get_orders' ) ) { + $order_ids = wc_get_orders( $args ); + if ( ! empty( $order_ids ) ) { + $last_order_id = current( $order_ids ); + if ( ! is_array( $orders_prior_to_800 ) || empty( $orders_prior_to_800 ) ) { + $orders_prior_to_800 = array(); + } + if ( ! array_key_exists( $last_order_id, $orders_prior_to_800 ) ) { + $last_array_element = array( absint( $last_order_id ) => '8.0.0' ); + $orders_prior_to_800 = $orders_prior_to_800 + $last_array_element; + } + update_option( 'wc_sc_old_orders_prior_to_800', $orders_prior_to_800, 'no' ); + } + } + } + } + + /** + * Format order item meta added by Smart Coupons. + * + * @param array $formatted_metas Existsing metas. + * @param WC_Order_Item $order_item The order item. + * @return array + */ + public function format_sc_meta_data( $formatted_metas = array(), $order_item = null ) { + if ( ! empty( $formatted_metas ) ) { + $sc_metas_label = array( + '_wc_sc_product_source' => __( 'Added by coupon', 'woocommerce-smart-coupons' ), + ); + foreach ( $formatted_metas as $meta_id => $meta ) { + if ( ! empty( $meta->key ) && array_key_exists( $meta->key, $sc_metas_label ) ) { + switch ( $meta->key ) { + default: + $formatted_metas[ $meta_id ]->display_key = $sc_metas_label[ $meta->key ]; + break; + } + } + } + } + return $formatted_metas; + } + + /** + * Hide order item metas that are added by the Smart Coupons plugin. + * + * @param array $metas The existing metas. + * @return array + */ + public function hidden_order_itemmeta( $metas = array() ) { + if ( ! is_array( $metas ) || empty( $metas ) ) { + $metas = array(); + } + $sc_metas = array( + 'sc_called_credit', + 'sc_refunded_discount', + 'sc_refunded_discount_tax', + 'sc_refunded_user_id', + 'sc_refunded_timestamp', + 'sc_refunded_coupon_id', + 'sc_revoke_refunded_discount', + 'sc_revoke_refunded_discount_tax', + 'sc_revoke_refunded_user_id', + 'sc_revoke_refunded_timestamp', + 'sc_revoke_refunded_coupon_id', + ); + $intersect = array_intersect( $metas, $sc_metas ); + if ( count( $sc_metas ) !== count( $intersect ) ) { + $metas = array_merge( $metas, $sc_metas ); + $metas = array_filter( array_unique( $metas ) ); + } + return $metas; + } + + /** + * Register endpoint data to handle data from Send Coupon Form + */ + public function register_endpoint_data() { + require_once $this->get_plugin_directory( '/blocks/class-wc-sc-extend-store-endpoint.php' ); + if ( class_exists( 'Automattic\WooCommerce\StoreApi\StoreApi' ) && $this->is_callable( 'Automattic\WooCommerce\StoreApi\StoreApi', 'container' ) ) { + $storeapi_container = Automattic\WooCommerce\StoreApi\StoreApi::container(); + if ( $this->is_callable( $storeapi_container, 'get' ) && class_exists( 'Automattic\WooCommerce\StoreApi\Schemas\ExtendSchema' ) ) { + $store = $storeapi_container->get( Automattic\WooCommerce\StoreApi\Schemas\ExtendSchema::class ); + if ( is_callable( array( $store, 'register_endpoint_data' ) ) && class_exists( 'Automattic\WooCommerce\StoreApi\Schemas\V1\CheckoutSchema' ) ) { + $store->register_endpoint_data( + array( + 'endpoint' => CheckoutSchema::IDENTIFIER, + 'namespace' => 'woocommerce-smart-coupons', + 'schema_callback' => array( 'WC_SC_Extend_Store_Endpoint', 'extend_checkout_schema' ), + 'schema_type' => ARRAY_A, + ) + ); + } + } + } + } + + /** + * Save coupon receiver details that is entered in Send Coupon Form from the Checkout page, in the respective order + * + * @param \WC_Order $order The order object. + * @param \WP_REST_Request $request The REST request object. + */ + public function save_coupon_receiver_detail_in_order( \WC_Order $order, \WP_REST_Request $request ) { + $extensions = $request->get_param( 'extensions' ); + $send_coupon_data = ( is_array( $extensions['woocommerce-smart-coupons'] ) && ! empty( $extensions['woocommerce-smart-coupons'] ) ) ? $extensions['woocommerce-smart-coupons'] : array(); + $order_billing_email = ( is_a( $order, 'WC_Order' ) && $this->is_callable( $order, 'get_billing_email' ) ) ? $order->get_billing_email() : ''; + if ( ! empty( $send_coupon_data['is_gift'] ) ) { + $order->update_meta_data( 'is_gift', $send_coupon_data['is_gift'] ); + } + if ( ! empty( $send_coupon_data['wc_sc_schedule_gift_sending'] ) && 'later' === $send_coupon_data['wc_sc_schedule_gift_sending'] ) { + $order->update_meta_data( 'wc_sc_schedule_gift_sending', 'yes' ); + } + if ( ! empty( $send_coupon_data['send_to'] ) && 'many' === $send_coupon_data['send_to'] ) { + if ( isset( $send_coupon_data['gift_receiver_email']['0_0'] ) ) { + unset( $send_coupon_data['gift_receiver_email']['0_0'] ); + } + if ( isset( $send_coupon_data['gift_sending_timestamp']['0_0'] ) ) { + unset( $send_coupon_data['gift_sending_timestamp']['0_0'] ); + } + if ( isset( $send_coupon_data['gift_receiver_message']['0_0'] ) ) { + unset( $send_coupon_data['gift_receiver_message']['0_0'] ); + } + } + $send_to_one = ( empty( $send_coupon_data['send_to'] ) || 'many' !== $send_coupon_data['send_to'] ); + if ( ! empty( $send_coupon_data['gift_receiver_email'] ) ) { + $gift_receiver_email = array(); + if ( ! is_scalar( $send_coupon_data['gift_receiver_email'] ) ) { + foreach ( $send_coupon_data['gift_receiver_email'] as $key => $email ) { + list( $coupon_id, $index ) = explode( '_', $key ); + $coupon_id = ( ! empty( $coupon_id ) ) ? intval( $coupon_id ) : 0; + $index = ( ! empty( $index ) ) ? intval( $index ) : 0; + if ( empty( $gift_receiver_email[ $coupon_id ] ) || ! is_array( $gift_receiver_email[ $coupon_id ] ) ) { + $gift_receiver_email[ $coupon_id ] = array(); + } + if ( true === $send_to_one ) { + $gift_receiver_email[ $coupon_id ][ $index ] = ( ! empty( $send_coupon_data['gift_receiver_email']['0_0'] ) ) ? $send_coupon_data['gift_receiver_email']['0_0'] : $order_billing_email; + } else { + $gift_receiver_email[ $coupon_id ][ $index ] = ( ! empty( $email ) ) ? $email : $order_billing_email; + } + } + } + if ( ! empty( $gift_receiver_email ) ) { + $order->update_meta_data( 'gift_receiver_email', $gift_receiver_email ); + } + } + if ( ! empty( $send_coupon_data['gift_sending_timestamp'] ) ) { + $gift_sending_timestamp = array(); + if ( ! is_scalar( $send_coupon_data['gift_sending_timestamp'] ) ) { + foreach ( $send_coupon_data['gift_sending_timestamp'] as $key => $timestamp ) { + list( $coupon_id, $index ) = explode( '_', $key ); + $coupon_id = ( ! empty( $coupon_id ) ) ? intval( $coupon_id ) : 0; + $index = ( ! empty( $index ) ) ? intval( $index ) : 0; + if ( empty( $gift_sending_timestamp[ $coupon_id ] ) || ! is_array( $gift_sending_timestamp[ $coupon_id ] ) ) { + $gift_sending_timestamp[ $coupon_id ] = array(); + } + if ( true === $send_to_one ) { + $gift_sending_timestamp[ $coupon_id ][ $index ] = ( ! empty( $send_coupon_data['gift_sending_timestamp']['0_0'] ) ) ? $send_coupon_data['gift_sending_timestamp']['0_0'] : time(); + } else { + $gift_sending_timestamp[ $coupon_id ][ $index ] = $timestamp; + } + } + } + if ( ! empty( $gift_sending_timestamp ) ) { + $order->update_meta_data( 'gift_sending_timestamp', $gift_sending_timestamp ); + } + } + if ( ! empty( $send_coupon_data['gift_receiver_message'] ) ) { + $gift_receiver_message = array(); + if ( ! is_scalar( $send_coupon_data['gift_receiver_message'] ) ) { + foreach ( $send_coupon_data['gift_receiver_message'] as $key => $message ) { + list( $coupon_id, $index ) = explode( '_', $key ); + $coupon_id = ( ! empty( $coupon_id ) ) ? intval( $coupon_id ) : 0; + $index = ( ! empty( $index ) ) ? intval( $index ) : 0; + if ( empty( $gift_receiver_message[ $coupon_id ] ) || ! is_array( $gift_receiver_message[ $coupon_id ] ) ) { + $gift_receiver_message[ $coupon_id ] = array(); + } + if ( true === $send_to_one ) { + $gift_receiver_message[ $coupon_id ][ $index ] = ( ! empty( $send_coupon_data['gift_receiver_message']['0_0'] ) ) ? $send_coupon_data['gift_receiver_message']['0_0'] : ''; + } else { + $gift_receiver_message[ $coupon_id ][ $index ] = $message; + } + } + } + if ( ! empty( $gift_receiver_message ) ) { + $order->update_meta_data( 'gift_receiver_message', $gift_receiver_message ); + } + } + $order->save(); + } + + /** + * Check if the order has at least one product that can generate coupon + * + * @param WC_Order $order The order object. + * @return boolean + */ + public function would_order_generate_coupons( $order = null ) { + if ( empty( $order ) ) { + return false; + } + if ( ! is_a( $order, 'WC_Order' ) && is_numeric( $order ) ) { + $order = wc_get_order( absint( $order ) ); + } + $order_items = $this->is_callable( $order, 'get_items' ) ? $order->get_items() : array(); + if ( empty( $order_items ) || is_scalar( $order_items ) ) { + return false; + } + foreach ( $order_items as $item ) { + if ( $item->is_type( 'line_item' ) ) { + $product = $this->is_callable( $item, 'get_product' ) ? $item->get_product() : ( $this->is_callable( $order, 'get_product_from_item' ) ? $order->get_product_from_item( $item ) : null ); + if ( ! is_a( $product, 'WC_Product' ) ) { + continue; + } + $linked_coupons = $this->is_callable( $product, 'get_meta' ) ? $product->get_meta( '_coupon_title' ) : array(); + if ( empty( $linked_coupons ) && $this->is_callable( $product, 'is_type' ) && true === $product->is_type( 'variation' ) ) { + $parent_id = $this->is_callable( $product, 'get_parent_id' ) ? $product->get_parent_id() : 0; + if ( ! empty( $parent_id ) ) { + $product = wc_get_product( $parent_id ); + $linked_coupons = $this->is_callable( $product, 'get_meta' ) ? $product->get_meta( '_coupon_title' ) : array(); + } + } + if ( ! empty( $linked_coupons ) ) { + return true; + } + } + } + return false; + } + + /** + * Resend coupons for an order + * + * @param integer $order_id The order id. + */ + public function resend_coupons( $order_id = 0 ) { + + if ( empty( $order_id ) ) { + return; // TODO: Show admin notice that no coupons are generated hence can't send email. + } + + $order = wc_get_order( $order_id ); + + $is_callable_order_get_meta = is_object( $order ) && $this->is_callable( $order, 'get_meta' ); + $sc_coupon_receiver_details = ( true === $is_callable_order_get_meta ) ? $order->get_meta( 'sc_coupon_receiver_details' ) : array(); + + if ( empty( $sc_coupon_receiver_details ) ) { + return; // TODO: Show admin notice that no coupons are generated hence can't send email. + } + + $order_billing_email = ( is_object( $order ) && $this->is_callable( $order, 'get_billing_email' ) ) ? $order->get_billing_email() : ''; + $order_billing_first_name = ( is_object( $order ) && $this->is_callable( $order, 'get_billing_first_name' ) ) ? $order->get_billing_first_name() : ''; + $order_billing_last_name = ( is_object( $order ) && $this->is_callable( $order, 'get_billing_last_name' ) ) ? $order->get_billing_last_name() : ''; + + $is_gift = ( true === $is_callable_order_get_meta ) ? $order->get_meta( 'is_gift' ) : ''; + + $gift_certificate_sender_email = $order_billing_email; + $gift_certificate_sender_name = $order_billing_first_name . ' ' . $order_billing_last_name; + + $coupon_receiver_details = array(); + foreach ( $sc_coupon_receiver_details as $detail ) { + if ( empty( $detail['email'] ) || empty( $detail['code'] ) ) { + continue; + } + $email = $detail['email']; + if ( empty( $coupon_receiver_details[ $email ] ) || ! is_array( $coupon_receiver_details[ $email ] ) ) { + $coupon_receiver_details[ $email ] = array(); + } + $coupon_receiver_details[ $email ][] = $detail; + } + + if ( empty( $coupon_receiver_details ) ) { + return; // TODO: Show admin notice that no coupons are generated hence can't send email. + } + + $is_send_email = $this->is_email_template_enabled(); + $combine_emails = $this->is_email_template_enabled( 'combine' ); + + if ( 'yes' === $is_send_email ) { + WC()->mailer(); + foreach ( $coupon_receiver_details as $receiver_email => $receiver_details ) { + if ( 'yes' === $combine_emails ) { + if ( count( $receiver_details ) === 1 ) { + $coupon_code = ( ! empty( $receiver_details[0]['code'] ) ) ? $receiver_details[0]['code'] : ''; + $message_from_sender = ( ! empty( $receiver_details[0]['message'] ) ) ? $receiver_details[0]['message'] : ''; + + $coupon = new WC_Coupon( $coupon_code ); + $coupon_amount = $this->get_amount( $coupon, true, $order ); + $discount_type = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_discount_type' ) ) ) ? $coupon->get_discount_type() : ''; + + $coupon_detail = array( + 'amount' => $coupon_amount, + 'code' => $coupon_code, + ); + + $action_args = apply_filters( + 'wc_sc_email_coupon_notification_args', + array( + 'order_id' => $order_id, + 'email' => $receiver_email, + 'coupon' => $coupon_detail, + 'discount_type' => $discount_type, + 'receiver_name' => '', + 'message_from_sender' => $message_from_sender, + 'gift_certificate_sender_name' => $gift_certificate_sender_name, + 'gift_certificate_sender_email' => $gift_certificate_sender_email, + 'is_gift' => $is_gift, + ) + ); + // Trigger single email notification. + do_action( 'wc_sc_email_coupon_notification', $action_args ); + return; + } + + $action_args = apply_filters( + 'wc_sc_email_coupon_notification_args', + array( + 'order_id' => $order_id, + 'email' => $receiver_email, + 'receiver_details' => $receiver_details, + 'gift_certificate_sender_name' => $gift_certificate_sender_name, + 'gift_certificate_sender_email' => $gift_certificate_sender_email, + 'is_gift' => $is_gift, + ) + ); + + // Trigger combined email notification. + do_action( 'wc_sc_combined_email_coupon_notification', $action_args ); + } else { + foreach ( $receiver_details as $receiver_detail ) { + $coupon_code = ( ! empty( $receiver_detail['code'] ) ) ? $receiver_detail['code'] : ''; + $message_from_sender = ( ! empty( $receiver_detail['message'] ) ) ? $receiver_detail['message'] : ''; + + $coupon = new WC_Coupon( $coupon_code ); + $coupon_amount = $this->get_amount( $coupon, true, $order ); + $discount_type = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_discount_type' ) ) ) ? $coupon->get_discount_type() : ''; + + $coupon_detail = array( + 'amount' => $coupon_amount, + 'code' => $coupon_code, + ); + + $action_args = apply_filters( + 'wc_sc_email_coupon_notification_args', + array( + 'order_id' => $order_id, + 'email' => $receiver_email, + 'coupon' => $coupon_detail, + 'discount_type' => $discount_type, + 'receiver_name' => '', + 'message_from_sender' => $message_from_sender, + 'gift_certificate_sender_name' => $gift_certificate_sender_name, + 'gift_certificate_sender_email' => $gift_certificate_sender_email, + 'is_gift' => $is_gift, + ) + ); + // Trigger single email notification. + do_action( 'wc_sc_email_coupon_notification', $action_args ); + } + } + } + } + } + + /** + * Order action to ignore for email + * + * @return array + */ + public function order_actions_to_ignore_for_email() { + return apply_filters( + 'wc_sc_order_actions_to_ignore_for_email', + array( + 'woocommerce_order_action_wc_sc_regenerate_coupons', + ), + array( 'source' => $this ) + ); + } + + /** + * Get current version of the plugin. + * + * @return string + */ + public function get_version() { + if ( empty( $this->plugin_data ) ) { + $this->plugin_data = self::get_smart_coupons_plugin_data(); + } + return $this->plugin_data['Version']; + } + + /** + * Function to compare with current version of Smart Coupons + * + * @param string $version Version number to compare. + * @return bool + */ + public function is_sc_gte( $version ) { + return version_compare( $this->get_version(), $version, '>=' ); + } + + /** + * Get the url of path with respect to plugin. + * + * @param string $path The path. + * @return string + */ + public function get_plugin_directory_url( $path = '' ) { + return plugins_url( $path, WC_SC_PLUGIN_FILE ); + } + + /** + * Get the path with respect to plugin. + * + * @param string $path The path. + * @return string + */ + public function get_plugin_directory( $path = '' ) { + return plugin_dir_path( WC_SC_PLUGIN_FILE ) . trim( $path, '/' ); + } + + /** + * Function to compare with current version of PHP + * + * @param string $version Version number to compare. + * @return boolean + */ + public function is_php_gte( $version ) { + return version_compare( PHP_VERSION, $version, '>=' ); + } + + /** + * Function to check if the passed id is of an order or not + * + * @param integer $post_id The post id. + * @return boolean + */ + public function is_hpos_order( $post_id = 0 ) { + if ( ! empty( $post_id ) && is_numeric( $post_id ) && $this->is_hpos() && $this->is_callable( '\Automattic\WooCommerce\Utilities\OrderUtil', 'is_order' ) ) { + return \Automattic\WooCommerce\Utilities\OrderUtil::is_order( $post_id, wc_get_order_types() ); + } + return false; + } + + /** + * Wrapper function to check if HPOS is enabled or not + * + * @return boolean + */ + public function is_hpos() { + if ( class_exists( '\Automattic\WooCommerce\Utilities\OrderUtil' ) && $this->is_callable( '\Automattic\WooCommerce\Utilities\OrderUtil', 'custom_orders_table_usage_is_enabled' ) ) { + return \Automattic\WooCommerce\Utilities\OrderUtil::custom_orders_table_usage_is_enabled(); + } + return false; + } + + /** + * Function to declare WooCommerce HPOS related compatibility status + */ + public function hpos_compat_declaration() { + if ( class_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) ) { + \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', 'woocommerce-smart-coupons/woocommerce-smart-coupons.php', true ); + } + } + + /** + * Function to declare WooCommerce Blocks related compatibility status + */ + public function blocks_compat_declaration() { + if ( class_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) ) { + \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'cart_checkout_blocks', 'woocommerce-smart-coupons/woocommerce-smart-coupons.php', true ); + } + } + + /** + * Removes a coupon when the corresponding cart item is removed. + * + * @param string $removed_cart_item_key The key of the removed cart item. + * @param WC_Cart $cart The cart array containing cart item data. + * @return void + */ + public function sc_remove_coupon_with_cart_item( $removed_cart_item_key, $cart ) { + if ( is_admin() ) { + return; + } + + if ( $removed_cart_item_key && isset( $cart->removed_cart_contents[ $removed_cart_item_key ]['wc_sc_product_source'] ) ) { + $coupon_code = $cart->removed_cart_contents[ $removed_cart_item_key ]['wc_sc_product_source']; + if ( ! empty( $coupon_code ) && WC()->cart->has_discount( $coupon_code ) ) { + WC()->cart->remove_coupon( $coupon_code ); + } + } + } + }//end class + +} // End class exists check diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/compat/class-sa-wc-compatibility-4-4.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/compat/class-sa-wc-compatibility-4-4.php new file mode 100644 index 00000000..351cb808 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/compat/class-sa-wc-compatibility-4-4.php @@ -0,0 +1,203 @@ +' ); + } + + } + +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/compat/class-sa-wc-compatibility-8-7.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/compat/class-sa-wc-compatibility-8-7.php new file mode 100644 index 00000000..690ee58a --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/compat/class-sa-wc-compatibility-8-7.php @@ -0,0 +1,33 @@ + $this ) ); + add_action( $form_position_hook, array( $wc_sc_purchase_credit, 'gift_certificate_receiver_detail_form' ) ); + } + add_action( 'wp_footer', array( $this, 'enqueue_styles_scripts' ), 99 ); + } + } + + /** + * Get single instance of WC_SC_KCO_Compatibility + * + * @return WC_SC_KCO_Compatibility Singleton object of WC_SC_KCO_Compatibility + */ + public static function get_instance() { + // Check if instance is already exists. + if ( is_null( self::$instance ) ) { + self::$instance = new self(); + } + + return self::$instance; + } + + /** + * Handle call to functions which is not available in this class + * + * @param string $function_name Function to call. + * @param array $arguments Array of arguments passed while calling $function_name. + * @return mixed Result of function call. + */ + public function __call( $function_name, $arguments = array() ) { + + global $woocommerce_smart_coupon; + + if ( ! is_callable( array( $woocommerce_smart_coupon, $function_name ) ) ) { + return; + } + + if ( ! empty( $arguments ) ) { + return call_user_func_array( array( $woocommerce_smart_coupon, $function_name ), $arguments ); + } else { + return call_user_func( array( $woocommerce_smart_coupon, $function_name ) ); + } + } + + /** + * Enqueue required styles/scripts for store credit frontend form + */ + public function enqueue_styles_scripts() { + + // Return if gift certificate form is not shown. + if ( ! did_action( 'wc_sc_gift_certificate_form_shown' ) ) { + return; + } + + if ( ! wp_script_is( 'jquery' ) ) { + wp_enqueue_script( 'jquery' ); + } + + ?> + + get_currency() : false; + $price = wmc_get_price( $price, $currency ); + } + return $price; + } + + /** + * Function to modify the value of the credit called + * + * @param mized $price The price. + * @param array $args Additional arguments. + * @return mized + */ + public function credit_called_price_cart( $price = 0, $args = array() ) { + if ( function_exists( 'wmc_get_price' ) ) { + $price = wmc_get_price( $price ); + } + return $price; + } + + } + +} + +WC_SC_WMC_Compatibility::get_instance(); diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/compat/class-wc-sc-woopayments-compatibility.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/compat/class-wc-sc-woopayments-compatibility.php new file mode 100644 index 00000000..9dbe8c5c --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/compat/class-wc-sc-woopayments-compatibility.php @@ -0,0 +1,137 @@ +get_raw_conversion( $price, $to_currency, $from_currency ); + if ( ! empty( $price ) && is_float( $price ) ) { + $price = wc_round_tax_total( $price, 4 ); + } + } + } + return $price; + } + /** + * Check if product price should be convert or not + * + * @param bool $should_convert should convert or not. + * @param object $product instance of the product. + * @return float + */ + public function should_convert_product_price( $should_convert = true, $product = null ) { + + global $woocommerce_smart_coupon; + if ( ! $product instanceof WC_Product ) { + return $should_convert; + } + + $coupons = $woocommerce_smart_coupon->get_coupon_titles( array( 'product_object' => $product ) ); + if ( ! empty( $coupons ) && $woocommerce_smart_coupon->is_coupon_amount_pick_from_product_price( $coupons ) ) { + + foreach ( $coupons as $coupon_title ) { + $coupon_of_product = new WC_Coupon( $coupon_title ); + $discount_type_of_product = ( is_object( $coupon_of_product ) && is_callable( array( $coupon_of_product, 'get_discount_type' ) ) ) ? $coupon_of_product->get_discount_type() : ''; + if ( 'smart_coupon' === $discount_type_of_product ) { + return false; + } + } + } + + return $should_convert; + } + + + } + +} + +WC_SC_WooPayments_Compatibility::get_instance(); diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/compat/class-wc-sc-wpml-compatibility.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/compat/class-wc-sc-wpml-compatibility.php new file mode 100644 index 00000000..e5dede3c --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/compat/class-wc-sc-wpml-compatibility.php @@ -0,0 +1,72 @@ +products ) && has_action( 'woocommerce_before_checkout_process', array( $woocommerce_wpml->products, 'wcml_refresh_cart_total' ) ) ) { + remove_action( 'woocommerce_before_checkout_process', array( $woocommerce_wpml->products, 'wcml_refresh_cart_total' ) ); + } + if ( ! empty( $woocommerce_wpml->cart ) && has_action( 'woocommerce_before_checkout_process', array( $woocommerce_wpml->cart, 'wcml_refresh_cart_total' ) ) ) { + remove_action( 'woocommerce_before_checkout_process', array( $woocommerce_wpml->cart, 'wcml_refresh_cart_total' ) ); + } + } + } + + } + +} + +WC_SC_WPML_Compatibility::get_instance(); diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/compat/class-wc-sc-wscp-compatibility.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/compat/class-wc-sc-wscp-compatibility.php new file mode 100644 index 00000000..6c348eb4 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/compat/class-wc-sc-wscp-compatibility.php @@ -0,0 +1,103 @@ +gift_certificate_receiver_detail_form(); + $fragments['wc_sc_receiver_detail_form'] = ob_get_clean(); + + return $fragments; + } + + /** + * Add Styles And Scripts + */ + public function add_styles_and_scripts() { + if ( ! class_exists( 'WC_SC_Purchase_Credit' ) ) { + include_once '../class-wc-sc-purchase-credit.php'; + } + $wc_sc_purchase_credit = WC_SC_Purchase_Credit::get_instance(); + $wc_sc_purchase_credit->enqueue_timepicker(); + add_action( 'wp_footer', array( $this, 'styles_and_scripts' ) ); + } + + /** + * Styles And Scripts + */ + public function styles_and_scripts() { + if ( ! wp_script_is( 'jquery' ) ) { + wp_enqueue_script( 'jquery' ); + } + ?> + + is_wc_gte_30() ) { + $subscription_parent_order = $subscription->get_parent(); + $original_order_id = ( is_object( $subscription_parent_order ) && is_callable( array( $subscription_parent_order, 'get_id' ) ) ) ? $subscription_parent_order->get_id() : 0; + } else { + $original_order_id = ( ! empty( $subscription->order->id ) ) ? $subscription->order->id : 0; + } + + if ( empty( $original_order_id ) ) { + return $subscription; + } + + $renewal_total = $subscription->get_total(); + $original_order = wc_get_order( $original_order_id ); + $coupon_used_in_original_order = $this->get_coupon_codes( $original_order ); + + if ( $this->is_wc_gte_30() ) { + $order_payment_method = $original_order->get_payment_method(); + } else { + $order_payment_method = ( ! empty( $original_order->payment_method ) ) ? $original_order->payment_method : 0; + } + + if ( count( $coupon_used_in_original_order ) > 0 ) { + foreach ( $coupon_used_in_original_order as $coupon_code ) { + $coupon = new WC_Coupon( $coupon_code ); + if ( $this->is_wc_gte_30() ) { + $discount_type = $coupon->get_discount_type(); + } else { + $discount_type = ( ! empty( $coupon->discount_type ) ) ? $coupon->discount_type : ''; + } + $coupon_amount = $this->get_amount( $coupon, true, $original_order ); + if ( ! empty( $discount_type ) && 'smart_coupon' === $discount_type && ! empty( $coupon_amount ) ) { + if ( $coupon_amount >= $renewal_total ) { + $subscription->set_payment_method( '' ); + } else { + $payment_gateways = WC()->payment_gateways->get_available_payment_gateways(); + if ( ! empty( $payment_gateways[ $order_payment_method ] ) ) { + $payment_method = $payment_gateways[ $order_payment_method ]; + $subscription->set_payment_method( $payment_method ); + } + } + } + } + } + } + + return $subscription; + } + + /** + * Function to add meta which is necessary for coupon processing, in order + * + * @param array $meta Order meta. + * @param WC_Order $to_order Order to copy meta to. + * @param WC_Order $from_order Order to copy meta from. + * @return array $meta + */ + public function sc_wcs_renewal_order_meta( $meta = array(), $to_order = null, $from_order = null ) { + + if ( $this->is_wc_gte_30() ) { + $order = $from_order->get_parent(); + $order_id = ( is_object( $order ) && is_callable( array( $order, 'get_id' ) ) ) ? $order->get_id() : 0; + } else { + $order = $from_order->order; + $order_id = ( ! empty( $order->id ) ) ? $order->id : 0; + } + + if ( empty( $order_id ) ) { + return $meta; + } + + $is_callable_order_get_meta = $this->is_callable( $order, 'get_meta' ); + + $meta_exists = array( + 'coupon_sent' => false, + 'gift_receiver_email' => false, + 'gift_receiver_message' => false, + 'sc_called_credit_details' => false, + 'smart_coupons_contribution' => false, + ); + + foreach ( $meta as $index => $data ) { + if ( $this->is_wcs_gte( '2.2.0' ) ) { + if ( is_object( $data ) ) { + $data = (array) $data; + } + $meta_key = ''; + if ( $this->is_wcs_gte( '4.7.0' ) ) { + $meta_key = $index; + } elseif ( is_array( $data ) && ! empty( $data['meta_key'] ) ) { + $meta_key = $data['meta_key']; + } + + if ( ! empty( $meta_key ) ) { + $unprefixed_key = ( wcs_maybe_prefix_key( $meta_key ) === $meta_key ) ? substr( $meta_key, 1 ) : $meta_key; + if ( array_key_exists( $unprefixed_key, $meta_exists ) ) { + unset( $meta[ $meta_key ] ); + } + } + } else { + if ( ! empty( $data['meta_key'] ) && array_key_exists( $data['meta_key'], $meta_exists ) ) { + $meta_exists[ $data['meta_key'] ] = true; // phpcs:ignore + } + } + } + + foreach ( $meta_exists as $key => $value ) { + if ( $value ) { + continue; + } + $meta_value = ( true === $is_callable_order_get_meta ) ? $order->get_meta( $key ) : get_post_meta( $order_id, $key, true ); + + if ( empty( $meta_value ) ) { + continue; + } + + if ( $this->is_wcs_gte( '2.2.0' ) ) { + $renewal_order_id = ( $this->is_callable( $to_order, 'get_id' ) ) ? $to_order->get_id() : 0; + $is_callable_to_order_update_meta = $this->is_callable( $to_order, 'update_meta_data' ); + if ( 'coupon_sent' === $key ) { + // No need to update meta 'coupon_sent' as it's being updated by function sc_modify_renewal_order in this class. + continue; + } elseif ( 'smart_coupons_contribution' === $key ) { + if ( true === $is_callable_to_order_update_meta ) { + $to_order->update_meta_data( $key, array() ); + } else { + update_post_meta( $renewal_order_id, $key, array() ); + } + } else { + if ( true === $is_callable_to_order_update_meta ) { + $to_order->update_meta_data( $key, $meta_value ); + } else { + update_post_meta( $renewal_order_id, $key, $meta_value ); + } + } + } else { + if ( ! isset( $meta ) || ! is_array( $meta ) ) { + $meta = array(); + } + $meta[] = array( + 'meta_key' => $key, // phpcs:ignore + 'meta_value' => $meta_value, // phpcs:ignore + ); + } + } + + return $meta; + } + + /** + * Function to modify renewal order meta + * + * @param WC_Order $renewal_order Order created on subscription renewal. + * @param WC_Subscription $subscription Subscription we're basing the order off of. + * @return WC_Order $renewal_order + */ + public function sc_wcs_modify_renewal_order_meta( $renewal_order = null, $subscription = null ) { + global $wpdb; + + if ( $this->is_wc_gte_30() ) { + $renewal_order_id = ( is_object( $renewal_order ) && is_callable( array( $renewal_order, 'get_id' ) ) ) ? $renewal_order->get_id() : 0; + } else { + $renewal_order_id = ( ! empty( $renewal_order->id ) ) ? $renewal_order->id : 0; + } + + if ( empty( $renewal_order_id ) ) { + return $renewal_order; + } + + $sc_called_credit_details = $this->get_post_meta( $renewal_order_id, 'sc_called_credit_details', true, true, $renewal_order ); + if ( empty( $sc_called_credit_details ) ) { + return $renewal_order; + } + + $old_order_item_ids = ( ! empty( $sc_called_credit_details ) ) ? array_keys( $sc_called_credit_details ) : array(); + + if ( ! empty( $old_order_item_ids ) ) { + + $old_order_item_ids = array_map( 'absint', $old_order_item_ids ); + + $meta_keys = array( '_variation_id', '_product_id' ); + $how_many = count( $old_order_item_ids ); + $placeholder = array_fill( 0, $how_many, '%d' ); + + $meta_keys = esc_sql( $meta_keys ); + + // @codingStandardsIgnoreStart. + $query_to_fetch_product_ids = $wpdb->prepare( + "SELECT woim.order_item_id, + (CASE + WHEN woim.meta_key = %s AND woim.meta_value > 0 THEN woim.meta_value + WHEN woim.meta_key = %s AND woim.meta_value > 0 THEN woim.meta_value + END) AS product_id + FROM {$wpdb->prefix}woocommerce_order_itemmeta AS woim + WHERE woim.order_item_id IN ( " . implode( ',', $placeholder ) . " ) + AND woim.meta_key IN ( %s, %s ) + GROUP BY woim.order_item_id", + array_merge( $meta_keys, $old_order_item_ids, array_reverse( $meta_keys ) ) + ); + // @codingStandardsIgnoreEnd. + + $product_ids_results = $wpdb->get_results( $query_to_fetch_product_ids, ARRAY_A ); // phpcs:ignore + + if ( ! is_wp_error( $product_ids_results ) && ! empty( $product_ids_results ) ) { + $product_to_old_item = array(); + foreach ( $product_ids_results as $result ) { + $product_to_old_item[ $result['product_id'] ] = $result['order_item_id']; + } + + $found_product_ids = ( ! empty( $product_to_old_item ) ) ? $product_to_old_item : array(); + + $query_to_fetch_new_order_item_ids = $wpdb->prepare( + "SELECT woim.order_item_id, + (CASE + WHEN woim.meta_value > 0 THEN woim.meta_value + END) AS product_id + FROM {$wpdb->prefix}woocommerce_order_items AS woi + LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS woim + ON (woim.order_item_id = woi.order_item_id AND woim.meta_key IN ( %s, %s )) + WHERE woi.order_id = %d + AND woim.order_item_id IS NOT NULL + GROUP BY woim.order_item_id", + '_product_id', + '_variation_id', + $renewal_order_id + ); + + $new_order_item_ids_result = $wpdb->get_results( $query_to_fetch_new_order_item_ids, ARRAY_A ); // phpcs:ignore + + if ( ! is_wp_error( $new_order_item_ids_result ) && ! empty( $new_order_item_ids_result ) ) { + $product_to_new_item = array(); + foreach ( $new_order_item_ids_result as $result ) { + $product_to_new_item[ $result['product_id'] ] = $result['order_item_id']; + } + } + } + } + foreach ( $sc_called_credit_details as $item_id => $credit_amount ) { + $product_id = array_search( $item_id, $product_to_old_item, true ); + if ( false !== $product_id ) { + $sc_called_credit_details[ $product_to_new_item[ $product_id ] ] = $credit_amount; + unset( $sc_called_credit_details[ $product_to_old_item[ $product_id ] ] ); + } + } + + $this->update_post_meta( $renewal_order_id, 'sc_called_credit_details', $sc_called_credit_details, true, $renewal_order ); + return $renewal_order; + } + + /** + * New function to handle auto generation of coupon from renewal orders (WCS 2.0+) + * + * @param array $order_items Order items. + * @param WC_Order $renewal_order Order created on subscription renewal. + * @param WC_Subscription $subscription Subscription we're basing the order off of. + * @return array $order_items + */ + public function sc_wcs_modify_renewal_order( $order_items = null, $renewal_order = null, $subscription = null ) { + + if ( $this->is_wc_gte_30() ) { + $subscription_parent_order = $subscription->get_parent(); + $subscription_order_id = ( is_object( $subscription_parent_order ) && is_callable( array( $subscription_parent_order, 'get_id' ) ) ) ? $subscription_parent_order->get_id() : 0; + $renewal_order_id = ( is_callable( array( $renewal_order, 'get_id' ) ) ) ? $renewal_order->get_id() : 0; + } else { + $subscription_order_id = ( ! empty( $subscription->order->id ) ) ? $subscription->order->id : 0; + $renewal_order_id = ( ! empty( $renewal_order->id ) ) ? $renewal_order->id : 0; + } + + $order_items = $this->sc_modify_renewal_order( $order_items, $subscription_order_id, $renewal_order_id ); + return $order_items; + } + + /** + * New function to modify order_items of renewal order (WCS 2.0+) + * + * @param array $order_items Order items. + * @param WC_Order $renewal_order Order created on subscription renewal. + * @param WC_Subscription $subscription Subscription we're basing the order off of. + * @return array $order_items + */ + public function sc_wcs_renewal_order_items( $order_items = null, $renewal_order = null, $subscription = null ) { + + if ( $this->is_wc_gte_30() ) { + $subscription_parent_order = $subscription->get_parent(); + $subscription_order_id = ( is_object( $subscription_parent_order ) && is_callable( array( $subscription_parent_order, 'get_id' ) ) ) ? $subscription_parent_order->get_id() : 0; + $renewal_order_id = ( is_callable( array( $renewal_order, 'get_id' ) ) ) ? $renewal_order->get_id() : 0; + } else { + $subscription_order_id = ( ! empty( $subscription->order->id ) ) ? $subscription->order->id : 0; + $renewal_order_id = ( ! empty( $renewal_order->id ) ) ? $renewal_order->id : 0; + } + + $order_items = $this->sc_subscriptions_renewal_order_items( $order_items, $subscription_order_id, $renewal_order_id, 0, 'child' ); + return $order_items; + } + + /** + * New function to mark payment complete for renewal order (WCS 2.0+) + * + * @param WC_Order $renewal_order Order object. + * @param WC_Subscription $subscription Subscription we're basing the order off of. + * @return WC_Order $renewal_order + */ + public function sc_wcs_renewal_complete_payment( $renewal_order = null, $subscription = null ) { + $this->sc_renewal_complete_payment( $renewal_order ); + return $renewal_order; + } + + /** + * Function to save Smart Coupon's contribution in discount + * + * @param int $order_id Order ID. + */ + public function smart_coupons_contribution( $order_id = 0 ) { + + if ( did_action( 'woocommerce_update_order' ) > 1 ) { + return; + } + + if ( self::is_wcs_gte( '2.0.0' ) ) { + $is_renewal_order = wcs_order_contains_renewal( $order_id ); + } else { + $is_renewal_order = WC_Subscriptions_Renewal_Order::is_renewal( $order_id ); + } + + if ( ! $is_renewal_order ) { + return; + } + + $applied_coupons = ( is_object( WC()->cart ) && isset( WC()->cart->applied_coupons ) ) ? WC()->cart->applied_coupons : array(); + + if ( ! empty( $applied_coupons ) ) { + + $order_id = absint( $order_id ); + $order = ( function_exists( 'wc_get_order' ) ) ? wc_get_order( $order_id ) : null; + + foreach ( $applied_coupons as $code ) { + + $smart_coupon = new WC_Coupon( $code ); + + if ( $this->is_wc_gte_30() ) { + $discount_type = $smart_coupon->get_discount_type(); + } else { + $discount_type = ( ! empty( $smart_coupon->discount_type ) ) ? $smart_coupon->discount_type : ''; + } + + if ( 'smart_coupon' === $discount_type ) { + + $smart_coupon_credit_used = ( $this->is_callable( $order, 'get_meta' ) ) ? $order->get_meta( 'smart_coupons_contribution' ) : $this->get_post_meta( $order_id, 'smart_coupons_contribution', true, true ); + + $cart_smart_coupon_credit_used = WC()->cart->smart_coupon_credit_used; + + $update = false; + + if ( ! empty( $smart_coupon_credit_used ) ) { + if ( ! empty( $cart_smart_coupon_credit_used ) ) { + foreach ( $cart_smart_coupon_credit_used as $code => $amount ) { + $smart_coupon_credit_used[ $code ] = $amount; + $update = true; + } + } + } else { + $smart_coupon_credit_used = $cart_smart_coupon_credit_used; + $update = true; + } + + if ( $update ) { + if ( $this->is_callable( $order, 'update_meta_data' ) ) { + $order->update_meta_data( 'smart_coupons_contribution', $smart_coupon_credit_used ); + } else { + $this->update_post_meta( $order_id, 'smart_coupons_contribution', $smart_coupon_credit_used, true, $order ); + } + } + } + } + } + } + + /** + * Get first order of a subscription to which the supplied order belongs + * + * @param integer $order_id The order id. + * @return integer + */ + public function get_first_order_id( $order_id = 0 ) { + if ( self::is_wcs_gte( '2.0.0' ) && ! empty( $order_id ) ) { + $subscriptions = wcs_get_subscriptions_for_order( $order_id ); + $related_order_ids = ( is_object( $subscriptions ) && is_callable( array( $subscriptions, 'get_related_order_ids' ) ) ) ? $subscriptions->get_related_order_ids() : array(); + $related_order_ids = array_filter( $related_order_ids ); + if ( ! empty( $related_order_ids ) ) { + sort( $related_order_ids, SORT_NUMERIC ); + reset( $related_order_ids ); + return current( $related_order_ids ); + } + } + return 0; + } + + /** + * Set 'coupon_sent' as 'no' for renewal order to allow auto generation of coupons (if applicable) + * + * @param array $order_items Associative array of order items. + * @param int $original_order_id Post ID of the order being used to purchased the subscription being renewed. + * @param int $renewal_order_id Post ID of the order created for renewing the subscription. + * @param int $product_id ID of the product being renewed. + * @param string $new_order_role The role the renewal order is taking, one of 'parent' or 'child'. + * @return array $order_items + */ + public function sc_modify_renewal_order( $order_items = null, $original_order_id = 0, $renewal_order_id = 0, $product_id = 0, $new_order_role = null ) { + + if ( empty( $original_order_id ) && empty( $renewal_order_id ) ) { + return $order_items; + } + + if ( empty( $original_order_id ) ) { + $original_order_id = $this->get_first_order_id( $renewal_order_id ); + if ( empty( $original_order_id ) ) { + return $order_items; + } + } + + if ( self::is_wcs_gte( '2.0.0' ) ) { + $is_subscription_order = wcs_order_contains_subscription( $original_order_id ); + } else { + $is_subscription_order = WC_Subscriptions_Order::order_contains_subscription( $original_order_id ); + } + if ( $is_subscription_order ) { + $return = false; + } else { + $return = true; + } + if ( $return ) { + return $order_items; + } + + $is_recursive = false; + if ( ! empty( $order_items ) ) { + foreach ( $order_items as $order_item ) { + $send_coupons_on_renewals = 'no'; + $item_product_id = ( $this->is_callable( $order_item, 'get_product_id' ) ) ? $order_item->get_product_id() : $order_item['product_id']; + $item_variation_id = ( $this->is_callable( $order_item, 'get_variation_id' ) ) ? $order_item->get_variation_id() : $order_item['variation_id']; + $item_product = ( ! empty( $item_product_id ) && function_exists( 'wc_get_product' ) ) ? wc_get_product( $item_product_id ) : null; + $item_variation = ( ! empty( $item_variation_id ) && function_exists( 'wc_get_product' ) ) ? wc_get_product( $item_variation_id ) : null; + $is_callable_item_product_get_meta = $this->is_callable( $item_product, 'get_meta' ); + $is_callable_item_variation_get_meta = $this->is_callable( $item_variation, 'get_meta' ); + if ( ! empty( $item_variation_id ) ) { + $coupon_titles = ( true === $is_callable_item_variation_get_meta ) ? $item_variation->get_meta( '_coupon_title' ) : get_post_meta( $item_variation_id, '_coupon_title', true ); + if ( empty( $coupon_titles ) ) { + $send_coupons_on_renewals = ( true === $is_callable_item_product_get_meta ) ? $item_product->get_meta( 'send_coupons_on_renewals' ) : get_post_meta( $item_product_id, 'send_coupons_on_renewals', true ); + } else { + $send_coupons_on_renewals = ( true === $is_callable_item_variation_get_meta ) ? $item_variation->get_meta( 'send_coupons_on_renewals' ) : get_post_meta( $item_variation_id, 'send_coupons_on_renewals', true ); + } + } elseif ( ! empty( $item_product_id ) ) { + $send_coupons_on_renewals = ( true === $is_callable_item_product_get_meta ) ? $item_product->get_meta( 'send_coupons_on_renewals' ) : get_post_meta( $item_product_id, 'send_coupons_on_renewals', true ); + } else { + continue; + } + if ( 'yes' === $send_coupons_on_renewals ) { + $is_recursive = true; + break; // if in any order item recursive is enabled, it will set coupon_sent as 'no'. + } + } + } + $renewal_order_id = absint( $renewal_order_id ); + $renewal_order = ( ! empty( $renewal_order_id ) && function_exists( 'wc_get_order' ) ) ? wc_get_order( $renewal_order_id ) : null; + $is_callable_renewal_order_update_meta = $this->is_callable( $renewal_order, 'update_meta_data' ); + + $stop_recursive_coupon_generation = get_option( 'stop_recursive_coupon_generation', 'no' ); + if ( ( empty( $stop_recursive_coupon_generation ) || 'no' === $stop_recursive_coupon_generation ) && $is_recursive ) { + if ( true === $is_callable_renewal_order_update_meta ) { + $renewal_order->update_meta_data( 'coupon_sent', 'no' ); + } else { + update_post_meta( $renewal_order_id, 'coupon_sent', 'no' ); + } + } else { + if ( true === $is_callable_renewal_order_update_meta ) { + $renewal_order->update_meta_data( 'coupon_sent', 'yes' ); + } else { + update_post_meta( $renewal_order_id, 'coupon_sent', 'yes' ); + } + } + + if ( $this->is_callable( $renewal_order, 'save' ) ) { + $renewal_order->save(); + } + + return $order_items; + } + + /** + * Get order item subtotal + * + * @param WC_Order_Item_Product $order_item The order item. + * @return mixed + */ + public function sc_get_order_item_subtotal( $order_item = null ) { + if ( is_object( $order_item ) && is_callable( array( $order_item, 'get_total' ) ) ) { + return $order_item->get_total(); + } + return floatval( 0 ); + } + + /** + * Function to modify order_items of renewal order + * + * @param array $order_items Associative array of order items. + * @param int $original_order_id Post ID of the order being used to purchased the subscription being renewed. + * @param int $renewal_order_id Post ID of the order created for renewing the subscription. + * @param int $product_id ID of the product being renewed. + * @param string $new_order_role The role the renewal order is taking, one of 'parent' or 'child'. + * @return array $order_items + */ + public function sc_subscriptions_renewal_order_items( $order_items = null, $original_order_id = 0, $renewal_order_id = 0, $product_id = 0, $new_order_role = null ) { + + if ( empty( $original_order_id ) && empty( $renewal_order_id ) ) { + return $order_items; + } + + if ( empty( $original_order_id ) ) { + $original_order_id = $this->get_first_order_id( $renewal_order_id ); + if ( empty( $original_order_id ) ) { + return $order_items; + } + } + + if ( self::is_wcs_gte( '2.0.0' ) ) { + $is_subscription_order = wcs_order_contains_subscription( $original_order_id ); + } else { + $is_subscription_order = WC_Subscriptions_Order::order_contains_subscription( $original_order_id ); + } + if ( $is_subscription_order ) { + $return = false; + } else { + $return = true; + } + if ( $return ) { + return $order_items; + } + + $pay_from_credit_of_original_order = get_option( 'pay_from_smart_coupon_of_original_order', 'yes' ); + + if ( 'child' !== $new_order_role ) { + return $order_items; + } + if ( empty( $renewal_order_id ) || empty( $original_order_id ) ) { + return $order_items; + } + + $original_order = wc_get_order( $original_order_id ); + $renewal_order = wc_get_order( $renewal_order_id ); + + $subscriptions = wcs_get_subscriptions_for_order( $original_order, array( 'order_type' => 'parent' ) ); + reset( $subscriptions ); + $subscription = current( $subscriptions ); + + $coupon_used_in_original_order = $this->get_coupon_codes( $original_order ); + $coupon_used_in_renewal_order = $this->get_coupon_codes( $renewal_order ); + + if ( $this->is_wc_gte_30() ) { + $renewal_order_billing_email = ( is_callable( array( $renewal_order, 'get_billing_email' ) ) ) ? $renewal_order->get_billing_email() : ''; + } else { + $renewal_order_billing_email = ( ! empty( $renewal_order->billing_email ) ) ? $renewal_order->billing_email : ''; + } + + $all_coupons = array_merge( $coupon_used_in_original_order, $coupon_used_in_renewal_order ); + $all_coupons = array_unique( $all_coupons ); + + if ( count( $all_coupons ) > 0 ) { + $apply_before_tax = get_option( 'woocommerce_smart_coupon_apply_before_tax', 'no' ); + + $smart_coupons_contribution = array(); + foreach ( $all_coupons as $coupon_code ) { + $coupon = new WC_Coupon( $coupon_code ); + if ( $this->is_wc_gte_30() ) { + $discount_type = $coupon->get_discount_type(); + $coupon_product_ids = $coupon->get_product_ids(); + $coupon_category_ids = $coupon->get_product_categories(); + } else { + $discount_type = ( ! empty( $coupon->discount_type ) ) ? $coupon->discount_type : ''; + $coupon_product_ids = ( ! empty( $coupon->product_ids ) ) ? $coupon->product_ids : array(); + $coupon_category_ids = ( ! empty( $coupon->product_categories ) ) ? $coupon->product_categories : array(); + } + + $coupon_amount = $this->get_amount( $coupon, true, $renewal_order ); + + if ( ! empty( $discount_type ) && 'smart_coupon' === $discount_type && ! empty( $coupon_amount ) ) { + if ( 'yes' !== $pay_from_credit_of_original_order && in_array( $coupon_code, $coupon_used_in_original_order, true ) ) { + continue; + } + if ( $this->is_wc_gte_30() && 'yes' === $apply_before_tax ) { + $renewal_order_items = ( is_object( $subscription ) && is_callable( array( $subscription, 'get_items' ) ) ) ? $subscription->get_items( 'line_item' ) : array(); + if ( empty( $renewal_order_items ) ) { + break; + } + $subtotal = 0; + $items_to_apply_credit = array(); + if ( count( $coupon_product_ids ) > 0 || count( $coupon_category_ids ) > 0 ) { + foreach ( $renewal_order_items as $renewal_order_item_id => $renewal_order_item ) { + $renewal_product_id = ( is_object( $renewal_order_item ) && is_callable( array( $renewal_order_item, 'get_product_id' ) ) ) ? $renewal_order_item->get_product_id() : $renewal_order_item['product_id']; + $renewal_variation_id = ( is_object( $renewal_order_item ) && is_callable( array( $renewal_order_item, 'get_variation_id' ) ) ) ? $renewal_order_item->get_variation_id() : $renewal_order_item['variation_id']; + $product_category_ids = wc_get_product_cat_ids( $renewal_product_id ); + if ( count( $coupon_product_ids ) > 0 && count( $coupon_category_ids ) > 0 ) { + if ( ( in_array( $renewal_product_id, $coupon_product_ids, true ) || in_array( $renewal_variation_id, $coupon_product_ids, true ) ) && count( array_intersect( $product_category_ids, $coupon_category_ids ) ) > 0 ) { + $items_to_apply_credit[ $renewal_order_item_id ] = $renewal_order_item; + } + } else { + if ( in_array( $renewal_product_id, $coupon_product_ids, true ) || in_array( $renewal_variation_id, $coupon_product_ids, true ) || count( array_intersect( $product_category_ids, $coupon_category_ids ) ) > 0 ) { + $items_to_apply_credit[ $renewal_order_item_id ] = $renewal_order_item; + } + } + } + } else { + $items_to_apply_credit = $renewal_order_items; + } + if ( empty( $items_to_apply_credit ) ) { + continue; + } + $subtotal = array_sum( array_map( array( $this, 'sc_get_order_item_subtotal' ), $items_to_apply_credit ) ); + if ( $subtotal <= 0 ) { + continue; + } + if ( ! class_exists( 'WC_SC_Apply_Before_Tax' ) ) { + include_once '../class-wc-sc-apply-before-tax.php'; + } + $sc_apply_before_tax = WC_SC_Apply_Before_Tax::get_instance(); + foreach ( $renewal_order_items as $renewal_order_item_id => $renewal_order_item ) { + if ( array_key_exists( $renewal_order_item_id, $items_to_apply_credit ) ) { + $discounting_amount = $renewal_order_item->get_total(); + $quantity = $renewal_order_item->get_quantity(); + $discount = $sc_apply_before_tax->sc_get_discounted_price( $discounting_amount, $quantity, $subtotal, $coupon_amount ); + $discount *= $quantity; + $renewal_order_items[ $renewal_order_item_id ]->set_total( $discounting_amount - $discount ); + } + } + $renewal_order_total = $subtotal; + $order_items = $renewal_order_items; + + $discount = min( $renewal_order_total, $coupon_amount ); + } else { + $renewal_order_total = $renewal_order->get_total(); + $renewal_total_tax = $renewal_order->get_total_tax(); + $renewal_order_total_excluding_tax = $renewal_order_total - $renewal_total_tax; + + $discount = min( $renewal_order_total_excluding_tax, $coupon_amount ); + $coupon_amount -= $discount; + if ( $this->is_callable( $renewal_order, 'set_discount_total' ) ) { + $renewal_order->set_discount_total( $discount ); + } + if ( $coupon_amount > 0 ) { + $discount_tax = min( $renewal_total_tax, $coupon_amount ); + $coupon_amount -= $discount_tax; + if ( $this->is_callable( $renewal_order, 'set_discount_tax' ) ) { + $renewal_order->set_discount_tax( $discount_tax ); + } + $discount += $discount_tax; + } + } + + if ( $discount > 0 ) { + $new_order_total = $renewal_order_total - $discount; + $this->update_post_meta( $renewal_order_id, '_order_total', $new_order_total, true, $renewal_order ); + $this->update_post_meta( $renewal_order_id, '_order_discount', $discount, true, $renewal_order ); + if ( $new_order_total <= floatval( 0 ) ) { + if ( $this->is_callable( $renewal_order, 'update_meta_data' ) && $this->is_callable( $renewal_order, 'save' ) ) { + $renewal_order->update_meta_data( '_renewal_paid_by_smart_coupon', 'yes' ); + $renewal_order->save(); + } else { + update_post_meta( $renewal_order_id, '_renewal_paid_by_smart_coupon', 'yes' ); + } + } + if ( $this->is_wc_gte_30() ) { + $item = new WC_Order_Item_Coupon(); + $item->set_props( + array( + 'code' => $coupon_code, + 'discount' => $discount, + 'order_id' => ( is_object( $renewal_order ) && is_callable( array( $renewal_order, 'get_id' ) ) ) ? $renewal_order->get_id() : 0, + ) + ); + $item->save(); + $renewal_order->add_item( $item ); + } else { + $renewal_order->add_coupon( $coupon_code, $discount ); + } + $smart_coupons_contribution[ $coupon_code ] = $discount; + } + } + } + if ( ! empty( $smart_coupons_contribution ) ) { + $this->update_post_meta( $renewal_order_id, 'smart_coupons_contribution', $smart_coupons_contribution, true, $renewal_order ); + $renewal_order->sc_total_credit_used = $smart_coupons_contribution; + } + } + + return $order_items; + } + + /** + * Function to trigger complete payment for renewal if it's paid by Smart Coupons + * + * @param WC_Order $renewal_order Order created on subscription renewal. + * @param WC_Order $original_order Order being used to purchased the subscription. + * @param int $product_id ID of the product being renewed. + * @param string $new_order_role The role the renewal order is taking, one of 'parent' or 'child'. + */ + public function sc_renewal_complete_payment( $renewal_order = null, $original_order = null, $product_id = 0, $new_order_role = null ) { + global $store_credit_label; + + if ( $this->is_wc_gte_30() ) { + $renewal_order_id = ( is_object( $renewal_order ) && is_callable( array( $renewal_order, 'get_id' ) ) ) ? $renewal_order->get_id() : 0; + } else { + $renewal_order_id = ( ! empty( $renewal_order->id ) ) ? $renewal_order->id : 0; + } + + if ( empty( $renewal_order_id ) ) { + return; + } + if ( self::is_wcs_gte( '2.0.0' ) ) { + $is_renewal_order = wcs_order_contains_renewal( $renewal_order_id ); + } else { + $is_renewal_order = WC_Subscriptions_Renewal_Order::is_renewal( $renewal_order_id ); + } + if ( $is_renewal_order ) { + $return = false; + } else { + $return = true; + } + if ( $return ) { + return; + } + + $order_needs_processing = false; + + if ( count( $renewal_order->get_items() ) > 0 ) { + foreach ( $renewal_order->get_items() as $item ) { + $_product = ( is_object( $item ) && is_callable( array( $item, 'get_product' ) ) ) ? $item->get_product() : $renewal_order->get_product_from_item( $item ); + + if ( $_product instanceof WC_Product ) { + $virtual_downloadable_item = $_product->is_downloadable() && $_product->is_virtual(); + + if ( apply_filters( 'woocommerce_order_item_needs_processing', ! $virtual_downloadable_item, $_product, $renewal_order_id ) ) { + $order_needs_processing = true; + break; + } + } else { + $order_needs_processing = true; + break; + } + } + } + + if ( $this->is_callable( $renewal_order, 'meta_exists' ) && true !== $renewal_order->meta_exists( '_renewal_paid_by_smart_coupon' ) ) { + $renewal_order->read_meta_data( true ); + } + + $is_renewal_paid_by_smart_coupon = ( $this->is_callable( $renewal_order, 'get_meta' ) ) ? $renewal_order->get_meta( '_renewal_paid_by_smart_coupon' ) : get_post_meta( $renewal_order_id, '_renewal_paid_by_smart_coupon', true ); + if ( ! empty( $is_renewal_paid_by_smart_coupon ) && 'yes' === $is_renewal_paid_by_smart_coupon ) { + + /* translators: %s: singular name for store credit */ + $order_paid_txt = ! empty( $store_credit_label['singular'] ) ? sprintf( __( 'Order paid by %s', 'woocommerce-smart-coupons' ), strtolower( $store_credit_label['singular'] ) ) : __( 'Order paid by store credit.', 'woocommerce-smart-coupons' ); + $renewal_order->update_status( apply_filters( 'woocommerce_payment_complete_order_status', $order_needs_processing ? 'processing' : 'completed', $renewal_order_id, $renewal_order ), $order_paid_txt ); // HN WC SA Support #7485. + } + } + + /** + * Get valid_subscription_coupon array and add smart_coupon type + * + * @param bool $is_validate_for_subscription Validate coupon or not. + * @param WC_Coupon $coupon Coupon object. + * @param bool $valid Coupon Validity. + * @return bool $is_validate_for_subscription whether to validate coupon for subscription or not. + */ + public function smart_coupon_as_valid_subscription_coupon_type( $is_validate_for_subscription, $coupon, $valid ) { + + if ( $this->is_wc_gte_30() ) { + $discount_type = ( ! empty( $coupon ) && is_callable( array( $coupon, 'get_discount_type' ) ) ) ? $coupon->get_discount_type() : 0; + } else { + $discount_type = ( ! empty( $coupon->discount_type ) ) ? $coupon->discount_type : ''; + } + + if ( ! empty( $discount_type ) && 'smart_coupon' === $discount_type ) { + $is_validate_for_subscription = false; + } + + return $is_validate_for_subscription; + } + + /** + * Function to show gift certificate received details form based on product type + * + * @param boolean $is_show Whether to show or not. + * @param array $args Additional arguments. + * @return boolean [description] + */ + public function is_show_gift_certificate_receiver_detail_form( $is_show = false, $args = array() ) { + + if ( wcs_cart_contains_renewal() ) { + return false; + } + + return $is_show; + } + + /** + * Function to add subscription specific settings + * + * @param array $settings Existing settings. + * @return array $settings + */ + public function smart_coupons_settings( $settings = array() ) { + global $store_credit_label; + + $singular = ( ! empty( $store_credit_label['singular'] ) ) ? $store_credit_label['singular'] : __( 'store credit', 'woocommerce-smart-coupons' ); + + $wc_subscriptions_options = array( + array( + 'name' => __( 'Recurring subscriptions', 'woocommerce-smart-coupons' ), + /* translators: %s: Label for store credit */ + 'desc' => sprintf( __( 'Use %s applied in first subscription order for subsequent renewals until credit reaches zero', 'woocommerce-smart-coupons' ), strtolower( $singular ) ), + 'id' => 'pay_from_smart_coupon_of_original_order', + 'type' => 'checkbox', + 'default' => 'no', + 'checkboxgroup' => 'start', + 'autoload' => false, + ), + array( + 'desc' => __( 'Renewal orders should not generate coupons even when they include a product that issues coupons', 'woocommerce-smart-coupons' ), + 'id' => 'stop_recursive_coupon_generation', + 'type' => 'checkbox', + 'default' => 'no', + 'checkboxgroup' => 'end', + 'autoload' => false, + ), + ); + + array_splice( $settings, ( count( $settings ) - 17 ), 0, $wc_subscriptions_options ); + + return $settings; + + } + + /** + * Whether to bypass coupon removal from recurring item + * + * @param boolean $bypass Bypass or not. + * @param WC_Coupon $coupon The coupon object. + * @param string $coupon_type The discount type. + * @param string $calculation_type The calculation type of subscription. + * @return boolean $bypass Bypass or not + */ + public function bypass_removal_of_coupon_having_coupon_actions( $bypass = false, $coupon = null, $coupon_type = '', $calculation_type = '' ) { + + if ( $this->is_wc_gte_30() ) { + $coupon_code = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_code' ) ) ) ? $coupon->get_code() : ''; + } else { + $coupon_code = ( ! empty( $coupon->code ) ) ? $coupon->code : ''; + } + + if ( ! class_exists( 'WC_SC_Coupon_Actions' ) ) { + include_once '../class-wc-sc-coupon-actions.php'; + } + + $wc_sc_coupon_actions = WC_SC_Coupon_Actions::get_instance(); + + $coupon_actions = $wc_sc_coupon_actions->get_coupon_actions( $coupon_code ); + + if ( false === $bypass && ! empty( $coupon_actions ) ) { + $coupon = new WC_Coupon( $coupon_code ); + $discount_type = $coupon->get_discount_type(); + if ( 'smart_coupon' === $discount_type ) { + return true; + } + } + + return $bypass; + } + + /** + * Modify recurring cart + * Specifically, remove coupons having coupon actions from recurring carts + * + * @param mixed $total The total. + * @return mixed $total + */ + public function modify_recurring_cart( $total ) { + + $recurring_carts = WC()->cart->recurring_carts; + + if ( ! empty( $recurring_carts ) ) { + + if ( ! class_exists( 'WC_SC_Coupon_Actions' ) ) { + include_once '../class-wc-sc-coupon-actions.php'; + } + + $wc_sc_coupon_actions = WC_SC_Coupon_Actions::get_instance(); + + foreach ( WC()->cart->recurring_carts as $cart_item_key => $cart ) { + if ( ! empty( $cart->applied_coupons ) ) { + foreach ( $cart->applied_coupons as $index => $coupon_code ) { + $coupon_actions = $wc_sc_coupon_actions->get_coupon_actions( $coupon_code ); + if ( ! empty( $coupon_actions ) ) { + $coupon = new WC_Coupon( $coupon_code ); + $discount_type = $coupon->get_discount_type(); + if ( 'smart_coupon' === $discount_type ) { + unset( WC()->cart->recurring_carts[ $cart_item_key ]->applied_coupons[ $index ] ); + } + } + } + } + } + } + + return $total; + + } + + /** + * Hooks for WCS 2.3.0+ + */ + public function hooks_for_wcs_230() { + if ( $this->is_wcs_gte( '2.3.0' ) ) { + add_filter( 'wc_smart_coupons_export_headers', array( $this, 'export_headers' ) ); + add_filter( 'smart_coupons_parser_postmeta_defaults', array( $this, 'postmeta_defaults' ) ); + add_filter( 'sc_generate_coupon_meta', array( $this, 'generate_coupon_meta' ), 10, 2 ); + add_action( 'wc_sc_new_coupon_generated', array( $this, 'copy_subscriptions_coupon_meta' ) ); + } + } + + /** + * Add subscriptions coupon meta in export headers + * + * @param array $headers Existing headers. + * @return array + */ + public function export_headers( $headers = array() ) { + + $action_headers = array( + '_wcs_number_payments' => __( 'Active for x payments', 'woocommerce-smart-coupons' ), + ); + + return array_merge( $headers, $action_headers ); + + } + + /** + * Post meta defaults for subscriptions coupon meta + * + * @param array $defaults Existing postmeta defaults. + * @return array + */ + public function postmeta_defaults( $defaults = array() ) { + + $actions_defaults = array( + '_wcs_number_payments' => '', + ); + + return array_merge( $defaults, $actions_defaults ); + } + + /** + * Add subscriptions coupons meta with value in coupon meta + * + * @param array $data The row data. + * @param array $post The POST values. + * @return array Modified data + */ + public function generate_coupon_meta( $data = array(), $post = array() ) { + + if ( isset( $post['wcs_number_payments'] ) ) { + $data['_wcs_number_payments'] = trim( $post['wcs_number_payments'] ); + } + + return $data; + } + + /** + * Function to copy subscription coupon meta in newly generated coupon + * + * @param array $args The arguments. + */ + public function copy_subscriptions_coupon_meta( $args = array() ) { + + $new_coupon_id = ( ! empty( $args['new_coupon_id'] ) ) ? absint( $args['new_coupon_id'] ) : 0; + $coupon = ( ! empty( $args['ref_coupon'] ) ) ? $args['ref_coupon'] : false; + + if ( empty( $new_coupon_id ) || empty( $coupon ) ) { + return; + } + + $wcs_number_payments = ''; + if ( $this->is_wc_gte_30() ) { + $wcs_number_payments = $coupon->get_meta( '_wcs_number_payments' ); + } else { + $old_coupon_id = ( ! empty( $coupon->id ) ) ? $coupon->id : 0; + $wcs_number_payments = get_post_meta( $old_coupon_id, '_wcs_number_payments', true ); + } + $this->update_post_meta( $new_coupon_id, '_wcs_number_payments', $wcs_number_payments ); + + } + + /** + * Get the reference key after which the setting will be inserted + * + * @param string $after_key The key after which the setting to be inserted. + * @param array $args Additional arguments. + * @return string + */ + public function endpoint_account_settings_after_key( $after_key = '', $args = array() ) { + return 'woocommerce_myaccount_subscription_payment_method_endpoint'; + } + + /** + * Function to change coupon display name for Subscription coupons + * + * @param string $coupon_type The type of the coupon. + * @param WC_Coupon $coupon Coupon object. + * @param array $all_discount_types List of available discount types. + * @return string + */ + public function valid_display_type( $coupon_type, $coupon, $all_discount_types ) { + if ( 'Recurring Product % Discount' === $coupon_type ) { + $coupon_type = 'Recurring Product Discount'; + } elseif ( 'Sign Up Fee % Discount' === $coupon_type ) { + $coupon_type = 'Sign Up Fee Discount'; + } + return $coupon_type; + } + + /** + * Function to change coupon amount display for Subscription coupons + * + * @param float $coupon_amount Coupon amount. + * @param WC_Coupon $coupon Coupon object. + * @return float + */ + public function valid_display_amount( $coupon_amount, $coupon ) { + $coupon_discount_type = $coupon->get_discount_type(); + if ( 'recurring_percent' === $coupon_discount_type || 'sign_up_fee_percent' === $coupon_discount_type ) { + $coupon_amount = $coupon_amount . '%'; + } elseif ( 'recurring_fee' === $coupon_discount_type || 'sign_up_fee' === $coupon_discount_type ) { + $coupon_amount = wc_price( $coupon_amount ); + } + return $coupon_amount; + } + + /** + * Coupon design thumbnail src set for subscription coupons + * + * @param array $src_set Existing src set. + * @param array $args Additional arguments. + * @return array + */ + public function coupon_design_thumbnail_src_set( $src_set = array(), $args = array() ) { + $coupon = ( ! empty( $args['coupon_object'] ) ) ? $args['coupon_object'] : null; + if ( $this->is_wc_gte_30() ) { + $discount_type = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_discount_type' ) ) ) ? $coupon->get_discount_type() : ''; + } else { + $discount_type = ( ! empty( $coupon->discount_type ) ) ? $coupon->discount_type : ''; + } + if ( ! empty( $discount_type ) ) { + switch ( $discount_type ) { + case 'sign_up_fee': + case 'sign_up_fee_percent': + $src_set = array( + 'subs-discount-voucher.svg', + ); + break; + + case 'recurring_fee': + case 'recurring_percent': + $src_set = array( + 'subs-calendar-discount.svg', + ); + break; + } + } + return $src_set; + } + + /** + * Get percent discount types fromm subscriptions + * + * @param array $discount_types Existing discount tyeps. + * @param array $args Additional arguments. + * @return array + */ + public function percent_discount_types( $discount_types = array(), $args = array() ) { + $subs_percent_discount_types = array( + 'sign_up_fee_percent', + 'recurring_percent', + ); + $discount_types = array_merge( $discount_types, $subs_percent_discount_types ); + return $discount_types; + } + + /** + * Function to check if a coupon can be auto applied or not + * + * @param boolean $is_auto_apply Is auto apply. + * @param array $args Additional arguments. + * @return boolean + */ + public function is_auto_apply( $is_auto_apply = true, $args = array() ) { + $cart_total = ( ! empty( $args['cart_total'] ) ) ? floatval( $args['cart_total'] ) : 0; + $cart_contains_subscription = self::is_cart_contains_subscription(); + if ( false === $is_auto_apply && empty( $cart_total ) && true === $cart_contains_subscription ) { + $is_auto_apply = true; + } + return $is_auto_apply; + } + + /** + * Function to check if cart contains subscription + * + * @return bool whether cart contains subscription or not + */ + public static function is_cart_contains_subscription() { + if ( class_exists( 'WC_Subscriptions_Cart' ) && WC_Subscriptions_Cart::cart_contains_subscription() ) { + return true; + } + return false; + } + + /** + * Function to check WooCommerce Subscription version + * + * @param string $version Subscription version. + * @return bool whether passed version is greater than or equal to current version of WooCommerce Subscription + */ + public static function is_wcs_gte( $version = null ) { + if ( is_null( $version ) ) { + return false; + } + if ( version_compare( $version, '4.0.0', '>=' ) && class_exists( 'WC_Subscriptions_Core_Plugin' ) ) { + return true; + } + if ( ! class_exists( 'WC_Subscriptions' ) || empty( WC_Subscriptions::$version ) ) { + return false; + } + return version_compare( WC_Subscriptions::$version, $version, '>=' ); + } + + /** + * Function to modify cart for actions tab product of coupon + * + * @param WC_Subscription $subscription The subscription object. This param is unused. It is the first parameter of the hook. + * @param WC_Order $order The renewal order object. + */ + public function maybe_revalidate_coupon_actions( $subscription = null, $order = null ) { + if ( is_null( $order ) ) { + return; + } + if ( ! class_exists( 'WC_SC_Coupon_Actions' ) ) { + include_once '../class-wc-sc-coupon-actions.php'; + } + $wc_sc_coupon_actions = WC_SC_Coupon_Actions::get_instance(); + $order_coupons = ( $this->is_callable( $order, 'get_used_coupons' ) ) ? $order->get_used_coupons() : array(); + if ( empty( $order_coupons ) ) { + return; + } + + $product_ids_added_by_coupon = array(); + $is_order_updated = false; + + foreach ( $order_coupons as $coupon_code ) { + $coupon_actions = ( $this->is_callable( $wc_sc_coupon_actions, 'get_coupon_actions' ) ) ? $wc_sc_coupon_actions->get_coupon_actions( $coupon_code ) : array(); + if ( ! empty( $coupon_actions ) && is_array( $coupon_actions ) ) { + $product_ids_added_by_coupon = wp_list_pluck( $coupon_actions, 'product_id' ); + } else { + $product_ids_added_by_coupon = array(); + } + if ( empty( $product_ids_added_by_coupon ) ) { + continue; + } + $order_items = ( $this->is_callable( $order, 'get_items' ) ) ? $order->get_items() : array(); + if ( ! empty( $order_items ) && ! is_scalar( $order_items ) ) { + foreach ( $order_items as $item_id => $item ) { + $wc_sc_product_coupon = $this->is_callable( $item, 'get_meta' ) ? $item->get_meta( '_wc_sc_product_source' ) : ''; + if ( empty( $wc_sc_product_coupon ) ) { + continue; + } + $item_product_id = ( $this->is_callable( $item, 'get_product_id' ) ) ? $item->get_product_id() : 0; + if ( empty( $item_product_id ) ) { + continue; + } + $product_ids_added_by_coupon = array_map( 'absint', $product_ids_added_by_coupon ); + if ( $coupon_code === $wc_sc_product_coupon && in_array( absint( $item_product_id ), $product_ids_added_by_coupon, true ) ) { + $order->remove_item( $item_id ); + $is_order_updated = true; + } + } + } + } + + if ( true === $is_order_updated ) { + $order->save(); + } + } + + /** + * Enqueue styles & scripts + */ + public function enqueue_styles_scripts() { + if ( ! class_exists( 'WC_Subscriptions_Core_Plugin' ) ) { + return; + } + if ( ! is_callable( 'WC_Subscriptions_Core_Plugin::instance' ) ) { + return; + } + $wc_subscriptions_core_plugin_instance = WC_Subscriptions_Core_Plugin::instance(); + // Get the script version. + $ver = ( $this->is_callable( $wc_subscriptions_core_plugin_instance, 'get_library_version' ) ) ? $wc_subscriptions_core_plugin_instance->get_library_version() : false; + if ( empty( $ver ) ) { + $ver = ( $this->is_callable( $wc_subscriptions_core_plugin_instance, 'get_plugin_version' ) ) ? $wc_subscriptions_core_plugin_instance->get_plugin_version() : false; + } + // Get admin screen ID. + $screen = get_current_screen(); + $screen_id = isset( $screen->id ) ? $screen->id : ''; + + if ( is_admin() && in_array( $screen_id, array( 'marketing_page_wc-smart-coupons' ), true ) ) { + wp_enqueue_script( + 'wcs-admin-coupon-meta-boxes', + WC_Subscriptions_Core_Plugin::instance()->get_subscriptions_core_directory_url( 'assets/js/admin/meta-boxes-coupon.js' ), + array( 'jquery', 'wc-admin-meta-boxes' ), + $ver, + false + ); + + } + } + + } + +} + +WCS_SC_Compatibility::get_instance(); diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/emails/class-wc-sc-acknowledgement-email.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/emails/class-wc-sc-acknowledgement-email.php new file mode 100644 index 00000000..e4c09cbd --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/emails/class-wc-sc-acknowledgement-email.php @@ -0,0 +1,350 @@ +id = 'wc_sc_acknowledgement_email'; + + $this->customer_email = true; + + // Set email title and description. + $this->title = __( 'Smart Coupons - Acknowledgement email', 'woocommerce-smart-coupons' ); + $this->description = __( 'Send an acknowledgement email to the purchaser. One email per customer.', 'woocommerce-smart-coupons' ); + + // Use our plugin templates directory as the template base. + $this->template_base = dirname( WC_SC_PLUGIN_FILE ) . '/templates/'; + + // Email template location. + $this->template_html = 'acknowledgement-email.php'; + $this->template_plain = 'plain/acknowledgement-email.php'; + + $this->placeholders = array( + '{coupon_type}' => '', + ); + + // Trigger for this email. + add_action( 'wc_sc_acknowledgement_email_notification', array( $this, 'trigger' ) ); + + // Call parent constructor to load any other defaults not explicity defined here. + parent::__construct(); + } + + /** + * Get default email subject. + * + * @return string Default email subject + */ + public function get_default_subject() { + return __( '{site_title}: {coupon_type} sent successfully', 'woocommerce-smart-coupons' ); + } + + /** + * Get default email heading. + * + * @return string Default email heading + */ + public function get_default_heading() { + return __( '{coupon_type} sent successfully', 'woocommerce-smart-coupons' ); + } + + /** + * Get default scheduled email subject. + * + * @return string Default email subject + */ + public function get_default_scheduled_subject() { + return __( '{site_title}: {coupon_type} has been successfully scheduled', 'woocommerce-smart-coupons' ); + } + + /** + * Get default scheduled email heading. + * + * @return string Default email heading + */ + public function get_default_scheduled_heading() { + return __( '{coupon_type} has been successfully scheduled', 'woocommerce-smart-coupons' ); + } + + /** + * Initialize Settings Form Fields + */ + public function init_form_fields() { + + /* translators: %s: list of placeholders */ + $placeholder_text = sprintf( __( 'This will be used when the setting "WooCommerce > Settings > Smart Coupons > Allow schedule sending of coupons?" is enabled. Available placeholders: %s.', 'woocommerce-smart-coupons' ), '' . implode( ', ', array_keys( $this->placeholders ) ) . '' ); + + $form_fields = array( + 'scheduled_subject' => array( + 'title' => __( 'Scheduled email subject', 'woocommerce-smart-coupons' ), + 'type' => 'text', + 'desc_tip' => true, + 'description' => $placeholder_text, + 'placeholder' => $this->get_default_scheduled_subject(), + 'default' => '', + ), + 'scheduled_heading' => array( + 'title' => __( 'Scheduled email heading', 'woocommerce-smart-coupons' ), + 'type' => 'text', + 'desc_tip' => true, + 'description' => $placeholder_text, + 'placeholder' => $this->get_default_scheduled_heading(), + 'default' => '', + ), + ); + + parent::init_form_fields(); + + $this->form_fields = array_merge( $this->form_fields, $form_fields ); + } + + /** + * Determine if the email should actually be sent and setup email merge variables + * + * @param array $args Email arguments. + */ + public function trigger( $args = array() ) { + + $this->email_args = wp_parse_args( $args, $this->email_args ); + + if ( ! isset( $this->email_args['email'] ) || empty( $this->email_args['email'] ) ) { + return; + } + + $email_scheduled_details = ! empty( $this->email_args['scheduled_email'] ) ? $this->email_args['scheduled_email'] : array(); + $this->is_email_scheduled = ! empty( $email_scheduled_details ); + + $this->setup_locale(); + + $this->recipient = $this->email_args['email']; + + $order_id = isset( $this->email_args['order_id'] ) ? $this->email_args['order_id'] : 0; + + // Get order object. + if ( ! empty( $order_id ) && 0 !== $order_id ) { + $order = wc_get_order( $order_id ); + if ( is_a( $order, 'WC_Order' ) ) { + $this->object = $order; + } + } + + $this->set_placeholders(); + + $email_content = $this->get_content(); + // Replace placeholders with values in the email content. + $email_content = ( is_callable( array( $this, 'format_string' ) ) ) ? $this->format_string( $email_content ) : $email_content; + + // Send email. + if ( $this->is_enabled() && $this->get_recipient() ) { + $this->send( $this->get_recipient(), $this->get_subject(), $email_content, $this->get_headers(), $this->get_attachments() ); + } + + $this->restore_locale(); + } + + /** + * Function to get email subject. + * + * @return string Email subject. + */ + public function get_subject() { + if ( true === $this->is_email_scheduled ) { + return $this->get_scheduled_subject(); + } + return parent::get_subject(); + } + + /** + * Function to get email subject. + * + * @return string Email subject. + */ + public function get_heading() { + if ( true === $this->is_email_scheduled ) { + return $this->get_scheduled_heading(); + } + return parent::get_heading(); + } + + /** + * Get scheduled email subject. + * + * @return string + */ + public function get_scheduled_subject() { + return apply_filters( + $this->id . '_scheduled_subject', + $this->format_string( $this->get_option( 'scheduled_subject', $this->get_default_scheduled_subject() ) ), + array( + 'email_object' => $this->object, + 'source' => $this, + ) + ); + } + + /** + * Get scheduled email heading. + * + * @return string + */ + public function get_scheduled_heading() { + return apply_filters( + $this->id . '_scheduled_heading', + $this->format_string( $this->get_option( 'scheduled_heading', $this->get_default_scheduled_heading() ) ), + array( + 'email_object' => $this->object, + 'source' => $this, + ) + ); + } + + /** + * Function to set placeholder variables used in email subject/heading + */ + public function set_placeholders() { + $this->placeholders['{coupon_type}'] = $this->get_coupon_type(); + } + + /** + * Function to load email html content + * + * @return string Email content html + */ + public function get_content_html() { + + global $woocommerce_smart_coupon; + + $order = $this->object; + + $email_heading = $this->get_heading(); + + $email = isset( $this->email_args['email'] ) ? $this->email_args['email'] : ''; + $receivers_detail = isset( $this->email_args['receivers_detail'] ) ? $this->email_args['receivers_detail'] : array(); + $receiver_name = isset( $this->email_args['receiver_name'] ) ? $this->email_args['receiver_name'] : ''; + $receiver_count = isset( $this->email_args['receiver_count'] ) ? $this->email_args['receiver_count'] : 0; + $email_scheduled_details = isset( $this->email_args['scheduled_email'] ) ? $this->email_args['scheduled_email'] : array(); + $contains_core_coupons = ( isset( $this->email_args['contains_core_coupons'] ) && 'yes' === $this->email_args['contains_core_coupons'] ) ? $this->email_args['contains_core_coupons'] : 'no'; + + $default_path = $this->template_base; + $template_path = $woocommerce_smart_coupon->get_template_base_dir( $this->template_html ); + + ob_start(); + + wc_get_template( + $this->template_html, + array( + 'email' => $email, + 'email_obj' => $this, + 'email_heading' => $email_heading, + 'order' => $order, + 'receivers_detail' => $receivers_detail, + 'gift_certificate_receiver_name' => $receiver_name, + 'receiver_count' => $receiver_count, + 'email_scheduled_details' => $email_scheduled_details, + 'contains_core_coupons' => $contains_core_coupons, + ), + $template_path, + $default_path + ); + + return ob_get_clean(); + } + + /** + * Function to load email plain content + * + * @return string Email plain content + */ + public function get_content_plain() { + + global $woocommerce_smart_coupon; + + $order = $this->object; + $email_heading = $this->get_heading(); + + $email = isset( $this->email_args['email'] ) ? $this->email_args['email'] : ''; + $receivers_detail = isset( $this->email_args['receivers_detail'] ) ? $this->email_args['receivers_detail'] : array(); + $receiver_name = isset( $this->email_args['receiver_name'] ) ? $this->email_args['receiver_name'] : ''; + $receiver_count = isset( $this->email_args['receiver_count'] ) ? $this->email_args['receiver_count'] : 0; + $email_scheduled_details = isset( $this->email_args['scheduled_email'] ) ? $this->email_args['scheduled_email'] : array(); + $contains_core_coupons = ( isset( $this->email_args['contains_core_coupons'] ) && 'yes' === $this->email_args['contains_core_coupons'] ) ? $this->email_args['contains_core_coupons'] : 'no'; + + $default_path = $this->template_base; + $template_path = $woocommerce_smart_coupon->get_template_base_dir( $this->template_html ); + + ob_start(); + + wc_get_template( + $this->template_plain, + array( + 'email' => $email, + 'email_obj' => $this, + 'email_heading' => $email_heading, + 'order' => $order, + 'receivers_detail' => $receivers_detail, + 'gift_certificate_receiver_name' => $receiver_name, + 'receiver_count' => $receiver_count, + 'email_scheduled_details' => $email_scheduled_details, + 'contains_core_coupons' => $contains_core_coupons, + ), + $template_path, + $default_path + ); + + return ob_get_clean(); + } + + /** + * Function to get coupon type for current coupon being sent. + * + * @return string $coupon_type Coupon type. + */ + public function get_coupon_type() { + + global $store_credit_label; + + $receiver_count = isset( $this->email_args['receiver_count'] ) ? $this->email_args['receiver_count'] : 0; + $singular = ( ! empty( $store_credit_label['singular'] ) ) ? ucwords( $store_credit_label['singular'] ) : __( 'Gift card', 'woocommerce-smart-coupons' ); + $plural = ( ! empty( $store_credit_label['plural'] ) ) ? ucwords( $store_credit_label['plural'] ) : __( 'Gift cards', 'woocommerce-smart-coupons' ); + $coupon_type = ( $receiver_count > 1 ) ? $plural : $singular; + $contains_core_coupons = ( isset( $this->email_args['contains_core_coupons'] ) && 'yes' === $this->email_args['contains_core_coupons'] ) ? $this->email_args['contains_core_coupons'] : 'no'; + + if ( 'yes' === $contains_core_coupons ) { + $coupon_type = _n( 'Coupon', 'Coupons', $receiver_count, 'woocommerce-smart-coupons' ); + } + + return $coupon_type; + } + + } + +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/emails/class-wc-sc-combined-email-coupon.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/emails/class-wc-sc-combined-email-coupon.php new file mode 100644 index 00000000..e3704978 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/emails/class-wc-sc-combined-email-coupon.php @@ -0,0 +1,267 @@ +id = 'wc_sc_combined_email_coupon'; + + $this->customer_email = true; + + // Set email title and description. + $this->title = __( 'Smart Coupons - Combined auto generated coupons email', 'woocommerce-smart-coupons' ); + $this->description = __( 'Send only one email instead of multiple emails when multiple coupons are generated per recipient.', 'woocommerce-smart-coupons' ); + + // Use our plugin templates directory as the template base. + $this->template_base = dirname( WC_SC_PLUGIN_FILE ) . '/templates/'; + + // Email template location. + $this->template_html = 'combined-email.php'; + $this->template_plain = 'plain/combined-email.php'; + + $this->placeholders = array( + '{sender_name}' => '', + ); + + // Trigger for this email. + add_action( 'wc_sc_combined_email_coupon_notification', array( $this, 'trigger' ) ); + + // Call parent constructor to load any other defaults not explicity defined here. + parent::__construct(); + } + + /** + * Get default email subject. + * + * @return string Default email subject + */ + public function get_default_subject() { + return __( '{site_title}: Congratulations! You\'ve received coupons from {sender_name}', 'woocommerce-smart-coupons' ); + } + + /** + * Get default email heading. + * + * @return string Default email heading + */ + public function get_default_heading() { + return __( 'You have received coupons.', 'woocommerce-smart-coupons' ); + } + + /** + * Determine if the email should actually be sent and setup email merge variables + * + * @param array $args Email arguments. + */ + public function trigger( $args = array() ) { + + $this->email_args = wp_parse_args( $args, $this->email_args ); + + if ( ! isset( $this->email_args['email'] ) || empty( $this->email_args['email'] ) ) { + return; + } + + $this->setup_locale(); + + $this->recipient = $this->email_args['email']; + + $order_id = isset( $this->email_args['order_id'] ) ? $this->email_args['order_id'] : 0; + + // Get order object. + if ( ! empty( $order_id ) && 0 !== $order_id ) { + $order = wc_get_order( $order_id ); + if ( is_a( $order, 'WC_Order' ) ) { + $this->object = $order; + } + } + + $this->set_placeholders(); + + $email_content = $this->get_content(); + // Replace placeholders with values in the email content. + $email_content = ( is_callable( array( $this, 'format_string' ) ) ) ? $this->format_string( $email_content ) : $email_content; + + // Send email. + if ( $this->is_enabled() && $this->get_recipient() ) { + $this->send( $this->get_recipient(), $this->get_subject(), $email_content, $this->get_headers(), $this->get_attachments() ); + } + + $this->restore_locale(); + } + + /** + * Function to set placeholder variables used in email subject/heading + */ + public function set_placeholders() { + $this->placeholders['{sender_name}'] = $this->get_sender_name(); + } + + /** + * Function to load email html content + * + * @return string Email content html + */ + public function get_content_html() { + + global $woocommerce_smart_coupon; + + $order = $this->object; + $url = $this->get_url(); + $email_heading = $this->get_heading(); + + $sender = ''; + $from = ''; + + $is_gift = isset( $this->email_args['is_gift'] ) ? $this->email_args['is_gift'] : ''; + + if ( 'yes' === $is_gift ) { + $sender_name = $this->get_sender_name(); + $sender_email = $this->get_sender_email(); + if ( ! empty( $sender_name ) && ! empty( $sender_email ) ) { + $sender = $sender_name . ' (' . $sender_email . ') '; + $from = ' ' . __( 'from', 'woocommerce-smart-coupons' ) . ' '; + } + } + + $email = isset( $this->email_args['email'] ) ? $this->email_args['email'] : ''; + $receiver_details = isset( $this->email_args['receiver_details'] ) ? $this->email_args['receiver_details'] : ''; + + $design = get_option( 'wc_sc_setting_coupon_design', 'basic' ); + $background_color = get_option( 'wc_sc_setting_coupon_background_color', '#39cccc' ); + $foreground_color = get_option( 'wc_sc_setting_coupon_foreground_color', '#30050b' ); + $third_color = get_option( 'wc_sc_setting_coupon_third_color', '#39cccc' ); + + $show_coupon_description = get_option( 'smart_coupons_show_coupon_description', 'no' ); + + $valid_designs = $woocommerce_smart_coupon->get_valid_coupon_designs(); + + if ( ! in_array( $design, $valid_designs, true ) ) { + $design = 'basic'; + } + + $design = ( 'custom-design' !== $design ) ? 'email-coupon' : $design; + + $coupon_styles = $woocommerce_smart_coupon->get_coupon_styles( $design, array( 'is_email' => 'yes' ) ); + + $default_path = $this->template_base; + $template_path = $woocommerce_smart_coupon->get_template_base_dir( $this->template_html ); + + ob_start(); + + wc_get_template( + $this->template_html, + array( + 'email' => $email, + 'email_obj' => $this, + 'email_heading' => $email_heading, + 'order' => $order, + 'url' => $url, + 'from' => $from, + 'background_color' => $background_color, + 'foreground_color' => $foreground_color, + 'third_color' => $third_color, + 'coupon_styles' => $coupon_styles, + 'sender' => $sender, + 'receiver_details' => $receiver_details, + 'show_coupon_description' => $show_coupon_description, + 'design' => $design, + ), + $template_path, + $default_path + ); + + return ob_get_clean(); + } + + /** + * Function to load email plain content + * + * @return string Email plain content + */ + public function get_content_plain() { + + global $woocommerce_smart_coupon; + + $order = $this->object; + $url = $this->get_url(); + $email_heading = $this->get_heading(); + + $sender = ''; + $from = ''; + + $is_gift = isset( $this->email_args['is_gift'] ) ? $this->email_args['is_gift'] : ''; + + if ( 'yes' === $is_gift ) { + $sender_name = $this->get_sender_name(); + $sender_email = $this->get_sender_email(); + if ( ! empty( $sender_name ) && ! empty( $sender_email ) ) { + $sender = $sender_name . ' (' . $sender_email . ') '; + $from = ' ' . __( 'from', 'woocommerce-smart-coupons' ) . ' '; + } + } + + $email = isset( $this->email_args['email'] ) ? $this->email_args['email'] : ''; + $receiver_details = isset( $this->email_args['receiver_details'] ) ? $this->email_args['receiver_details'] : ''; + + $default_path = $this->template_base; + $template_path = $woocommerce_smart_coupon->get_template_base_dir( $this->template_plain ); + + ob_start(); + + wc_get_template( + $this->template_plain, + array( + 'email' => $email, + 'email_obj' => $this, + 'email_heading' => $email_heading, + 'order' => $order, + 'url' => $url, + 'from' => $from, + 'sender' => $sender, + 'receiver_details' => $receiver_details, + ), + $template_path, + $default_path + ); + + return ob_get_clean(); + } + + /** + * Function to update SC admin email settings when WC email settings get updated + */ + public function process_admin_options() { + // Save regular options. + parent::process_admin_options(); + + $is_email_enabled = $this->get_field_value( 'enabled', $this->form_fields['enabled'] ); + + if ( ! empty( $is_email_enabled ) ) { + update_option( 'smart_coupons_combine_emails', $is_email_enabled, 'no' ); + } + } + + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/emails/class-wc-sc-email-coupon.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/emails/class-wc-sc-email-coupon.php new file mode 100644 index 00000000..15e8ce41 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/emails/class-wc-sc-email-coupon.php @@ -0,0 +1,508 @@ +id = 'wc_sc_email_coupon'; + + $this->customer_email = true; + + // Set email title and description. + $this->title = __( 'Smart Coupons - Auto generated coupon email', 'woocommerce-smart-coupons' ); + $this->description = __( 'Email auto generated coupon to recipients. One email per coupon.', 'woocommerce-smart-coupons' ); + + // Use our plugin templates directory as the template base. + $this->template_base = dirname( WC_SC_PLUGIN_FILE ) . '/templates/'; + + // Email template location. + $this->template_html = 'email.php'; + $this->template_plain = 'plain/email.php'; + + $this->placeholders = array( + '{coupon_code}' => '', + '{coupon_type}' => '', + '{coupon_value}' => '', + '{sender_name}' => '', + ); + + // Trigger for this email. + add_action( 'wc_sc_email_coupon_notification', array( $this, 'trigger' ) ); + + // Call parent constructor to load any other defaults not explicity defined here. + parent::__construct(); + } + + /** + * Get default email subject. + * + * @return string Default email subject + */ + public function get_default_subject() { + return __( '{site_title}: Congratulations! You\'ve received a {coupon_type} from {sender_name}', 'woocommerce-smart-coupons' ); + } + + /** + * Get default email heading. + * + * @return string Default email heading + */ + public function get_default_heading() { + return __( 'You have received a {coupon_type} {coupon_value}', 'woocommerce-smart-coupons' ); + } + + /** + * Determine if the email should actually be sent and setup email merge variables + * + * @param array $args Email arguments. + */ + public function trigger( $args = array() ) { + + $this->email_args = wp_parse_args( $args, $this->email_args ); + + if ( ! isset( $this->email_args['email'] ) || empty( $this->email_args['email'] ) ) { + return; + } + + $this->setup_locale(); + + $this->recipient = $this->email_args['email']; + + $order_id = isset( $this->email_args['order_id'] ) ? $this->email_args['order_id'] : 0; + + // Get order object. + if ( ! empty( $order_id ) && 0 !== $order_id ) { + $order = wc_get_order( $order_id ); + if ( is_a( $order, 'WC_Order' ) ) { + $this->object = $order; + } + } + + $this->set_placeholders(); + + $email_content = $this->get_content(); + // Replace placeholders with values in the email content. + $email_content = ( is_callable( array( $this, 'format_string' ) ) ) ? $this->format_string( $email_content ) : $email_content; + + // Send email. + if ( $this->is_enabled() && $this->get_recipient() ) { + $this->send( $this->get_recipient(), $this->get_subject(), $email_content, $this->get_headers(), $this->get_attachments() ); + } + + $this->restore_locale(); + } + + /** + * Function to set placeholder variables used in email subject/heading + */ + public function set_placeholders() { + $this->placeholders['{coupon_code}'] = $this->get_coupon_code(); + $this->placeholders['{coupon_type}'] = $this->get_coupon_type(); + $this->placeholders['{coupon_value}'] = $this->get_coupon_value(); + $this->placeholders['{coupon_expiry}'] = $this->get_coupon_expiry(); + $this->placeholders['{sender_name}'] = $this->get_sender_name(); + } + + /** + * Function to get coupon expiry date/time for current coupon being sent. + * + * @return string $coupon_expiry Coupon expiry. + */ + public function get_coupon_expiry() { + + global $woocommerce_smart_coupon; + + $coupon_expiry = ''; + $coupon = isset( $this->email_args['coupon'] ) ? $this->email_args['coupon'] : ''; + + if ( empty( $coupon ) ) { + return $coupon_expiry; + } + + $coupon_code = ( ! empty( $coupon['code'] ) ) ? $coupon['code'] : ''; + if ( empty( $coupon_code ) ) { + return $coupon_expiry; + } + + $_coupon = new WC_Coupon( $coupon_code ); + if ( $woocommerce_smart_coupon->is_wc_gte_30() ) { + $coupon_id = ( is_object( $_coupon ) && is_callable( array( $_coupon, 'get_id' ) ) ) ? $_coupon->get_id() : 0; + $expiry_date = ( is_object( $_coupon ) && is_callable( array( $_coupon, 'get_date_expires' ) ) ) ? $_coupon->get_date_expires() : ''; + } else { + $coupon_id = ( ! empty( $_coupon->id ) ) ? $_coupon->id : 0; + $expiry_date = ( ! empty( $_coupon->expiry_date ) ) ? $_coupon->expiry_date : ''; + } + + if ( ! empty( $expiry_date ) ) { + if ( $woocommerce_smart_coupon->is_wc_gte_30() && $expiry_date instanceof WC_DateTime ) { + $expiry_date = ( is_callable( array( $expiry_date, 'getTimestamp' ) ) ) ? $expiry_date->getTimestamp() : null; + } elseif ( ! is_int( $expiry_date ) ) { + $expiry_date = strtotime( $expiry_date ); + } + + if ( ! empty( $expiry_date ) && is_int( $expiry_date ) ) { + $expiry_time = (int) $woocommerce_smart_coupon->get_post_meta( $coupon_id, 'wc_sc_expiry_time', true ); + if ( ! empty( $expiry_time ) ) { + $expiry_date += $expiry_time; // Adding expiry time to expiry date. + } + } + $coupon_expiry = $woocommerce_smart_coupon->get_expiration_format( $expiry_date ); + } else { + $coupon_expiry = esc_html__( 'Never expires', 'woocommerce-smart-coupons' ); + } + + return $coupon_expiry; + } + + /** + * Function to load email html content + * + * @return string Email content html + */ + public function get_content_html() { + + global $woocommerce_smart_coupon; + + $order = $this->object; + $url = $this->get_url(); + $email_heading = $this->get_heading(); + + $sender = ''; + $from = ''; + + $is_gift = isset( $this->email_args['is_gift'] ) ? $this->email_args['is_gift'] : ''; + + if ( 'yes' === $is_gift ) { + $sender_name = $this->get_sender_name(); + $sender_email = $this->get_sender_email(); + if ( ! empty( $sender_name ) && ! empty( $sender_email ) ) { + $sender = $sender_name . ' (' . $sender_email . ') '; + $from = ' ' . __( 'from', 'woocommerce-smart-coupons' ) . ' '; + } + } + + $email = isset( $this->email_args['email'] ) ? $this->email_args['email'] : ''; + $message_from_sender = isset( $this->email_args['message_from_sender'] ) ? $this->email_args['message_from_sender'] : ''; + $coupon_code = isset( $this->email_args['coupon']['code'] ) ? $this->email_args['coupon']['code'] : ''; + + $design = get_option( 'wc_sc_setting_coupon_design', 'basic' ); + $background_color = get_option( 'wc_sc_setting_coupon_background_color', '#39cccc' ); + $foreground_color = get_option( 'wc_sc_setting_coupon_foreground_color', '#30050b' ); + $third_color = get_option( 'wc_sc_setting_coupon_third_color', '#39cccc' ); + + $show_coupon_description = get_option( 'smart_coupons_show_coupon_description', 'no' ); + + $valid_designs = $woocommerce_smart_coupon->get_valid_coupon_designs(); + + if ( ! in_array( $design, $valid_designs, true ) ) { + $design = 'basic'; + } + + $design = ( 'custom-design' !== $design ) ? 'email-coupon' : $design; + + $coupon_styles = $woocommerce_smart_coupon->get_coupon_styles( $design, array( 'is_email' => 'yes' ) ); + + $default_path = $this->template_base; + $template_path = $woocommerce_smart_coupon->get_template_base_dir( $this->template_html ); + + ob_start(); + + wc_get_template( + $this->template_html, + array( + 'email' => $email, + 'email_obj' => $this, + 'email_heading' => $email_heading, + 'order' => $order, + 'url' => $url, + 'message_from_sender' => $message_from_sender, + 'from' => $from, + 'coupon_code' => $coupon_code, + 'background_color' => $background_color, + 'foreground_color' => $foreground_color, + 'third_color' => $third_color, + 'coupon_styles' => $coupon_styles, + 'sender' => $sender, + 'design' => $design, + 'show_coupon_description' => $show_coupon_description, + ), + $template_path, + $default_path + ); + + return ob_get_clean(); + } + + /** + * Function to load email plain content + * + * @return string Email plain content + */ + public function get_content_plain() { + + global $woocommerce_smart_coupon; + + $order = $this->object; + $url = $this->get_url(); + $email_heading = $this->get_heading(); + + $sender = ''; + $from = ''; + + $is_gift = isset( $this->email_args['is_gift'] ) ? $this->email_args['is_gift'] : ''; + + if ( 'yes' === $is_gift ) { + $sender_name = $this->get_sender_name(); + $sender_email = $this->get_sender_email(); + if ( ! empty( $sender_name ) && ! empty( $sender_email ) ) { + $sender = $sender_name . ' (' . $sender_email . ') '; + $from = ' ' . __( 'from', 'woocommerce-smart-coupons' ) . ' '; + } + } + + $email = isset( $this->email_args['email'] ) ? $this->email_args['email'] : ''; + $message_from_sender = isset( $this->email_args['message_from_sender'] ) ? $this->email_args['message_from_sender'] : ''; + $coupon_code = isset( $this->email_args['coupon']['code'] ) ? $this->email_args['coupon']['code'] : ''; + + $default_path = $this->template_base; + $template_path = $woocommerce_smart_coupon->get_template_base_dir( $this->template_plain ); + + ob_start(); + + wc_get_template( + $this->template_plain, + array( + 'email' => $email, + 'email_obj' => $this, + 'email_heading' => $email_heading, + 'order' => $order, + 'url' => $url, + 'message_from_sender' => $message_from_sender, + 'from' => $from, + 'coupon_code' => $coupon_code, + 'sender' => $sender, + ), + $template_path, + $default_path + ); + + return ob_get_clean(); + } + + + + /** + * Get coupon code + * + * @return string + */ + public function get_coupon_code() { + + $coupon_code = isset( $this->email_args['coupon']['code'] ) ? $this->email_args['coupon']['code'] : ''; + + return $coupon_code; + } + + /** + * Get coupon value + * + * @return string + */ + public function get_coupon_value() { + + global $woocommerce_smart_coupon, $store_credit_label; + + $coupon = isset( $this->email_args['coupon'] ) ? $this->email_args['coupon'] : ''; + + if ( empty( $coupon ) ) { + return ''; + } + + $order_id = isset( $this->email_args['order_id'] ) ? $this->email_args['order_id'] : 0; + $order = ( ! empty( $order_id ) ) ? wc_get_order( $order_id ) : null; + + $wc_price_args = array( + 'currency' => is_callable( array( $order, 'get_currency' ) ) ? $order->get_currency() : '', + ); + + $discount_type = isset( $this->email_args['discount_type'] ) ? $this->email_args['discount_type'] : ''; + $is_gift = isset( $this->email_args['is_gift'] ) ? $this->email_args['is_gift'] : ''; + + // Get smart coupon type string. + if ( 'smart_coupon' === $discount_type && 'yes' === $is_gift ) { + $smart_coupon_type = __( 'Gift Card', 'woocommerce-smart-coupons' ); + } else { + $smart_coupon_type = __( 'Store Credit', 'woocommerce-smart-coupons' ); + } + + if ( ! empty( $store_credit_label['singular'] ) ) { + $smart_coupon_type = ucwords( $store_credit_label['singular'] ); + } + + $amount = $coupon['amount']; + $coupon_code = $coupon['code']; + + // Get coupon types. + $all_discount_types = wc_get_coupon_types(); + + $_coupon = new WC_Coupon( $coupon_code ); + + if ( $woocommerce_smart_coupon->is_wc_gte_30() ) { + $_coupon_id = ( is_object( $_coupon ) && is_callable( array( $_coupon, 'get_id' ) ) ) ? $_coupon->get_id() : 0; + $_is_free_shipping = ( $_coupon->get_free_shipping() ) ? 'yes' : 'no'; + $_discount_type = $_coupon->get_discount_type(); + $_product_ids = $_coupon->get_product_ids(); + $_excluded_product_ids = $_coupon->get_excluded_product_ids(); + $_product_categories = $_coupon->get_product_categories(); + $_excluded_product_categories = $_coupon->get_excluded_product_categories(); + } else { + $_coupon_id = ( ! empty( $_coupon->id ) ) ? $_coupon->id : 0; + $_is_free_shipping = ( ! empty( $_coupon->free_shipping ) ) ? $_coupon->free_shipping : ''; + $_discount_type = ( ! empty( $_coupon->discount_type ) ) ? $_coupon->discount_type : ''; + $_product_ids = ( ! empty( $_coupon->product_ids ) ) ? $_coupon->product_ids : array(); + $_excluded_product_ids = ( ! empty( $_coupon->exclude_product_ids ) ) ? $_coupon->exclude_product_ids : array(); + $_product_categories = ( ! empty( $_coupon->product_categories ) ) ? $_coupon->product_categories : array(); + $_excluded_product_categories = ( ! empty( $_coupon->exclude_product_categories ) ) ? $_coupon->exclude_product_categories : array(); + } + + if ( false === stripos( $discount_type, 'percent' ) ) { + $amount = $woocommerce_smart_coupon->read_price( $amount, true, $order ); + } + + switch ( $discount_type ) { + + case 'smart_coupon': + /* translators: %s coupon amount */ + $coupon_value = sprintf( __( 'worth %s ', 'woocommerce-smart-coupons' ), wc_price( $amount, $wc_price_args ) ); + break; + + case 'fixed_cart': + /* translators: %s: coupon amount */ + $coupon_value = sprintf( __( 'worth %s (for entire purchase) ', 'woocommerce-smart-coupons' ), wc_price( $amount, $wc_price_args ) ); + break; + + case 'fixed_product': + if ( ! empty( $_product_ids ) || ! empty( $_excluded_product_ids ) || ! empty( $_product_categories ) || ! empty( $_excluded_product_categories ) ) { + $_discount_for_text = __( 'for some products', 'woocommerce-smart-coupons' ); + } else { + $_discount_for_text = __( 'for all products', 'woocommerce-smart-coupons' ); + } + + /* translators: 1: coupon amount 2: discount for text */ + $coupon_value = sprintf( __( 'worth %1$s (%2$s) ', 'woocommerce-smart-coupons' ), wc_price( $amount, $wc_price_args ), $_discount_for_text ); + break; + + case 'percent_product': + if ( ! empty( $_product_ids ) || ! empty( $_excluded_product_ids ) || ! empty( $_product_categories ) || ! empty( $_excluded_product_categories ) ) { + $_discount_for_text = __( 'for some products', 'woocommerce-smart-coupons' ); + } else { + $_discount_for_text = __( 'for all products', 'woocommerce-smart-coupons' ); + } + + /* translators: 1: coupon amount 2: discount for text */ + $coupon_value = sprintf( __( 'worth %1$s%% (%2$s) ', 'woocommerce-smart-coupons' ), $amount, $_discount_for_text ); + break; + + case 'percent': + if ( ! empty( $_product_ids ) || ! empty( $_excluded_product_ids ) || ! empty( $_product_categories ) || ! empty( $_excluded_product_categories ) ) { + $_discount_for_text = __( 'for some products', 'woocommerce-smart-coupons' ); + } else { + $_discount_for_text = __( 'for entire purchase', 'woocommerce-smart-coupons' ); + } + + $max_discount_text = ''; + $max_discount = $woocommerce_smart_coupon->get_post_meta( $_coupon_id, 'wc_sc_max_discount', true, true, $order ); + if ( ! empty( $max_discount ) && is_numeric( $max_discount ) ) { + /* translators: %s: Maximum coupon discount amount */ + $max_discount_text = sprintf( __( ' upto %s', 'woocommerce-smart-coupons' ), wc_price( $max_discount, $wc_price_args ) ); + } + + /* translators: 1: coupon amount 2: max discount text 3: discount for text */ + $coupon_value = sprintf( __( 'worth %1$s%% %2$s (%3$s) ', 'woocommerce-smart-coupons' ), $amount, $max_discount_text, $_discount_for_text ); + break; + + default: + $default_coupon_type = ( ! empty( $all_discount_types[ $discount_type ] ) ) ? $all_discount_types[ $discount_type ] : ucwords( str_replace( array( '_', '-' ), ' ', $discount_type ) ); + $coupon_type = apply_filters( 'wc_sc_coupon_type', $default_coupon_type, $_coupon, $all_discount_types ); + $coupon_amount = apply_filters( 'wc_sc_coupon_amount', $amount, $_coupon ); + + /* translators: 1: coupon type 2: coupon amount */ + $coupon_value = sprintf( __( '%1$s coupon of %2$s', 'woocommerce-smart-coupons' ), $coupon_type, $coupon_amount ); + $coupon_value = apply_filters( 'wc_sc_email_heading', $coupon_value, $_coupon ); + break; + + } + + if ( 'yes' === $_is_free_shipping && in_array( $_discount_type, array( 'fixed_cart', 'fixed_product', 'percent_product', 'percent' ), true ) ) { + /* translators: 1: email heading 2: suffix */ + $coupon_value = sprintf( __( '%1$s Free Shipping%2$s', 'woocommerce-smart-coupons' ), ( ( ! empty( $amount ) ) ? $coupon_value . __( '&', 'woocommerce-smart-coupons' ) : __( 'You have received a', 'woocommerce-smart-coupons' ) ), ( ( empty( $amount ) ) ? __( ' coupon', 'woocommerce-smart-coupons' ) : '' ) ); + } + + return wp_strip_all_tags( $coupon_value ); + } + + /** + * Function to get coupon type for current coupon being sent. + * + * @return string $coupon_type Coupon type. + */ + public function get_coupon_type() { + + global $store_credit_label; + + $discount_type = isset( $this->email_args['discount_type'] ) ? $this->email_args['discount_type'] : ''; + $is_gift = isset( $this->email_args['is_gift'] ) ? $this->email_args['is_gift'] : ''; + + if ( 'smart_coupon' === $discount_type && 'yes' === $is_gift ) { + $smart_coupon_type = __( 'Gift Card', 'woocommerce-smart-coupons' ); + } else { + $smart_coupon_type = __( 'Store Credit', 'woocommerce-smart-coupons' ); + } + + if ( ! empty( $store_credit_label['singular'] ) ) { + $smart_coupon_type = ucwords( $store_credit_label['singular'] ); + } + + $coupon_type = ( 'smart_coupon' === $discount_type && ! empty( $smart_coupon_type ) ) ? $smart_coupon_type : __( 'coupon', 'woocommerce-smart-coupons' ); + + return $coupon_type; + } + + /** + * Function to update SC admin email settings when WC email settings get updated + */ + public function process_admin_options() { + // Save regular options. + parent::process_admin_options(); + + $is_email_enabled = $this->get_field_value( 'enabled', $this->form_fields['enabled'] ); + + if ( ! empty( $is_email_enabled ) ) { + update_option( 'smart_coupons_is_send_email', $is_email_enabled, 'no' ); + } + } + + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/emails/class-wc-sc-email.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/emails/class-wc-sc-email.php new file mode 100644 index 00000000..904a4bce --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/emails/class-wc-sc-email.php @@ -0,0 +1,149 @@ + '', + 'coupon' => array(), + 'discount_type' => 'smart_coupon', + 'smart_coupon_type' => '', + 'receiver_name' => '', + 'message_from_sender' => '', + 'gift_certificate_sender_name' => '', + 'gift_certificate_sender_email' => '', + 'from' => '', + 'sender' => '', + 'is_gift' => false, + ); + + /** + * Get shop page url + * + * @return string $url Shop page url + */ + public function get_url() { + + global $woocommerce_smart_coupon; + + if ( $woocommerce_smart_coupon->is_wc_gte_30() ) { + $page_id = wc_get_page_id( 'shop' ); + } else { + $page_id = woocommerce_get_page_id( 'shop' ); + } + + $url = ( get_option( 'permalink_structure' ) ) ? get_permalink( $page_id ) : get_post_type_archive_link( 'product' ); + + return $url; + } + + /** + * Function to get sender name. + * + * @return string $sender_name Sender name. + */ + public function get_sender_name() { + + if ( isset( $this->email_args['gift_certificate_sender_name'] ) && ! empty( $this->email_args['gift_certificate_sender_name'] ) ) { + $sender_name = $this->email_args['gift_certificate_sender_name']; + } else { + $sender_name = is_callable( array( $this, 'get_blogname' ) ) ? $this->get_blogname() : ''; + } + + return $sender_name; + } + + /** + * Function to get sender email. + * + * @return string $sender_email Sender email. + */ + public function get_sender_email() { + + $sender_email = isset( $this->email_args['gift_certificate_sender_email'] ) ? $this->email_args['gift_certificate_sender_email'] : ''; + + return $sender_email; + } + + /** + * Initialize Settings Form Fields + */ + public function init_form_fields() { + + /* translators: %s: list of placeholders */ + $placeholder_text = sprintf( __( 'Available placeholders: %s', 'woocommerce-smart-coupons' ), '' . implode( ', ', array_keys( $this->placeholders ) ) . '' ); + + $this->form_fields = array( + 'enabled' => array( + 'title' => __( 'Enable/Disable', 'woocommerce-smart-coupons' ), + 'type' => 'checkbox', + 'label' => __( 'Enable this email notification', 'woocommerce-smart-coupons' ), + 'default' => 'yes', + ), + 'email_type' => array( + 'title' => __( 'Email type', 'woocommerce-smart-coupons' ), + 'type' => 'select', + 'description' => __( 'Choose which format of email to send.', 'woocommerce-smart-coupons' ), + 'default' => 'html', + 'class' => 'email_type wc-enhanced-select', + 'options' => $this->get_email_type_options(), + 'desc_tip' => true, + ), + 'subject' => array( + 'title' => __( 'Subject', 'woocommerce-smart-coupons' ), + 'type' => 'text', + 'desc_tip' => true, + 'description' => $placeholder_text, + 'placeholder' => $this->get_default_subject(), + 'default' => '', + ), + 'heading' => array( + 'title' => __( 'Email heading', 'woocommerce-smart-coupons' ), + 'type' => 'text', + 'desc_tip' => true, + 'description' => $placeholder_text, + 'placeholder' => $this->get_default_heading(), + 'default' => '', + ), + ); + } + + /** + * Function to update SC admin email settings when WC email settings get updated + */ + public function process_admin_options() { + // Save regular options. + parent::process_admin_options(); + + $is_email_enabled = $this->get_field_value( 'enabled', $this->form_fields['enabled'] ); + + if ( ! empty( $is_email_enabled ) ) { + update_option( 'smart_coupons_is_send_email', $is_email_enabled, 'no' ); + } + } + + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/action-scheduler.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/action-scheduler.php new file mode 100644 index 00000000..1eda21e9 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/action-scheduler.php @@ -0,0 +1,69 @@ +. + * + * @package ActionScheduler + */ + +if ( ! function_exists( 'action_scheduler_register_3_dot_7_dot_0' ) && function_exists( 'add_action' ) ) { // WRCS: DEFINED_VERSION. + + if ( ! class_exists( 'ActionScheduler_Versions', false ) ) { + require_once __DIR__ . '/classes/ActionScheduler_Versions.php'; + add_action( 'plugins_loaded', array( 'ActionScheduler_Versions', 'initialize_latest_version' ), 1, 0 ); + } + + add_action( 'plugins_loaded', 'action_scheduler_register_3_dot_7_dot_0', 0, 0 ); // WRCS: DEFINED_VERSION. + + /** + * Registers this version of Action Scheduler. + */ + function action_scheduler_register_3_dot_7_dot_0() { // WRCS: DEFINED_VERSION. + $versions = ActionScheduler_Versions::instance(); + $versions->register( '3.7.0', 'action_scheduler_initialize_3_dot_7_dot_0' ); // WRCS: DEFINED_VERSION. + } + + /** + * Initializes this version of Action Scheduler. + */ + function action_scheduler_initialize_3_dot_7_dot_0() { // WRCS: DEFINED_VERSION. + // A final safety check is required even here, because historic versions of Action Scheduler + // followed a different pattern (in some unusual cases, we could reach this point and the + // ActionScheduler class is already defined—so we need to guard against that). + if ( ! class_exists( 'ActionScheduler', false ) ) { + require_once __DIR__ . '/classes/abstracts/ActionScheduler.php'; + ActionScheduler::init( __FILE__ ); + } + } + + // Support usage in themes - load this version if no plugin has loaded a version yet. + if ( did_action( 'plugins_loaded' ) && ! doing_action( 'plugins_loaded' ) && ! class_exists( 'ActionScheduler', false ) ) { + action_scheduler_initialize_3_dot_7_dot_0(); // WRCS: DEFINED_VERSION. + do_action( 'action_scheduler_pre_theme_init' ); + ActionScheduler_Versions::initialize_latest_version(); + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/changelog.txt b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/changelog.txt new file mode 100644 index 00000000..e595b912 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/changelog.txt @@ -0,0 +1,135 @@ +*** Changelog *** + += 3.7.0 - 2023-11-20 = +* Add extended indexes for hook_status_scheduled_date_gmt and status_sheduled_date_gmt. +* Catch and log exceptions thrown when actions can't be created, e.g. under a corrupt database schema. +* Release/3.6.4. +* Tweak - WP 6.4 compatibility. +* Update unit tests for upcoming dependency version policy. +* make sure hook action_scheduler_failed_execution can access original exception object. +* mention dependency version policy in usage.md. + += 3.6.4 - 2023-10-11 = +* Performance improvements when bulk cancelling actions. +* Dev-related fixes. + += 3.6.3 - 2023-09-13 = +* Use `_doing_it_wrong` in initialization check. + += 3.6.2 - 2023-08-09 = +* Add guidance about passing arguments. +* Atomic option locking. +* Improve bulk delete handling. +* Include database error in the exception message. +* Tweak - WP 6.3 compatibility. + += 3.6.1 - 2023-06-14 = +* Document new optional `$priority` arg for various API functions. +* Document the new `--exclude-groups` WP CLI option. +* Document the new `action_scheduler_init` hook. +* Ensure actions within each claim are executed in the expected order. +* Fix incorrect text domain. +* Remove SHOW TABLES usage when checking if tables exist. + += 3.6.0 - 2023-05-10 = +* Add $unique parameter to function signatures. +* Add a cast-to-int for extra safety before forming new DateTime object. +* Add a hook allowing exceptions for consistently failing recurring actions. +* Add action priorities. +* Add init hook. +* Always raise the time limit. +* Bump minimatch from 3.0.4 to 3.0.8. +* Bump yaml from 2.2.1 to 2.2.2. +* Defensive coding relating to gaps in declared schedule types. +* Do not process an action if it cannot be set to `in-progress`. +* Filter view labels (status names) should be translatable | #919. +* Fix WPCLI progress messages. +* Improve data-store initialization flow. +* Improve error handling across all supported PHP versions. +* Improve logic for flushing the runtime cache. +* Support exclusion of multiple groups. +* Update lint-staged and Node/NPM requirements. +* add CLI clean command. +* add CLI exclude-group filter. +* exclude past-due from list table all filter count. +* throwing an exception if as_schedule_recurring_action interval param is not of type integer. + += 3.5.4 - 2023-01-17 = +* Add pre filters during action registration. +* Async scheduling. +* Calculate timeouts based on total actions. +* Correctly order the parameters for `ActionScheduler_ActionFactory`'s calls to `single_unique`. +* Fetch action in memory first before releasing claim to avoid deadlock. +* PHP 8.2: declare property to fix creation of dynamic property warning. +* PHP 8.2: fix "Using ${var} in strings is deprecated, use {$var} instead". +* Prevent `undefined variable` warning for `$num_pastdue_actions`. + += 3.5.3 - 2022-11-09 = +* Query actions with partial match. + += 3.5.2 - 2022-09-16 = +* Fix - erroneous 3.5.1 release. + += 3.5.1 - 2022-09-13 = +* Maintenance on A/S docs. +* fix: PHP 8.2 deprecated notice. + += 3.5.0 - 2022-08-25 = +* Add - The active view link within the "Tools > Scheduled Actions" screen is now clickable. +* Add - A warning when there are past-due actions. +* Enhancement - Added the ability to schedule unique actions via an atomic operation. +* Enhancement - Improvements to cache invalidation when processing batches (when running on WordPress 6.0+). +* Enhancement - If a recurring action is found to be consistently failing, it will stop being rescheduled. +* Enhancement - Adds a new "Past Due" view to the scheduled actions list table. + += 3.4.2 - 2022-06-08 = +* Fix - Change the include for better linting. +* Fix - update: Added Action scheduler completed action hook. + += 3.4.1 - 2022-05-24 = +* Fix - Change the include for better linting. +* Fix - Fix the documented return type. + += 3.4.0 - 2021-10-29 = +* Enhancement - Number of items per page can now be set for the Scheduled Actions view (props @ovidiul). #771 +* Fix - Do not lower the max_execution_time if it is already set to 0 (unlimited) (props @barryhughes). #755 +* Fix - Avoid triggering autoloaders during the version resolution process (props @olegabr). #731 & #776 +* Dev - ActionScheduler_wcSystemStatus PHPCS fixes (props @ovidiul). #761 +* Dev - ActionScheduler_DBLogger.php PHPCS fixes (props @ovidiul). #768 +* Dev - Fixed phpcs for ActionScheduler_Schedule_Deprecated (props @ovidiul). #762 +* Dev - Improve actions table indicies (props @glagonikas). #774 & #777 +* Dev - PHPCS fixes for ActionScheduler_DBStore.php (props @ovidiul). #769 & #778 +* Dev - PHPCS Fixes for ActionScheduler_Abstract_ListTable (props @ovidiul). #763 & #779 +* Dev - Adds new filter action_scheduler_claim_actions_order_by to allow tuning of the claim query (props @glagonikas). #773 +* Dev - PHPCS fixes for ActionScheduler_WpPostStore class (props @ovidiul). #780 + += 3.3.0 - 2021-09-15 = +* Enhancement - Adds as_has_scheduled_action() to provide a performant way to test for existing actions. #645 +* Fix - Improves compatibility with environments where NO_ZERO_DATE is enabled. #519 +* Fix - Adds safety checks to guard against errors when our database tables cannot be created. #645 +* Dev - Now supports queries that use multiple statuses. #649 +* Dev - Minimum requirements for WordPress and PHP bumped (to 5.2 and 5.6 respectively). #723 + += 3.2.1 - 2021-06-21 = +* Fix - Add extra safety/account for different versions of AS and different loading patterns. #714 +* Fix - Handle hidden columns (Tools → Scheduled Actions) | #600. + += 3.2.0 - 2021-06-03 = +* Fix - Add "no ordering" option to as_next_scheduled_action(). +* Fix - Add secondary scheduled date checks when claiming actions (DBStore) | #634. +* Fix - Add secondary scheduled date checks when claiming actions (wpPostStore) | #634. +* Fix - Adds a new index to the action table, reducing the potential for deadlocks (props: @glagonikas). +* Fix - Fix unit tests infrastructure and adapt tests to PHP 8. +* Fix - Identify in-use data store. +* Fix - Improve test_migration_is_scheduled. +* Fix - PHP notice on list table. +* Fix - Speed up clean up and batch selects. +* Fix - Update pending dependencies. +* Fix - [PHP 8.0] Only pass action arg values through to do_action_ref_array(). +* Fix - [PHP 8] Set the PHP version to 7.1 in composer.json for PHP 8 compatibility. +* Fix - add is_initialized() to docs. +* Fix - fix file permissions. +* Fix - fixes #664 by replacing __ with esc_html__. + += 3.1.6 - 2020-05-12 = +* Change log starts. diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_ActionClaim.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_ActionClaim.php new file mode 100644 index 00000000..262158f9 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_ActionClaim.php @@ -0,0 +1,24 @@ +id = $id; + $this->action_ids = $action_ids; + } + + public function get_id() { + return $this->id; + } + + public function get_actions() { + return $this->action_ids; + } +} + \ No newline at end of file diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_ActionFactory.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_ActionFactory.php new file mode 100644 index 00000000..7c17576d --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_ActionFactory.php @@ -0,0 +1,358 @@ += 6 ? (int) func_get_arg( 5 ) : 10; + + switch ( $status ) { + case ActionScheduler_Store::STATUS_PENDING: + $action_class = 'ActionScheduler_Action'; + break; + case ActionScheduler_Store::STATUS_CANCELED: + $action_class = 'ActionScheduler_CanceledAction'; + if ( ! is_null( $schedule ) && ! is_a( $schedule, 'ActionScheduler_CanceledSchedule' ) && ! is_a( $schedule, 'ActionScheduler_NullSchedule' ) ) { + $schedule = new ActionScheduler_CanceledSchedule( $schedule->get_date() ); + } + break; + default: + $action_class = 'ActionScheduler_FinishedAction'; + break; + } + + $action_class = apply_filters( 'action_scheduler_stored_action_class', $action_class, $status, $hook, $args, $schedule, $group ); + + $action = new $action_class( $hook, $args, $schedule, $group ); + $action->set_priority( $priority ); + + /** + * Allow 3rd party code to change the instantiated action for a given hook, args, schedule and group. + * + * @param ActionScheduler_Action $action The instantiated action. + * @param string $hook The instantiated action's hook. + * @param array $args The instantiated action's args. + * @param ActionScheduler_Schedule $schedule The instantiated action's schedule. + * @param string $group The instantiated action's group. + * @param int $priority The action priority. + */ + return apply_filters( 'action_scheduler_stored_action_instance', $action, $hook, $args, $schedule, $group, $priority ); + } + + /** + * Enqueue an action to run one time, as soon as possible (rather a specific scheduled time). + * + * This method creates a new action using the NullSchedule. In practice, this results in an action scheduled to + * execute "now". Therefore, it will generally run as soon as possible but is not prioritized ahead of other actions + * that are already past-due. + * + * @param string $hook The hook to trigger when this action runs. + * @param array $args Args to pass when the hook is triggered. + * @param string $group A group to put the action in. + * + * @return int The ID of the stored action. + */ + public function async( $hook, $args = array(), $group = '' ) { + return $this->async_unique( $hook, $args, $group, false ); + } + + /** + * Same as async, but also supports $unique param. + * + * @param string $hook The hook to trigger when this action runs. + * @param array $args Args to pass when the hook is triggered. + * @param string $group A group to put the action in. + * @param bool $unique Whether to ensure the action is unique. + * + * @return int The ID of the stored action. + */ + public function async_unique( $hook, $args = array(), $group = '', $unique = true ) { + $schedule = new ActionScheduler_NullSchedule(); + $action = new ActionScheduler_Action( $hook, $args, $schedule, $group ); + return $unique ? $this->store_unique_action( $action, $unique ) : $this->store( $action ); + } + + /** + * Create single action. + * + * @param string $hook The hook to trigger when this action runs. + * @param array $args Args to pass when the hook is triggered. + * @param int $when Unix timestamp when the action will run. + * @param string $group A group to put the action in. + * + * @return int The ID of the stored action. + */ + public function single( $hook, $args = array(), $when = null, $group = '' ) { + return $this->single_unique( $hook, $args, $when, $group, false ); + } + + /** + * Create single action only if there is no pending or running action with same name and params. + * + * @param string $hook The hook to trigger when this action runs. + * @param array $args Args to pass when the hook is triggered. + * @param int $when Unix timestamp when the action will run. + * @param string $group A group to put the action in. + * @param bool $unique Whether action scheduled should be unique. + * + * @return int The ID of the stored action. + */ + public function single_unique( $hook, $args = array(), $when = null, $group = '', $unique = true ) { + $date = as_get_datetime_object( $when ); + $schedule = new ActionScheduler_SimpleSchedule( $date ); + $action = new ActionScheduler_Action( $hook, $args, $schedule, $group ); + return $unique ? $this->store_unique_action( $action ) : $this->store( $action ); + } + + /** + * Create the first instance of an action recurring on a given interval. + * + * @param string $hook The hook to trigger when this action runs. + * @param array $args Args to pass when the hook is triggered. + * @param int $first Unix timestamp for the first run. + * @param int $interval Seconds between runs. + * @param string $group A group to put the action in. + * + * @return int The ID of the stored action. + */ + public function recurring( $hook, $args = array(), $first = null, $interval = null, $group = '' ) { + return $this->recurring_unique( $hook, $args, $first, $interval, $group, false ); + } + + /** + * Create the first instance of an action recurring on a given interval only if there is no pending or running action with same name and params. + * + * @param string $hook The hook to trigger when this action runs. + * @param array $args Args to pass when the hook is triggered. + * @param int $first Unix timestamp for the first run. + * @param int $interval Seconds between runs. + * @param string $group A group to put the action in. + * @param bool $unique Whether action scheduled should be unique. + * + * @return int The ID of the stored action. + */ + public function recurring_unique( $hook, $args = array(), $first = null, $interval = null, $group = '', $unique = true ) { + if ( empty( $interval ) ) { + return $this->single_unique( $hook, $args, $first, $group, $unique ); + } + $date = as_get_datetime_object( $first ); + $schedule = new ActionScheduler_IntervalSchedule( $date, $interval ); + $action = new ActionScheduler_Action( $hook, $args, $schedule, $group ); + return $unique ? $this->store_unique_action( $action ) : $this->store( $action ); + } + + /** + * Create the first instance of an action recurring on a Cron schedule. + * + * @param string $hook The hook to trigger when this action runs. + * @param array $args Args to pass when the hook is triggered. + * @param int $base_timestamp The first instance of the action will be scheduled + * to run at a time calculated after this timestamp matching the cron + * expression. This can be used to delay the first instance of the action. + * @param int $schedule A cron definition string. + * @param string $group A group to put the action in. + * + * @return int The ID of the stored action. + */ + public function cron( $hook, $args = array(), $base_timestamp = null, $schedule = null, $group = '' ) { + return $this->cron_unique( $hook, $args, $base_timestamp, $schedule, $group, false ); + } + + + /** + * Create the first instance of an action recurring on a Cron schedule only if there is no pending or running action with same name and params. + * + * @param string $hook The hook to trigger when this action runs. + * @param array $args Args to pass when the hook is triggered. + * @param int $base_timestamp The first instance of the action will be scheduled + * to run at a time calculated after this timestamp matching the cron + * expression. This can be used to delay the first instance of the action. + * @param int $schedule A cron definition string. + * @param string $group A group to put the action in. + * @param bool $unique Whether action scheduled should be unique. + * + * @return int The ID of the stored action. + **/ + public function cron_unique( $hook, $args = array(), $base_timestamp = null, $schedule = null, $group = '', $unique = true ) { + if ( empty( $schedule ) ) { + return $this->single_unique( $hook, $args, $base_timestamp, $group, $unique ); + } + $date = as_get_datetime_object( $base_timestamp ); + $cron = CronExpression::factory( $schedule ); + $schedule = new ActionScheduler_CronSchedule( $date, $cron ); + $action = new ActionScheduler_Action( $hook, $args, $schedule, $group ); + return $unique ? $this->store_unique_action( $action ) : $this->store( $action ); + } + + /** + * Create a successive instance of a recurring or cron action. + * + * Importantly, the action will be rescheduled to run based on the current date/time. + * That means when the action is scheduled to run in the past, the next scheduled date + * will be pushed forward. For example, if a recurring action set to run every hour + * was scheduled to run 5 seconds ago, it will be next scheduled for 1 hour in the + * future, which is 1 hour and 5 seconds from when it was last scheduled to run. + * + * Alternatively, if the action is scheduled to run in the future, and is run early, + * likely via manual intervention, then its schedule will change based on the time now. + * For example, if a recurring action set to run every day, and is run 12 hours early, + * it will run again in 24 hours, not 36 hours. + * + * This slippage is less of an issue with Cron actions, as the specific run time can + * be set for them to run, e.g. 1am each day. In those cases, and entire period would + * need to be missed before there was any change is scheduled, e.g. in the case of an + * action scheduled for 1am each day, the action would need to run an entire day late. + * + * @param ActionScheduler_Action $action The existing action. + * + * @return string The ID of the stored action + * @throws InvalidArgumentException If $action is not a recurring action. + */ + public function repeat( $action ) { + $schedule = $action->get_schedule(); + $next = $schedule->get_next( as_get_datetime_object() ); + + if ( is_null( $next ) || ! $schedule->is_recurring() ) { + throw new InvalidArgumentException( __( 'Invalid action - must be a recurring action.', 'woocommerce' ) ); + } + + $schedule_class = get_class( $schedule ); + $new_schedule = new $schedule( $next, $schedule->get_recurrence(), $schedule->get_first_date() ); + $new_action = new ActionScheduler_Action( $action->get_hook(), $action->get_args(), $new_schedule, $action->get_group() ); + $new_action->set_priority( $action->get_priority() ); + return $this->store( $new_action ); + } + + /** + * Creates a scheduled action. + * + * This general purpose method can be used in place of specific methods such as async(), + * async_unique(), single() or single_unique(), etc. + * + * @internal Not intended for public use, should not be overriden by subclasses. + * + * @param array $options { + * Describes the action we wish to schedule. + * + * @type string $type Must be one of 'async', 'cron', 'recurring', or 'single'. + * @type string $hook The hook to be executed. + * @type array $arguments Arguments to be passed to the callback. + * @type string $group The action group. + * @type bool $unique If the action should be unique. + * @type int $when Timestamp. Indicates when the action, or first instance of the action in the case + * of recurring or cron actions, becomes due. + * @type int|string $pattern Recurrence pattern. This is either an interval in seconds for recurring actions + * or a cron expression for cron actions. + * @type int $priority Lower values means higher priority. Should be in the range 0-255. + * } + * + * @return int The action ID. Zero if there was an error scheduling the action. + */ + public function create( array $options = array() ) { + $defaults = array( + 'type' => 'single', + 'hook' => '', + 'arguments' => array(), + 'group' => '', + 'unique' => false, + 'when' => time(), + 'pattern' => null, + 'priority' => 10, + ); + + $options = array_merge( $defaults, $options ); + + // Cron/recurring actions without a pattern are treated as single actions (this gives calling code the ability + // to use functions like as_schedule_recurring_action() to schedule recurring as well as single actions). + if ( ( 'cron' === $options['type'] || 'recurring' === $options['type'] ) && empty( $options['pattern'] ) ) { + $options['type'] = 'single'; + } + + switch ( $options['type'] ) { + case 'async': + $schedule = new ActionScheduler_NullSchedule(); + break; + + case 'cron': + $date = as_get_datetime_object( $options['when'] ); + $cron = CronExpression::factory( $options['pattern'] ); + $schedule = new ActionScheduler_CronSchedule( $date, $cron ); + break; + + case 'recurring': + $date = as_get_datetime_object( $options['when'] ); + $schedule = new ActionScheduler_IntervalSchedule( $date, $options['pattern'] ); + break; + + case 'single': + $date = as_get_datetime_object( $options['when'] ); + $schedule = new ActionScheduler_SimpleSchedule( $date ); + break; + + default: + error_log( "Unknown action type '{$options['type']}' specified when trying to create an action for '{$options['hook']}'." ); + return 0; + } + + $action = new ActionScheduler_Action( $options['hook'], $options['arguments'], $schedule, $options['group'] ); + $action->set_priority( $options['priority'] ); + + $action_id = 0; + try { + $action_id = $options['unique'] ? $this->store_unique_action( $action ) : $this->store( $action ); + } catch ( Exception $e ) { + error_log( + sprintf( + /* translators: %1$s is the name of the hook to be enqueued, %2$s is the exception message. */ + __( 'Caught exception while enqueuing action "%1$s": %2$s', 'woocommerce' ), + $options['hook'], + $e->getMessage() + ) + ); + } + return $action_id; + } + + /** + * Save action to database. + * + * @param ActionScheduler_Action $action Action object to save. + * + * @return int The ID of the stored action + */ + protected function store( ActionScheduler_Action $action ) { + $store = ActionScheduler_Store::instance(); + return $store->save_action( $action ); + } + + /** + * Store action if it's unique. + * + * @param ActionScheduler_Action $action Action object to store. + * + * @return int ID of the created action. Will be 0 if action was not created. + */ + protected function store_unique_action( ActionScheduler_Action $action ) { + $store = ActionScheduler_Store::instance(); + return method_exists( $store, 'save_unique_action' ) ? + $store->save_unique_action( $action ) : $store->save_action( $action ); + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_AdminView.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_AdminView.php new file mode 100644 index 00000000..cddb422e --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_AdminView.php @@ -0,0 +1,253 @@ +render(); + } + + /** + * Registers action-scheduler into WooCommerce > System status. + * + * @param array $tabs An associative array of tab key => label. + * @return array $tabs An associative array of tab key => label, including Action Scheduler's tabs + */ + public function register_system_status_tab( array $tabs ) { + $tabs['action-scheduler'] = __( 'Scheduled Actions', 'woocommerce' ); + + return $tabs; + } + + /** + * Include Action Scheduler's administration under the Tools menu. + * + * A menu under the Tools menu is important for backward compatibility (as that's + * where it started), and also provides more convenient access than the WooCommerce + * System Status page, and for sites where WooCommerce isn't active. + */ + public function register_menu() { + $hook_suffix = add_submenu_page( + 'tools.php', + __( 'Scheduled Actions', 'woocommerce' ), + __( 'Scheduled Actions', 'woocommerce' ), + 'manage_options', + 'action-scheduler', + array( $this, 'render_admin_ui' ) + ); + add_action( 'load-' . $hook_suffix , array( $this, 'process_admin_ui' ) ); + } + + /** + * Triggers processing of any pending actions. + */ + public function process_admin_ui() { + $this->get_list_table(); + } + + /** + * Renders the Admin UI + */ + public function render_admin_ui() { + $table = $this->get_list_table(); + $table->display_page(); + } + + /** + * Get the admin UI object and process any requested actions. + * + * @return ActionScheduler_ListTable + */ + protected function get_list_table() { + if ( null === $this->list_table ) { + $this->list_table = new ActionScheduler_ListTable( ActionScheduler::store(), ActionScheduler::logger(), ActionScheduler::runner() ); + $this->list_table->process_actions(); + } + + return $this->list_table; + } + + /** + * Action: admin_notices + * + * Maybe check past-due actions, and print notice. + * + * @uses $this->check_pastdue_actions() + */ + public function maybe_check_pastdue_actions() { + + # Filter to prevent checking actions (ex: inappropriate user). + if ( ! apply_filters( 'action_scheduler_check_pastdue_actions', current_user_can( 'manage_options' ) ) ) { + return; + } + + # Get last check transient. + $last_check = get_transient( 'action_scheduler_last_pastdue_actions_check' ); + + # If transient exists, we're within interval, so bail. + if ( ! empty( $last_check ) ) { + return; + } + + # Perform the check. + $this->check_pastdue_actions(); + } + + /** + * Check past-due actions, and print notice. + * + * @todo update $link_url to "Past-due" filter when released (see issue #510, PR #511) + */ + protected function check_pastdue_actions() { + + # Set thresholds. + $threshold_seconds = ( int ) apply_filters( 'action_scheduler_pastdue_actions_seconds', DAY_IN_SECONDS ); + $threshhold_min = ( int ) apply_filters( 'action_scheduler_pastdue_actions_min', 1 ); + + // Set fallback value for past-due actions count. + $num_pastdue_actions = 0; + + // Allow third-parties to preempt the default check logic. + $check = apply_filters( 'action_scheduler_pastdue_actions_check_pre', null ); + + // If no third-party preempted and there are no past-due actions, return early. + if ( ! is_null( $check ) ) { + return; + } + + # Scheduled actions query arguments. + $query_args = array( + 'date' => as_get_datetime_object( time() - $threshold_seconds ), + 'status' => ActionScheduler_Store::STATUS_PENDING, + 'per_page' => $threshhold_min, + ); + + # If no third-party preempted, run default check. + if ( is_null( $check ) ) { + $store = ActionScheduler_Store::instance(); + $num_pastdue_actions = ( int ) $store->query_actions( $query_args, 'count' ); + + # Check if past-due actions count is greater than or equal to threshold. + $check = ( $num_pastdue_actions >= $threshhold_min ); + $check = ( bool ) apply_filters( 'action_scheduler_pastdue_actions_check', $check, $num_pastdue_actions, $threshold_seconds, $threshhold_min ); + } + + # If check failed, set transient and abort. + if ( ! boolval( $check ) ) { + $interval = apply_filters( 'action_scheduler_pastdue_actions_check_interval', round( $threshold_seconds / 4 ), $threshold_seconds ); + set_transient( 'action_scheduler_last_pastdue_actions_check', time(), $interval ); + + return; + } + + $actions_url = add_query_arg( array( + 'page' => 'action-scheduler', + 'status' => 'past-due', + 'order' => 'asc', + ), admin_url( 'tools.php' ) ); + + # Print notice. + echo '

            '; + printf( + _n( + // translators: 1) is the number of affected actions, 2) is a link to an admin screen. + 'Action Scheduler: %1$d past-due action found; something may be wrong. Read documentation »', + 'Action Scheduler: %1$d past-due actions found; something may be wrong. Read documentation »', + $num_pastdue_actions, + 'woocommerce' + ), + $num_pastdue_actions, + esc_attr( esc_url( $actions_url ) ) + ); + echo '

            '; + + # Facilitate third-parties to evaluate and print notices. + do_action( 'action_scheduler_pastdue_actions_extra_notices', $query_args ); + } + + /** + * Provide more information about the screen and its data in the help tab. + */ + public function add_help_tabs() { + $screen = get_current_screen(); + + if ( ! $screen || self::$screen_id != $screen->id ) { + return; + } + + $as_version = ActionScheduler_Versions::instance()->latest_version(); + $screen->add_help_tab( + array( + 'id' => 'action_scheduler_about', + 'title' => __( 'About', 'woocommerce' ), + 'content' => + '

            ' . sprintf( __( 'About Action Scheduler %s', 'woocommerce' ), $as_version ) . '

            ' . + '

            ' . + __( 'Action Scheduler is a scalable, traceable job queue for background processing large sets of actions. Action Scheduler works by triggering an action hook to run at some time in the future. Scheduled actions can also be scheduled to run on a recurring schedule.', 'woocommerce' ) . + '

            ', + ) + ); + + $screen->add_help_tab( + array( + 'id' => 'action_scheduler_columns', + 'title' => __( 'Columns', 'woocommerce' ), + 'content' => + '

            ' . __( 'Scheduled Action Columns', 'woocommerce' ) . '

            ' . + '
              ' . + sprintf( '
            • %1$s: %2$s
            • ', __( 'Hook', 'woocommerce' ), __( 'Name of the action hook that will be triggered.', 'woocommerce' ) ) . + sprintf( '
            • %1$s: %2$s
            • ', __( 'Status', 'woocommerce' ), __( 'Action statuses are Pending, Complete, Canceled, Failed', 'woocommerce' ) ) . + sprintf( '
            • %1$s: %2$s
            • ', __( 'Arguments', 'woocommerce' ), __( 'Optional data array passed to the action hook.', 'woocommerce' ) ) . + sprintf( '
            • %1$s: %2$s
            • ', __( 'Group', 'woocommerce' ), __( 'Optional action group.', 'woocommerce' ) ) . + sprintf( '
            • %1$s: %2$s
            • ', __( 'Recurrence', 'woocommerce' ), __( 'The action\'s schedule frequency.', 'woocommerce' ) ) . + sprintf( '
            • %1$s: %2$s
            • ', __( 'Scheduled', 'woocommerce' ), __( 'The date/time the action is/was scheduled to run.', 'woocommerce' ) ) . + sprintf( '
            • %1$s: %2$s
            • ', __( 'Log', 'woocommerce' ), __( 'Activity log for the action.', 'woocommerce' ) ) . + '
            ', + ) + ); + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_AsyncRequest_QueueRunner.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_AsyncRequest_QueueRunner.php new file mode 100644 index 00000000..9e5a139a --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_AsyncRequest_QueueRunner.php @@ -0,0 +1,98 @@ +store = $store; + } + + /** + * Handle async requests + * + * Run a queue, and maybe dispatch another async request to run another queue + * if there are still pending actions after completing a queue in this request. + */ + protected function handle() { + do_action( 'action_scheduler_run_queue', 'Async Request' ); // run a queue in the same way as WP Cron, but declare the Async Request context + + $sleep_seconds = $this->get_sleep_seconds(); + + if ( $sleep_seconds ) { + sleep( $sleep_seconds ); + } + + $this->maybe_dispatch(); + } + + /** + * If the async request runner is needed and allowed to run, dispatch a request. + */ + public function maybe_dispatch() { + if ( ! $this->allow() ) { + return; + } + + $this->dispatch(); + ActionScheduler_QueueRunner::instance()->unhook_dispatch_async_request(); + } + + /** + * Only allow async requests when needed. + * + * Also allow 3rd party code to disable running actions via async requests. + */ + protected function allow() { + + if ( ! has_action( 'action_scheduler_run_queue' ) || ActionScheduler::runner()->has_maximum_concurrent_batches() || ! $this->store->has_pending_actions_due() ) { + $allow = false; + } else { + $allow = true; + } + + return apply_filters( 'action_scheduler_allow_async_request_runner', $allow ); + } + + /** + * Chaining async requests can crash MySQL. A brief sleep call in PHP prevents that. + */ + protected function get_sleep_seconds() { + return apply_filters( 'action_scheduler_async_request_sleep_seconds', 5, $this ); + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_Compatibility.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_Compatibility.php new file mode 100644 index 00000000..210d5be8 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_Compatibility.php @@ -0,0 +1,106 @@ + $wp_max_limit_int && $filtered_limit_int > $current_limit_int ) ) { + if ( false !== @ini_set( 'memory_limit', $filtered_limit ) ) { + return $filtered_limit; + } else { + return false; + } + } elseif ( -1 === $wp_max_limit_int || $wp_max_limit_int > $current_limit_int ) { + if ( false !== @ini_set( 'memory_limit', $wp_max_limit ) ) { + return $wp_max_limit; + } else { + return false; + } + } + return false; + } + + /** + * Attempts to raise the PHP timeout for time intensive processes. + * + * Only allows raising the existing limit and prevents lowering it. Wrapper for wc_set_time_limit(), when available. + * + * @param int $limit The time limit in seconds. + */ + public static function raise_time_limit( $limit = 0 ) { + $limit = (int) $limit; + $max_execution_time = (int) ini_get( 'max_execution_time' ); + + // If the max execution time is already set to zero (unlimited), there is no reason to make a further change. + if ( 0 === $max_execution_time ) { + return; + } + + // Whichever of $max_execution_time or $limit is higher is the amount by which we raise the time limit. + $raise_by = 0 === $limit || $limit > $max_execution_time ? $limit : $max_execution_time; + + if ( function_exists( 'wc_set_time_limit' ) ) { + wc_set_time_limit( $raise_by ); + } elseif ( function_exists( 'set_time_limit' ) && false === strpos( ini_get( 'disable_functions' ), 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) { // phpcs:ignore PHPCompatibility.IniDirectives.RemovedIniDirectives.safe_modeDeprecatedRemoved + @set_time_limit( $raise_by ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged + } + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_DataController.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_DataController.php new file mode 100644 index 00000000..1449bfd8 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_DataController.php @@ -0,0 +1,188 @@ +=' ); + return $php_support && apply_filters( 'action_scheduler_migration_dependencies_met', true ); + } + + /** + * Get a flag indicating whether the migration is complete. + * + * @return bool Whether the flag has been set marking the migration as complete + */ + public static function is_migration_complete() { + return get_option( self::STATUS_FLAG ) === self::STATUS_COMPLETE; + } + + /** + * Mark the migration as complete. + */ + public static function mark_migration_complete() { + update_option( self::STATUS_FLAG, self::STATUS_COMPLETE ); + } + + /** + * Unmark migration when a plugin is de-activated. Will not work in case of silent activation, for example in an update. + * We do this to mitigate the bug of lost actions which happens if there was an AS 2.x to AS 3.x migration in the past, but that plugin is now + * deactivated and the site was running on AS 2.x again. + */ + public static function mark_migration_incomplete() { + delete_option( self::STATUS_FLAG ); + } + + /** + * Set the action store class name. + * + * @param string $class Classname of the store class. + * + * @return string + */ + public static function set_store_class( $class ) { + return self::DATASTORE_CLASS; + } + + /** + * Set the action logger class name. + * + * @param string $class Classname of the logger class. + * + * @return string + */ + public static function set_logger_class( $class ) { + return self::LOGGER_CLASS; + } + + /** + * Set the sleep time in seconds. + * + * @param integer $sleep_time The number of seconds to pause before resuming operation. + */ + public static function set_sleep_time( $sleep_time ) { + self::$sleep_time = (int) $sleep_time; + } + + /** + * Set the tick count required for freeing memory. + * + * @param integer $free_ticks The number of ticks to free memory on. + */ + public static function set_free_ticks( $free_ticks ) { + self::$free_ticks = (int) $free_ticks; + } + + /** + * Free memory if conditions are met. + * + * @param int $ticks Current tick count. + */ + public static function maybe_free_memory( $ticks ) { + if ( self::$free_ticks && 0 === $ticks % self::$free_ticks ) { + self::free_memory(); + } + } + + /** + * Reduce memory footprint by clearing the database query and object caches. + */ + public static function free_memory() { + if ( 0 < self::$sleep_time ) { + /* translators: %d: amount of time */ + \WP_CLI::warning( sprintf( _n( 'Stopped the insanity for %d second', 'Stopped the insanity for %d seconds', self::$sleep_time, 'woocommerce' ), self::$sleep_time ) ); + sleep( self::$sleep_time ); + } + + \WP_CLI::warning( __( 'Attempting to reduce used memory...', 'woocommerce' ) ); + + /** + * @var $wpdb \wpdb + * @var $wp_object_cache \WP_Object_Cache + */ + global $wpdb, $wp_object_cache; + + $wpdb->queries = array(); + + if ( ! is_a( $wp_object_cache, 'WP_Object_Cache' ) ) { + return; + } + + $wp_object_cache->group_ops = array(); + $wp_object_cache->stats = array(); + $wp_object_cache->memcache_debug = array(); + $wp_object_cache->cache = array(); + + if ( is_callable( array( $wp_object_cache, '__remoteset' ) ) ) { + call_user_func( array( $wp_object_cache, '__remoteset' ) ); // important + } + } + + /** + * Connect to table datastores if migration is complete. + * Otherwise, proceed with the migration if the dependencies have been met. + */ + public static function init() { + if ( self::is_migration_complete() ) { + add_filter( 'action_scheduler_store_class', array( 'ActionScheduler_DataController', 'set_store_class' ), 100 ); + add_filter( 'action_scheduler_logger_class', array( 'ActionScheduler_DataController', 'set_logger_class' ), 100 ); + add_action( 'deactivate_plugin', array( 'ActionScheduler_DataController', 'mark_migration_incomplete' ) ); + } elseif ( self::dependencies_met() ) { + Controller::init(); + } + + add_action( 'action_scheduler/progress_tick', array( 'ActionScheduler_DataController', 'maybe_free_memory' ) ); + } + + /** + * Singleton factory. + */ + public static function instance() { + if ( ! isset( self::$instance ) ) { + self::$instance = new static(); + } + + return self::$instance; + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_DateTime.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_DateTime.php new file mode 100644 index 00000000..88e4065d --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_DateTime.php @@ -0,0 +1,80 @@ +format( 'U' ); + } + + /** + * Set the UTC offset. + * + * This represents a fixed offset instead of a timezone setting. + * + * @param $offset + */ + public function setUtcOffset( $offset ) { + $this->utcOffset = intval( $offset ); + } + + /** + * Returns the timezone offset. + * + * @return int + * @link http://php.net/manual/en/datetime.getoffset.php + */ + #[\ReturnTypeWillChange] + public function getOffset() { + return $this->utcOffset ? $this->utcOffset : parent::getOffset(); + } + + /** + * Set the TimeZone associated with the DateTime + * + * @param DateTimeZone $timezone + * + * @return static + * @link http://php.net/manual/en/datetime.settimezone.php + */ + #[\ReturnTypeWillChange] + public function setTimezone( $timezone ) { + $this->utcOffset = 0; + parent::setTimezone( $timezone ); + + return $this; + } + + /** + * Get the timestamp with the WordPress timezone offset added or subtracted. + * + * @since 3.0.0 + * @return int + */ + public function getOffsetTimestamp() { + return $this->getTimestamp() + $this->getOffset(); + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_Exception.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_Exception.php new file mode 100644 index 00000000..c701ee32 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_Exception.php @@ -0,0 +1,12 @@ +store = $store; + } + + public function attach( ActionScheduler_ActionClaim $claim ) { + $this->claim = $claim; + add_action( 'shutdown', array( $this, 'handle_unexpected_shutdown' ) ); + add_action( 'action_scheduler_before_execute', array( $this, 'track_current_action' ), 0, 1 ); + add_action( 'action_scheduler_after_execute', array( $this, 'untrack_action' ), 0, 0 ); + add_action( 'action_scheduler_execution_ignored', array( $this, 'untrack_action' ), 0, 0 ); + add_action( 'action_scheduler_failed_execution', array( $this, 'untrack_action' ), 0, 0 ); + } + + public function detach() { + $this->claim = NULL; + $this->untrack_action(); + remove_action( 'shutdown', array( $this, 'handle_unexpected_shutdown' ) ); + remove_action( 'action_scheduler_before_execute', array( $this, 'track_current_action' ), 0 ); + remove_action( 'action_scheduler_after_execute', array( $this, 'untrack_action' ), 0 ); + remove_action( 'action_scheduler_execution_ignored', array( $this, 'untrack_action' ), 0 ); + remove_action( 'action_scheduler_failed_execution', array( $this, 'untrack_action' ), 0 ); + } + + public function track_current_action( $action_id ) { + $this->action_id = $action_id; + } + + public function untrack_action() { + $this->action_id = 0; + } + + public function handle_unexpected_shutdown() { + if ( $error = error_get_last() ) { + if ( in_array( $error['type'], array( E_ERROR, E_PARSE, E_COMPILE_ERROR, E_USER_ERROR, E_RECOVERABLE_ERROR ) ) ) { + if ( !empty($this->action_id) ) { + $this->store->mark_failure( $this->action_id ); + do_action( 'action_scheduler_unexpected_shutdown', $this->action_id, $error ); + } + } + $this->store->release_claim( $this->claim ); + } + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_InvalidActionException.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_InvalidActionException.php new file mode 100644 index 00000000..fe5b3daf --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_InvalidActionException.php @@ -0,0 +1,48 @@ + label). + * + * @var array + */ + protected $columns = array(); + + /** + * Actions (name => label). + * + * @var array + */ + protected $row_actions = array(); + + /** + * The active data stores + * + * @var ActionScheduler_Store + */ + protected $store; + + /** + * A logger to use for getting action logs to display + * + * @var ActionScheduler_Logger + */ + protected $logger; + + /** + * A ActionScheduler_QueueRunner runner instance (or child class) + * + * @var ActionScheduler_QueueRunner + */ + protected $runner; + + /** + * Bulk actions. The key of the array is the method name of the implementation: + * + * bulk_(array $ids, string $sql_in). + * + * See the comments in the parent class for further details + * + * @var array + */ + protected $bulk_actions = array(); + + /** + * Flag variable to render our notifications, if any, once. + * + * @var bool + */ + protected static $did_notification = false; + + /** + * Array of seconds for common time periods, like week or month, alongside an internationalised string representation, i.e. "Day" or "Days" + * + * @var array + */ + private static $time_periods; + + /** + * Sets the current data store object into `store->action` and initialises the object. + * + * @param ActionScheduler_Store $store + * @param ActionScheduler_Logger $logger + * @param ActionScheduler_QueueRunner $runner + */ + public function __construct( ActionScheduler_Store $store, ActionScheduler_Logger $logger, ActionScheduler_QueueRunner $runner ) { + + $this->store = $store; + $this->logger = $logger; + $this->runner = $runner; + + $this->table_header = __( 'Scheduled Actions', 'woocommerce' ); + + $this->bulk_actions = array( + 'delete' => __( 'Delete', 'woocommerce' ), + ); + + $this->columns = array( + 'hook' => __( 'Hook', 'woocommerce' ), + 'status' => __( 'Status', 'woocommerce' ), + 'args' => __( 'Arguments', 'woocommerce' ), + 'group' => __( 'Group', 'woocommerce' ), + 'recurrence' => __( 'Recurrence', 'woocommerce' ), + 'schedule' => __( 'Scheduled Date', 'woocommerce' ), + 'log_entries' => __( 'Log', 'woocommerce' ), + ); + + $this->sort_by = array( + 'schedule', + 'hook', + 'group', + ); + + $this->search_by = array( + 'hook', + 'args', + 'claim_id', + ); + + $request_status = $this->get_request_status(); + + if ( empty( $request_status ) ) { + $this->sort_by[] = 'status'; + } elseif ( in_array( $request_status, array( 'in-progress', 'failed' ) ) ) { + $this->columns += array( 'claim_id' => __( 'Claim ID', 'woocommerce' ) ); + $this->sort_by[] = 'claim_id'; + } + + $this->row_actions = array( + 'hook' => array( + 'run' => array( + 'name' => __( 'Run', 'woocommerce' ), + 'desc' => __( 'Process the action now as if it were run as part of a queue', 'woocommerce' ), + ), + 'cancel' => array( + 'name' => __( 'Cancel', 'woocommerce' ), + 'desc' => __( 'Cancel the action now to avoid it being run in future', 'woocommerce' ), + 'class' => 'cancel trash', + ), + ), + ); + + self::$time_periods = array( + array( + 'seconds' => YEAR_IN_SECONDS, + /* translators: %s: amount of time */ + 'names' => _n_noop( '%s year', '%s years', 'woocommerce' ), + ), + array( + 'seconds' => MONTH_IN_SECONDS, + /* translators: %s: amount of time */ + 'names' => _n_noop( '%s month', '%s months', 'woocommerce' ), + ), + array( + 'seconds' => WEEK_IN_SECONDS, + /* translators: %s: amount of time */ + 'names' => _n_noop( '%s week', '%s weeks', 'woocommerce' ), + ), + array( + 'seconds' => DAY_IN_SECONDS, + /* translators: %s: amount of time */ + 'names' => _n_noop( '%s day', '%s days', 'woocommerce' ), + ), + array( + 'seconds' => HOUR_IN_SECONDS, + /* translators: %s: amount of time */ + 'names' => _n_noop( '%s hour', '%s hours', 'woocommerce' ), + ), + array( + 'seconds' => MINUTE_IN_SECONDS, + /* translators: %s: amount of time */ + 'names' => _n_noop( '%s minute', '%s minutes', 'woocommerce' ), + ), + array( + 'seconds' => 1, + /* translators: %s: amount of time */ + 'names' => _n_noop( '%s second', '%s seconds', 'woocommerce' ), + ), + ); + + parent::__construct( + array( + 'singular' => 'action-scheduler', + 'plural' => 'action-scheduler', + 'ajax' => false, + ) + ); + + add_screen_option( + 'per_page', + array( + 'default' => $this->items_per_page, + ) + ); + + add_filter( 'set_screen_option_' . $this->get_per_page_option_name(), array( $this, 'set_items_per_page_option' ), 10, 3 ); + set_screen_options(); + } + + /** + * Handles setting the items_per_page option for this screen. + * + * @param mixed $status Default false (to skip saving the current option). + * @param string $option Screen option name. + * @param int $value Screen option value. + * @return int + */ + public function set_items_per_page_option( $status, $option, $value ) { + return $value; + } + /** + * Convert an interval of seconds into a two part human friendly string. + * + * The WordPress human_time_diff() function only calculates the time difference to one degree, meaning + * even if an action is 1 day and 11 hours away, it will display "1 day". This function goes one step + * further to display two degrees of accuracy. + * + * Inspired by the Crontrol::interval() function by Edward Dale: https://wordpress.org/plugins/wp-crontrol/ + * + * @param int $interval A interval in seconds. + * @param int $periods_to_include Depth of time periods to include, e.g. for an interval of 70, and $periods_to_include of 2, both minutes and seconds would be included. With a value of 1, only minutes would be included. + * @return string A human friendly string representation of the interval. + */ + private static function human_interval( $interval, $periods_to_include = 2 ) { + + if ( $interval <= 0 ) { + return __( 'Now!', 'woocommerce' ); + } + + $output = ''; + + for ( $time_period_index = 0, $periods_included = 0, $seconds_remaining = $interval; $time_period_index < count( self::$time_periods ) && $seconds_remaining > 0 && $periods_included < $periods_to_include; $time_period_index++ ) { + + $periods_in_interval = floor( $seconds_remaining / self::$time_periods[ $time_period_index ]['seconds'] ); + + if ( $periods_in_interval > 0 ) { + if ( ! empty( $output ) ) { + $output .= ' '; + } + $output .= sprintf( _n( self::$time_periods[ $time_period_index ]['names'][0], self::$time_periods[ $time_period_index ]['names'][1], $periods_in_interval, 'woocommerce' ), $periods_in_interval ); + $seconds_remaining -= $periods_in_interval * self::$time_periods[ $time_period_index ]['seconds']; + $periods_included++; + } + } + + return $output; + } + + /** + * Returns the recurrence of an action or 'Non-repeating'. The output is human readable. + * + * @param ActionScheduler_Action $action + * + * @return string + */ + protected function get_recurrence( $action ) { + $schedule = $action->get_schedule(); + if ( $schedule->is_recurring() && method_exists( $schedule, 'get_recurrence' ) ) { + $recurrence = $schedule->get_recurrence(); + + if ( is_numeric( $recurrence ) ) { + /* translators: %s: time interval */ + return sprintf( __( 'Every %s', 'woocommerce' ), self::human_interval( $recurrence ) ); + } else { + return $recurrence; + } + } + + return __( 'Non-repeating', 'woocommerce' ); + } + + /** + * Serializes the argument of an action to render it in a human friendly format. + * + * @param array $row The array representation of the current row of the table + * + * @return string + */ + public function column_args( array $row ) { + if ( empty( $row['args'] ) ) { + return apply_filters( 'action_scheduler_list_table_column_args', '', $row ); + } + + $row_html = '
              '; + foreach ( $row['args'] as $key => $value ) { + $row_html .= sprintf( '
            • %s => %s
            • ', esc_html( var_export( $key, true ) ), esc_html( var_export( $value, true ) ) ); + } + $row_html .= '
            '; + + return apply_filters( 'action_scheduler_list_table_column_args', $row_html, $row ); + } + + /** + * Prints the logs entries inline. We do so to avoid loading Javascript and other hacks to show it in a modal. + * + * @param array $row Action array. + * @return string + */ + public function column_log_entries( array $row ) { + + $log_entries_html = '
              '; + + $timezone = new DateTimezone( 'UTC' ); + + foreach ( $row['log_entries'] as $log_entry ) { + $log_entries_html .= $this->get_log_entry_html( $log_entry, $timezone ); + } + + $log_entries_html .= '
            '; + + return $log_entries_html; + } + + /** + * Prints the logs entries inline. We do so to avoid loading Javascript and other hacks to show it in a modal. + * + * @param ActionScheduler_LogEntry $log_entry + * @param DateTimezone $timezone + * @return string + */ + protected function get_log_entry_html( ActionScheduler_LogEntry $log_entry, DateTimezone $timezone ) { + $date = $log_entry->get_date(); + $date->setTimezone( $timezone ); + return sprintf( '
          • %s
            %s
          • ', esc_html( $date->format( 'Y-m-d H:i:s O' ) ), esc_html( $log_entry->get_message() ) ); + } + + /** + * Only display row actions for pending actions. + * + * @param array $row Row to render + * @param string $column_name Current row + * + * @return string + */ + protected function maybe_render_actions( $row, $column_name ) { + if ( 'pending' === strtolower( $row[ 'status_name' ] ) ) { + return parent::maybe_render_actions( $row, $column_name ); + } + + return ''; + } + + /** + * Renders admin notifications + * + * Notifications: + * 1. When the maximum number of tasks are being executed simultaneously. + * 2. Notifications when a task is manually executed. + * 3. Tables are missing. + */ + public function display_admin_notices() { + global $wpdb; + + if ( ( is_a( $this->store, 'ActionScheduler_HybridStore' ) || is_a( $this->store, 'ActionScheduler_DBStore' ) ) && apply_filters( 'action_scheduler_enable_recreate_data_store', true ) ) { + $table_list = array( + 'actionscheduler_actions', + 'actionscheduler_logs', + 'actionscheduler_groups', + 'actionscheduler_claims', + ); + + $found_tables = $wpdb->get_col( "SHOW TABLES LIKE '{$wpdb->prefix}actionscheduler%'" ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared + foreach ( $table_list as $table_name ) { + if ( ! in_array( $wpdb->prefix . $table_name, $found_tables ) ) { + $this->admin_notices[] = array( + 'class' => 'error', + 'message' => __( 'It appears one or more database tables were missing. Attempting to re-create the missing table(s).' , 'woocommerce' ), + ); + $this->recreate_tables(); + parent::display_admin_notices(); + + return; + } + } + } + + if ( $this->runner->has_maximum_concurrent_batches() ) { + $claim_count = $this->store->get_claim_count(); + $this->admin_notices[] = array( + 'class' => 'updated', + 'message' => sprintf( + /* translators: %s: amount of claims */ + _n( + 'Maximum simultaneous queues already in progress (%s queue). No additional queues will begin processing until the current queues are complete.', + 'Maximum simultaneous queues already in progress (%s queues). No additional queues will begin processing until the current queues are complete.', + $claim_count, + 'woocommerce' + ), + $claim_count + ), + ); + } elseif ( $this->store->has_pending_actions_due() ) { + + $async_request_lock_expiration = ActionScheduler::lock()->get_expiration( 'async-request-runner' ); + + // No lock set or lock expired + if ( false === $async_request_lock_expiration || $async_request_lock_expiration < time() ) { + $in_progress_url = add_query_arg( 'status', 'in-progress', remove_query_arg( 'status' ) ); + /* translators: %s: process URL */ + $async_request_message = sprintf( __( 'A new queue has begun processing. View actions in-progress »', 'woocommerce' ), esc_url( $in_progress_url ) ); + } else { + /* translators: %d: seconds */ + $async_request_message = sprintf( __( 'The next queue will begin processing in approximately %d seconds.', 'woocommerce' ), $async_request_lock_expiration - time() ); + } + + $this->admin_notices[] = array( + 'class' => 'notice notice-info', + 'message' => $async_request_message, + ); + } + + $notification = get_transient( 'action_scheduler_admin_notice' ); + + if ( is_array( $notification ) ) { + delete_transient( 'action_scheduler_admin_notice' ); + + $action = $this->store->fetch_action( $notification['action_id'] ); + $action_hook_html = '' . $action->get_hook() . ''; + if ( 1 == $notification['success'] ) { + $class = 'updated'; + switch ( $notification['row_action_type'] ) { + case 'run' : + /* translators: %s: action HTML */ + $action_message_html = sprintf( __( 'Successfully executed action: %s', 'woocommerce' ), $action_hook_html ); + break; + case 'cancel' : + /* translators: %s: action HTML */ + $action_message_html = sprintf( __( 'Successfully canceled action: %s', 'woocommerce' ), $action_hook_html ); + break; + default : + /* translators: %s: action HTML */ + $action_message_html = sprintf( __( 'Successfully processed change for action: %s', 'woocommerce' ), $action_hook_html ); + break; + } + } else { + $class = 'error'; + /* translators: 1: action HTML 2: action ID 3: error message */ + $action_message_html = sprintf( __( 'Could not process change for action: "%1$s" (ID: %2$d). Error: %3$s', 'woocommerce' ), $action_hook_html, esc_html( $notification['action_id'] ), esc_html( $notification['error_message'] ) ); + } + + $action_message_html = apply_filters( 'action_scheduler_admin_notice_html', $action_message_html, $action, $notification ); + + $this->admin_notices[] = array( + 'class' => $class, + 'message' => $action_message_html, + ); + } + + parent::display_admin_notices(); + } + + /** + * Prints the scheduled date in a human friendly format. + * + * @param array $row The array representation of the current row of the table + * + * @return string + */ + public function column_schedule( $row ) { + return $this->get_schedule_display_string( $row['schedule'] ); + } + + /** + * Get the scheduled date in a human friendly format. + * + * @param ActionScheduler_Schedule $schedule + * @return string + */ + protected function get_schedule_display_string( ActionScheduler_Schedule $schedule ) { + + $schedule_display_string = ''; + + if ( is_a( $schedule, 'ActionScheduler_NullSchedule' ) ) { + return __( 'async', 'woocommerce' ); + } + + if ( ! method_exists( $schedule, 'get_date' ) || ! $schedule->get_date() ) { + return '0000-00-00 00:00:00'; + } + + $next_timestamp = $schedule->get_date()->getTimestamp(); + + $schedule_display_string .= $schedule->get_date()->format( 'Y-m-d H:i:s O' ); + $schedule_display_string .= '
            '; + + if ( gmdate( 'U' ) > $next_timestamp ) { + /* translators: %s: date interval */ + $schedule_display_string .= sprintf( __( ' (%s ago)', 'woocommerce' ), self::human_interval( gmdate( 'U' ) - $next_timestamp ) ); + } else { + /* translators: %s: date interval */ + $schedule_display_string .= sprintf( __( ' (%s)', 'woocommerce' ), self::human_interval( $next_timestamp - gmdate( 'U' ) ) ); + } + + return $schedule_display_string; + } + + /** + * Bulk delete + * + * Deletes actions based on their ID. This is the handler for the bulk delete. It assumes the data + * properly validated by the callee and it will delete the actions without any extra validation. + * + * @param array $ids + * @param string $ids_sql Inherited and unused + */ + protected function bulk_delete( array $ids, $ids_sql ) { + foreach ( $ids as $id ) { + try { + $this->store->delete_action( $id ); + } catch ( Exception $e ) { + // A possible reason for an exception would include a scenario where the same action is deleted by a + // concurrent request. + error_log( + sprintf( + /* translators: 1: action ID 2: exception message. */ + __( 'Action Scheduler was unable to delete action %1$d. Reason: %2$s', 'woocommerce' ), + $id, + $e->getMessage() + ) + ); + } + } + } + + /** + * Implements the logic behind running an action. ActionScheduler_Abstract_ListTable validates the request and their + * parameters are valid. + * + * @param int $action_id + */ + protected function row_action_cancel( $action_id ) { + $this->process_row_action( $action_id, 'cancel' ); + } + + /** + * Implements the logic behind running an action. ActionScheduler_Abstract_ListTable validates the request and their + * parameters are valid. + * + * @param int $action_id + */ + protected function row_action_run( $action_id ) { + $this->process_row_action( $action_id, 'run' ); + } + + /** + * Force the data store schema updates. + */ + protected function recreate_tables() { + if ( is_a( $this->store, 'ActionScheduler_HybridStore' ) ) { + $store = $this->store; + } else { + $store = new ActionScheduler_HybridStore(); + } + add_action( 'action_scheduler/created_table', array( $store, 'set_autoincrement' ), 10, 2 ); + + $store_schema = new ActionScheduler_StoreSchema(); + $logger_schema = new ActionScheduler_LoggerSchema(); + $store_schema->register_tables( true ); + $logger_schema->register_tables( true ); + + remove_action( 'action_scheduler/created_table', array( $store, 'set_autoincrement' ), 10 ); + } + /** + * Implements the logic behind processing an action once an action link is clicked on the list table. + * + * @param int $action_id + * @param string $row_action_type The type of action to perform on the action. + */ + protected function process_row_action( $action_id, $row_action_type ) { + try { + switch ( $row_action_type ) { + case 'run' : + $this->runner->process_action( $action_id, 'Admin List Table' ); + break; + case 'cancel' : + $this->store->cancel_action( $action_id ); + break; + } + $success = 1; + $error_message = ''; + } catch ( Exception $e ) { + $success = 0; + $error_message = $e->getMessage(); + } + + set_transient( 'action_scheduler_admin_notice', compact( 'action_id', 'success', 'error_message', 'row_action_type' ), 30 ); + } + + /** + * {@inheritDoc} + */ + public function prepare_items() { + $this->prepare_column_headers(); + + $per_page = $this->get_items_per_page( $this->get_per_page_option_name(), $this->items_per_page ); + + $query = array( + 'per_page' => $per_page, + 'offset' => $this->get_items_offset(), + 'status' => $this->get_request_status(), + 'orderby' => $this->get_request_orderby(), + 'order' => $this->get_request_order(), + 'search' => $this->get_request_search_query(), + ); + + /** + * Change query arguments to query for past-due actions. + * Past-due actions have the 'pending' status and are in the past. + * This is needed because registering 'past-due' as a status is overkill. + */ + if ( 'past-due' === $this->get_request_status() ) { + $query['status'] = ActionScheduler_Store::STATUS_PENDING; + $query['date'] = as_get_datetime_object(); + } + + $this->items = array(); + + $total_items = $this->store->query_actions( $query, 'count' ); + + $status_labels = $this->store->get_status_labels(); + + foreach ( $this->store->query_actions( $query ) as $action_id ) { + try { + $action = $this->store->fetch_action( $action_id ); + } catch ( Exception $e ) { + continue; + } + if ( is_a( $action, 'ActionScheduler_NullAction' ) ) { + continue; + } + $this->items[ $action_id ] = array( + 'ID' => $action_id, + 'hook' => $action->get_hook(), + 'status_name' => $this->store->get_status( $action_id ), + 'status' => $status_labels[ $this->store->get_status( $action_id ) ], + 'args' => $action->get_args(), + 'group' => $action->get_group(), + 'log_entries' => $this->logger->get_logs( $action_id ), + 'claim_id' => $this->store->get_claim_id( $action_id ), + 'recurrence' => $this->get_recurrence( $action ), + 'schedule' => $action->get_schedule(), + ); + } + + $this->set_pagination_args( array( + 'total_items' => $total_items, + 'per_page' => $per_page, + 'total_pages' => ceil( $total_items / $per_page ), + ) ); + } + + /** + * Prints the available statuses so the user can click to filter. + */ + protected function display_filter_by_status() { + $this->status_counts = $this->store->action_counts() + $this->store->extra_action_counts(); + parent::display_filter_by_status(); + } + + /** + * Get the text to display in the search box on the list table. + */ + protected function get_search_box_button_text() { + return __( 'Search hook, args and claim ID', 'woocommerce' ); + } + + /** + * {@inheritDoc} + */ + protected function get_per_page_option_name() { + return str_replace( '-', '_', $this->screen->id ) . '_per_page'; + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_LogEntry.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_LogEntry.php new file mode 100644 index 00000000..714efe37 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_LogEntry.php @@ -0,0 +1,68 @@ +comment_type + * to ActionScheduler_LogEntry::__construct(), goodness knows why, and the Follow-up Emails plugin + * hard-codes loading its own version of ActionScheduler_wpCommentLogger with that out-dated method, + * goodness knows why, so we need to guard against that here instead of using a DateTime type declaration + * for the constructor's 3rd param of $date and causing a fatal error with older versions of FUE. + */ + if ( null !== $date && ! is_a( $date, 'DateTime' ) ) { + _doing_it_wrong( __METHOD__, 'The third parameter must be a valid DateTime instance, or null.', '2.0.0' ); + $date = null; + } + + $this->action_id = $action_id; + $this->message = $message; + $this->date = $date ? $date : new Datetime; + } + + /** + * Returns the date when this log entry was created + * + * @return Datetime + */ + public function get_date() { + return $this->date; + } + + public function get_action_id() { + return $this->action_id; + } + + public function get_message() { + return $this->message; + } +} + diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_NullLogEntry.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_NullLogEntry.php new file mode 100644 index 00000000..fcb4c5f3 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_NullLogEntry.php @@ -0,0 +1,12 @@ +maybe_dispatch_async_request() uses a lock to avoid + * calling ActionScheduler_QueueRunner->has_maximum_concurrent_batches() every time the 'shutdown', + * hook is triggered, because that method calls ActionScheduler_QueueRunner->store->get_claim_count() + * to find the current number of claims in the database. + * + * @param string $lock_type A string to identify different lock types. + * @bool True if lock value has changed, false if not or if set failed. + */ + public function set( $lock_type ) { + global $wpdb; + + $lock_key = $this->get_key( $lock_type ); + $existing_lock_value = $this->get_existing_lock( $lock_type ); + $new_lock_value = $this->new_lock_value( $lock_type ); + + // The lock may not exist yet, or may have been deleted. + if ( empty( $existing_lock_value ) ) { + return (bool) $wpdb->insert( + $wpdb->options, + array( + 'option_name' => $lock_key, + 'option_value' => $new_lock_value, + 'autoload' => 'no', + ) + ); + } + + if ( $this->get_expiration_from( $existing_lock_value ) >= time() ) { + return false; + } + + // Otherwise, try to obtain the lock. + return (bool) $wpdb->update( + $wpdb->options, + array( 'option_value' => $new_lock_value ), + array( + 'option_name' => $lock_key, + 'option_value' => $existing_lock_value, + ) + ); + } + + /** + * If a lock is set, return the timestamp it was set to expiry. + * + * @param string $lock_type A string to identify different lock types. + * @return bool|int False if no lock is set, otherwise the timestamp for when the lock is set to expire. + */ + public function get_expiration( $lock_type ) { + return $this->get_expiration_from( $this->get_existing_lock( $lock_type ) ); + } + + /** + * Given the lock string, derives the lock expiration timestamp (or false if it cannot be determined). + * + * @param string $lock_value String containing a timestamp, or pipe-separated combination of unique value and timestamp. + * + * @return false|int + */ + private function get_expiration_from( $lock_value ) { + $lock_string = explode( '|', $lock_value ); + + // Old style lock? + if ( count( $lock_string ) === 1 && is_numeric( $lock_string[0] ) ) { + return (int) $lock_string[0]; + } + + // New style lock? + if ( count( $lock_string ) === 2 && is_numeric( $lock_string[1] ) ) { + return (int) $lock_string[1]; + } + + return false; + } + + /** + * Get the key to use for storing the lock in the transient + * + * @param string $lock_type A string to identify different lock types. + * @return string + */ + protected function get_key( $lock_type ) { + return sprintf( 'action_scheduler_lock_%s', $lock_type ); + } + + /** + * Supplies the existing lock value, or an empty string if not set. + * + * @param string $lock_type A string to identify different lock types. + * + * @return string + */ + private function get_existing_lock( $lock_type ) { + global $wpdb; + + // Now grab the existing lock value, if there is one. + return (string) $wpdb->get_var( + $wpdb->prepare( + "SELECT option_value FROM $wpdb->options WHERE option_name = %s", + $this->get_key( $lock_type ) + ) + ); + } + + /** + * Supplies a lock value consisting of a unique value and the current timestamp, which are separated by a pipe + * character. + * + * Example: (string) "649de012e6b262.09774912|1688068114" + * + * @param string $lock_type A string to identify different lock types. + * + * @return string + */ + private function new_lock_value( $lock_type ) { + return uniqid( '', true ) . '|' . ( time() + $this->get_duration( $lock_type ) ); + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_QueueCleaner.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_QueueCleaner.php new file mode 100644 index 00000000..89417184 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_QueueCleaner.php @@ -0,0 +1,234 @@ +store = $store ? $store : ActionScheduler_Store::instance(); + $this->batch_size = $batch_size; + } + + /** + * Default queue cleaner process used by queue runner. + * + * @return array + */ + public function delete_old_actions() { + /** + * Filter the minimum scheduled date age for action deletion. + * + * @param int $retention_period Minimum scheduled age in seconds of the actions to be deleted. + */ + $lifespan = apply_filters( 'action_scheduler_retention_period', $this->month_in_seconds ); + + try { + $cutoff = as_get_datetime_object( $lifespan . ' seconds ago' ); + } catch ( Exception $e ) { + _doing_it_wrong( + __METHOD__, + sprintf( + /* Translators: %s is the exception message. */ + esc_html__( 'It was not possible to determine a valid cut-off time: %s.', 'woocommerce' ), + esc_html( $e->getMessage() ) + ), + '3.5.5' + ); + + return array(); + } + + + /** + * Filter the statuses when cleaning the queue. + * + * @param string[] $default_statuses_to_purge Action statuses to clean. + */ + $statuses_to_purge = (array) apply_filters( 'action_scheduler_default_cleaner_statuses', $this->default_statuses_to_purge ); + + return $this->clean_actions( $statuses_to_purge, $cutoff, $this->get_batch_size() ); + } + + /** + * Delete selected actions limited by status and date. + * + * @param string[] $statuses_to_purge List of action statuses to purge. Defaults to canceled, complete. + * @param DateTime $cutoff_date Date limit for selecting actions. Defaults to 31 days ago. + * @param int|null $batch_size Maximum number of actions per status to delete. Defaults to 20. + * @param string $context Calling process context. Defaults to `old`. + * @return array Actions deleted. + */ + public function clean_actions( array $statuses_to_purge, DateTime $cutoff_date, $batch_size = null, $context = 'old' ) { + $batch_size = $batch_size !== null ? $batch_size : $this->batch_size; + $cutoff = $cutoff_date !== null ? $cutoff_date : as_get_datetime_object( $this->month_in_seconds . ' seconds ago' ); + $lifespan = time() - $cutoff->getTimestamp(); + if ( empty( $statuses_to_purge ) ) { + $statuses_to_purge = $this->default_statuses_to_purge; + } + + $deleted_actions = []; + foreach ( $statuses_to_purge as $status ) { + $actions_to_delete = $this->store->query_actions( array( + 'status' => $status, + 'modified' => $cutoff, + 'modified_compare' => '<=', + 'per_page' => $batch_size, + 'orderby' => 'none', + ) ); + + $deleted_actions = array_merge( $deleted_actions, $this->delete_actions( $actions_to_delete, $lifespan, $context ) ); + } + + return $deleted_actions; + } + + /** + * @param int[] $actions_to_delete List of action IDs to delete. + * @param int $lifespan Minimum scheduled age in seconds of the actions being deleted. + * @param string $context Context of the delete request. + * @return array Deleted action IDs. + */ + private function delete_actions( array $actions_to_delete, $lifespan = null, $context = 'old' ) { + $deleted_actions = []; + if ( $lifespan === null ) { + $lifespan = $this->month_in_seconds; + } + + foreach ( $actions_to_delete as $action_id ) { + try { + $this->store->delete_action( $action_id ); + $deleted_actions[] = $action_id; + } catch ( Exception $e ) { + /** + * Notify 3rd party code of exceptions when deleting a completed action older than the retention period + * + * This hook provides a way for 3rd party code to log or otherwise handle exceptions relating to their + * actions. + * + * @param int $action_id The scheduled actions ID in the data store + * @param Exception $e The exception thrown when attempting to delete the action from the data store + * @param int $lifespan The retention period, in seconds, for old actions + * @param int $count_of_actions_to_delete The number of old actions being deleted in this batch + * @since 2.0.0 + * + */ + do_action( "action_scheduler_failed_{$context}_action_deletion", $action_id, $e, $lifespan, count( $actions_to_delete ) ); + } + } + return $deleted_actions; + } + + /** + * Unclaim pending actions that have not been run within a given time limit. + * + * When called by ActionScheduler_Abstract_QueueRunner::run_cleanup(), the time limit passed + * as a parameter is 10x the time limit used for queue processing. + * + * @param int $time_limit The number of seconds to allow a queue to run before unclaiming its pending actions. Default 300 (5 minutes). + */ + public function reset_timeouts( $time_limit = 300 ) { + $timeout = apply_filters( 'action_scheduler_timeout_period', $time_limit ); + if ( $timeout < 0 ) { + return; + } + $cutoff = as_get_datetime_object($timeout.' seconds ago'); + $actions_to_reset = $this->store->query_actions( array( + 'status' => ActionScheduler_Store::STATUS_PENDING, + 'modified' => $cutoff, + 'modified_compare' => '<=', + 'claimed' => true, + 'per_page' => $this->get_batch_size(), + 'orderby' => 'none', + ) ); + + foreach ( $actions_to_reset as $action_id ) { + $this->store->unclaim_action( $action_id ); + do_action( 'action_scheduler_reset_action', $action_id ); + } + } + + /** + * Mark actions that have been running for more than a given time limit as failed, based on + * the assumption some uncatachable and unloggable fatal error occurred during processing. + * + * When called by ActionScheduler_Abstract_QueueRunner::run_cleanup(), the time limit passed + * as a parameter is 10x the time limit used for queue processing. + * + * @param int $time_limit The number of seconds to allow an action to run before it is considered to have failed. Default 300 (5 minutes). + */ + public function mark_failures( $time_limit = 300 ) { + $timeout = apply_filters( 'action_scheduler_failure_period', $time_limit ); + if ( $timeout < 0 ) { + return; + } + $cutoff = as_get_datetime_object($timeout.' seconds ago'); + $actions_to_reset = $this->store->query_actions( array( + 'status' => ActionScheduler_Store::STATUS_RUNNING, + 'modified' => $cutoff, + 'modified_compare' => '<=', + 'per_page' => $this->get_batch_size(), + 'orderby' => 'none', + ) ); + + foreach ( $actions_to_reset as $action_id ) { + $this->store->mark_failure( $action_id ); + do_action( 'action_scheduler_failed_action', $action_id, $timeout ); + } + } + + /** + * Do all of the cleaning actions. + * + * @param int $time_limit The number of seconds to use as the timeout and failure period. Default 300 (5 minutes). + * @author Jeremy Pry + */ + public function clean( $time_limit = 300 ) { + $this->delete_old_actions(); + $this->reset_timeouts( $time_limit ); + $this->mark_failures( $time_limit ); + } + + /** + * Get the batch size for cleaning the queue. + * + * @author Jeremy Pry + * @return int + */ + protected function get_batch_size() { + /** + * Filter the batch size when cleaning the queue. + * + * @param int $batch_size The number of actions to clean in one batch. + */ + return absint( apply_filters( 'action_scheduler_cleanup_batch_size', $this->batch_size ) ); + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_QueueRunner.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_QueueRunner.php new file mode 100644 index 00000000..e7e2b6ac --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_QueueRunner.php @@ -0,0 +1,230 @@ +store ); + } + + $this->async_request = $async_request; + } + + /** + * @codeCoverageIgnore + */ + public function init() { + + add_filter( 'cron_schedules', array( self::instance(), 'add_wp_cron_schedule' ) ); + + // Check for and remove any WP Cron hook scheduled by Action Scheduler < 3.0.0, which didn't include the $context param + $next_timestamp = wp_next_scheduled( self::WP_CRON_HOOK ); + if ( $next_timestamp ) { + wp_unschedule_event( $next_timestamp, self::WP_CRON_HOOK ); + } + + $cron_context = array( 'WP Cron' ); + + if ( ! wp_next_scheduled( self::WP_CRON_HOOK, $cron_context ) ) { + $schedule = apply_filters( 'action_scheduler_run_schedule', self::WP_CRON_SCHEDULE ); + wp_schedule_event( time(), $schedule, self::WP_CRON_HOOK, $cron_context ); + } + + add_action( self::WP_CRON_HOOK, array( self::instance(), 'run' ) ); + $this->hook_dispatch_async_request(); + } + + /** + * Hook check for dispatching an async request. + */ + public function hook_dispatch_async_request() { + add_action( 'shutdown', array( $this, 'maybe_dispatch_async_request' ) ); + } + + /** + * Unhook check for dispatching an async request. + */ + public function unhook_dispatch_async_request() { + remove_action( 'shutdown', array( $this, 'maybe_dispatch_async_request' ) ); + } + + /** + * Check if we should dispatch an async request to process actions. + * + * This method is attached to 'shutdown', so is called frequently. To avoid slowing down + * the site, it mitigates the work performed in each request by: + * 1. checking if it's in the admin context and then + * 2. haven't run on the 'shutdown' hook within the lock time (60 seconds by default) + * 3. haven't exceeded the number of allowed batches. + * + * The order of these checks is important, because they run from a check on a value: + * 1. in memory - is_admin() maps to $GLOBALS or the WP_ADMIN constant + * 2. in memory - transients use autoloaded options by default + * 3. from a database query - has_maximum_concurrent_batches() run the query + * $this->store->get_claim_count() to find the current number of claims in the DB. + * + * If all of these conditions are met, then we request an async runner check whether it + * should dispatch a request to process pending actions. + */ + public function maybe_dispatch_async_request() { + // Only start an async queue at most once every 60 seconds. + if ( + is_admin() + && ! ActionScheduler::lock()->is_locked( 'async-request-runner' ) + && ActionScheduler::lock()->set( 'async-request-runner' ) + ) { + $this->async_request->maybe_dispatch(); + } + } + + /** + * Process actions in the queue. Attached to self::WP_CRON_HOOK i.e. 'action_scheduler_run_queue' + * + * The $context param of this method defaults to 'WP Cron', because prior to Action Scheduler 3.0.0 + * that was the only context in which this method was run, and the self::WP_CRON_HOOK hook had no context + * passed along with it. New code calling this method directly, or by triggering the self::WP_CRON_HOOK, + * should set a context as the first parameter. For an example of this, refer to the code seen in + * @see ActionScheduler_AsyncRequest_QueueRunner::handle() + * + * @param string $context Optional identifer for the context in which this action is being processed, e.g. 'WP CLI' or 'WP Cron' + * Generally, this should be capitalised and not localised as it's a proper noun. + * @return int The number of actions processed. + */ + public function run( $context = 'WP Cron' ) { + ActionScheduler_Compatibility::raise_memory_limit(); + ActionScheduler_Compatibility::raise_time_limit( $this->get_time_limit() ); + do_action( 'action_scheduler_before_process_queue' ); + $this->run_cleanup(); + + $this->processed_actions_count = 0; + if ( false === $this->has_maximum_concurrent_batches() ) { + $batch_size = apply_filters( 'action_scheduler_queue_runner_batch_size', 25 ); + do { + $processed_actions_in_batch = $this->do_batch( $batch_size, $context ); + $this->processed_actions_count += $processed_actions_in_batch; + } while ( $processed_actions_in_batch > 0 && ! $this->batch_limits_exceeded( $this->processed_actions_count ) ); // keep going until we run out of actions, time, or memory + } + + do_action( 'action_scheduler_after_process_queue' ); + return $this->processed_actions_count; + } + + /** + * Process a batch of actions pending in the queue. + * + * Actions are processed by claiming a set of pending actions then processing each one until either the batch + * size is completed, or memory or time limits are reached, defined by @see $this->batch_limits_exceeded(). + * + * @param int $size The maximum number of actions to process in the batch. + * @param string $context Optional identifer for the context in which this action is being processed, e.g. 'WP CLI' or 'WP Cron' + * Generally, this should be capitalised and not localised as it's a proper noun. + * @return int The number of actions processed. + */ + protected function do_batch( $size = 100, $context = '' ) { + $claim = $this->store->stake_claim($size); + $this->monitor->attach($claim); + $processed_actions = 0; + + foreach ( $claim->get_actions() as $action_id ) { + // bail if we lost the claim + if ( ! in_array( $action_id, $this->store->find_actions_by_claim_id( $claim->get_id() ) ) ) { + break; + } + $this->process_action( $action_id, $context ); + $processed_actions++; + + if ( $this->batch_limits_exceeded( $processed_actions + $this->processed_actions_count ) ) { + break; + } + } + $this->store->release_claim($claim); + $this->monitor->detach(); + $this->clear_caches(); + return $processed_actions; + } + + /** + * Flush the cache if possible (intended for use after a batch of actions has been processed). + * + * This is useful because running large batches can eat up memory and because invalid data can accrue in the + * runtime cache, which may lead to unexpected results. + */ + protected function clear_caches() { + /* + * Calling wp_cache_flush_runtime() lets us clear the runtime cache without invalidating the external object + * cache, so we will always prefer this method (as compared to calling wp_cache_flush()) when it is available. + * + * However, this function was only introduced in WordPress 6.0. Additionally, the preferred way of detecting if + * it is supported changed in WordPress 6.1 so we use two different methods to decide if we should utilize it. + */ + $flushing_runtime_cache_explicitly_supported = function_exists( 'wp_cache_supports' ) && wp_cache_supports( 'flush_runtime' ); + $flushing_runtime_cache_implicitly_supported = ! function_exists( 'wp_cache_supports' ) && function_exists( 'wp_cache_flush_runtime' ); + + if ( $flushing_runtime_cache_explicitly_supported || $flushing_runtime_cache_implicitly_supported ) { + wp_cache_flush_runtime(); + } elseif ( + ! wp_using_ext_object_cache() + /** + * When an external object cache is in use, and when wp_cache_flush_runtime() is not available, then + * normally the cache will not be flushed after processing a batch of actions (to avoid a performance + * penalty for other processes). + * + * This filter makes it possible to override this behavior and always flush the cache, even if an external + * object cache is in use. + * + * @since 1.0 + * + * @param bool $flush_cache If the cache should be flushed. + */ + || apply_filters( 'action_scheduler_queue_runner_flush_cache', false ) + ) { + wp_cache_flush(); + } + } + + public function add_wp_cron_schedule( $schedules ) { + $schedules['every_minute'] = array( + 'interval' => 60, // in seconds + 'display' => __( 'Every minute', 'woocommerce' ), + ); + + return $schedules; + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_Versions.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_Versions.php new file mode 100644 index 00000000..8bf228cb --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_Versions.php @@ -0,0 +1,63 @@ +versions[$version_string]) ) { + return FALSE; + } + $this->versions[$version_string] = $initialization_callback; + return TRUE; + } + + public function get_versions() { + return $this->versions; + } + + public function latest_version() { + $keys = array_keys($this->versions); + if ( empty($keys) ) { + return false; + } + uasort( $keys, 'version_compare' ); + return end($keys); + } + + public function latest_version_callback() { + $latest = $this->latest_version(); + if ( empty($latest) || !isset($this->versions[$latest]) ) { + return '__return_null'; + } + return $this->versions[$latest]; + } + + /** + * @return ActionScheduler_Versions + * @codeCoverageIgnore + */ + public static function instance() { + if ( empty(self::$instance) ) { + self::$instance = new self(); + } + return self::$instance; + } + + /** + * @codeCoverageIgnore + */ + public static function initialize_latest_version() { + $self = self::instance(); + call_user_func($self->latest_version_callback()); + } +} + \ No newline at end of file diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_WPCommentCleaner.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_WPCommentCleaner.php new file mode 100644 index 00000000..f2747438 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_WPCommentCleaner.php @@ -0,0 +1,116 @@ + Status administration screen + add_action( 'load-tools_page_action-scheduler', array( __CLASS__, 'register_admin_notice' ) ); + add_action( 'load-woocommerce_page_wc-status', array( __CLASS__, 'register_admin_notice' ) ); + } + + /** + * Determines if there are log entries in the wp comments table. + * + * Uses the flag set on migration completion set by @see self::maybe_schedule_cleanup(). + * + * @return boolean Whether there are scheduled action comments in the comments table. + */ + public static function has_logs() { + return 'yes' === get_option( self::$has_logs_option_key ); + } + + /** + * Schedules the WP Post comment table cleanup to run in 6 months if it's not already scheduled. + * Attached to the migration complete hook 'action_scheduler/migration_complete'. + */ + public static function maybe_schedule_cleanup() { + if ( (bool) get_comments( array( 'type' => ActionScheduler_wpCommentLogger::TYPE, 'number' => 1, 'fields' => 'ids' ) ) ) { + update_option( self::$has_logs_option_key, 'yes' ); + + if ( ! as_next_scheduled_action( self::$cleanup_hook ) ) { + as_schedule_single_action( gmdate( 'U' ) + ( 6 * MONTH_IN_SECONDS ), self::$cleanup_hook ); + } + } + } + + /** + * Delete all action comments from the WP Comments table. + */ + public static function delete_all_action_comments() { + global $wpdb; + $wpdb->delete( $wpdb->comments, array( 'comment_type' => ActionScheduler_wpCommentLogger::TYPE, 'comment_agent' => ActionScheduler_wpCommentLogger::AGENT ) ); + delete_option( self::$has_logs_option_key ); + } + + /** + * Registers admin notices about the orphaned action logs. + */ + public static function register_admin_notice() { + add_action( 'admin_notices', array( __CLASS__, 'print_admin_notice' ) ); + } + + /** + * Prints details about the orphaned action logs and includes information on where to learn more. + */ + public static function print_admin_notice() { + $next_cleanup_message = ''; + $next_scheduled_cleanup_hook = as_next_scheduled_action( self::$cleanup_hook ); + + if ( $next_scheduled_cleanup_hook ) { + /* translators: %s: date interval */ + $next_cleanup_message = sprintf( __( 'This data will be deleted in %s.', 'woocommerce' ), human_time_diff( gmdate( 'U' ), $next_scheduled_cleanup_hook ) ); + } + + $notice = sprintf( + /* translators: 1: next cleanup message 2: github issue URL */ + __( 'Action Scheduler has migrated data to custom tables; however, orphaned log entries exist in the WordPress Comments table. %1$s Learn more »', 'woocommerce' ), + $next_cleanup_message, + 'https://github.com/woocommerce/action-scheduler/issues/368' + ); + + echo '

            ' . wp_kses_post( $notice ) . '

            '; + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_wcSystemStatus.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_wcSystemStatus.php new file mode 100644 index 00000000..d9c48d8b --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/ActionScheduler_wcSystemStatus.php @@ -0,0 +1,167 @@ +store = $store; + } + + /** + * Display action data, including number of actions grouped by status and the oldest & newest action in each status. + * + * Helpful to identify issues, like a clogged queue. + */ + public function render() { + $action_counts = $this->store->action_counts(); + $status_labels = $this->store->get_status_labels(); + $oldest_and_newest = $this->get_oldest_and_newest( array_keys( $status_labels ) ); + + $this->get_template( $status_labels, $action_counts, $oldest_and_newest ); + } + + /** + * Get oldest and newest scheduled dates for a given set of statuses. + * + * @param array $status_keys Set of statuses to find oldest & newest action for. + * @return array + */ + protected function get_oldest_and_newest( $status_keys ) { + + $oldest_and_newest = array(); + + foreach ( $status_keys as $status ) { + $oldest_and_newest[ $status ] = array( + 'oldest' => '–', + 'newest' => '–', + ); + + if ( 'in-progress' === $status ) { + continue; + } + + $oldest_and_newest[ $status ]['oldest'] = $this->get_action_status_date( $status, 'oldest' ); + $oldest_and_newest[ $status ]['newest'] = $this->get_action_status_date( $status, 'newest' ); + } + + return $oldest_and_newest; + } + + /** + * Get oldest or newest scheduled date for a given status. + * + * @param string $status Action status label/name string. + * @param string $date_type Oldest or Newest. + * @return DateTime + */ + protected function get_action_status_date( $status, $date_type = 'oldest' ) { + + $order = 'oldest' === $date_type ? 'ASC' : 'DESC'; + + $action = $this->store->query_actions( + array( + 'claimed' => false, + 'status' => $status, + 'per_page' => 1, + 'order' => $order, + ) + ); + + if ( ! empty( $action ) ) { + $date_object = $this->store->get_date( $action[0] ); + $action_date = $date_object->format( 'Y-m-d H:i:s O' ); + } else { + $action_date = '–'; + } + + return $action_date; + } + + /** + * Get oldest or newest scheduled date for a given status. + * + * @param array $status_labels Set of statuses to find oldest & newest action for. + * @param array $action_counts Number of actions grouped by status. + * @param array $oldest_and_newest Date of the oldest and newest action with each status. + */ + protected function get_template( $status_labels, $action_counts, $oldest_and_newest ) { + $as_version = ActionScheduler_Versions::instance()->latest_version(); + $as_datastore = get_class( ActionScheduler_Store::instance() ); + ?> + + + + + + + + + + + + + + + + + + + + + + + + $count ) { + // WC uses the 3rd column for export, so we need to display more data in that (hidden when viewed as part of the table) and add an empty 2nd column. + printf( + '', + esc_html( $status_labels[ $status ] ), + esc_html( number_format_i18n( $count ) ), + esc_html( $oldest_and_newest[ $status ]['oldest'] ), + esc_html( $oldest_and_newest[ $status ]['newest'] ) + ); + } + ?> + +

             
            %1$s %2$s, Oldest: %3$s, Newest: %4$s%3$s%4$s
            + + ] + * : The maximum number of actions to delete per batch. Defaults to 20. + * + * [--batches=] + * : Limit execution to a number of batches. Defaults to 0, meaning batches will continue all eligible actions are deleted. + * + * [--status=] + * : Only clean actions with the specified status. Defaults to Canceled, Completed. Define multiple statuses as a comma separated string (without spaces), e.g. `--status=complete,failed,canceled` + * + * [--before=] + * : Only delete actions with scheduled date older than this. Defaults to 31 days. e.g `--before='7 days ago'`, `--before='02-Feb-2020 20:20:20'` + * + * [--pause=] + * : The number of seconds to pause between batches. Default no pause. + * + * @param array $args Positional arguments. + * @param array $assoc_args Keyed arguments. + * @throws \WP_CLI\ExitException When an error occurs. + * + * @subcommand clean + */ + public function clean( $args, $assoc_args ) { + // Handle passed arguments. + $batch = absint( \WP_CLI\Utils\get_flag_value( $assoc_args, 'batch-size', 20 ) ); + $batches = absint( \WP_CLI\Utils\get_flag_value( $assoc_args, 'batches', 0 ) ); + $status = explode( ',', WP_CLI\Utils\get_flag_value( $assoc_args, 'status', '' ) ); + $status = array_filter( array_map( 'trim', $status ) ); + $before = \WP_CLI\Utils\get_flag_value( $assoc_args, 'before', '' ); + $sleep = \WP_CLI\Utils\get_flag_value( $assoc_args, 'pause', 0 ); + + $batches_completed = 0; + $actions_deleted = 0; + $unlimited = $batches === 0; + try { + $lifespan = as_get_datetime_object( $before ); + } catch ( Exception $e ) { + $lifespan = null; + } + + try { + // Custom queue cleaner instance. + $cleaner = new ActionScheduler_QueueCleaner( null, $batch ); + + // Clean actions for as long as possible. + while ( $unlimited || $batches_completed < $batches ) { + if ( $sleep && $batches_completed > 0 ) { + sleep( $sleep ); + } + + $deleted = count( $cleaner->clean_actions( $status, $lifespan, null,'CLI' ) ); + if ( $deleted <= 0 ) { + break; + } + $actions_deleted += $deleted; + $batches_completed++; + $this->print_success( $deleted ); + } + } catch ( Exception $e ) { + $this->print_error( $e ); + } + + $this->print_total_batches( $batches_completed ); + if ( $batches_completed > 1 ) { + $this->print_success( $actions_deleted ); + } + } + + /** + * Print WP CLI message about how many batches of actions were processed. + * + * @param int $batches_processed + */ + protected function print_total_batches( int $batches_processed ) { + WP_CLI::log( + sprintf( + /* translators: %d refers to the total number of batches processed */ + _n( '%d batch processed.', '%d batches processed.', $batches_processed, 'woocommerce' ), + $batches_processed + ) + ); + } + + /** + * Convert an exception into a WP CLI error. + * + * @param Exception $e The error object. + * + * @throws \WP_CLI\ExitException + */ + protected function print_error( Exception $e ) { + WP_CLI::error( + sprintf( + /* translators: %s refers to the exception error message */ + __( 'There was an error deleting an action: %s', 'woocommerce' ), + $e->getMessage() + ) + ); + } + + /** + * Print a success message with the number of completed actions. + * + * @param int $actions_deleted + */ + protected function print_success( int $actions_deleted ) { + WP_CLI::success( + sprintf( + /* translators: %d refers to the total number of actions deleted */ + _n( '%d action deleted.', '%d actions deleted.', $actions_deleted, 'woocommerce' ), + $actions_deleted + ) + ); + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/WP_CLI/ActionScheduler_WPCLI_QueueRunner.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/WP_CLI/ActionScheduler_WPCLI_QueueRunner.php new file mode 100644 index 00000000..6b2eb5f0 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/WP_CLI/ActionScheduler_WPCLI_QueueRunner.php @@ -0,0 +1,198 @@ +run_cleanup(); + $this->add_hooks(); + + // Check to make sure there aren't too many concurrent processes running. + if ( $this->has_maximum_concurrent_batches() ) { + if ( $force ) { + WP_CLI::warning( __( 'There are too many concurrent batches, but the run is forced to continue.', 'woocommerce' ) ); + } else { + WP_CLI::error( __( 'There are too many concurrent batches.', 'woocommerce' ) ); + } + } + + // Stake a claim and store it. + $this->claim = $this->store->stake_claim( $batch_size, null, $hooks, $group ); + $this->monitor->attach( $this->claim ); + $this->actions = $this->claim->get_actions(); + + return count( $this->actions ); + } + + /** + * Add our hooks to the appropriate actions. + * + * @author Jeremy Pry + */ + protected function add_hooks() { + add_action( 'action_scheduler_before_execute', array( $this, 'before_execute' ) ); + add_action( 'action_scheduler_after_execute', array( $this, 'after_execute' ), 10, 2 ); + add_action( 'action_scheduler_failed_execution', array( $this, 'action_failed' ), 10, 2 ); + } + + /** + * Set up the WP CLI progress bar. + * + * @author Jeremy Pry + */ + protected function setup_progress_bar() { + $count = count( $this->actions ); + $this->progress_bar = new ProgressBar( + /* translators: %d: amount of actions */ + sprintf( _n( 'Running %d action', 'Running %d actions', $count, 'woocommerce' ), $count ), + $count + ); + } + + /** + * Process actions in the queue. + * + * @author Jeremy Pry + * + * @param string $context Optional runner context. Default 'WP CLI'. + * + * @return int The number of actions processed. + */ + public function run( $context = 'WP CLI' ) { + do_action( 'action_scheduler_before_process_queue' ); + $this->setup_progress_bar(); + foreach ( $this->actions as $action_id ) { + // Error if we lost the claim. + if ( ! in_array( $action_id, $this->store->find_actions_by_claim_id( $this->claim->get_id() ) ) ) { + WP_CLI::warning( __( 'The claim has been lost. Aborting current batch.', 'woocommerce' ) ); + break; + } + + $this->process_action( $action_id, $context ); + $this->progress_bar->tick(); + } + + $completed = $this->progress_bar->current(); + $this->progress_bar->finish(); + $this->store->release_claim( $this->claim ); + do_action( 'action_scheduler_after_process_queue' ); + + return $completed; + } + + /** + * Handle WP CLI message when the action is starting. + * + * @author Jeremy Pry + * + * @param $action_id + */ + public function before_execute( $action_id ) { + /* translators: %s refers to the action ID */ + WP_CLI::log( sprintf( __( 'Started processing action %s', 'woocommerce' ), $action_id ) ); + } + + /** + * Handle WP CLI message when the action has completed. + * + * @author Jeremy Pry + * + * @param int $action_id + * @param null|ActionScheduler_Action $action The instance of the action. Default to null for backward compatibility. + */ + public function after_execute( $action_id, $action = null ) { + // backward compatibility + if ( null === $action ) { + $action = $this->store->fetch_action( $action_id ); + } + /* translators: 1: action ID 2: hook name */ + WP_CLI::log( sprintf( __( 'Completed processing action %1$s with hook: %2$s', 'woocommerce' ), $action_id, $action->get_hook() ) ); + } + + /** + * Handle WP CLI message when the action has failed. + * + * @author Jeremy Pry + * + * @param int $action_id + * @param Exception $exception + * @throws \WP_CLI\ExitException With failure message. + */ + public function action_failed( $action_id, $exception ) { + WP_CLI::error( + /* translators: 1: action ID 2: exception message */ + sprintf( __( 'Error processing action %1$s: %2$s', 'woocommerce' ), $action_id, $exception->getMessage() ), + false + ); + } + + /** + * Sleep and help avoid hitting memory limit + * + * @param int $sleep_time Amount of seconds to sleep + * @deprecated 3.0.0 + */ + protected function stop_the_insanity( $sleep_time = 0 ) { + _deprecated_function( 'ActionScheduler_WPCLI_QueueRunner::stop_the_insanity', '3.0.0', 'ActionScheduler_DataController::free_memory' ); + + ActionScheduler_DataController::free_memory(); + } + + /** + * Maybe trigger the stop_the_insanity() method to free up memory. + */ + protected function maybe_stop_the_insanity() { + // The value returned by progress_bar->current() might be padded. Remove padding, and convert to int. + $current_iteration = intval( trim( $this->progress_bar->current() ) ); + if ( 0 === $current_iteration % 50 ) { + $this->stop_the_insanity(); + } + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/WP_CLI/ActionScheduler_WPCLI_Scheduler_command.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/WP_CLI/ActionScheduler_WPCLI_Scheduler_command.php new file mode 100644 index 00000000..69b5ef89 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/WP_CLI/ActionScheduler_WPCLI_Scheduler_command.php @@ -0,0 +1,211 @@ +init(); + $obj->register_tables( true ); + + WP_CLI::success( + sprintf( + /* translators: %s refers to the schema name*/ + __( 'Registered schema for %s', 'woocommerce' ), + $classname + ) + ); + } + } + } + + /** + * Run the Action Scheduler + * + * ## OPTIONS + * + * [--batch-size=] + * : The maximum number of actions to run. Defaults to 100. + * + * [--batches=] + * : Limit execution to a number of batches. Defaults to 0, meaning batches will continue being executed until all actions are complete. + * + * [--cleanup-batch-size=] + * : The maximum number of actions to clean up. Defaults to the value of --batch-size. + * + * [--hooks=] + * : Only run actions with the specified hook. Omitting this option runs actions with any hook. Define multiple hooks as a comma separated string (without spaces), e.g. `--hooks=hook_one,hook_two,hook_three` + * + * [--group=] + * : Only run actions from the specified group. Omitting this option runs actions from all groups. + * + * [--exclude-groups=] + * : Run actions from all groups except the specified group(s). Define multiple groups as a comma separated string (without spaces), e.g. '--group_a,group_b'. This option is ignored when `--group` is used. + * + * [--free-memory-on=] + * : The number of actions to process between freeing memory. 0 disables freeing memory. Default 50. + * + * [--pause=] + * : The number of seconds to pause when freeing memory. Default no pause. + * + * [--force] + * : Whether to force execution despite the maximum number of concurrent processes being exceeded. + * + * @param array $args Positional arguments. + * @param array $assoc_args Keyed arguments. + * @throws \WP_CLI\ExitException When an error occurs. + * + * @subcommand run + */ + public function run( $args, $assoc_args ) { + // Handle passed arguments. + $batch = absint( \WP_CLI\Utils\get_flag_value( $assoc_args, 'batch-size', 100 ) ); + $batches = absint( \WP_CLI\Utils\get_flag_value( $assoc_args, 'batches', 0 ) ); + $clean = absint( \WP_CLI\Utils\get_flag_value( $assoc_args, 'cleanup-batch-size', $batch ) ); + $hooks = explode( ',', WP_CLI\Utils\get_flag_value( $assoc_args, 'hooks', '' ) ); + $hooks = array_filter( array_map( 'trim', $hooks ) ); + $group = \WP_CLI\Utils\get_flag_value( $assoc_args, 'group', '' ); + $exclude_groups = \WP_CLI\Utils\get_flag_value( $assoc_args, 'exclude-groups', '' ); + $free_on = \WP_CLI\Utils\get_flag_value( $assoc_args, 'free-memory-on', 50 ); + $sleep = \WP_CLI\Utils\get_flag_value( $assoc_args, 'pause', 0 ); + $force = \WP_CLI\Utils\get_flag_value( $assoc_args, 'force', false ); + + ActionScheduler_DataController::set_free_ticks( $free_on ); + ActionScheduler_DataController::set_sleep_time( $sleep ); + + $batches_completed = 0; + $actions_completed = 0; + $unlimited = $batches === 0; + if ( is_callable( [ ActionScheduler::store(), 'set_claim_filter' ] ) ) { + $exclude_groups = $this->parse_comma_separated_string( $exclude_groups ); + + if ( ! empty( $exclude_groups ) ) { + ActionScheduler::store()->set_claim_filter('exclude-groups', $exclude_groups ); + } + } + + try { + // Custom queue cleaner instance. + $cleaner = new ActionScheduler_QueueCleaner( null, $clean ); + + // Get the queue runner instance + $runner = new ActionScheduler_WPCLI_QueueRunner( null, null, $cleaner ); + + // Determine how many tasks will be run in the first batch. + $total = $runner->setup( $batch, $hooks, $group, $force ); + + // Run actions for as long as possible. + while ( $total > 0 ) { + $this->print_total_actions( $total ); + $actions_completed += $runner->run(); + $batches_completed++; + + // Maybe set up tasks for the next batch. + $total = ( $unlimited || $batches_completed < $batches ) ? $runner->setup( $batch, $hooks, $group, $force ) : 0; + } + } catch ( Exception $e ) { + $this->print_error( $e ); + } + + $this->print_total_batches( $batches_completed ); + $this->print_success( $actions_completed ); + } + + /** + * Converts a string of comma-separated values into an array of those same values. + * + * @param string $string The string of one or more comma separated values. + * + * @return array + */ + private function parse_comma_separated_string( $string ): array { + return array_filter( str_getcsv( $string ) ); + } + + /** + * Print WP CLI message about how many actions are about to be processed. + * + * @author Jeremy Pry + * + * @param int $total + */ + protected function print_total_actions( $total ) { + WP_CLI::log( + sprintf( + /* translators: %d refers to how many scheduled tasks were found to run */ + _n( 'Found %d scheduled task', 'Found %d scheduled tasks', $total, 'woocommerce' ), + $total + ) + ); + } + + /** + * Print WP CLI message about how many batches of actions were processed. + * + * @author Jeremy Pry + * + * @param int $batches_completed + */ + protected function print_total_batches( $batches_completed ) { + WP_CLI::log( + sprintf( + /* translators: %d refers to the total number of batches executed */ + _n( '%d batch executed.', '%d batches executed.', $batches_completed, 'woocommerce' ), + $batches_completed + ) + ); + } + + /** + * Convert an exception into a WP CLI error. + * + * @author Jeremy Pry + * + * @param Exception $e The error object. + * + * @throws \WP_CLI\ExitException + */ + protected function print_error( Exception $e ) { + WP_CLI::error( + sprintf( + /* translators: %s refers to the exception error message */ + __( 'There was an error running the action scheduler: %s', 'woocommerce' ), + $e->getMessage() + ) + ); + } + + /** + * Print a success message with the number of completed actions. + * + * @author Jeremy Pry + * + * @param int $actions_completed + */ + protected function print_success( $actions_completed ) { + WP_CLI::success( + sprintf( + /* translators: %d refers to the total number of tasks completed */ + _n( '%d scheduled task completed.', '%d scheduled tasks completed.', $actions_completed, 'woocommerce' ), + $actions_completed + ) + ); + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/WP_CLI/Migration_Command.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/WP_CLI/Migration_Command.php new file mode 100644 index 00000000..b5b1043a --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/WP_CLI/Migration_Command.php @@ -0,0 +1,149 @@ + 'Migrates actions to the DB tables store', + 'synopsis' => [ + [ + 'type' => 'assoc', + 'name' => 'batch-size', + 'optional' => true, + 'default' => 100, + 'description' => 'The number of actions to process in each batch', + ], + [ + 'type' => 'assoc', + 'name' => 'free-memory-on', + 'optional' => true, + 'default' => 50, + 'description' => 'The number of actions to process between freeing memory. 0 disables freeing memory', + ], + [ + 'type' => 'assoc', + 'name' => 'pause', + 'optional' => true, + 'default' => 0, + 'description' => 'The number of seconds to pause when freeing memory', + ], + [ + 'type' => 'flag', + 'name' => 'dry-run', + 'optional' => true, + 'description' => 'Reports on the actions that would have been migrated, but does not change any data', + ], + ], + ] ); + } + + /** + * Process the data migration. + * + * @param array $positional_args Required for WP CLI. Not used in migration. + * @param array $assoc_args Optional arguments. + * + * @return void + */ + public function migrate( $positional_args, $assoc_args ) { + $this->init_logging(); + + $config = $this->get_migration_config( $assoc_args ); + $runner = new Runner( $config ); + $runner->init_destination(); + + $batch_size = isset( $assoc_args[ 'batch-size' ] ) ? (int) $assoc_args[ 'batch-size' ] : 100; + $free_on = isset( $assoc_args[ 'free-memory-on' ] ) ? (int) $assoc_args[ 'free-memory-on' ] : 50; + $sleep = isset( $assoc_args[ 'pause' ] ) ? (int) $assoc_args[ 'pause' ] : 0; + \ActionScheduler_DataController::set_free_ticks( $free_on ); + \ActionScheduler_DataController::set_sleep_time( $sleep ); + + do { + $actions_processed = $runner->run( $batch_size ); + $this->total_processed += $actions_processed; + } while ( $actions_processed > 0 ); + + if ( ! $config->get_dry_run() ) { + // let the scheduler know that there's nothing left to do + $scheduler = new Scheduler(); + $scheduler->mark_complete(); + } + + WP_CLI::success( sprintf( '%s complete. %d actions processed.', $config->get_dry_run() ? 'Dry run' : 'Migration', $this->total_processed ) ); + } + + /** + * Build the config object used to create the Runner + * + * @param array $args Optional arguments. + * + * @return ActionScheduler\Migration\Config + */ + private function get_migration_config( $args ) { + $args = wp_parse_args( $args, [ + 'dry-run' => false, + ] ); + + $config = Controller::instance()->get_migration_config_object(); + $config->set_dry_run( ! empty( $args[ 'dry-run' ] ) ); + + return $config; + } + + /** + * Hook command line logging into migration actions. + */ + private function init_logging() { + add_action( 'action_scheduler/migrate_action_dry_run', function ( $action_id ) { + WP_CLI::debug( sprintf( 'Dry-run: migrated action %d', $action_id ) ); + }, 10, 1 ); + add_action( 'action_scheduler/no_action_to_migrate', function ( $action_id ) { + WP_CLI::debug( sprintf( 'No action found to migrate for ID %d', $action_id ) ); + }, 10, 1 ); + add_action( 'action_scheduler/migrate_action_failed', function ( $action_id ) { + WP_CLI::warning( sprintf( 'Failed migrating action with ID %d', $action_id ) ); + }, 10, 1 ); + add_action( 'action_scheduler/migrate_action_incomplete', function ( $source_id, $destination_id ) { + WP_CLI::warning( sprintf( 'Unable to remove source action with ID %d after migrating to new ID %d', $source_id, $destination_id ) ); + }, 10, 2 ); + add_action( 'action_scheduler/migrated_action', function ( $source_id, $destination_id ) { + WP_CLI::debug( sprintf( 'Migrated source action with ID %d to new store with ID %d', $source_id, $destination_id ) ); + }, 10, 2 ); + add_action( 'action_scheduler/migration_batch_starting', function ( $batch ) { + WP_CLI::debug( 'Beginning migration of batch: ' . print_r( $batch, true ) ); + }, 10, 1 ); + add_action( 'action_scheduler/migration_batch_complete', function ( $batch ) { + WP_CLI::log( sprintf( 'Completed migration of %d actions', count( $batch ) ) ); + }, 10, 1 ); + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/WP_CLI/ProgressBar.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/WP_CLI/ProgressBar.php new file mode 100644 index 00000000..97bb2fdc --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/WP_CLI/ProgressBar.php @@ -0,0 +1,120 @@ +total_ticks = 0; + $this->message = $message; + $this->count = $count; + $this->interval = $interval; + } + + /** + * Increment the progress bar ticks. + */ + public function tick() { + if ( null === $this->progress_bar ) { + $this->setup_progress_bar(); + } + + $this->progress_bar->tick(); + $this->total_ticks++; + + do_action( 'action_scheduler/progress_tick', $this->total_ticks ); + } + + /** + * Get the progress bar tick count. + * + * @return int + */ + public function current() { + return $this->progress_bar ? $this->progress_bar->current() : 0; + } + + /** + * Finish the current progress bar. + */ + public function finish() { + if ( null !== $this->progress_bar ) { + $this->progress_bar->finish(); + } + + $this->progress_bar = null; + } + + /** + * Set the message used when creating the progress bar. + * + * @param string $message The message to be used when the next progress bar is created. + */ + public function set_message( $message ) { + $this->message = $message; + } + + /** + * Set the count for a new progress bar. + * + * @param integer $count The total number of ticks expected to complete. + */ + public function set_count( $count ) { + $this->count = $count; + $this->finish(); + } + + /** + * Set up the progress bar. + */ + protected function setup_progress_bar() { + $this->progress_bar = \WP_CLI\Utils\make_progress_bar( + $this->message, + $this->count, + $this->interval + ); + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler.php new file mode 100644 index 00000000..85269c9d --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler.php @@ -0,0 +1,338 @@ +init() (or it's parent method) set this itself, + * once it has initialized, however that would cause problems in cases where a custom data store is in + * use and it has not yet been updated to follow that same logic. + */ + function () { + self::$data_store_initialized = true; + + /** + * Fires when Action Scheduler is ready: it is safe to use the procedural API after this point. + * + * @since 3.5.5 + */ + do_action( 'action_scheduler_init' ); + }, + 1 + ); + } else { + $admin_view->init(); + $store->init(); + $logger->init(); + $runner->init(); + self::$data_store_initialized = true; + + /** + * Fires when Action Scheduler is ready: it is safe to use the procedural API after this point. + * + * @since 3.5.5 + */ + do_action( 'action_scheduler_init' ); + } + + if ( apply_filters( 'action_scheduler_load_deprecated_functions', true ) ) { + require_once( self::plugin_path( 'deprecated/functions.php' ) ); + } + + if ( defined( 'WP_CLI' ) && WP_CLI ) { + WP_CLI::add_command( 'action-scheduler', 'ActionScheduler_WPCLI_Scheduler_command' ); + WP_CLI::add_command( 'action-scheduler', 'ActionScheduler_WPCLI_Clean_Command' ); + if ( ! ActionScheduler_DataController::is_migration_complete() && Controller::instance()->allow_migration() ) { + $command = new Migration_Command(); + $command->register(); + } + } + + /** + * Handle WP comment cleanup after migration. + */ + if ( is_a( $logger, 'ActionScheduler_DBLogger' ) && ActionScheduler_DataController::is_migration_complete() && ActionScheduler_WPCommentCleaner::has_logs() ) { + ActionScheduler_WPCommentCleaner::init(); + } + + add_action( 'action_scheduler/migration_complete', 'ActionScheduler_WPCommentCleaner::maybe_schedule_cleanup' ); + } + + /** + * Check whether the AS data store has been initialized. + * + * @param string $function_name The name of the function being called. Optional. Default `null`. + * @return bool + */ + public static function is_initialized( $function_name = null ) { + if ( ! self::$data_store_initialized && ! empty( $function_name ) ) { + $message = sprintf( + /* translators: %s function name. */ + __( '%s() was called before the Action Scheduler data store was initialized', 'woocommerce' ), + esc_attr( $function_name ) + ); + _doing_it_wrong( $function_name, $message, '3.1.6' ); + } + + return self::$data_store_initialized; + } + + /** + * Determine if the class is one of our abstract classes. + * + * @since 3.0.0 + * + * @param string $class The class name. + * + * @return bool + */ + protected static function is_class_abstract( $class ) { + static $abstracts = array( + 'ActionScheduler' => true, + 'ActionScheduler_Abstract_ListTable' => true, + 'ActionScheduler_Abstract_QueueRunner' => true, + 'ActionScheduler_Abstract_Schedule' => true, + 'ActionScheduler_Abstract_RecurringSchedule' => true, + 'ActionScheduler_Lock' => true, + 'ActionScheduler_Logger' => true, + 'ActionScheduler_Abstract_Schema' => true, + 'ActionScheduler_Store' => true, + 'ActionScheduler_TimezoneHelper' => true, + ); + + return isset( $abstracts[ $class ] ) && $abstracts[ $class ]; + } + + /** + * Determine if the class is one of our migration classes. + * + * @since 3.0.0 + * + * @param string $class The class name. + * + * @return bool + */ + protected static function is_class_migration( $class ) { + static $migration_segments = array( + 'ActionMigrator' => true, + 'BatchFetcher' => true, + 'DBStoreMigrator' => true, + 'DryRun' => true, + 'LogMigrator' => true, + 'Config' => true, + 'Controller' => true, + 'Runner' => true, + 'Scheduler' => true, + ); + + $segments = explode( '_', $class ); + $segment = isset( $segments[ 1 ] ) ? $segments[ 1 ] : $class; + + return isset( $migration_segments[ $segment ] ) && $migration_segments[ $segment ]; + } + + /** + * Determine if the class is one of our WP CLI classes. + * + * @since 3.0.0 + * + * @param string $class The class name. + * + * @return bool + */ + protected static function is_class_cli( $class ) { + static $cli_segments = array( + 'QueueRunner' => true, + 'Command' => true, + 'ProgressBar' => true, + ); + + $segments = explode( '_', $class ); + $segment = isset( $segments[ 1 ] ) ? $segments[ 1 ] : $class; + + return isset( $cli_segments[ $segment ] ) && $cli_segments[ $segment ]; + } + + final public function __clone() { + trigger_error("Singleton. No cloning allowed!", E_USER_ERROR); + } + + final public function __wakeup() { + trigger_error("Singleton. No serialization allowed!", E_USER_ERROR); + } + + final private function __construct() {} + + /** Deprecated **/ + + public static function get_datetime_object( $when = null, $timezone = 'UTC' ) { + _deprecated_function( __METHOD__, '2.0', 'wcs_add_months()' ); + return as_get_datetime_object( $when, $timezone ); + } + + /** + * Issue deprecated warning if an Action Scheduler function is called in the shutdown hook. + * + * @param string $function_name The name of the function being called. + * @deprecated 3.1.6. + */ + public static function check_shutdown_hook( $function_name ) { + _deprecated_function( __FUNCTION__, '3.1.6' ); + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_ListTable.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_ListTable.php new file mode 100644 index 00000000..bf35e6eb --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_ListTable.php @@ -0,0 +1,777 @@ + value pair. The + * key must much the table column name and the value is the label, which is + * automatically translated. + * + * @var array + */ + protected $columns = array(); + + /** + * Defines the row-actions. It expects an array where the key + * is the column name and the value is an array of actions. + * + * The array of actions are key => value, where key is the method name + * (with the prefix row_action_) and the value is the label + * and title. + * + * @var array + */ + protected $row_actions = array(); + + /** + * The Primary key of our table + * + * @var string + */ + protected $ID = 'ID'; + + /** + * Enables sorting, it expects an array + * of columns (the column names are the values) + * + * @var array + */ + protected $sort_by = array(); + + /** + * The default sort order + * + * @var string + */ + protected $filter_by = array(); + + /** + * The status name => count combinations for this table's items. Used to display status filters. + * + * @var array + */ + protected $status_counts = array(); + + /** + * Notices to display when loading the table. Array of arrays of form array( 'class' => {updated|error}, 'message' => 'This is the notice text display.' ). + * + * @var array + */ + protected $admin_notices = array(); + + /** + * Localised string displayed in the

            element above the able. + * + * @var string + */ + protected $table_header; + + /** + * Enables bulk actions. It must be an array where the key is the action name + * and the value is the label (which is translated automatically). It is important + * to notice that it will check that the method exists (`bulk_$name`) and will throw + * an exception if it does not exists. + * + * This class will automatically check if the current request has a bulk action, will do the + * validations and afterwards will execute the bulk method, with two arguments. The first argument + * is the array with primary keys, the second argument is a string with a list of the primary keys, + * escaped and ready to use (with `IN`). + * + * @var array + */ + protected $bulk_actions = array(); + + /** + * Makes translation easier, it basically just wraps + * `_x` with some default (the package name). + * + * @param string $text The new text to translate. + * @param string $context The context of the text. + * @return string|void The translated text. + * + * @deprecated 3.0.0 Use `_x()` instead. + */ + protected function translate( $text, $context = '' ) { + return $text; + } + + /** + * Reads `$this->bulk_actions` and returns an array that WP_List_Table understands. It + * also validates that the bulk method handler exists. It throws an exception because + * this is a library meant for developers and missing a bulk method is a development-time error. + * + * @return array + * + * @throws RuntimeException Throws RuntimeException when the bulk action does not have a callback method. + */ + protected function get_bulk_actions() { + $actions = array(); + + foreach ( $this->bulk_actions as $action => $label ) { + if ( ! is_callable( array( $this, 'bulk_' . $action ) ) ) { + throw new RuntimeException( "The bulk action $action does not have a callback method" ); + } + + $actions[ $action ] = $label; + } + + return $actions; + } + + /** + * Checks if the current request has a bulk action. If that is the case it will validate and will + * execute the bulk method handler. Regardless if the action is valid or not it will redirect to + * the previous page removing the current arguments that makes this request a bulk action. + */ + protected function process_bulk_action() { + global $wpdb; + // Detect when a bulk action is being triggered. + $action = $this->current_action(); + if ( ! $action ) { + return; + } + + check_admin_referer( 'bulk-' . $this->_args['plural'] ); + + $method = 'bulk_' . $action; + if ( array_key_exists( $action, $this->bulk_actions ) && is_callable( array( $this, $method ) ) && ! empty( $_GET['ID'] ) && is_array( $_GET['ID'] ) ) { + $ids_sql = '(' . implode( ',', array_fill( 0, count( $_GET['ID'] ), '%s' ) ) . ')'; + $id = array_map( 'absint', $_GET['ID'] ); + $this->$method( $id, $wpdb->prepare( $ids_sql, $id ) ); //phpcs:ignore WordPress.DB.PreparedSQL + } + + if ( isset( $_SERVER['REQUEST_URI'] ) ) { + wp_safe_redirect( + remove_query_arg( + array( '_wp_http_referer', '_wpnonce', 'ID', 'action', 'action2' ), + esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) + ) + ); + exit; + } + } + + /** + * Default code for deleting entries. + * validated already by process_bulk_action() + * + * @param array $ids ids of the items to delete. + * @param string $ids_sql the sql for the ids. + * @return void + */ + protected function bulk_delete( array $ids, $ids_sql ) { + $store = ActionScheduler::store(); + foreach ( $ids as $action_id ) { + $store->delete( $action_id ); + } + } + + /** + * Prepares the _column_headers property which is used by WP_Table_List at rendering. + * It merges the columns and the sortable columns. + */ + protected function prepare_column_headers() { + $this->_column_headers = array( + $this->get_columns(), + get_hidden_columns( $this->screen ), + $this->get_sortable_columns(), + ); + } + + /** + * Reads $this->sort_by and returns the columns name in a format that WP_Table_List + * expects + */ + public function get_sortable_columns() { + $sort_by = array(); + foreach ( $this->sort_by as $column ) { + $sort_by[ $column ] = array( $column, true ); + } + return $sort_by; + } + + /** + * Returns the columns names for rendering. It adds a checkbox for selecting everything + * as the first column + */ + public function get_columns() { + $columns = array_merge( + array( 'cb' => '' ), + $this->columns + ); + + return $columns; + } + + /** + * Get prepared LIMIT clause for items query + * + * @global wpdb $wpdb + * + * @return string Prepared LIMIT clause for items query. + */ + protected function get_items_query_limit() { + global $wpdb; + + $per_page = $this->get_items_per_page( $this->get_per_page_option_name(), $this->items_per_page ); + return $wpdb->prepare( 'LIMIT %d', $per_page ); + } + + /** + * Returns the number of items to offset/skip for this current view. + * + * @return int + */ + protected function get_items_offset() { + $per_page = $this->get_items_per_page( $this->get_per_page_option_name(), $this->items_per_page ); + $current_page = $this->get_pagenum(); + if ( 1 < $current_page ) { + $offset = $per_page * ( $current_page - 1 ); + } else { + $offset = 0; + } + + return $offset; + } + + /** + * Get prepared OFFSET clause for items query + * + * @global wpdb $wpdb + * + * @return string Prepared OFFSET clause for items query. + */ + protected function get_items_query_offset() { + global $wpdb; + + return $wpdb->prepare( 'OFFSET %d', $this->get_items_offset() ); + } + + /** + * Prepares the ORDER BY sql statement. It uses `$this->sort_by` to know which + * columns are sortable. This requests validates the orderby $_GET parameter is a valid + * column and sortable. It will also use order (ASC|DESC) using DESC by default. + */ + protected function get_items_query_order() { + if ( empty( $this->sort_by ) ) { + return ''; + } + + $orderby = esc_sql( $this->get_request_orderby() ); + $order = esc_sql( $this->get_request_order() ); + + return "ORDER BY {$orderby} {$order}"; + } + + /** + * Return the sortable column specified for this request to order the results by, if any. + * + * @return string + */ + protected function get_request_orderby() { + + $valid_sortable_columns = array_values( $this->sort_by ); + + if ( ! empty( $_GET['orderby'] ) && in_array( $_GET['orderby'], $valid_sortable_columns, true ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended + $orderby = sanitize_text_field( wp_unslash( $_GET['orderby'] ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended + } else { + $orderby = $valid_sortable_columns[0]; + } + + return $orderby; + } + + /** + * Return the sortable column order specified for this request. + * + * @return string + */ + protected function get_request_order() { + + if ( ! empty( $_GET['order'] ) && 'desc' === strtolower( sanitize_text_field( wp_unslash( $_GET['order'] ) ) ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended + $order = 'DESC'; + } else { + $order = 'ASC'; + } + + return $order; + } + + /** + * Return the status filter for this request, if any. + * + * @return string + */ + protected function get_request_status() { + $status = ( ! empty( $_GET['status'] ) ) ? sanitize_text_field( wp_unslash( $_GET['status'] ) ) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Recommended + return $status; + } + + /** + * Return the search filter for this request, if any. + * + * @return string + */ + protected function get_request_search_query() { + $search_query = ( ! empty( $_GET['s'] ) ) ? sanitize_text_field( wp_unslash( $_GET['s'] ) ) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Recommended + return $search_query; + } + + /** + * Process and return the columns name. This is meant for using with SQL, this means it + * always includes the primary key. + * + * @return array + */ + protected function get_table_columns() { + $columns = array_keys( $this->columns ); + if ( ! in_array( $this->ID, $columns, true ) ) { + $columns[] = $this->ID; + } + + return $columns; + } + + /** + * Check if the current request is doing a "full text" search. If that is the case + * prepares the SQL to search texts using LIKE. + * + * If the current request does not have any search or if this list table does not support + * that feature it will return an empty string. + * + * @return string + */ + protected function get_items_query_search() { + global $wpdb; + + if ( empty( $_GET['s'] ) || empty( $this->search_by ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended + return ''; + } + + $search_string = sanitize_text_field( wp_unslash( $_GET['s'] ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended + + $filter = array(); + foreach ( $this->search_by as $column ) { + $wild = '%'; + $sql_like = $wild . $wpdb->esc_like( $search_string ) . $wild; + $filter[] = $wpdb->prepare( '`' . $column . '` LIKE %s', $sql_like ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.DB.PreparedSQL.NotPrepared + } + return implode( ' OR ', $filter ); + } + + /** + * Prepares the SQL to filter rows by the options defined at `$this->filter_by`. Before trusting + * any data sent by the user it validates that it is a valid option. + */ + protected function get_items_query_filters() { + global $wpdb; + + if ( ! $this->filter_by || empty( $_GET['filter_by'] ) || ! is_array( $_GET['filter_by'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended + return ''; + } + + $filter = array(); + + foreach ( $this->filter_by as $column => $options ) { + if ( empty( $_GET['filter_by'][ $column ] ) || empty( $options[ $_GET['filter_by'][ $column ] ] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended + continue; + } + + $filter[] = $wpdb->prepare( "`$column` = %s", sanitize_text_field( wp_unslash( $_GET['filter_by'][ $column ] ) ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.DB.PreparedSQL.InterpolatedNotPrepared + } + + return implode( ' AND ', $filter ); + + } + + /** + * Prepares the data to feed WP_Table_List. + * + * This has the core for selecting, sorting and filting data. To keep the code simple + * its logic is split among many methods (get_items_query_*). + * + * Beside populating the items this function will also count all the records that matches + * the filtering criteria and will do fill the pagination variables. + */ + public function prepare_items() { + global $wpdb; + + $this->process_bulk_action(); + + $this->process_row_actions(); + + if ( ! empty( $_REQUEST['_wp_http_referer'] && ! empty( $_SERVER['REQUEST_URI'] ) ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended + // _wp_http_referer is used only on bulk actions, we remove it to keep the $_GET shorter + wp_safe_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) ); + exit; + } + + $this->prepare_column_headers(); + + $limit = $this->get_items_query_limit(); + $offset = $this->get_items_query_offset(); + $order = $this->get_items_query_order(); + $where = array_filter( + array( + $this->get_items_query_search(), + $this->get_items_query_filters(), + ) + ); + $columns = '`' . implode( '`, `', $this->get_table_columns() ) . '`'; + + if ( ! empty( $where ) ) { + $where = 'WHERE (' . implode( ') AND (', $where ) . ')'; + } else { + $where = ''; + } + + $sql = "SELECT $columns FROM {$this->table_name} {$where} {$order} {$limit} {$offset}"; + + $this->set_items( $wpdb->get_results( $sql, ARRAY_A ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared + + $query_count = "SELECT COUNT({$this->ID}) FROM {$this->table_name} {$where}"; + $total_items = $wpdb->get_var( $query_count ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared + $per_page = $this->get_items_per_page( $this->get_per_page_option_name(), $this->items_per_page ); + $this->set_pagination_args( + array( + 'total_items' => $total_items, + 'per_page' => $per_page, + 'total_pages' => ceil( $total_items / $per_page ), + ) + ); + } + + /** + * Display the table. + * + * @param string $which The name of the table. + */ + public function extra_tablenav( $which ) { + if ( ! $this->filter_by || 'top' !== $which ) { + return; + } + + echo '
            '; + + foreach ( $this->filter_by as $id => $options ) { + $default = ! empty( $_GET['filter_by'][ $id ] ) ? sanitize_text_field( wp_unslash( $_GET['filter_by'][ $id ] ) ) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Recommended + if ( empty( $options[ $default ] ) ) { + $default = ''; + } + + echo ''; + } + + submit_button( esc_html__( 'Filter', 'woocommerce' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) ); + echo '
            '; + } + + /** + * Set the data for displaying. It will attempt to unserialize (There is a chance that some columns + * are serialized). This can be override in child classes for futher data transformation. + * + * @param array $items Items array. + */ + protected function set_items( array $items ) { + $this->items = array(); + foreach ( $items as $item ) { + $this->items[ $item[ $this->ID ] ] = array_map( 'maybe_unserialize', $item ); + } + } + + /** + * Renders the checkbox for each row, this is the first column and it is named ID regardless + * of how the primary key is named (to keep the code simpler). The bulk actions will do the proper + * name transformation though using `$this->ID`. + * + * @param array $row The row to render. + */ + public function column_cb( $row ) { + return ''; + } + + /** + * Renders the row-actions. + * + * This method renders the action menu, it reads the definition from the $row_actions property, + * and it checks that the row action method exists before rendering it. + * + * @param array $row Row to be rendered. + * @param string $column_name Column name. + * @return string + */ + protected function maybe_render_actions( $row, $column_name ) { + if ( empty( $this->row_actions[ $column_name ] ) ) { + return; + } + + $row_id = $row[ $this->ID ]; + + $actions = '
            '; + $action_count = 0; + foreach ( $this->row_actions[ $column_name ] as $action_key => $action ) { + + $action_count++; + + if ( ! method_exists( $this, 'row_action_' . $action_key ) ) { + continue; + } + + $action_link = ! empty( $action['link'] ) ? $action['link'] : add_query_arg( + array( + 'row_action' => $action_key, + 'row_id' => $row_id, + 'nonce' => wp_create_nonce( $action_key . '::' . $row_id ), + ) + ); + $span_class = ! empty( $action['class'] ) ? $action['class'] : $action_key; + $separator = ( $action_count < count( $this->row_actions[ $column_name ] ) ) ? ' | ' : ''; + + $actions .= sprintf( '', esc_attr( $span_class ) ); + $actions .= sprintf( '%3$s', esc_url( $action_link ), esc_attr( $action['desc'] ), esc_html( $action['name'] ) ); + $actions .= sprintf( '%s', $separator ); + } + $actions .= '
            '; + return $actions; + } + + /** + * Process the bulk actions. + * + * @return void + */ + protected function process_row_actions() { + $parameters = array( 'row_action', 'row_id', 'nonce' ); + foreach ( $parameters as $parameter ) { + if ( empty( $_REQUEST[ $parameter ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended + return; + } + } + + $action = sanitize_text_field( wp_unslash( $_REQUEST['row_action'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotValidated + $row_id = sanitize_text_field( wp_unslash( $_REQUEST['row_id'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotValidated + $nonce = sanitize_text_field( wp_unslash( $_REQUEST['nonce'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotValidated + $method = 'row_action_' . $action; // phpcs:ignore WordPress.Security.NonceVerification.Recommended + + if ( wp_verify_nonce( $nonce, $action . '::' . $row_id ) && method_exists( $this, $method ) ) { + $this->$method( sanitize_text_field( wp_unslash( $row_id ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended + } + + if ( isset( $_SERVER['REQUEST_URI'] ) ) { + wp_safe_redirect( + remove_query_arg( + array( 'row_id', 'row_action', 'nonce' ), + esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) + ) + ); + exit; + } + } + + /** + * Default column formatting, it will escape everythig for security. + * + * @param array $item The item array. + * @param string $column_name Column name to display. + * + * @return string + */ + public function column_default( $item, $column_name ) { + $column_html = esc_html( $item[ $column_name ] ); + $column_html .= $this->maybe_render_actions( $item, $column_name ); + return $column_html; + } + + /** + * Display the table heading and search query, if any + */ + protected function display_header() { + echo '

            ' . esc_attr( $this->table_header ) . '

            '; + if ( $this->get_request_search_query() ) { + /* translators: %s: search query */ + echo '' . esc_attr( sprintf( __( 'Search results for "%s"', 'woocommerce' ), $this->get_request_search_query() ) ) . ''; + } + echo '
            '; + } + + /** + * Display the table heading and search query, if any + */ + protected function display_admin_notices() { + foreach ( $this->admin_notices as $notice ) { + echo '
            '; + echo '

            ' . wp_kses_post( $notice['message'] ) . '

            '; + echo '
            '; + } + } + + /** + * Prints the available statuses so the user can click to filter. + */ + protected function display_filter_by_status() { + + $status_list_items = array(); + $request_status = $this->get_request_status(); + + // Helper to set 'all' filter when not set on status counts passed in. + if ( ! isset( $this->status_counts['all'] ) ) { + $all_count = array_sum( $this->status_counts ); + if ( isset( $this->status_counts['past-due'] ) ) { + $all_count -= $this->status_counts['past-due']; + } + $this->status_counts = array( 'all' => $all_count ) + $this->status_counts; + } + + // Translated status labels. + $status_labels = ActionScheduler_Store::instance()->get_status_labels(); + $status_labels['all'] = _x( 'All', 'status labels', 'woocommerce' ); + $status_labels['past-due'] = _x( 'Past-due', 'status labels', 'woocommerce' ); + + foreach ( $this->status_counts as $status_slug => $count ) { + + if ( 0 === $count ) { + continue; + } + + if ( $status_slug === $request_status || ( empty( $request_status ) && 'all' === $status_slug ) ) { + $status_list_item = '
          • %3$s (%4$d)
          • '; + } else { + $status_list_item = '
          • %3$s (%4$d)
          • '; + } + + $status_name = isset( $status_labels[ $status_slug ] ) ? $status_labels[ $status_slug ] : ucfirst( $status_slug ); + $status_filter_url = ( 'all' === $status_slug ) ? remove_query_arg( 'status' ) : add_query_arg( 'status', $status_slug ); + $status_filter_url = remove_query_arg( array( 'paged', 's' ), $status_filter_url ); + $status_list_items[] = sprintf( $status_list_item, esc_attr( $status_slug ), esc_url( $status_filter_url ), esc_html( $status_name ), absint( $count ) ); + } + + if ( $status_list_items ) { + echo '
              '; + echo implode( " | \n", $status_list_items ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + echo '
            '; + } + } + + /** + * Renders the table list, we override the original class to render the table inside a form + * and to render any needed HTML (like the search box). By doing so the callee of a function can simple + * forget about any extra HTML. + */ + protected function display_table() { + echo '
            '; + foreach ( $_GET as $key => $value ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended + if ( '_' === $key[0] || 'paged' === $key || 'ID' === $key ) { + continue; + } + echo ''; + } + if ( ! empty( $this->search_by ) ) { + echo $this->search_box( $this->get_search_box_button_text(), 'plugin' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + } + parent::display(); + echo '
            '; + } + + /** + * Process any pending actions. + */ + public function process_actions() { + $this->process_bulk_action(); + $this->process_row_actions(); + + if ( ! empty( $_REQUEST['_wp_http_referer'] ) && ! empty( $_SERVER['REQUEST_URI'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended + // _wp_http_referer is used only on bulk actions, we remove it to keep the $_GET shorter + wp_safe_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) ); + exit; + } + } + + /** + * Render the list table page, including header, notices, status filters and table. + */ + public function display_page() { + $this->prepare_items(); + + echo '
            '; + $this->display_header(); + $this->display_admin_notices(); + $this->display_filter_by_status(); + $this->display_table(); + echo '
            '; + } + + /** + * Get the text to display in the search box on the list table. + */ + protected function get_search_box_placeholder() { + return esc_html__( 'Search', 'woocommerce' ); + } + + /** + * Gets the screen per_page option name. + * + * @return string + */ + protected function get_per_page_option_name() { + return $this->package . '_items_per_page'; + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_QueueRunner.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_QueueRunner.php new file mode 100644 index 00000000..885bcfdf --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_QueueRunner.php @@ -0,0 +1,373 @@ +created_time = microtime( true ); + + $this->store = $store ? $store : ActionScheduler_Store::instance(); + $this->monitor = $monitor ? $monitor : new ActionScheduler_FatalErrorMonitor( $this->store ); + $this->cleaner = $cleaner ? $cleaner : new ActionScheduler_QueueCleaner( $this->store ); + } + + /** + * Process an individual action. + * + * @param int $action_id The action ID to process. + * @param string $context Optional identifer for the context in which this action is being processed, e.g. 'WP CLI' or 'WP Cron' + * Generally, this should be capitalised and not localised as it's a proper noun. + */ + public function process_action( $action_id, $context = '' ) { + // Temporarily override the error handler while we process the current action. + set_error_handler( + /** + * Temporary error handler which can catch errors and convert them into exceptions. This faciliates more + * robust error handling across all supported PHP versions. + * + * @throws Exception + * + * @param int $type Error level expressed as an integer. + * @param string $message Error message. + */ + function ( $type, $message ) { + throw new Exception( $message ); + }, + E_USER_ERROR | E_RECOVERABLE_ERROR + ); + + /* + * The nested try/catch structure is required because we potentially need to convert thrown errors into + * exceptions (and an exception thrown from a catch block cannot be caught by a later catch block in the *same* + * structure). + */ + try { + try { + $valid_action = false; + do_action( 'action_scheduler_before_execute', $action_id, $context ); + + if ( ActionScheduler_Store::STATUS_PENDING !== $this->store->get_status( $action_id ) ) { + do_action( 'action_scheduler_execution_ignored', $action_id, $context ); + return; + } + + $valid_action = true; + do_action( 'action_scheduler_begin_execute', $action_id, $context ); + + $action = $this->store->fetch_action( $action_id ); + $this->store->log_execution( $action_id ); + $action->execute(); + do_action( 'action_scheduler_after_execute', $action_id, $action, $context ); + $this->store->mark_complete( $action_id ); + } catch ( Throwable $e ) { + // Throwable is defined when executing under PHP 7.0 and up. We convert it to an exception, for + // compatibility with ActionScheduler_Logger. + throw new Exception( $e->getMessage(), $e->getCode(), $e ); + } + } catch ( Exception $e ) { + // This catch block exists for compatibility with PHP 5.6. + $this->handle_action_error( $action_id, $e, $context, $valid_action ); + } finally { + restore_error_handler(); + } + + if ( isset( $action ) && is_a( $action, 'ActionScheduler_Action' ) && $action->get_schedule()->is_recurring() ) { + $this->schedule_next_instance( $action, $action_id ); + } + } + + /** + * Marks actions as either having failed execution or failed validation, as appropriate. + * + * @param int $action_id Action ID. + * @param Exception $e Exception instance. + * @param string $context Execution context. + * @param bool $valid_action If the action is valid. + * + * @return void + */ + private function handle_action_error( $action_id, $e, $context, $valid_action ) { + if ( $valid_action ) { + $this->store->mark_failure( $action_id ); + /** + * Runs when action execution fails. + * + * @param int $action_id Action ID. + * @param Exception $e Exception instance. + * @param string $context Execution context. + */ + do_action( 'action_scheduler_failed_execution', $action_id, $e, $context ); + } else { + /** + * Runs when action validation fails. + * + * @param int $action_id Action ID. + * @param Exception $e Exception instance. + * @param string $context Execution context. + */ + do_action( 'action_scheduler_failed_validation', $action_id, $e, $context ); + } + } + + /** + * Schedule the next instance of the action if necessary. + * + * @param ActionScheduler_Action $action + * @param int $action_id + */ + protected function schedule_next_instance( ActionScheduler_Action $action, $action_id ) { + // If a recurring action has been consistently failing, we may wish to stop rescheduling it. + if ( + ActionScheduler_Store::STATUS_FAILED === $this->store->get_status( $action_id ) + && $this->recurring_action_is_consistently_failing( $action, $action_id ) + ) { + ActionScheduler_Logger::instance()->log( + $action_id, + __( 'This action appears to be consistently failing. A new instance will not be scheduled.', 'woocommerce' ) + ); + + return; + } + + try { + ActionScheduler::factory()->repeat( $action ); + } catch ( Exception $e ) { + do_action( 'action_scheduler_failed_to_schedule_next_instance', $action_id, $e, $action ); + } + } + + /** + * Determine if the specified recurring action has been consistently failing. + * + * @param ActionScheduler_Action $action The recurring action to be rescheduled. + * @param int $action_id The ID of the recurring action. + * + * @return bool + */ + private function recurring_action_is_consistently_failing( ActionScheduler_Action $action, $action_id ) { + /** + * Controls the failure threshold for recurring actions. + * + * Before rescheduling a recurring action, we look at its status. If it failed, we then check if all of the most + * recent actions (upto the threshold set by this filter) sharing the same hook have also failed: if they have, + * that is considered consistent failure and a new instance of the action will not be scheduled. + * + * @param int $failure_threshold Number of actions of the same hook to examine for failure. Defaults to 5. + */ + $consistent_failure_threshold = (int) apply_filters( 'action_scheduler_recurring_action_failure_threshold', 5 ); + + // This query should find the earliest *failing* action (for the hook we are interested in) within our threshold. + $query_args = array( + 'hook' => $action->get_hook(), + 'status' => ActionScheduler_Store::STATUS_FAILED, + 'date' => date_create( 'now', timezone_open( 'UTC' ) )->format( 'Y-m-d H:i:s' ), + 'date_compare' => '<', + 'per_page' => 1, + 'offset' => $consistent_failure_threshold - 1 + ); + + $first_failing_action_id = $this->store->query_actions( $query_args ); + + // If we didn't retrieve an action ID, then there haven't been enough failures for us to worry about. + if ( empty( $first_failing_action_id ) ) { + return false; + } + + // Now let's fetch the first action (having the same hook) of *any status* within the same window. + unset( $query_args['status'] ); + $first_action_id_with_the_same_hook = $this->store->query_actions( $query_args ); + + /** + * If a recurring action is assessed as consistently failing, it will not be rescheduled. This hook provides a + * way to observe and optionally override that assessment. + * + * @param bool $is_consistently_failing If the action is considered to be consistently failing. + * @param ActionScheduler_Action $action The action being assessed. + */ + return (bool) apply_filters( + 'action_scheduler_recurring_action_is_consistently_failing', + $first_action_id_with_the_same_hook === $first_failing_action_id, + $action + ); + } + + /** + * Run the queue cleaner. + * + * @author Jeremy Pry + */ + protected function run_cleanup() { + $this->cleaner->clean( 10 * $this->get_time_limit() ); + } + + /** + * Get the number of concurrent batches a runner allows. + * + * @return int + */ + public function get_allowed_concurrent_batches() { + return apply_filters( 'action_scheduler_queue_runner_concurrent_batches', 1 ); + } + + /** + * Check if the number of allowed concurrent batches is met or exceeded. + * + * @return bool + */ + public function has_maximum_concurrent_batches() { + return $this->store->get_claim_count() >= $this->get_allowed_concurrent_batches(); + } + + /** + * Get the maximum number of seconds a batch can run for. + * + * @return int The number of seconds. + */ + protected function get_time_limit() { + + $time_limit = 30; + + // Apply deprecated filter from deprecated get_maximum_execution_time() method + if ( has_filter( 'action_scheduler_maximum_execution_time' ) ) { + _deprecated_function( 'action_scheduler_maximum_execution_time', '2.1.1', 'action_scheduler_queue_runner_time_limit' ); + $time_limit = apply_filters( 'action_scheduler_maximum_execution_time', $time_limit ); + } + + return absint( apply_filters( 'action_scheduler_queue_runner_time_limit', $time_limit ) ); + } + + /** + * Get the number of seconds the process has been running. + * + * @return int The number of seconds. + */ + protected function get_execution_time() { + $execution_time = microtime( true ) - $this->created_time; + + // Get the CPU time if the hosting environment uses it rather than wall-clock time to calculate a process's execution time. + if ( function_exists( 'getrusage' ) && apply_filters( 'action_scheduler_use_cpu_execution_time', defined( 'PANTHEON_ENVIRONMENT' ) ) ) { + $resource_usages = getrusage(); + + if ( isset( $resource_usages['ru_stime.tv_usec'], $resource_usages['ru_stime.tv_usec'] ) ) { + $execution_time = $resource_usages['ru_stime.tv_sec'] + ( $resource_usages['ru_stime.tv_usec'] / 1000000 ); + } + } + + return $execution_time; + } + + /** + * Check if the host's max execution time is (likely) to be exceeded if processing more actions. + * + * @param int $processed_actions The number of actions processed so far - used to determine the likelihood of exceeding the time limit if processing another action + * @return bool + */ + protected function time_likely_to_be_exceeded( $processed_actions ) { + $execution_time = $this->get_execution_time(); + $max_execution_time = $this->get_time_limit(); + + // Safety against division by zero errors. + if ( 0 === $processed_actions ) { + return $execution_time >= $max_execution_time; + } + + $time_per_action = $execution_time / $processed_actions; + $estimated_time = $execution_time + ( $time_per_action * 3 ); + $likely_to_be_exceeded = $estimated_time > $max_execution_time; + + return apply_filters( 'action_scheduler_maximum_execution_time_likely_to_be_exceeded', $likely_to_be_exceeded, $this, $processed_actions, $execution_time, $max_execution_time ); + } + + /** + * Get memory limit + * + * Based on WP_Background_Process::get_memory_limit() + * + * @return int + */ + protected function get_memory_limit() { + if ( function_exists( 'ini_get' ) ) { + $memory_limit = ini_get( 'memory_limit' ); + } else { + $memory_limit = '128M'; // Sensible default, and minimum required by WooCommerce + } + + if ( ! $memory_limit || -1 === $memory_limit || '-1' === $memory_limit ) { + // Unlimited, set to 32GB. + $memory_limit = '32G'; + } + + return ActionScheduler_Compatibility::convert_hr_to_bytes( $memory_limit ); + } + + /** + * Memory exceeded + * + * Ensures the batch process never exceeds 90% of the maximum WordPress memory. + * + * Based on WP_Background_Process::memory_exceeded() + * + * @return bool + */ + protected function memory_exceeded() { + + $memory_limit = $this->get_memory_limit() * 0.90; + $current_memory = memory_get_usage( true ); + $memory_exceeded = $current_memory >= $memory_limit; + + return apply_filters( 'action_scheduler_memory_exceeded', $memory_exceeded, $this ); + } + + /** + * See if the batch limits have been exceeded, which is when memory usage is almost at + * the maximum limit, or the time to process more actions will exceed the max time limit. + * + * Based on WC_Background_Process::batch_limits_exceeded() + * + * @param int $processed_actions The number of actions processed so far - used to determine the likelihood of exceeding the time limit if processing another action + * @return bool + */ + protected function batch_limits_exceeded( $processed_actions ) { + return $this->memory_exceeded() || $this->time_likely_to_be_exceeded( $processed_actions ); + } + + /** + * Process actions in the queue. + * + * @author Jeremy Pry + * @param string $context Optional identifer for the context in which this action is being processed, e.g. 'WP CLI' or 'WP Cron' + * Generally, this should be capitalised and not localised as it's a proper noun. + * @return int The number of actions processed. + */ + abstract public function run( $context = '' ); +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_RecurringSchedule.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_RecurringSchedule.php new file mode 100644 index 00000000..8fb3bc5c --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_RecurringSchedule.php @@ -0,0 +1,103 @@ +start - and logic to calculate the next run date after + * that - @see $this->calculate_next(). The $first_date property also keeps a record of when the very + * first instance of this chain of schedules ran. + * + * @var DateTime + */ + private $first_date = NULL; + + /** + * Timestamp equivalent of @see $this->first_date + * + * @var int + */ + protected $first_timestamp = NULL; + + /** + * The recurrance between each time an action is run using this schedule. + * Used to calculate the start date & time. Can be a number of seconds, in the + * case of ActionScheduler_IntervalSchedule, or a cron expression, as in the + * case of ActionScheduler_CronSchedule. Or something else. + * + * @var mixed + */ + protected $recurrence; + + /** + * @param DateTime $date The date & time to run the action. + * @param mixed $recurrence The data used to determine the schedule's recurrance. + * @param DateTime|null $first (Optional) The date & time the first instance of this interval schedule ran. Default null, meaning this is the first instance. + */ + public function __construct( DateTime $date, $recurrence, DateTime $first = null ) { + parent::__construct( $date ); + $this->first_date = empty( $first ) ? $date : $first; + $this->recurrence = $recurrence; + } + + /** + * @return bool + */ + public function is_recurring() { + return true; + } + + /** + * Get the date & time of the first schedule in this recurring series. + * + * @return DateTime|null + */ + public function get_first_date() { + return clone $this->first_date; + } + + /** + * @return string + */ + public function get_recurrence() { + return $this->recurrence; + } + + /** + * For PHP 5.2 compat, since DateTime objects can't be serialized + * @return array + */ + public function __sleep() { + $sleep_params = parent::__sleep(); + $this->first_timestamp = $this->first_date->getTimestamp(); + return array_merge( $sleep_params, array( + 'first_timestamp', + 'recurrence' + ) ); + } + + /** + * Unserialize recurring schedules serialized/stored prior to AS 3.0.0 + * + * Prior to Action Scheduler 3.0.0, schedules used different property names to refer + * to equivalent data. For example, ActionScheduler_IntervalSchedule::start_timestamp + * was the same as ActionScheduler_SimpleSchedule::timestamp. This was addressed in + * Action Scheduler 3.0.0, where properties and property names were aligned for better + * inheritance. To maintain backward compatibility with scheduled serialized and stored + * prior to 3.0, we need to correctly map the old property names. + */ + public function __wakeup() { + parent::__wakeup(); + if ( $this->first_timestamp > 0 ) { + $this->first_date = as_get_datetime_object( $this->first_timestamp ); + } else { + $this->first_date = $this->get_date(); + } + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_Schedule.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_Schedule.php new file mode 100644 index 00000000..2d5e158f --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_Schedule.php @@ -0,0 +1,84 @@ +scheduled_date + * + * @var int + */ + protected $scheduled_timestamp = NULL; + + /** + * @param DateTime $date The date & time to run the action. + */ + public function __construct( DateTime $date ) { + $this->scheduled_date = $date; + } + + /** + * Check if a schedule should recur. + * + * @return bool + */ + abstract public function is_recurring(); + + /** + * Calculate when the next instance of this schedule would run based on a given date & time. + * + * @param DateTime $after + * @return DateTime + */ + abstract protected function calculate_next( DateTime $after ); + + /** + * Get the next date & time when this schedule should run after a given date & time. + * + * @param DateTime $after + * @return DateTime|null + */ + public function get_next( DateTime $after ) { + $after = clone $after; + if ( $after > $this->scheduled_date ) { + $after = $this->calculate_next( $after ); + return $after; + } + return clone $this->scheduled_date; + } + + /** + * Get the date & time the schedule is set to run. + * + * @return DateTime|null + */ + public function get_date() { + return $this->scheduled_date; + } + + /** + * For PHP 5.2 compat, since DateTime objects can't be serialized + * @return array + */ + public function __sleep() { + $this->scheduled_timestamp = $this->scheduled_date->getTimestamp(); + return array( + 'scheduled_timestamp', + ); + } + + public function __wakeup() { + $this->scheduled_date = as_get_datetime_object( $this->scheduled_timestamp ); + unset( $this->scheduled_timestamp ); + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_Schema.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_Schema.php new file mode 100644 index 00000000..76e38d5a --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_Schema.php @@ -0,0 +1,178 @@ +tables as $table ) { + $wpdb->tables[] = $table; + $name = $this->get_full_table_name( $table ); + $wpdb->$table = $name; + } + + // create the tables + if ( $this->schema_update_required() || $force_update ) { + foreach ( $this->tables as $table ) { + /** + * Allow custom processing before updating a table schema. + * + * @param string $table Name of table being updated. + * @param string $db_version Existing version of the table being updated. + */ + do_action( 'action_scheduler_before_schema_update', $table, $this->db_version ); + $this->update_table( $table ); + } + $this->mark_schema_update_complete(); + } + } + + /** + * @param string $table The name of the table + * + * @return string The CREATE TABLE statement, suitable for passing to dbDelta + */ + abstract protected function get_table_definition( $table ); + + /** + * Determine if the database schema is out of date + * by comparing the integer found in $this->schema_version + * with the option set in the WordPress options table + * + * @return bool + */ + private function schema_update_required() { + $option_name = 'schema-' . static::class; + $this->db_version = get_option( $option_name, 0 ); + + // Check for schema option stored by the Action Scheduler Custom Tables plugin in case site has migrated from that plugin with an older schema + if ( 0 === $this->db_version ) { + + $plugin_option_name = 'schema-'; + + switch ( static::class ) { + case 'ActionScheduler_StoreSchema': + $plugin_option_name .= 'Action_Scheduler\Custom_Tables\DB_Store_Table_Maker'; + break; + case 'ActionScheduler_LoggerSchema': + $plugin_option_name .= 'Action_Scheduler\Custom_Tables\DB_Logger_Table_Maker'; + break; + } + + $this->db_version = get_option( $plugin_option_name, 0 ); + + delete_option( $plugin_option_name ); + } + + return version_compare( $this->db_version, $this->schema_version, '<' ); + } + + /** + * Update the option in WordPress to indicate that + * our schema is now up to date + * + * @return void + */ + private function mark_schema_update_complete() { + $option_name = 'schema-' . static::class; + + // work around race conditions and ensure that our option updates + $value_to_save = (string) $this->schema_version . '.0.' . time(); + + update_option( $option_name, $value_to_save ); + } + + /** + * Update the schema for the given table + * + * @param string $table The name of the table to update + * + * @return void + */ + private function update_table( $table ) { + require_once ABSPATH . 'wp-admin/includes/upgrade.php'; + $definition = $this->get_table_definition( $table ); + if ( $definition ) { + $updated = dbDelta( $definition ); + foreach ( $updated as $updated_table => $update_description ) { + if ( strpos( $update_description, 'Created table' ) === 0 ) { + do_action( 'action_scheduler/created_table', $updated_table, $table ); + } + } + } + } + + /** + * @param string $table + * + * @return string The full name of the table, including the + * table prefix for the current blog + */ + protected function get_full_table_name( $table ) { + return $GLOBALS['wpdb']->prefix . $table; + } + + /** + * Confirms that all of the tables registered by this schema class have been created. + * + * @return bool + */ + public function tables_exist() { + global $wpdb; + + $tables_exist = true; + + foreach ( $this->tables as $table_name ) { + $table_name = $wpdb->prefix . $table_name; + $pattern = str_replace( '_', '\\_', $table_name ); + $existing_table = $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $pattern ) ); + + if ( $existing_table !== $table_name ) { + $tables_exist = false; + break; + } + } + + return $tables_exist; + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Lock.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Lock.php new file mode 100644 index 00000000..2a22b275 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Lock.php @@ -0,0 +1,65 @@ +get_expiration( $lock_type ) >= time() ); + } + + /** + * Set a lock. + * + * To prevent race conditions, implementations should avoid setting the lock if the lock is already held. + * + * @param string $lock_type A string to identify different lock types. + * @return bool + */ + abstract public function set( $lock_type ); + + /** + * If a lock is set, return the timestamp it was set to expiry. + * + * @param string $lock_type A string to identify different lock types. + * @return bool|int False if no lock is set, otherwise the timestamp for when the lock is set to expire. + */ + abstract public function get_expiration( $lock_type ); + + /** + * Get the amount of time to set for a given lock. 60 seconds by default. + * + * @param string $lock_type A string to identify different lock types. + * @return int + */ + protected function get_duration( $lock_type ) { + return apply_filters( 'action_scheduler_lock_duration', self::$lock_duration, $lock_type ); + } + + /** + * @return ActionScheduler_Lock + */ + public static function instance() { + if ( empty( self::$locker ) ) { + $class = apply_filters( 'action_scheduler_lock_class', 'ActionScheduler_OptionLock' ); + self::$locker = new $class(); + } + return self::$locker; + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Logger.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Logger.php new file mode 100644 index 00000000..37a8cb80 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Logger.php @@ -0,0 +1,177 @@ +hook_stored_action(); + add_action( 'action_scheduler_canceled_action', array( $this, 'log_canceled_action' ), 10, 1 ); + add_action( 'action_scheduler_begin_execute', array( $this, 'log_started_action' ), 10, 2 ); + add_action( 'action_scheduler_after_execute', array( $this, 'log_completed_action' ), 10, 3 ); + add_action( 'action_scheduler_failed_execution', array( $this, 'log_failed_action' ), 10, 3 ); + add_action( 'action_scheduler_failed_action', array( $this, 'log_timed_out_action' ), 10, 2 ); + add_action( 'action_scheduler_unexpected_shutdown', array( $this, 'log_unexpected_shutdown' ), 10, 2 ); + add_action( 'action_scheduler_reset_action', array( $this, 'log_reset_action' ), 10, 1 ); + add_action( 'action_scheduler_execution_ignored', array( $this, 'log_ignored_action' ), 10, 2 ); + add_action( 'action_scheduler_failed_fetch_action', array( $this, 'log_failed_fetch_action' ), 10, 2 ); + add_action( 'action_scheduler_failed_to_schedule_next_instance', array( $this, 'log_failed_schedule_next_instance' ), 10, 2 ); + add_action( 'action_scheduler_bulk_cancel_actions', array( $this, 'bulk_log_cancel_actions' ), 10, 1 ); + } + + public function hook_stored_action() { + add_action( 'action_scheduler_stored_action', array( $this, 'log_stored_action' ) ); + } + + public function unhook_stored_action() { + remove_action( 'action_scheduler_stored_action', array( $this, 'log_stored_action' ) ); + } + + public function log_stored_action( $action_id ) { + $this->log( $action_id, __( 'action created', 'woocommerce' ) ); + } + + public function log_canceled_action( $action_id ) { + $this->log( $action_id, __( 'action canceled', 'woocommerce' ) ); + } + + public function log_started_action( $action_id, $context = '' ) { + if ( ! empty( $context ) ) { + /* translators: %s: context */ + $message = sprintf( __( 'action started via %s', 'woocommerce' ), $context ); + } else { + $message = __( 'action started', 'woocommerce' ); + } + $this->log( $action_id, $message ); + } + + public function log_completed_action( $action_id, $action = NULL, $context = '' ) { + if ( ! empty( $context ) ) { + /* translators: %s: context */ + $message = sprintf( __( 'action complete via %s', 'woocommerce' ), $context ); + } else { + $message = __( 'action complete', 'woocommerce' ); + } + $this->log( $action_id, $message ); + } + + public function log_failed_action( $action_id, Exception $exception, $context = '' ) { + if ( ! empty( $context ) ) { + /* translators: 1: context 2: exception message */ + $message = sprintf( __( 'action failed via %1$s: %2$s', 'woocommerce' ), $context, $exception->getMessage() ); + } else { + /* translators: %s: exception message */ + $message = sprintf( __( 'action failed: %s', 'woocommerce' ), $exception->getMessage() ); + } + $this->log( $action_id, $message ); + } + + public function log_timed_out_action( $action_id, $timeout ) { + /* translators: %s: amount of time */ + $this->log( $action_id, sprintf( __( 'action marked as failed after %s seconds. Unknown error occurred. Check server, PHP and database error logs to diagnose cause.', 'woocommerce' ), $timeout ) ); + } + + public function log_unexpected_shutdown( $action_id, $error ) { + if ( ! empty( $error ) ) { + /* translators: 1: error message 2: filename 3: line */ + $this->log( $action_id, sprintf( __( 'unexpected shutdown: PHP Fatal error %1$s in %2$s on line %3$s', 'woocommerce' ), $error['message'], $error['file'], $error['line'] ) ); + } + } + + public function log_reset_action( $action_id ) { + $this->log( $action_id, __( 'action reset', 'woocommerce' ) ); + } + + public function log_ignored_action( $action_id, $context = '' ) { + if ( ! empty( $context ) ) { + /* translators: %s: context */ + $message = sprintf( __( 'action ignored via %s', 'woocommerce' ), $context ); + } else { + $message = __( 'action ignored', 'woocommerce' ); + } + $this->log( $action_id, $message ); + } + + /** + * @param string $action_id + * @param Exception|NULL $exception The exception which occured when fetching the action. NULL by default for backward compatibility. + * + * @return ActionScheduler_LogEntry[] + */ + public function log_failed_fetch_action( $action_id, Exception $exception = NULL ) { + + if ( ! is_null( $exception ) ) { + /* translators: %s: exception message */ + $log_message = sprintf( __( 'There was a failure fetching this action: %s', 'woocommerce' ), $exception->getMessage() ); + } else { + $log_message = __( 'There was a failure fetching this action', 'woocommerce' ); + } + + $this->log( $action_id, $log_message ); + } + + public function log_failed_schedule_next_instance( $action_id, Exception $exception ) { + /* translators: %s: exception message */ + $this->log( $action_id, sprintf( __( 'There was a failure scheduling the next instance of this action: %s', 'woocommerce' ), $exception->getMessage() ) ); + } + + /** + * Bulk add cancel action log entries. + * + * Implemented here for backward compatibility. Should be implemented in parent loggers + * for more performant bulk logging. + * + * @param array $action_ids List of action ID. + */ + public function bulk_log_cancel_actions( $action_ids ) { + if ( empty( $action_ids ) ) { + return; + } + + foreach ( $action_ids as $action_id ) { + $this->log_canceled_action( $action_id ); + } + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Store.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Store.php new file mode 100644 index 00000000..a56d47c1 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Store.php @@ -0,0 +1,451 @@ + null, + 'status' => self::STATUS_PENDING, + 'group' => '', + ) + ); + + // These params are fixed for this method. + $params['hook'] = $hook; + $params['orderby'] = 'date'; + $params['per_page'] = 1; + + if ( ! empty( $params['status'] ) ) { + if ( self::STATUS_PENDING === $params['status'] ) { + $params['order'] = 'ASC'; // Find the next action that matches. + } else { + $params['order'] = 'DESC'; // Find the most recent action that matches. + } + } + + $results = $this->query_actions( $params ); + + return empty( $results ) ? null : $results[0]; + } + + /** + * Query for action count or list of action IDs. + * + * @since 3.3.0 $query['status'] accepts array of statuses instead of a single status. + * + * @param array $query { + * Query filtering options. + * + * @type string $hook The name of the actions. Optional. + * @type string|array $status The status or statuses of the actions. Optional. + * @type array $args The args array of the actions. Optional. + * @type DateTime $date The scheduled date of the action. Used in UTC timezone. Optional. + * @type string $date_compare Operator for selecting by $date param. Accepted values are '!=', '>', '>=', '<', '<=', '='. Defaults to '<='. + * @type DateTime $modified The last modified date of the action. Used in UTC timezone. Optional. + * @type string $modified_compare Operator for comparing $modified param. Accepted values are '!=', '>', '>=', '<', '<=', '='. Defaults to '<='. + * @type string $group The group the action belongs to. Optional. + * @type bool|int $claimed TRUE to find claimed actions, FALSE to find unclaimed actions, an int to find a specific claim ID. Optional. + * @type int $per_page Number of results to return. Defaults to 5. + * @type int $offset The query pagination offset. Defaults to 0. + * @type int $orderby Accepted values are 'hook', 'group', 'modified', 'date' or 'none'. Defaults to 'date'. + * @type string $order Accepted values are 'ASC' or 'DESC'. Defaults to 'ASC'. + * } + * @param string $query_type Whether to select or count the results. Default, select. + * + * @return string|array|null The IDs of actions matching the query. Null on failure. + */ + abstract public function query_actions( $query = array(), $query_type = 'select' ); + + /** + * Run query to get a single action ID. + * + * @since 3.3.0 + * + * @see ActionScheduler_Store::query_actions for $query arg usage but 'per_page' and 'offset' can't be used. + * + * @param array $query Query parameters. + * + * @return int|null + */ + public function query_action( $query ) { + $query['per_page'] = 1; + $query['offset'] = 0; + $results = $this->query_actions( $query ); + + if ( empty( $results ) ) { + return null; + } else { + return (int) $results[0]; + } + } + + /** + * Get a count of all actions in the store, grouped by status + * + * @return array + */ + abstract public function action_counts(); + + /** + * Get additional action counts. + * + * - add past-due actions + * + * @return array + */ + public function extra_action_counts() { + $extra_actions = array(); + + $pastdue_action_counts = ( int ) $this->query_actions( array( + 'status' => self::STATUS_PENDING, + 'date' => as_get_datetime_object(), + ), 'count' ); + + if ( $pastdue_action_counts ) { + $extra_actions['past-due'] = $pastdue_action_counts; + } + + /** + * Allows 3rd party code to add extra action counts (used in filters in the list table). + * + * @since 3.5.0 + * @param $extra_actions array Array with format action_count_identifier => action count. + */ + return apply_filters( 'action_scheduler_extra_action_counts', $extra_actions ); + } + + /** + * @param string $action_id + */ + abstract public function cancel_action( $action_id ); + + /** + * @param string $action_id + */ + abstract public function delete_action( $action_id ); + + /** + * @param string $action_id + * + * @return DateTime The date the action is schedule to run, or the date that it ran. + */ + abstract public function get_date( $action_id ); + + + /** + * @param int $max_actions + * @param DateTime $before_date Claim only actions schedule before the given date. Defaults to now. + * @param array $hooks Claim only actions with a hook or hooks. + * @param string $group Claim only actions in the given group. + * + * @return ActionScheduler_ActionClaim + */ + abstract public function stake_claim( $max_actions = 10, DateTime $before_date = null, $hooks = array(), $group = '' ); + + /** + * @return int + */ + abstract public function get_claim_count(); + + /** + * @param ActionScheduler_ActionClaim $claim + */ + abstract public function release_claim( ActionScheduler_ActionClaim $claim ); + + /** + * @param string $action_id + */ + abstract public function unclaim_action( $action_id ); + + /** + * @param string $action_id + */ + abstract public function mark_failure( $action_id ); + + /** + * @param string $action_id + */ + abstract public function log_execution( $action_id ); + + /** + * @param string $action_id + */ + abstract public function mark_complete( $action_id ); + + /** + * @param string $action_id + * + * @return string + */ + abstract public function get_status( $action_id ); + + /** + * @param string $action_id + * @return mixed + */ + abstract public function get_claim_id( $action_id ); + + /** + * @param string $claim_id + * @return array + */ + abstract public function find_actions_by_claim_id( $claim_id ); + + /** + * @param string $comparison_operator + * @return string + */ + protected function validate_sql_comparator( $comparison_operator ) { + if ( in_array( $comparison_operator, array('!=', '>', '>=', '<', '<=', '=') ) ) { + return $comparison_operator; + } + return '='; + } + + /** + * Get the time MySQL formated date/time string for an action's (next) scheduled date. + * + * @param ActionScheduler_Action $action + * @param DateTime $scheduled_date (optional) + * @return string + */ + protected function get_scheduled_date_string( ActionScheduler_Action $action, DateTime $scheduled_date = NULL ) { + $next = null === $scheduled_date ? $action->get_schedule()->get_date() : $scheduled_date; + if ( ! $next ) { + $next = date_create(); + } + $next->setTimezone( new DateTimeZone( 'UTC' ) ); + + return $next->format( 'Y-m-d H:i:s' ); + } + + /** + * Get the time MySQL formated date/time string for an action's (next) scheduled date. + * + * @param ActionScheduler_Action $action + * @param DateTime $scheduled_date (optional) + * @return string + */ + protected function get_scheduled_date_string_local( ActionScheduler_Action $action, DateTime $scheduled_date = NULL ) { + $next = null === $scheduled_date ? $action->get_schedule()->get_date() : $scheduled_date; + if ( ! $next ) { + $next = date_create(); + } + + ActionScheduler_TimezoneHelper::set_local_timezone( $next ); + return $next->format( 'Y-m-d H:i:s' ); + } + + /** + * Validate that we could decode action arguments. + * + * @param mixed $args The decoded arguments. + * @param int $action_id The action ID. + * + * @throws ActionScheduler_InvalidActionException When the decoded arguments are invalid. + */ + protected function validate_args( $args, $action_id ) { + // Ensure we have an array of args. + if ( ! is_array( $args ) ) { + throw ActionScheduler_InvalidActionException::from_decoding_args( $action_id ); + } + + // Validate JSON decoding if possible. + if ( function_exists( 'json_last_error' ) && JSON_ERROR_NONE !== json_last_error() ) { + throw ActionScheduler_InvalidActionException::from_decoding_args( $action_id, $args ); + } + } + + /** + * Validate a ActionScheduler_Schedule object. + * + * @param mixed $schedule The unserialized ActionScheduler_Schedule object. + * @param int $action_id The action ID. + * + * @throws ActionScheduler_InvalidActionException When the schedule is invalid. + */ + protected function validate_schedule( $schedule, $action_id ) { + if ( empty( $schedule ) || ! is_a( $schedule, 'ActionScheduler_Schedule' ) ) { + throw ActionScheduler_InvalidActionException::from_schedule( $action_id, $schedule ); + } + } + + /** + * InnoDB indexes have a maximum size of 767 bytes by default, which is only 191 characters with utf8mb4. + * + * Previously, AS wasn't concerned about args length, as we used the (unindex) post_content column. However, + * with custom tables, we use an indexed VARCHAR column instead. + * + * @param ActionScheduler_Action $action Action to be validated. + * @throws InvalidArgumentException When json encoded args is too long. + */ + protected function validate_action( ActionScheduler_Action $action ) { + if ( strlen( json_encode( $action->get_args() ) ) > static::$max_args_length ) { + throw new InvalidArgumentException( sprintf( __( 'ActionScheduler_Action::$args too long. To ensure the args column can be indexed, action args should not be more than %d characters when encoded as JSON.', 'woocommerce' ), static::$max_args_length ) ); + } + } + + /** + * Cancel pending actions by hook. + * + * @since 3.0.0 + * + * @param string $hook Hook name. + * + * @return void + */ + public function cancel_actions_by_hook( $hook ) { + $action_ids = true; + while ( ! empty( $action_ids ) ) { + $action_ids = $this->query_actions( + array( + 'hook' => $hook, + 'status' => self::STATUS_PENDING, + 'per_page' => 1000, + 'orderby' => 'none', + ) + ); + + $this->bulk_cancel_actions( $action_ids ); + } + } + + /** + * Cancel pending actions by group. + * + * @since 3.0.0 + * + * @param string $group Group slug. + * + * @return void + */ + public function cancel_actions_by_group( $group ) { + $action_ids = true; + while ( ! empty( $action_ids ) ) { + $action_ids = $this->query_actions( + array( + 'group' => $group, + 'status' => self::STATUS_PENDING, + 'per_page' => 1000, + 'orderby' => 'none', + ) + ); + + $this->bulk_cancel_actions( $action_ids ); + } + } + + /** + * Cancel a set of action IDs. + * + * @since 3.0.0 + * + * @param array $action_ids List of action IDs. + * + * @return void + */ + private function bulk_cancel_actions( $action_ids ) { + foreach ( $action_ids as $action_id ) { + $this->cancel_action( $action_id ); + } + + do_action( 'action_scheduler_bulk_cancel_actions', $action_ids ); + } + + /** + * @return array + */ + public function get_status_labels() { + return array( + self::STATUS_COMPLETE => __( 'Complete', 'woocommerce' ), + self::STATUS_PENDING => __( 'Pending', 'woocommerce' ), + self::STATUS_RUNNING => __( 'In-progress', 'woocommerce' ), + self::STATUS_FAILED => __( 'Failed', 'woocommerce' ), + self::STATUS_CANCELED => __( 'Canceled', 'woocommerce' ), + ); + } + + /** + * Check if there are any pending scheduled actions due to run. + * + * @param ActionScheduler_Action $action + * @param DateTime $scheduled_date (optional) + * @return string + */ + public function has_pending_actions_due() { + $pending_actions = $this->query_actions( array( + 'date' => as_get_datetime_object(), + 'status' => ActionScheduler_Store::STATUS_PENDING, + 'orderby' => 'none', + ) ); + + return ! empty( $pending_actions ); + } + + /** + * Callable initialization function optionally overridden in derived classes. + */ + public function init() {} + + /** + * Callable function to mark an action as migrated optionally overridden in derived classes. + */ + public function mark_migrated( $action_id ) {} + + /** + * @return ActionScheduler_Store + */ + public static function instance() { + if ( empty( self::$store ) ) { + $class = apply_filters( 'action_scheduler_store_class', self::DEFAULT_CLASS ); + self::$store = new $class(); + } + return self::$store; + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_TimezoneHelper.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_TimezoneHelper.php new file mode 100644 index 00000000..2f96834a --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_TimezoneHelper.php @@ -0,0 +1,153 @@ +format( 'U' ) ); + } + + if ( get_option( 'timezone_string' ) ) { + $date->setTimezone( new DateTimeZone( self::get_local_timezone_string() ) ); + } else { + $date->setUtcOffset( self::get_local_timezone_offset() ); + } + + return $date; + } + + /** + * Helper to retrieve the timezone string for a site until a WP core method exists + * (see https://core.trac.wordpress.org/ticket/24730). + * + * Adapted from wc_timezone_string() and https://secure.php.net/manual/en/function.timezone-name-from-abbr.php#89155. + * + * If no timezone string is set, and its not possible to match the UTC offset set for the site to a timezone + * string, then an empty string will be returned, and the UTC offset should be used to set a DateTime's + * timezone. + * + * @since 2.1.0 + * @return string PHP timezone string for the site or empty if no timezone string is available. + */ + protected static function get_local_timezone_string( $reset = false ) { + // If site timezone string exists, return it. + $timezone = get_option( 'timezone_string' ); + if ( $timezone ) { + return $timezone; + } + + // Get UTC offset, if it isn't set then return UTC. + $utc_offset = intval( get_option( 'gmt_offset', 0 ) ); + if ( 0 === $utc_offset ) { + return 'UTC'; + } + + // Adjust UTC offset from hours to seconds. + $utc_offset *= 3600; + + // Attempt to guess the timezone string from the UTC offset. + $timezone = timezone_name_from_abbr( '', $utc_offset ); + if ( $timezone ) { + return $timezone; + } + + // Last try, guess timezone string manually. + foreach ( timezone_abbreviations_list() as $abbr ) { + foreach ( $abbr as $city ) { + if ( (bool) date( 'I' ) === (bool) $city['dst'] && $city['timezone_id'] && intval( $city['offset'] ) === $utc_offset ) { + return $city['timezone_id']; + } + } + } + + // No timezone string + return ''; + } + + /** + * Get timezone offset in seconds. + * + * @since 2.1.0 + * @return float + */ + protected static function get_local_timezone_offset() { + $timezone = get_option( 'timezone_string' ); + + if ( $timezone ) { + $timezone_object = new DateTimeZone( $timezone ); + return $timezone_object->getOffset( new DateTime( 'now' ) ); + } else { + return floatval( get_option( 'gmt_offset', 0 ) ) * HOUR_IN_SECONDS; + } + } + + /** + * @deprecated 2.1.0 + */ + public static function get_local_timezone( $reset = FALSE ) { + _deprecated_function( __FUNCTION__, '2.1.0', 'ActionScheduler_TimezoneHelper::set_local_timezone()' ); + if ( $reset ) { + self::$local_timezone = NULL; + } + if ( !isset(self::$local_timezone) ) { + $tzstring = get_option('timezone_string'); + + if ( empty($tzstring) ) { + $gmt_offset = get_option('gmt_offset'); + if ( $gmt_offset == 0 ) { + $tzstring = 'UTC'; + } else { + $gmt_offset *= HOUR_IN_SECONDS; + $tzstring = timezone_name_from_abbr( '', $gmt_offset, 1 ); + + // If there's no timezone string, try again with no DST. + if ( false === $tzstring ) { + $tzstring = timezone_name_from_abbr( '', $gmt_offset, 0 ); + } + + // Try mapping to the first abbreviation we can find. + if ( false === $tzstring ) { + $is_dst = date( 'I' ); + foreach ( timezone_abbreviations_list() as $abbr ) { + foreach ( $abbr as $city ) { + if ( $city['dst'] == $is_dst && $city['offset'] == $gmt_offset ) { + // If there's no valid timezone ID, keep looking. + if ( null === $city['timezone_id'] ) { + continue; + } + + $tzstring = $city['timezone_id']; + break 2; + } + } + } + } + + // If we still have no valid string, then fall back to UTC. + if ( false === $tzstring ) { + $tzstring = 'UTC'; + } + } + } + + self::$local_timezone = new DateTimeZone($tzstring); + } + return self::$local_timezone; + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/actions/ActionScheduler_Action.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/actions/ActionScheduler_Action.php new file mode 100644 index 00000000..f4b48bb1 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/actions/ActionScheduler_Action.php @@ -0,0 +1,136 @@ +set_hook($hook); + $this->set_schedule($schedule); + $this->set_args($args); + $this->set_group($group); + } + + /** + * Executes the action. + * + * If no callbacks are registered, an exception will be thrown and the action will not be + * fired. This is useful to help detect cases where the code responsible for setting up + * a scheduled action no longer exists. + * + * @throws Exception If no callbacks are registered for this action. + */ + public function execute() { + $hook = $this->get_hook(); + + if ( ! has_action( $hook ) ) { + throw new Exception( + sprintf( + /* translators: 1: action hook. */ + __( 'Scheduled action for %1$s will not be executed as no callbacks are registered.', 'woocommerce' ), + $hook + ) + ); + } + + do_action_ref_array( $hook, array_values( $this->get_args() ) ); + } + + /** + * @param string $hook + */ + protected function set_hook( $hook ) { + $this->hook = $hook; + } + + public function get_hook() { + return $this->hook; + } + + protected function set_schedule( ActionScheduler_Schedule $schedule ) { + $this->schedule = $schedule; + } + + /** + * @return ActionScheduler_Schedule + */ + public function get_schedule() { + return $this->schedule; + } + + protected function set_args( array $args ) { + $this->args = $args; + } + + public function get_args() { + return $this->args; + } + + /** + * @param string $group + */ + protected function set_group( $group ) { + $this->group = $group; + } + + /** + * @return string + */ + public function get_group() { + return $this->group; + } + + /** + * @return bool If the action has been finished + */ + public function is_finished() { + return FALSE; + } + + /** + * Sets the priority of the action. + * + * @param int $priority Priority level (lower is higher priority). Should be in the range 0-255. + * + * @return void + */ + public function set_priority( $priority ) { + if ( $priority < 0 ) { + $priority = 0; + } elseif ( $priority > 255 ) { + $priority = 255; + } + + $this->priority = (int) $priority; + } + + /** + * Gets the action priority. + * + * @return int + */ + public function get_priority() { + return $this->priority; + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/actions/ActionScheduler_CanceledAction.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/actions/ActionScheduler_CanceledAction.php new file mode 100644 index 00000000..0172da12 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/actions/ActionScheduler_CanceledAction.php @@ -0,0 +1,24 @@ +set_schedule( new ActionScheduler_NullSchedule() ); + } + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/actions/ActionScheduler_FinishedAction.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/actions/ActionScheduler_FinishedAction.php new file mode 100644 index 00000000..fd1ddb32 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/actions/ActionScheduler_FinishedAction.php @@ -0,0 +1,17 @@ +set_schedule( new ActionScheduler_NullSchedule() ); + } + + public function execute() { + // don't execute + } +} + \ No newline at end of file diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_DBLogger.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_DBLogger.php new file mode 100644 index 00000000..0718f8bd --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_DBLogger.php @@ -0,0 +1,155 @@ +format( 'Y-m-d H:i:s' ); + ActionScheduler_TimezoneHelper::set_local_timezone( $date ); + $date_local = $date->format( 'Y-m-d H:i:s' ); + + /** @var \wpdb $wpdb */ //phpcs:ignore Generic.Commenting.DocComment.MissingShort + global $wpdb; + $wpdb->insert( + $wpdb->actionscheduler_logs, + array( + 'action_id' => $action_id, + 'message' => $message, + 'log_date_gmt' => $date_gmt, + 'log_date_local' => $date_local, + ), + array( '%d', '%s', '%s', '%s' ) + ); + + return $wpdb->insert_id; + } + + /** + * Retrieve an action log entry. + * + * @param int $entry_id Log entry ID. + * + * @return ActionScheduler_LogEntry + */ + public function get_entry( $entry_id ) { + /** @var \wpdb $wpdb */ //phpcs:ignore Generic.Commenting.DocComment.MissingShort + global $wpdb; + $entry = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->actionscheduler_logs} WHERE log_id=%d", $entry_id ) ); + + return $this->create_entry_from_db_record( $entry ); + } + + /** + * Create an action log entry from a database record. + * + * @param object $record Log entry database record object. + * + * @return ActionScheduler_LogEntry + */ + private function create_entry_from_db_record( $record ) { + if ( empty( $record ) ) { + return new ActionScheduler_NullLogEntry(); + } + + if ( is_null( $record->log_date_gmt ) ) { + $date = as_get_datetime_object( ActionScheduler_StoreSchema::DEFAULT_DATE ); + } else { + $date = as_get_datetime_object( $record->log_date_gmt ); + } + + return new ActionScheduler_LogEntry( $record->action_id, $record->message, $date ); + } + + /** + * Retrieve an action's log entries from the database. + * + * @param int $action_id Action ID. + * + * @return ActionScheduler_LogEntry[] + */ + public function get_logs( $action_id ) { + /** @var \wpdb $wpdb */ //phpcs:ignore Generic.Commenting.DocComment.MissingShort + global $wpdb; + + $records = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->actionscheduler_logs} WHERE action_id=%d", $action_id ) ); + + return array_map( array( $this, 'create_entry_from_db_record' ), $records ); + } + + /** + * Initialize the data store. + * + * @codeCoverageIgnore + */ + public function init() { + $table_maker = new ActionScheduler_LoggerSchema(); + $table_maker->init(); + $table_maker->register_tables(); + + parent::init(); + + add_action( 'action_scheduler_deleted_action', array( $this, 'clear_deleted_action_logs' ), 10, 1 ); + } + + /** + * Delete the action logs for an action. + * + * @param int $action_id Action ID. + */ + public function clear_deleted_action_logs( $action_id ) { + /** @var \wpdb $wpdb */ //phpcs:ignore Generic.Commenting.DocComment.MissingShort + global $wpdb; + $wpdb->delete( $wpdb->actionscheduler_logs, array( 'action_id' => $action_id ), array( '%d' ) ); + } + + /** + * Bulk add cancel action log entries. + * + * @param array $action_ids List of action ID. + */ + public function bulk_log_cancel_actions( $action_ids ) { + if ( empty( $action_ids ) ) { + return; + } + + /** @var \wpdb $wpdb */ //phpcs:ignore Generic.Commenting.DocComment.MissingShort + global $wpdb; + $date = as_get_datetime_object(); + $date_gmt = $date->format( 'Y-m-d H:i:s' ); + ActionScheduler_TimezoneHelper::set_local_timezone( $date ); + $date_local = $date->format( 'Y-m-d H:i:s' ); + $message = __( 'action canceled', 'woocommerce' ); + $format = '(%d, ' . $wpdb->prepare( '%s, %s, %s', $message, $date_gmt, $date_local ) . ')'; + $sql_query = "INSERT {$wpdb->actionscheduler_logs} (action_id, message, log_date_gmt, log_date_local) VALUES "; + $value_rows = array(); + + foreach ( $action_ids as $action_id ) { + $value_rows[] = $wpdb->prepare( $format, $action_id ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared + } + $sql_query .= implode( ',', $value_rows ); + + $wpdb->query( $sql_query ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_DBStore.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_DBStore.php new file mode 100644 index 00000000..69f0d7fd --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_DBStore.php @@ -0,0 +1,1181 @@ + '', + 'hooks' => '', + 'exclude-groups' => '', + ]; + + /** + * Initialize the data store + * + * @codeCoverageIgnore + */ + public function init() { + $table_maker = new ActionScheduler_StoreSchema(); + $table_maker->init(); + $table_maker->register_tables(); + } + + /** + * Save an action, checks if this is a unique action before actually saving. + * + * @param ActionScheduler_Action $action Action object. + * @param \DateTime $scheduled_date Optional schedule date. Default null. + * + * @return int Action ID. + * @throws RuntimeException Throws exception when saving the action fails. + */ + public function save_unique_action( ActionScheduler_Action $action, \DateTime $scheduled_date = null ) { + return $this->save_action_to_db( $action, $scheduled_date, true ); + } + + /** + * Save an action. Can save duplicate action as well, prefer using `save_unique_action` instead. + * + * @param ActionScheduler_Action $action Action object. + * @param \DateTime $scheduled_date Optional schedule date. Default null. + * + * @return int Action ID. + * @throws RuntimeException Throws exception when saving the action fails. + */ + public function save_action( ActionScheduler_Action $action, \DateTime $scheduled_date = null ) { + return $this->save_action_to_db( $action, $scheduled_date, false ); + } + + /** + * Save an action. + * + * @param ActionScheduler_Action $action Action object. + * @param ?DateTime $date Optional schedule date. Default null. + * @param bool $unique Whether the action should be unique. + * + * @return int Action ID. + * @throws RuntimeException Throws exception when saving the action fails. + */ + private function save_action_to_db( ActionScheduler_Action $action, DateTime $date = null, $unique = false ) { + global $wpdb; + + try { + $this->validate_action( $action ); + + $data = array( + 'hook' => $action->get_hook(), + 'status' => ( $action->is_finished() ? self::STATUS_COMPLETE : self::STATUS_PENDING ), + 'scheduled_date_gmt' => $this->get_scheduled_date_string( $action, $date ), + 'scheduled_date_local' => $this->get_scheduled_date_string_local( $action, $date ), + 'schedule' => serialize( $action->get_schedule() ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize + 'group_id' => current( $this->get_group_ids( $action->get_group() ) ), + 'priority' => $action->get_priority(), + ); + + $args = wp_json_encode( $action->get_args() ); + if ( strlen( $args ) <= static::$max_index_length ) { + $data['args'] = $args; + } else { + $data['args'] = $this->hash_args( $args ); + $data['extended_args'] = $args; + } + + $insert_sql = $this->build_insert_sql( $data, $unique ); + + // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- $insert_sql should be already prepared. + $wpdb->query( $insert_sql ); + $action_id = $wpdb->insert_id; + + if ( is_wp_error( $action_id ) ) { + throw new \RuntimeException( $action_id->get_error_message() ); + } elseif ( empty( $action_id ) ) { + if ( $unique ) { + return 0; + } + throw new \RuntimeException( $wpdb->last_error ? $wpdb->last_error : __( 'Database error.', 'woocommerce' ) ); + } + + do_action( 'action_scheduler_stored_action', $action_id ); + + return $action_id; + } catch ( \Exception $e ) { + /* translators: %s: error message */ + throw new \RuntimeException( sprintf( __( 'Error saving action: %s', 'woocommerce' ), $e->getMessage() ), 0 ); + } + } + + /** + * Helper function to build insert query. + * + * @param array $data Row data for action. + * @param bool $unique Whether the action should be unique. + * + * @return string Insert query. + */ + private function build_insert_sql( array $data, $unique ) { + global $wpdb; + $columns = array_keys( $data ); + $values = array_values( $data ); + $placeholders = array_map( array( $this, 'get_placeholder_for_column' ), $columns ); + + $table_name = ! empty( $wpdb->actionscheduler_actions ) ? $wpdb->actionscheduler_actions : $wpdb->prefix . 'actionscheduler_actions'; + + $column_sql = '`' . implode( '`, `', $columns ) . '`'; + $placeholder_sql = implode( ', ', $placeholders ); + $where_clause = $this->build_where_clause_for_insert( $data, $table_name, $unique ); + // phpcs:disable WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- $column_sql and $where_clause are already prepared. $placeholder_sql is hardcoded. + $insert_query = $wpdb->prepare( + " +INSERT INTO $table_name ( $column_sql ) +SELECT $placeholder_sql FROM DUAL +WHERE ( $where_clause ) IS NULL", + $values + ); + // phpcs:enable + + return $insert_query; + } + + /** + * Helper method to build where clause for action insert statement. + * + * @param array $data Row data for action. + * @param string $table_name Action table name. + * @param bool $unique Where action should be unique. + * + * @return string Where clause to be used with insert. + */ + private function build_where_clause_for_insert( $data, $table_name, $unique ) { + global $wpdb; + + if ( ! $unique ) { + return 'SELECT NULL FROM DUAL'; + } + + $pending_statuses = array( + ActionScheduler_Store::STATUS_PENDING, + ActionScheduler_Store::STATUS_RUNNING, + ); + $pending_status_placeholders = implode( ', ', array_fill( 0, count( $pending_statuses ), '%s' ) ); + + // phpcs:disable WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- $pending_status_placeholders is hardcoded. + $where_clause = $wpdb->prepare( + " +SELECT action_id FROM $table_name +WHERE status IN ( $pending_status_placeholders ) +AND hook = %s +AND `group_id` = %d +", + array_merge( + $pending_statuses, + array( + $data['hook'], + $data['group_id'], + ) + ) + ); + // phpcs:enable + + return "$where_clause" . ' LIMIT 1'; + } + + /** + * Helper method to get $wpdb->prepare placeholder for a given column name. + * + * @param string $column_name Name of column in actions table. + * + * @return string Placeholder to use for given column. + */ + private function get_placeholder_for_column( $column_name ) { + $string_columns = array( + 'hook', + 'status', + 'scheduled_date_gmt', + 'scheduled_date_local', + 'args', + 'schedule', + 'last_attempt_gmt', + 'last_attempt_local', + 'extended_args', + ); + + return in_array( $column_name, $string_columns ) ? '%s' : '%d'; + } + + /** + * Generate a hash from json_encoded $args using MD5 as this isn't for security. + * + * @param string $args JSON encoded action args. + * @return string + */ + protected function hash_args( $args ) { + return md5( $args ); + } + + /** + * Get action args query param value from action args. + * + * @param array $args Action args. + * @return string + */ + protected function get_args_for_query( $args ) { + $encoded = wp_json_encode( $args ); + if ( strlen( $encoded ) <= static::$max_index_length ) { + return $encoded; + } + return $this->hash_args( $encoded ); + } + /** + * Get a group's ID based on its name/slug. + * + * @param string|array $slugs The string name of a group, or names for several groups. + * @param bool $create_if_not_exists Whether to create the group if it does not already exist. Default, true - create the group. + * + * @return array The group IDs, if they exist or were successfully created. May be empty. + */ + protected function get_group_ids( $slugs, $create_if_not_exists = true ) { + $slugs = (array) $slugs; + $group_ids = array(); + + if ( empty( $slugs ) ) { + return array(); + } + + /** @var \wpdb $wpdb */ + global $wpdb; + + foreach ( $slugs as $slug ) { + $group_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT group_id FROM {$wpdb->actionscheduler_groups} WHERE slug=%s", $slug ) ); + + if ( empty( $group_id ) && $create_if_not_exists ) { + $group_id = $this->create_group( $slug ); + } + + if ( $group_id ) { + $group_ids[] = $group_id; + } + } + + return $group_ids; + } + + /** + * Create an action group. + * + * @param string $slug Group slug. + * + * @return int Group ID. + */ + protected function create_group( $slug ) { + /** @var \wpdb $wpdb */ + global $wpdb; + $wpdb->insert( $wpdb->actionscheduler_groups, array( 'slug' => $slug ) ); + + return (int) $wpdb->insert_id; + } + + /** + * Retrieve an action. + * + * @param int $action_id Action ID. + * + * @return ActionScheduler_Action + */ + public function fetch_action( $action_id ) { + /** @var \wpdb $wpdb */ + global $wpdb; + $data = $wpdb->get_row( + $wpdb->prepare( + "SELECT a.*, g.slug AS `group` FROM {$wpdb->actionscheduler_actions} a LEFT JOIN {$wpdb->actionscheduler_groups} g ON a.group_id=g.group_id WHERE a.action_id=%d", + $action_id + ) + ); + + if ( empty( $data ) ) { + return $this->get_null_action(); + } + + if ( ! empty( $data->extended_args ) ) { + $data->args = $data->extended_args; + unset( $data->extended_args ); + } + + // Convert NULL dates to zero dates. + $date_fields = array( + 'scheduled_date_gmt', + 'scheduled_date_local', + 'last_attempt_gmt', + 'last_attempt_gmt', + ); + foreach ( $date_fields as $date_field ) { + if ( is_null( $data->$date_field ) ) { + $data->$date_field = ActionScheduler_StoreSchema::DEFAULT_DATE; + } + } + + try { + $action = $this->make_action_from_db_record( $data ); + } catch ( ActionScheduler_InvalidActionException $exception ) { + do_action( 'action_scheduler_failed_fetch_action', $action_id, $exception ); + return $this->get_null_action(); + } + + return $action; + } + + /** + * Create a null action. + * + * @return ActionScheduler_NullAction + */ + protected function get_null_action() { + return new ActionScheduler_NullAction(); + } + + /** + * Create an action from a database record. + * + * @param object $data Action database record. + * + * @return ActionScheduler_Action|ActionScheduler_CanceledAction|ActionScheduler_FinishedAction + */ + protected function make_action_from_db_record( $data ) { + + $hook = $data->hook; + $args = json_decode( $data->args, true ); + $schedule = unserialize( $data->schedule ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_unserialize + + $this->validate_args( $args, $data->action_id ); + $this->validate_schedule( $schedule, $data->action_id ); + + if ( empty( $schedule ) ) { + $schedule = new ActionScheduler_NullSchedule(); + } + $group = $data->group ? $data->group : ''; + + return ActionScheduler::factory()->get_stored_action( $data->status, $data->hook, $args, $schedule, $group, $data->priority ); + } + + /** + * Returns the SQL statement to query (or count) actions. + * + * @since 3.3.0 $query['status'] accepts array of statuses instead of a single status. + * + * @param array $query Filtering options. + * @param string $select_or_count Whether the SQL should select and return the IDs or just the row count. + * + * @return string SQL statement already properly escaped. + * @throws InvalidArgumentException If the query is invalid. + */ + protected function get_query_actions_sql( array $query, $select_or_count = 'select' ) { + + if ( ! in_array( $select_or_count, array( 'select', 'count' ), true ) ) { + throw new InvalidArgumentException( __( 'Invalid value for select or count parameter. Cannot query actions.', 'woocommerce' ) ); + } + + $query = wp_parse_args( $query, array( + 'hook' => '', + 'args' => null, + 'partial_args_matching' => 'off', // can be 'like' or 'json' + 'date' => null, + 'date_compare' => '<=', + 'modified' => null, + 'modified_compare' => '<=', + 'group' => '', + 'status' => '', + 'claimed' => null, + 'per_page' => 5, + 'offset' => 0, + 'orderby' => 'date', + 'order' => 'ASC', + ) ); + + /** @var \wpdb $wpdb */ + global $wpdb; + + $db_server_info = is_callable( array( $wpdb, 'db_server_info' ) ) ? $wpdb->db_server_info() : $wpdb->db_version(); + if ( false !== strpos( $db_server_info, 'MariaDB' ) ) { + $supports_json = version_compare( + PHP_VERSION_ID >= 80016 ? $wpdb->db_version() : preg_replace( '/[^0-9.].*/', '', str_replace( '5.5.5-', '', $db_server_info ) ), + '10.2', + '>=' + ); + } else { + $supports_json = version_compare( $wpdb->db_version(), '5.7', '>=' ); + } + + $sql = ( 'count' === $select_or_count ) ? 'SELECT count(a.action_id)' : 'SELECT a.action_id'; + $sql .= " FROM {$wpdb->actionscheduler_actions} a"; + $sql_params = array(); + + if ( ! empty( $query['group'] ) || 'group' === $query['orderby'] ) { + $sql .= " LEFT JOIN {$wpdb->actionscheduler_groups} g ON g.group_id=a.group_id"; + } + + $sql .= " WHERE 1=1"; + + if ( ! empty( $query['group'] ) ) { + $sql .= " AND g.slug=%s"; + $sql_params[] = $query['group']; + } + + if ( ! empty( $query['hook'] ) ) { + $sql .= " AND a.hook=%s"; + $sql_params[] = $query['hook']; + } + + if ( ! is_null( $query['args'] ) ) { + switch ( $query['partial_args_matching'] ) { + case 'json': + if ( ! $supports_json ) { + throw new \RuntimeException( __( 'JSON partial matching not supported in your environment. Please check your MySQL/MariaDB version.', 'woocommerce' ) ); + } + $supported_types = array( + 'integer' => '%d', + 'boolean' => '%s', + 'double' => '%f', + 'string' => '%s', + ); + foreach ( $query['args'] as $key => $value ) { + $value_type = gettype( $value ); + if ( 'boolean' === $value_type ) { + $value = $value ? 'true' : 'false'; + } + $placeholder = isset( $supported_types[ $value_type ] ) ? $supported_types[ $value_type ] : false; + if ( ! $placeholder ) { + throw new \RuntimeException( sprintf( + /* translators: %s: provided value type */ + __( 'The value type for the JSON partial matching is not supported. Must be either integer, boolean, double or string. %s type provided.', 'woocommerce' ), + $value_type + ) ); + } + $sql .= ' AND JSON_EXTRACT(a.args, %s)='.$placeholder; + $sql_params[] = '$.'.$key; + $sql_params[] = $value; + } + break; + case 'like': + foreach ( $query['args'] as $key => $value ) { + $sql .= ' AND a.args LIKE %s'; + $json_partial = $wpdb->esc_like( trim( json_encode( array( $key => $value ) ), '{}' ) ); + $sql_params[] = "%{$json_partial}%"; + } + break; + case 'off': + $sql .= " AND a.args=%s"; + $sql_params[] = $this->get_args_for_query( $query['args'] ); + break; + default: + throw new \RuntimeException( __( 'Unknown partial args matching value.', 'woocommerce' ) ); + } + } + + if ( $query['status'] ) { + $statuses = (array) $query['status']; + $placeholders = array_fill( 0, count( $statuses ), '%s' ); + $sql .= ' AND a.status IN (' . join( ', ', $placeholders ) . ')'; + $sql_params = array_merge( $sql_params, array_values( $statuses ) ); + } + + if ( $query['date'] instanceof \DateTime ) { + $date = clone $query['date']; + $date->setTimezone( new \DateTimeZone( 'UTC' ) ); + $date_string = $date->format( 'Y-m-d H:i:s' ); + $comparator = $this->validate_sql_comparator( $query['date_compare'] ); + $sql .= " AND a.scheduled_date_gmt $comparator %s"; + $sql_params[] = $date_string; + } + + if ( $query['modified'] instanceof \DateTime ) { + $modified = clone $query['modified']; + $modified->setTimezone( new \DateTimeZone( 'UTC' ) ); + $date_string = $modified->format( 'Y-m-d H:i:s' ); + $comparator = $this->validate_sql_comparator( $query['modified_compare'] ); + $sql .= " AND a.last_attempt_gmt $comparator %s"; + $sql_params[] = $date_string; + } + + if ( true === $query['claimed'] ) { + $sql .= ' AND a.claim_id != 0'; + } elseif ( false === $query['claimed'] ) { + $sql .= ' AND a.claim_id = 0'; + } elseif ( ! is_null( $query['claimed'] ) ) { + $sql .= ' AND a.claim_id = %d'; + $sql_params[] = $query['claimed']; + } + + if ( ! empty( $query['search'] ) ) { + $sql .= ' AND (a.hook LIKE %s OR (a.extended_args IS NULL AND a.args LIKE %s) OR a.extended_args LIKE %s'; + for ( $i = 0; $i < 3; $i++ ) { + $sql_params[] = sprintf( '%%%s%%', $query['search'] ); + } + + $search_claim_id = (int) $query['search']; + if ( $search_claim_id ) { + $sql .= ' OR a.claim_id = %d'; + $sql_params[] = $search_claim_id; + } + + $sql .= ')'; + } + + if ( 'select' === $select_or_count ) { + if ( 'ASC' === strtoupper( $query['order'] ) ) { + $order = 'ASC'; + } else { + $order = 'DESC'; + } + switch ( $query['orderby'] ) { + case 'hook': + $sql .= " ORDER BY a.hook $order"; + break; + case 'group': + $sql .= " ORDER BY g.slug $order"; + break; + case 'modified': + $sql .= " ORDER BY a.last_attempt_gmt $order"; + break; + case 'none': + break; + case 'action_id': + $sql .= " ORDER BY a.action_id $order"; + break; + case 'date': + default: + $sql .= " ORDER BY a.scheduled_date_gmt $order"; + break; + } + + if ( $query['per_page'] > 0 ) { + $sql .= ' LIMIT %d, %d'; + $sql_params[] = $query['offset']; + $sql_params[] = $query['per_page']; + } + } + + if ( ! empty( $sql_params ) ) { + $sql = $wpdb->prepare( $sql, $sql_params ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared + } + + return $sql; + } + + /** + * Query for action count or list of action IDs. + * + * @since 3.3.0 $query['status'] accepts array of statuses instead of a single status. + * + * @see ActionScheduler_Store::query_actions for $query arg usage. + * + * @param array $query Query filtering options. + * @param string $query_type Whether to select or count the results. Defaults to select. + * + * @return string|array|null The IDs of actions matching the query. Null on failure. + */ + public function query_actions( $query = array(), $query_type = 'select' ) { + /** @var wpdb $wpdb */ + global $wpdb; + + $sql = $this->get_query_actions_sql( $query, $query_type ); + + return ( 'count' === $query_type ) ? $wpdb->get_var( $sql ) : $wpdb->get_col( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.NoSql, WordPress.DB.DirectDatabaseQuery.NoCaching + } + + /** + * Get a count of all actions in the store, grouped by status. + * + * @return array Set of 'status' => int $count pairs for statuses with 1 or more actions of that status. + */ + public function action_counts() { + global $wpdb; + + $sql = "SELECT a.status, count(a.status) as 'count'"; + $sql .= " FROM {$wpdb->actionscheduler_actions} a"; + $sql .= ' GROUP BY a.status'; + + $actions_count_by_status = array(); + $action_stati_and_labels = $this->get_status_labels(); + + foreach ( $wpdb->get_results( $sql ) as $action_data ) { // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared + // Ignore any actions with invalid status. + if ( array_key_exists( $action_data->status, $action_stati_and_labels ) ) { + $actions_count_by_status[ $action_data->status ] = $action_data->count; + } + } + + return $actions_count_by_status; + } + + /** + * Cancel an action. + * + * @param int $action_id Action ID. + * + * @return void + * @throws \InvalidArgumentException If the action update failed. + */ + public function cancel_action( $action_id ) { + /** @var \wpdb $wpdb */ + global $wpdb; + + $updated = $wpdb->update( + $wpdb->actionscheduler_actions, + array( 'status' => self::STATUS_CANCELED ), + array( 'action_id' => $action_id ), + array( '%s' ), + array( '%d' ) + ); + if ( false === $updated ) { + /* translators: %s: action ID */ + throw new \InvalidArgumentException( sprintf( __( 'Unidentified action %s', 'woocommerce' ), $action_id ) ); + } + do_action( 'action_scheduler_canceled_action', $action_id ); + } + + /** + * Cancel pending actions by hook. + * + * @since 3.0.0 + * + * @param string $hook Hook name. + * + * @return void + */ + public function cancel_actions_by_hook( $hook ) { + $this->bulk_cancel_actions( array( 'hook' => $hook ) ); + } + + /** + * Cancel pending actions by group. + * + * @param string $group Group slug. + * + * @return void + */ + public function cancel_actions_by_group( $group ) { + $this->bulk_cancel_actions( array( 'group' => $group ) ); + } + + /** + * Bulk cancel actions. + * + * @since 3.0.0 + * + * @param array $query_args Query parameters. + */ + protected function bulk_cancel_actions( $query_args ) { + /** @var \wpdb $wpdb */ + global $wpdb; + + if ( ! is_array( $query_args ) ) { + return; + } + + // Don't cancel actions that are already canceled. + if ( isset( $query_args['status'] ) && self::STATUS_CANCELED === $query_args['status'] ) { + return; + } + + $action_ids = true; + $query_args = wp_parse_args( + $query_args, + array( + 'per_page' => 1000, + 'status' => self::STATUS_PENDING, + 'orderby' => 'none', + ) + ); + + while ( $action_ids ) { + $action_ids = $this->query_actions( $query_args ); + if ( empty( $action_ids ) ) { + break; + } + + $format = array_fill( 0, count( $action_ids ), '%d' ); + $query_in = '(' . implode( ',', $format ) . ')'; + $parameters = $action_ids; + array_unshift( $parameters, self::STATUS_CANCELED ); + + $wpdb->query( + $wpdb->prepare( + "UPDATE {$wpdb->actionscheduler_actions} SET status = %s WHERE action_id IN {$query_in}", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared + $parameters + ) + ); + + do_action( 'action_scheduler_bulk_cancel_actions', $action_ids ); + } + } + + /** + * Delete an action. + * + * @param int $action_id Action ID. + * @throws \InvalidArgumentException If the action deletion failed. + */ + public function delete_action( $action_id ) { + /** @var \wpdb $wpdb */ + global $wpdb; + $deleted = $wpdb->delete( $wpdb->actionscheduler_actions, array( 'action_id' => $action_id ), array( '%d' ) ); + if ( empty( $deleted ) ) { + throw new \InvalidArgumentException( sprintf( __( 'Unidentified action %s', 'woocommerce' ), $action_id ) ); //phpcs:ignore WordPress.WP.I18n.MissingTranslatorsComment + } + do_action( 'action_scheduler_deleted_action', $action_id ); + } + + /** + * Get the schedule date for an action. + * + * @param string $action_id Action ID. + * + * @return \DateTime The local date the action is scheduled to run, or the date that it ran. + */ + public function get_date( $action_id ) { + $date = $this->get_date_gmt( $action_id ); + ActionScheduler_TimezoneHelper::set_local_timezone( $date ); + return $date; + } + + /** + * Get the GMT schedule date for an action. + * + * @param int $action_id Action ID. + * + * @throws \InvalidArgumentException If action cannot be identified. + * @return \DateTime The GMT date the action is scheduled to run, or the date that it ran. + */ + protected function get_date_gmt( $action_id ) { + /** @var \wpdb $wpdb */ + global $wpdb; + $record = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->actionscheduler_actions} WHERE action_id=%d", $action_id ) ); + if ( empty( $record ) ) { + throw new \InvalidArgumentException( sprintf( __( 'Unidentified action %s', 'woocommerce' ), $action_id ) ); //phpcs:ignore WordPress.WP.I18n.MissingTranslatorsComment + } + if ( self::STATUS_PENDING === $record->status ) { + return as_get_datetime_object( $record->scheduled_date_gmt ); + } else { + return as_get_datetime_object( $record->last_attempt_gmt ); + } + } + + /** + * Stake a claim on actions. + * + * @param int $max_actions Maximum number of action to include in claim. + * @param \DateTime $before_date Jobs must be schedule before this date. Defaults to now. + * @param array $hooks Hooks to filter for. + * @param string $group Group to filter for. + * + * @return ActionScheduler_ActionClaim + */ + public function stake_claim( $max_actions = 10, \DateTime $before_date = null, $hooks = array(), $group = '' ) { + $claim_id = $this->generate_claim_id(); + + $this->claim_before_date = $before_date; + $this->claim_actions( $claim_id, $max_actions, $before_date, $hooks, $group ); + $action_ids = $this->find_actions_by_claim_id( $claim_id ); + $this->claim_before_date = null; + + return new ActionScheduler_ActionClaim( $claim_id, $action_ids ); + } + + /** + * Generate a new action claim. + * + * @return int Claim ID. + */ + protected function generate_claim_id() { + /** @var \wpdb $wpdb */ + global $wpdb; + $now = as_get_datetime_object(); + $wpdb->insert( $wpdb->actionscheduler_claims, array( 'date_created_gmt' => $now->format( 'Y-m-d H:i:s' ) ) ); + + return $wpdb->insert_id; + } + + /** + * Set a claim filter. + * + * @param string $filter_name Claim filter name. + * @param mixed $filter_values Values to filter. + * @return void + */ + public function set_claim_filter( $filter_name, $filter_values ) { + if ( isset( $this->claim_filters[ $filter_name ] ) ) { + $this->claim_filters[ $filter_name ] = $filter_values; + } + } + + /** + * Get the claim filter value. + * + * @param string $filter_name Claim filter name. + * @return mixed + */ + public function get_claim_filter( $filter_name ) { + if ( isset( $this->claim_filters[ $filter_name ] ) ) { + return $this->claim_filters[ $filter_name ]; + } + + return ''; + } + + /** + * Mark actions claimed. + * + * @param string $claim_id Claim Id. + * @param int $limit Number of action to include in claim. + * @param \DateTime $before_date Should use UTC timezone. + * @param array $hooks Hooks to filter for. + * @param string $group Group to filter for. + * + * @return int The number of actions that were claimed. + * @throws \InvalidArgumentException Throws InvalidArgumentException if group doesn't exist. + * @throws \RuntimeException Throws RuntimeException if unable to claim action. + */ + protected function claim_actions( $claim_id, $limit, \DateTime $before_date = null, $hooks = array(), $group = '' ) { + /** @var \wpdb $wpdb */ + global $wpdb; + + $now = as_get_datetime_object(); + $date = is_null( $before_date ) ? $now : clone $before_date; + // can't use $wpdb->update() because of the <= condition. + $update = "UPDATE {$wpdb->actionscheduler_actions} SET claim_id=%d, last_attempt_gmt=%s, last_attempt_local=%s"; + $params = array( + $claim_id, + $now->format( 'Y-m-d H:i:s' ), + current_time( 'mysql' ), + ); + + // Set claim filters. + if ( ! empty( $hooks ) ) { + $this->set_claim_filter( 'hooks', $hooks ); + } else { + $hooks = $this->get_claim_filter( 'hooks' ); + } + if ( ! empty( $group ) ) { + $this->set_claim_filter( 'group', $group ); + } else { + $group = $this->get_claim_filter( 'group' ); + } + + $where = 'WHERE claim_id = 0 AND scheduled_date_gmt <= %s AND status=%s'; + $params[] = $date->format( 'Y-m-d H:i:s' ); + $params[] = self::STATUS_PENDING; + + if ( ! empty( $hooks ) ) { + $placeholders = array_fill( 0, count( $hooks ), '%s' ); + $where .= ' AND hook IN (' . join( ', ', $placeholders ) . ')'; + $params = array_merge( $params, array_values( $hooks ) ); + } + + $group_operator = 'IN'; + if ( empty( $group ) ) { + $group = $this->get_claim_filter( 'exclude-groups' ); + $group_operator = 'NOT IN'; + } + + if ( ! empty( $group ) ) { + $group_ids = $this->get_group_ids( $group, false ); + + // throw exception if no matching group(s) found, this matches ActionScheduler_wpPostStore's behaviour. + if ( empty( $group_ids ) ) { + throw new InvalidArgumentException( + sprintf( + /* translators: %s: group name(s) */ + _n( + 'The group "%s" does not exist.', + 'The groups "%s" do not exist.', + is_array( $group ) ? count( $group ) : 1, + 'woocommerce' + ), + $group + ) + ); + } + + $id_list = implode( ',', array_map( 'intval', $group_ids ) ); + $where .= " AND group_id {$group_operator} ( $id_list )"; + } + + /** + * Sets the order-by clause used in the action claim query. + * + * @since 3.4.0 + * + * @param string $order_by_sql + */ + $order = apply_filters( 'action_scheduler_claim_actions_order_by', 'ORDER BY priority ASC, attempts ASC, scheduled_date_gmt ASC, action_id ASC' ); + $params[] = $limit; + + $sql = $wpdb->prepare( "{$update} {$where} {$order} LIMIT %d", $params ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders + $rows_affected = $wpdb->query( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching + if ( false === $rows_affected ) { + $error = empty( $wpdb->last_error ) + ? _x( 'unknown', 'database error', 'woocommerce' ) + : $wpdb->last_error; + + throw new \RuntimeException( + sprintf( + /* translators: %s database error. */ + __( 'Unable to claim actions. Database error: %s.', 'woocommerce' ), + $error + ) + ); + } + + return (int) $rows_affected; + } + + /** + * Get the number of active claims. + * + * @return int + */ + public function get_claim_count() { + global $wpdb; + + $sql = "SELECT COUNT(DISTINCT claim_id) FROM {$wpdb->actionscheduler_actions} WHERE claim_id != 0 AND status IN ( %s, %s)"; + $sql = $wpdb->prepare( $sql, array( self::STATUS_PENDING, self::STATUS_RUNNING ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared + + return (int) $wpdb->get_var( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared + } + + /** + * Return an action's claim ID, as stored in the claim_id column. + * + * @param string $action_id Action ID. + * @return mixed + */ + public function get_claim_id( $action_id ) { + /** @var \wpdb $wpdb */ + global $wpdb; + + $sql = "SELECT claim_id FROM {$wpdb->actionscheduler_actions} WHERE action_id=%d"; + $sql = $wpdb->prepare( $sql, $action_id ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared + + return (int) $wpdb->get_var( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared + } + + /** + * Retrieve the action IDs of action in a claim. + * + * @param int $claim_id Claim ID. + * @return int[] + */ + public function find_actions_by_claim_id( $claim_id ) { + /** @var \wpdb $wpdb */ + global $wpdb; + + $action_ids = array(); + $before_date = isset( $this->claim_before_date ) ? $this->claim_before_date : as_get_datetime_object(); + $cut_off = $before_date->format( 'Y-m-d H:i:s' ); + + $sql = $wpdb->prepare( + "SELECT action_id, scheduled_date_gmt FROM {$wpdb->actionscheduler_actions} WHERE claim_id = %d ORDER BY priority ASC, attempts ASC, scheduled_date_gmt ASC, action_id ASC", + $claim_id + ); + + // Verify that the scheduled date for each action is within the expected bounds (in some unusual + // cases, we cannot depend on MySQL to honor all of the WHERE conditions we specify). + foreach ( $wpdb->get_results( $sql ) as $claimed_action ) { // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared + if ( $claimed_action->scheduled_date_gmt <= $cut_off ) { + $action_ids[] = absint( $claimed_action->action_id ); + } + } + + return $action_ids; + } + + /** + * Release actions from a claim and delete the claim. + * + * @param ActionScheduler_ActionClaim $claim Claim object. + */ + public function release_claim( ActionScheduler_ActionClaim $claim ) { + /** @var \wpdb $wpdb */ + global $wpdb; + /** + * Deadlock warning: This function modifies actions to release them from claims that have been processed. Earlier, we used to it in a atomic query, i.e. we would update all actions belonging to a particular claim_id with claim_id = 0. + * While this was functionally correct, it would cause deadlock, since this update query will hold a lock on the claim_id_.. index on the action table. + * This allowed the possibility of a race condition, where the claimer query is also running at the same time, then the claimer query will also try to acquire a lock on the claim_id_.. index, and in this case if claim release query has already progressed to the point of acquiring the lock, but have not updated yet, it would cause a deadlock. + * + * We resolve this by getting all the actions_id that we want to release claim from in a separate query, and then releasing the claim on each of them. This way, our lock is acquired on the action_id index instead of the claim_id index. Note that the lock on claim_id will still be acquired, but it will only when we actually make the update, rather than when we select the actions. + */ + $action_ids = $wpdb->get_col( $wpdb->prepare( "SELECT action_id FROM {$wpdb->actionscheduler_actions} WHERE claim_id = %d", $claim->get_id() ) ); + + $row_updates = 0; + if ( count( $action_ids ) > 0 ) { + $action_id_string = implode( ',', array_map( 'absint', $action_ids ) ); + $row_updates = $wpdb->query( "UPDATE {$wpdb->actionscheduler_actions} SET claim_id = 0 WHERE action_id IN ({$action_id_string})" ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared + } + + $wpdb->delete( $wpdb->actionscheduler_claims, array( 'claim_id' => $claim->get_id() ), array( '%d' ) ); + + if ( $row_updates < count( $action_ids ) ) { + throw new RuntimeException( + sprintf( + __( 'Unable to release actions from claim id %d.', 'woocommerce' ), + $claim->get_id() + ) + ); + } + } + + /** + * Remove the claim from an action. + * + * @param int $action_id Action ID. + * + * @return void + */ + public function unclaim_action( $action_id ) { + /** @var \wpdb $wpdb */ + global $wpdb; + $wpdb->update( + $wpdb->actionscheduler_actions, + array( 'claim_id' => 0 ), + array( 'action_id' => $action_id ), + array( '%s' ), + array( '%d' ) + ); + } + + /** + * Mark an action as failed. + * + * @param int $action_id Action ID. + * @throws \InvalidArgumentException Throw an exception if action was not updated. + */ + public function mark_failure( $action_id ) { + /** @var \wpdb $wpdb */ + global $wpdb; + $updated = $wpdb->update( + $wpdb->actionscheduler_actions, + array( 'status' => self::STATUS_FAILED ), + array( 'action_id' => $action_id ), + array( '%s' ), + array( '%d' ) + ); + if ( empty( $updated ) ) { + throw new \InvalidArgumentException( sprintf( __( 'Unidentified action %s', 'woocommerce' ), $action_id ) ); //phpcs:ignore WordPress.WP.I18n.MissingTranslatorsComment + } + } + + /** + * Add execution message to action log. + * + * @throws Exception If the action status cannot be updated to self::STATUS_RUNNING ('in-progress'). + * + * @param int $action_id Action ID. + * + * @return void + */ + public function log_execution( $action_id ) { + /** @var \wpdb $wpdb */ + global $wpdb; + + $sql = "UPDATE {$wpdb->actionscheduler_actions} SET attempts = attempts+1, status=%s, last_attempt_gmt = %s, last_attempt_local = %s WHERE action_id = %d"; + $sql = $wpdb->prepare( $sql, self::STATUS_RUNNING, current_time( 'mysql', true ), current_time( 'mysql' ), $action_id ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared + + // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared + $status_updated = $wpdb->query( $sql ); + + if ( ! $status_updated ) { + throw new Exception( + sprintf( + /* translators: 1: action ID. 2: status slug. */ + __( 'Unable to update the status of action %1$d to %2$s.', 'woocommerce' ), + $action_id, + self::STATUS_RUNNING + ) + ); + } + } + + /** + * Mark an action as complete. + * + * @param int $action_id Action ID. + * + * @return void + * @throws \InvalidArgumentException Throw an exception if action was not updated. + */ + public function mark_complete( $action_id ) { + /** @var \wpdb $wpdb */ + global $wpdb; + $updated = $wpdb->update( + $wpdb->actionscheduler_actions, + array( + 'status' => self::STATUS_COMPLETE, + 'last_attempt_gmt' => current_time( 'mysql', true ), + 'last_attempt_local' => current_time( 'mysql' ), + ), + array( 'action_id' => $action_id ), + array( '%s' ), + array( '%d' ) + ); + if ( empty( $updated ) ) { + throw new \InvalidArgumentException( sprintf( __( 'Unidentified action %s', 'woocommerce' ), $action_id ) ); //phpcs:ignore WordPress.WP.I18n.MissingTranslatorsComment + } + + /** + * Fires after a scheduled action has been completed. + * + * @since 3.4.2 + * + * @param int $action_id Action ID. + */ + do_action( 'action_scheduler_completed_action', $action_id ); + } + + /** + * Get an action's status. + * + * @param int $action_id Action ID. + * + * @return string + * @throws \InvalidArgumentException Throw an exception if not status was found for action_id. + * @throws \RuntimeException Throw an exception if action status could not be retrieved. + */ + public function get_status( $action_id ) { + /** @var \wpdb $wpdb */ + global $wpdb; + $sql = "SELECT status FROM {$wpdb->actionscheduler_actions} WHERE action_id=%d"; + $sql = $wpdb->prepare( $sql, $action_id ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared + $status = $wpdb->get_var( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared + + if ( null === $status ) { + throw new \InvalidArgumentException( __( 'Invalid action ID. No status found.', 'woocommerce' ) ); + } elseif ( empty( $status ) ) { + throw new \RuntimeException( __( 'Unknown status found for action.', 'woocommerce' ) ); + } else { + return $status; + } + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_HybridStore.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_HybridStore.php new file mode 100644 index 00000000..36779d47 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_HybridStore.php @@ -0,0 +1,427 @@ +demarkation_id = (int) get_option( self::DEMARKATION_OPTION, 0 ); + if ( empty( $config ) ) { + $config = Controller::instance()->get_migration_config_object(); + } + $this->primary_store = $config->get_destination_store(); + $this->secondary_store = $config->get_source_store(); + $this->migration_runner = new Runner( $config ); + } + + /** + * Initialize the table data store tables. + * + * @codeCoverageIgnore + */ + public function init() { + add_action( 'action_scheduler/created_table', [ $this, 'set_autoincrement' ], 10, 2 ); + $this->primary_store->init(); + $this->secondary_store->init(); + remove_action( 'action_scheduler/created_table', [ $this, 'set_autoincrement' ], 10 ); + } + + /** + * When the actions table is created, set its autoincrement + * value to be one higher than the posts table to ensure that + * there are no ID collisions. + * + * @param string $table_name + * @param string $table_suffix + * + * @return void + * @codeCoverageIgnore + */ + public function set_autoincrement( $table_name, $table_suffix ) { + if ( ActionScheduler_StoreSchema::ACTIONS_TABLE === $table_suffix ) { + if ( empty( $this->demarkation_id ) ) { + $this->demarkation_id = $this->set_demarkation_id(); + } + /** @var \wpdb $wpdb */ + global $wpdb; + /** + * A default date of '0000-00-00 00:00:00' is invalid in MySQL 5.7 when configured with + * sql_mode including both STRICT_TRANS_TABLES and NO_ZERO_DATE. + */ + $default_date = new DateTime( 'tomorrow' ); + $null_action = new ActionScheduler_NullAction(); + $date_gmt = $this->get_scheduled_date_string( $null_action, $default_date ); + $date_local = $this->get_scheduled_date_string_local( $null_action, $default_date ); + + $row_count = $wpdb->insert( + $wpdb->{ActionScheduler_StoreSchema::ACTIONS_TABLE}, + [ + 'action_id' => $this->demarkation_id, + 'hook' => '', + 'status' => '', + 'scheduled_date_gmt' => $date_gmt, + 'scheduled_date_local' => $date_local, + 'last_attempt_gmt' => $date_gmt, + 'last_attempt_local' => $date_local, + ] + ); + if ( $row_count > 0 ) { + $wpdb->delete( + $wpdb->{ActionScheduler_StoreSchema::ACTIONS_TABLE}, + [ 'action_id' => $this->demarkation_id ] + ); + } + } + } + + /** + * Store the demarkation id in WP options. + * + * @param int $id The ID to set as the demarkation point between the two stores + * Leave null to use the next ID from the WP posts table. + * + * @return int The new ID. + * + * @codeCoverageIgnore + */ + private function set_demarkation_id( $id = null ) { + if ( empty( $id ) ) { + /** @var \wpdb $wpdb */ + global $wpdb; + $id = (int) $wpdb->get_var( "SELECT MAX(ID) FROM $wpdb->posts" ); + $id ++; + } + update_option( self::DEMARKATION_OPTION, $id ); + + return $id; + } + + /** + * Find the first matching action from the secondary store. + * If it exists, migrate it to the primary store immediately. + * After it migrates, the secondary store will logically contain + * the next matching action, so return the result thence. + * + * @param string $hook + * @param array $params + * + * @return string + */ + public function find_action( $hook, $params = [] ) { + $found_unmigrated_action = $this->secondary_store->find_action( $hook, $params ); + if ( ! empty( $found_unmigrated_action ) ) { + $this->migrate( [ $found_unmigrated_action ] ); + } + + return $this->primary_store->find_action( $hook, $params ); + } + + /** + * Find actions matching the query in the secondary source first. + * If any are found, migrate them immediately. Then the secondary + * store will contain the canonical results. + * + * @param array $query + * @param string $query_type Whether to select or count the results. Default, select. + * + * @return int[] + */ + public function query_actions( $query = [], $query_type = 'select' ) { + $found_unmigrated_actions = $this->secondary_store->query_actions( $query, 'select' ); + if ( ! empty( $found_unmigrated_actions ) ) { + $this->migrate( $found_unmigrated_actions ); + } + + return $this->primary_store->query_actions( $query, $query_type ); + } + + /** + * Get a count of all actions in the store, grouped by status + * + * @return array Set of 'status' => int $count pairs for statuses with 1 or more actions of that status. + */ + public function action_counts() { + $unmigrated_actions_count = $this->secondary_store->action_counts(); + $migrated_actions_count = $this->primary_store->action_counts(); + $actions_count_by_status = array(); + + foreach ( $this->get_status_labels() as $status_key => $status_label ) { + + $count = 0; + + if ( isset( $unmigrated_actions_count[ $status_key ] ) ) { + $count += $unmigrated_actions_count[ $status_key ]; + } + + if ( isset( $migrated_actions_count[ $status_key ] ) ) { + $count += $migrated_actions_count[ $status_key ]; + } + + $actions_count_by_status[ $status_key ] = $count; + } + + $actions_count_by_status = array_filter( $actions_count_by_status ); + + return $actions_count_by_status; + } + + /** + * If any actions would have been claimed by the secondary store, + * migrate them immediately, then ask the primary store for the + * canonical claim. + * + * @param int $max_actions + * @param DateTime|null $before_date + * + * @return ActionScheduler_ActionClaim + */ + public function stake_claim( $max_actions = 10, DateTime $before_date = null, $hooks = array(), $group = '' ) { + $claim = $this->secondary_store->stake_claim( $max_actions, $before_date, $hooks, $group ); + + $claimed_actions = $claim->get_actions(); + if ( ! empty( $claimed_actions ) ) { + $this->migrate( $claimed_actions ); + } + + $this->secondary_store->release_claim( $claim ); + + return $this->primary_store->stake_claim( $max_actions, $before_date, $hooks, $group ); + } + + /** + * Migrate a list of actions to the table data store. + * + * @param array $action_ids List of action IDs. + */ + private function migrate( $action_ids ) { + $this->migration_runner->migrate_actions( $action_ids ); + } + + /** + * Save an action to the primary store. + * + * @param ActionScheduler_Action $action Action object to be saved. + * @param DateTime $date Optional. Schedule date. Default null. + * + * @return int The action ID + */ + public function save_action( ActionScheduler_Action $action, DateTime $date = null ) { + return $this->primary_store->save_action( $action, $date ); + } + + /** + * Retrieve an existing action whether migrated or not. + * + * @param int $action_id Action ID. + */ + public function fetch_action( $action_id ) { + $store = $this->get_store_from_action_id( $action_id, true ); + if ( $store ) { + return $store->fetch_action( $action_id ); + } else { + return new ActionScheduler_NullAction(); + } + } + + /** + * Cancel an existing action whether migrated or not. + * + * @param int $action_id Action ID. + */ + public function cancel_action( $action_id ) { + $store = $this->get_store_from_action_id( $action_id ); + if ( $store ) { + $store->cancel_action( $action_id ); + } + } + + /** + * Delete an existing action whether migrated or not. + * + * @param int $action_id Action ID. + */ + public function delete_action( $action_id ) { + $store = $this->get_store_from_action_id( $action_id ); + if ( $store ) { + $store->delete_action( $action_id ); + } + } + + /** + * Get the schedule date an existing action whether migrated or not. + * + * @param int $action_id Action ID. + */ + public function get_date( $action_id ) { + $store = $this->get_store_from_action_id( $action_id ); + if ( $store ) { + return $store->get_date( $action_id ); + } else { + return null; + } + } + + /** + * Mark an existing action as failed whether migrated or not. + * + * @param int $action_id Action ID. + */ + public function mark_failure( $action_id ) { + $store = $this->get_store_from_action_id( $action_id ); + if ( $store ) { + $store->mark_failure( $action_id ); + } + } + + /** + * Log the execution of an existing action whether migrated or not. + * + * @param int $action_id Action ID. + */ + public function log_execution( $action_id ) { + $store = $this->get_store_from_action_id( $action_id ); + if ( $store ) { + $store->log_execution( $action_id ); + } + } + + /** + * Mark an existing action complete whether migrated or not. + * + * @param int $action_id Action ID. + */ + public function mark_complete( $action_id ) { + $store = $this->get_store_from_action_id( $action_id ); + if ( $store ) { + $store->mark_complete( $action_id ); + } + } + + /** + * Get an existing action status whether migrated or not. + * + * @param int $action_id Action ID. + */ + public function get_status( $action_id ) { + $store = $this->get_store_from_action_id( $action_id ); + if ( $store ) { + return $store->get_status( $action_id ); + } + return null; + } + + /** + * Return which store an action is stored in. + * + * @param int $action_id ID of the action. + * @param bool $primary_first Optional flag indicating search the primary store first. + * @return ActionScheduler_Store + */ + protected function get_store_from_action_id( $action_id, $primary_first = false ) { + if ( $primary_first ) { + $stores = [ + $this->primary_store, + $this->secondary_store, + ]; + } elseif ( $action_id < $this->demarkation_id ) { + $stores = [ + $this->secondary_store, + $this->primary_store, + ]; + } else { + $stores = [ + $this->primary_store, + ]; + } + + foreach ( $stores as $store ) { + $action = $store->fetch_action( $action_id ); + if ( ! is_a( $action, 'ActionScheduler_NullAction' ) ) { + return $store; + } + } + return null; + } + + /* * * * * * * * * * * * * * * * * * * * * * * * * * * + * All claim-related functions should operate solely + * on the primary store. + * * * * * * * * * * * * * * * * * * * * * * * * * * */ + + /** + * Get the claim count from the table data store. + */ + public function get_claim_count() { + return $this->primary_store->get_claim_count(); + } + + /** + * Retrieve the claim ID for an action from the table data store. + * + * @param int $action_id Action ID. + */ + public function get_claim_id( $action_id ) { + return $this->primary_store->get_claim_id( $action_id ); + } + + /** + * Release a claim in the table data store. + * + * @param ActionScheduler_ActionClaim $claim Claim object. + */ + public function release_claim( ActionScheduler_ActionClaim $claim ) { + $this->primary_store->release_claim( $claim ); + } + + /** + * Release claims on an action in the table data store. + * + * @param int $action_id Action ID. + */ + public function unclaim_action( $action_id ) { + $this->primary_store->unclaim_action( $action_id ); + } + + /** + * Retrieve a list of action IDs by claim. + * + * @param int $claim_id Claim ID. + */ + public function find_actions_by_claim_id( $claim_id ) { + return $this->primary_store->find_actions_by_claim_id( $claim_id ); + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpCommentLogger.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpCommentLogger.php new file mode 100644 index 00000000..edbca31d --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpCommentLogger.php @@ -0,0 +1,241 @@ +create_wp_comment( $action_id, $message, $date ); + return $comment_id; + } + + protected function create_wp_comment( $action_id, $message, DateTime $date ) { + + $comment_date_gmt = $date->format('Y-m-d H:i:s'); + ActionScheduler_TimezoneHelper::set_local_timezone( $date ); + $comment_data = array( + 'comment_post_ID' => $action_id, + 'comment_date' => $date->format('Y-m-d H:i:s'), + 'comment_date_gmt' => $comment_date_gmt, + 'comment_author' => self::AGENT, + 'comment_content' => $message, + 'comment_agent' => self::AGENT, + 'comment_type' => self::TYPE, + ); + return wp_insert_comment($comment_data); + } + + /** + * @param string $entry_id + * + * @return ActionScheduler_LogEntry + */ + public function get_entry( $entry_id ) { + $comment = $this->get_comment( $entry_id ); + if ( empty($comment) || $comment->comment_type != self::TYPE ) { + return new ActionScheduler_NullLogEntry(); + } + + $date = as_get_datetime_object( $comment->comment_date_gmt ); + ActionScheduler_TimezoneHelper::set_local_timezone( $date ); + return new ActionScheduler_LogEntry( $comment->comment_post_ID, $comment->comment_content, $date ); + } + + /** + * @param string $action_id + * + * @return ActionScheduler_LogEntry[] + */ + public function get_logs( $action_id ) { + $status = 'all'; + if ( get_post_status($action_id) == 'trash' ) { + $status = 'post-trashed'; + } + $comments = get_comments(array( + 'post_id' => $action_id, + 'orderby' => 'comment_date_gmt', + 'order' => 'ASC', + 'type' => self::TYPE, + 'status' => $status, + )); + $logs = array(); + foreach ( $comments as $c ) { + $entry = $this->get_entry( $c ); + if ( !empty($entry) ) { + $logs[] = $entry; + } + } + return $logs; + } + + protected function get_comment( $comment_id ) { + return get_comment( $comment_id ); + } + + + + /** + * @param WP_Comment_Query $query + */ + public function filter_comment_queries( $query ) { + foreach ( array('ID', 'parent', 'post_author', 'post_name', 'post_parent', 'type', 'post_type', 'post_id', 'post_ID') as $key ) { + if ( !empty($query->query_vars[$key]) ) { + return; // don't slow down queries that wouldn't include action_log comments anyway + } + } + $query->query_vars['action_log_filter'] = TRUE; + add_filter( 'comments_clauses', array( $this, 'filter_comment_query_clauses' ), 10, 2 ); + } + + /** + * @param array $clauses + * @param WP_Comment_Query $query + * + * @return array + */ + public function filter_comment_query_clauses( $clauses, $query ) { + if ( !empty($query->query_vars['action_log_filter']) ) { + $clauses['where'] .= $this->get_where_clause(); + } + return $clauses; + } + + /** + * Make sure Action Scheduler logs are excluded from comment feeds, which use WP_Query, not + * the WP_Comment_Query class handled by @see self::filter_comment_queries(). + * + * @param string $where + * @param WP_Query $query + * + * @return string + */ + public function filter_comment_feed( $where, $query ) { + if ( is_comment_feed() ) { + $where .= $this->get_where_clause(); + } + return $where; + } + + /** + * Return a SQL clause to exclude Action Scheduler comments. + * + * @return string + */ + protected function get_where_clause() { + global $wpdb; + return sprintf( " AND {$wpdb->comments}.comment_type != '%s'", self::TYPE ); + } + + /** + * Remove action log entries from wp_count_comments() + * + * @param array $stats + * @param int $post_id + * + * @return object + */ + public function filter_comment_count( $stats, $post_id ) { + global $wpdb; + + if ( 0 === $post_id ) { + $stats = $this->get_comment_count(); + } + + return $stats; + } + + /** + * Retrieve the comment counts from our cache, or the database if the cached version isn't set. + * + * @return object + */ + protected function get_comment_count() { + global $wpdb; + + $stats = get_transient( 'as_comment_count' ); + + if ( ! $stats ) { + $stats = array(); + + $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} WHERE comment_type NOT IN('order_note','action_log') GROUP BY comment_approved", ARRAY_A ); + + $total = 0; + $stats = array(); + $approved = array( '0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed' ); + + foreach ( (array) $count as $row ) { + // Don't count post-trashed toward totals + if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] ) { + $total += $row['num_comments']; + } + if ( isset( $approved[ $row['comment_approved'] ] ) ) { + $stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments']; + } + } + + $stats['total_comments'] = $total; + $stats['all'] = $total; + + foreach ( $approved as $key ) { + if ( empty( $stats[ $key ] ) ) { + $stats[ $key ] = 0; + } + } + + $stats = (object) $stats; + set_transient( 'as_comment_count', $stats ); + } + + return $stats; + } + + /** + * Delete comment count cache whenever there is new comment or the status of a comment changes. Cache + * will be regenerated next time ActionScheduler_wpCommentLogger::filter_comment_count() is called. + */ + public function delete_comment_count_cache() { + delete_transient( 'as_comment_count' ); + } + + /** + * @codeCoverageIgnore + */ + public function init() { + add_action( 'action_scheduler_before_process_queue', array( $this, 'disable_comment_counting' ), 10, 0 ); + add_action( 'action_scheduler_after_process_queue', array( $this, 'enable_comment_counting' ), 10, 0 ); + + parent::init(); + + add_action( 'pre_get_comments', array( $this, 'filter_comment_queries' ), 10, 1 ); + add_action( 'wp_count_comments', array( $this, 'filter_comment_count' ), 20, 2 ); // run after WC_Comments::wp_count_comments() to make sure we exclude order notes and action logs + add_action( 'comment_feed_where', array( $this, 'filter_comment_feed' ), 10, 2 ); + + // Delete comments count cache whenever there is a new comment or a comment status changes + add_action( 'wp_insert_comment', array( $this, 'delete_comment_count_cache' ) ); + add_action( 'wp_set_comment_status', array( $this, 'delete_comment_count_cache' ) ); + } + + public function disable_comment_counting() { + wp_defer_comment_counting(true); + } + public function enable_comment_counting() { + wp_defer_comment_counting(false); + } + +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpPostStore.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpPostStore.php new file mode 100644 index 00000000..d8ab9a35 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpPostStore.php @@ -0,0 +1,1089 @@ +validate_action( $action ); + $post_array = $this->create_post_array( $action, $scheduled_date ); + $post_id = $this->save_post_array( $post_array ); + $this->save_post_schedule( $post_id, $action->get_schedule() ); + $this->save_action_group( $post_id, $action->get_group() ); + do_action( 'action_scheduler_stored_action', $post_id ); + return $post_id; + } catch ( Exception $e ) { + /* translators: %s: action error message */ + throw new RuntimeException( sprintf( __( 'Error saving action: %s', 'woocommerce' ), $e->getMessage() ), 0 ); + } + } + + /** + * Create post array. + * + * @param ActionScheduler_Action $action Scheduled Action. + * @param DateTime $scheduled_date Scheduled Date. + * + * @return array Returns an array of post data. + */ + protected function create_post_array( ActionScheduler_Action $action, DateTime $scheduled_date = null ) { + $post = array( + 'post_type' => self::POST_TYPE, + 'post_title' => $action->get_hook(), + 'post_content' => wp_json_encode( $action->get_args() ), + 'post_status' => ( $action->is_finished() ? 'publish' : 'pending' ), + 'post_date_gmt' => $this->get_scheduled_date_string( $action, $scheduled_date ), + 'post_date' => $this->get_scheduled_date_string_local( $action, $scheduled_date ), + ); + return $post; + } + + /** + * Save post array. + * + * @param array $post_array Post array. + * @return int Returns the post ID. + * @throws RuntimeException Throws an exception if the action could not be saved. + */ + protected function save_post_array( $post_array ) { + add_filter( 'wp_insert_post_data', array( $this, 'filter_insert_post_data' ), 10, 1 ); + add_filter( 'pre_wp_unique_post_slug', array( $this, 'set_unique_post_slug' ), 10, 5 ); + + $has_kses = false !== has_filter( 'content_save_pre', 'wp_filter_post_kses' ); + + if ( $has_kses ) { + // Prevent KSES from corrupting JSON in post_content. + kses_remove_filters(); + } + + $post_id = wp_insert_post( $post_array ); + + if ( $has_kses ) { + kses_init_filters(); + } + + remove_filter( 'wp_insert_post_data', array( $this, 'filter_insert_post_data' ), 10 ); + remove_filter( 'pre_wp_unique_post_slug', array( $this, 'set_unique_post_slug' ), 10 ); + + if ( is_wp_error( $post_id ) || empty( $post_id ) ) { + throw new RuntimeException( __( 'Unable to save action.', 'woocommerce' ) ); + } + return $post_id; + } + + /** + * Filter insert post data. + * + * @param array $postdata Post data to filter. + * + * @return array + */ + public function filter_insert_post_data( $postdata ) { + if ( self::POST_TYPE === $postdata['post_type'] ) { + $postdata['post_author'] = 0; + if ( 'future' === $postdata['post_status'] ) { + $postdata['post_status'] = 'publish'; + } + } + return $postdata; + } + + /** + * Create a (probably unique) post name for scheduled actions in a more performant manner than wp_unique_post_slug(). + * + * When an action's post status is transitioned to something other than 'draft', 'pending' or 'auto-draft, like 'publish' + * or 'failed' or 'trash', WordPress will find a unique slug (stored in post_name column) using the wp_unique_post_slug() + * function. This is done to ensure URL uniqueness. The approach taken by wp_unique_post_slug() is to iterate over existing + * post_name values that match, and append a number 1 greater than the largest. This makes sense when manually creating a + * post from the Edit Post screen. It becomes a bottleneck when automatically processing thousands of actions, with a + * database containing thousands of related post_name values. + * + * WordPress 5.1 introduces the 'pre_wp_unique_post_slug' filter for plugins to address this issue. + * + * We can short-circuit WordPress's wp_unique_post_slug() approach using the 'pre_wp_unique_post_slug' filter. This + * method is available to be used as a callback on that filter. It provides a more scalable approach to generating a + * post_name/slug that is probably unique. Because Action Scheduler never actually uses the post_name field, or an + * action's slug, being probably unique is good enough. + * + * For more backstory on this issue, see: + * - https://github.com/woocommerce/action-scheduler/issues/44 and + * - https://core.trac.wordpress.org/ticket/21112 + * + * @param string $override_slug Short-circuit return value. + * @param string $slug The desired slug (post_name). + * @param int $post_ID Post ID. + * @param string $post_status The post status. + * @param string $post_type Post type. + * @return string + */ + public function set_unique_post_slug( $override_slug, $slug, $post_ID, $post_status, $post_type ) { + if ( self::POST_TYPE === $post_type ) { + $override_slug = uniqid( self::POST_TYPE . '-', true ) . '-' . wp_generate_password( 32, false ); + } + return $override_slug; + } + + /** + * Save post schedule. + * + * @param int $post_id Post ID of the scheduled action. + * @param string $schedule Schedule to save. + * + * @return void + */ + protected function save_post_schedule( $post_id, $schedule ) { + update_post_meta( $post_id, self::SCHEDULE_META_KEY, $schedule ); + } + + /** + * Save action group. + * + * @param int $post_id Post ID. + * @param string $group Group to save. + * @return void + */ + protected function save_action_group( $post_id, $group ) { + if ( empty( $group ) ) { + wp_set_object_terms( $post_id, array(), self::GROUP_TAXONOMY, false ); + } else { + wp_set_object_terms( $post_id, array( $group ), self::GROUP_TAXONOMY, false ); + } + } + + /** + * Fetch actions. + * + * @param int $action_id Action ID. + * @return object + */ + public function fetch_action( $action_id ) { + $post = $this->get_post( $action_id ); + if ( empty( $post ) || self::POST_TYPE !== $post->post_type ) { + return $this->get_null_action(); + } + + try { + $action = $this->make_action_from_post( $post ); + } catch ( ActionScheduler_InvalidActionException $exception ) { + do_action( 'action_scheduler_failed_fetch_action', $post->ID, $exception ); + return $this->get_null_action(); + } + + return $action; + } + + /** + * Get post. + * + * @param string $action_id - Action ID. + * @return WP_Post|null + */ + protected function get_post( $action_id ) { + if ( empty( $action_id ) ) { + return null; + } + return get_post( $action_id ); + } + + /** + * Get NULL action. + * + * @return ActionScheduler_NullAction + */ + protected function get_null_action() { + return new ActionScheduler_NullAction(); + } + + /** + * Make action from post. + * + * @param WP_Post $post Post object. + * @return WP_Post + */ + protected function make_action_from_post( $post ) { + $hook = $post->post_title; + + $args = json_decode( $post->post_content, true ); + $this->validate_args( $args, $post->ID ); + + $schedule = get_post_meta( $post->ID, self::SCHEDULE_META_KEY, true ); + $this->validate_schedule( $schedule, $post->ID ); + + $group = wp_get_object_terms( $post->ID, self::GROUP_TAXONOMY, array( 'fields' => 'names' ) ); + $group = empty( $group ) ? '' : reset( $group ); + + return ActionScheduler::factory()->get_stored_action( $this->get_action_status_by_post_status( $post->post_status ), $hook, $args, $schedule, $group ); + } + + /** + * Get action status by post status. + * + * @param string $post_status Post status. + * + * @throws InvalidArgumentException Throw InvalidArgumentException if $post_status not in known status fields returned by $this->get_status_labels(). + * @return string + */ + protected function get_action_status_by_post_status( $post_status ) { + + switch ( $post_status ) { + case 'publish': + $action_status = self::STATUS_COMPLETE; + break; + case 'trash': + $action_status = self::STATUS_CANCELED; + break; + default: + if ( ! array_key_exists( $post_status, $this->get_status_labels() ) ) { + throw new InvalidArgumentException( sprintf( 'Invalid post status: "%s". No matching action status available.', $post_status ) ); + } + $action_status = $post_status; + break; + } + + return $action_status; + } + + /** + * Get post status by action status. + * + * @param string $action_status Action status. + * + * @throws InvalidArgumentException Throws InvalidArgumentException if $post_status not in known status fields returned by $this->get_status_labels(). + * @return string + */ + protected function get_post_status_by_action_status( $action_status ) { + + switch ( $action_status ) { + case self::STATUS_COMPLETE: + $post_status = 'publish'; + break; + case self::STATUS_CANCELED: + $post_status = 'trash'; + break; + default: + if ( ! array_key_exists( $action_status, $this->get_status_labels() ) ) { + throw new InvalidArgumentException( sprintf( 'Invalid action status: "%s".', $action_status ) ); + } + $post_status = $action_status; + break; + } + + return $post_status; + } + + /** + * Returns the SQL statement to query (or count) actions. + * + * @param array $query - Filtering options. + * @param string $select_or_count - Whether the SQL should select and return the IDs or just the row count. + * + * @throws InvalidArgumentException - Throw InvalidArgumentException if $select_or_count not count or select. + * @return string SQL statement. The returned SQL is already properly escaped. + */ + protected function get_query_actions_sql( array $query, $select_or_count = 'select' ) { + + if ( ! in_array( $select_or_count, array( 'select', 'count' ), true ) ) { + throw new InvalidArgumentException( __( 'Invalid schedule. Cannot save action.', 'woocommerce' ) ); + } + + $query = wp_parse_args( + $query, + array( + 'hook' => '', + 'args' => null, + 'date' => null, + 'date_compare' => '<=', + 'modified' => null, + 'modified_compare' => '<=', + 'group' => '', + 'status' => '', + 'claimed' => null, + 'per_page' => 5, + 'offset' => 0, + 'orderby' => 'date', + 'order' => 'ASC', + 'search' => '', + ) + ); + + /** + * Global wpdb object. + * + * @var wpdb $wpdb + */ + global $wpdb; + $sql = ( 'count' === $select_or_count ) ? 'SELECT count(p.ID)' : 'SELECT p.ID '; + $sql .= "FROM {$wpdb->posts} p"; + $sql_params = array(); + if ( empty( $query['group'] ) && 'group' === $query['orderby'] ) { + $sql .= " LEFT JOIN {$wpdb->term_relationships} tr ON tr.object_id=p.ID"; + $sql .= " LEFT JOIN {$wpdb->term_taxonomy} tt ON tr.term_taxonomy_id=tt.term_taxonomy_id"; + $sql .= " LEFT JOIN {$wpdb->terms} t ON tt.term_id=t.term_id"; + } elseif ( ! empty( $query['group'] ) ) { + $sql .= " INNER JOIN {$wpdb->term_relationships} tr ON tr.object_id=p.ID"; + $sql .= " INNER JOIN {$wpdb->term_taxonomy} tt ON tr.term_taxonomy_id=tt.term_taxonomy_id"; + $sql .= " INNER JOIN {$wpdb->terms} t ON tt.term_id=t.term_id"; + $sql .= ' AND t.slug=%s'; + $sql_params[] = $query['group']; + } + $sql .= ' WHERE post_type=%s'; + $sql_params[] = self::POST_TYPE; + if ( $query['hook'] ) { + $sql .= ' AND p.post_title=%s'; + $sql_params[] = $query['hook']; + } + if ( ! is_null( $query['args'] ) ) { + $sql .= ' AND p.post_content=%s'; + $sql_params[] = wp_json_encode( $query['args'] ); + } + + if ( $query['status'] ) { + $post_statuses = array_map( array( $this, 'get_post_status_by_action_status' ), (array) $query['status'] ); + $placeholders = array_fill( 0, count( $post_statuses ), '%s' ); + $sql .= ' AND p.post_status IN (' . join( ', ', $placeholders ) . ')'; + $sql_params = array_merge( $sql_params, array_values( $post_statuses ) ); + } + + if ( $query['date'] instanceof DateTime ) { + $date = clone $query['date']; + $date->setTimezone( new DateTimeZone( 'UTC' ) ); + $date_string = $date->format( 'Y-m-d H:i:s' ); + $comparator = $this->validate_sql_comparator( $query['date_compare'] ); + $sql .= " AND p.post_date_gmt $comparator %s"; + $sql_params[] = $date_string; + } + + if ( $query['modified'] instanceof DateTime ) { + $modified = clone $query['modified']; + $modified->setTimezone( new DateTimeZone( 'UTC' ) ); + $date_string = $modified->format( 'Y-m-d H:i:s' ); + $comparator = $this->validate_sql_comparator( $query['modified_compare'] ); + $sql .= " AND p.post_modified_gmt $comparator %s"; + $sql_params[] = $date_string; + } + + if ( true === $query['claimed'] ) { + $sql .= " AND p.post_password != ''"; + } elseif ( false === $query['claimed'] ) { + $sql .= " AND p.post_password = ''"; + } elseif ( ! is_null( $query['claimed'] ) ) { + $sql .= ' AND p.post_password = %s'; + $sql_params[] = $query['claimed']; + } + + if ( ! empty( $query['search'] ) ) { + $sql .= ' AND (p.post_title LIKE %s OR p.post_content LIKE %s OR p.post_password LIKE %s)'; + for ( $i = 0; $i < 3; $i++ ) { + $sql_params[] = sprintf( '%%%s%%', $query['search'] ); + } + } + + if ( 'select' === $select_or_count ) { + switch ( $query['orderby'] ) { + case 'hook': + $orderby = 'p.post_title'; + break; + case 'group': + $orderby = 't.name'; + break; + case 'status': + $orderby = 'p.post_status'; + break; + case 'modified': + $orderby = 'p.post_modified'; + break; + case 'claim_id': + $orderby = 'p.post_password'; + break; + case 'schedule': + case 'date': + default: + $orderby = 'p.post_date_gmt'; + break; + } + if ( 'ASC' === strtoupper( $query['order'] ) ) { + $order = 'ASC'; + } else { + $order = 'DESC'; + } + $sql .= " ORDER BY $orderby $order"; + if ( $query['per_page'] > 0 ) { + $sql .= ' LIMIT %d, %d'; + $sql_params[] = $query['offset']; + $sql_params[] = $query['per_page']; + } + } + + return $wpdb->prepare( $sql, $sql_params ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared + } + + /** + * Query for action count or list of action IDs. + * + * @since 3.3.0 $query['status'] accepts array of statuses instead of a single status. + * + * @see ActionScheduler_Store::query_actions for $query arg usage. + * + * @param array $query Query filtering options. + * @param string $query_type Whether to select or count the results. Defaults to select. + * + * @return string|array|null The IDs of actions matching the query. Null on failure. + */ + public function query_actions( $query = array(), $query_type = 'select' ) { + /** + * Global $wpdb object. + * + * @var wpdb $wpdb + */ + global $wpdb; + + $sql = $this->get_query_actions_sql( $query, $query_type ); + + return ( 'count' === $query_type ) ? $wpdb->get_var( $sql ) : $wpdb->get_col( $sql ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.PreparedSQL.NotPrepared + } + + /** + * Get a count of all actions in the store, grouped by status + * + * @return array + */ + public function action_counts() { + + $action_counts_by_status = array(); + $action_stati_and_labels = $this->get_status_labels(); + $posts_count_by_status = (array) wp_count_posts( self::POST_TYPE, 'readable' ); + + foreach ( $posts_count_by_status as $post_status_name => $count ) { + + try { + $action_status_name = $this->get_action_status_by_post_status( $post_status_name ); + } catch ( Exception $e ) { + // Ignore any post statuses that aren't for actions. + continue; + } + if ( array_key_exists( $action_status_name, $action_stati_and_labels ) ) { + $action_counts_by_status[ $action_status_name ] = $count; + } + } + + return $action_counts_by_status; + } + + /** + * Cancel action. + * + * @param int $action_id Action ID. + * + * @throws InvalidArgumentException If $action_id is not identified. + */ + public function cancel_action( $action_id ) { + $post = get_post( $action_id ); + if ( empty( $post ) || ( self::POST_TYPE !== $post->post_type ) ) { + /* translators: %s is the action ID */ + throw new InvalidArgumentException( sprintf( __( 'Unidentified action %s', 'woocommerce' ), $action_id ) ); + } + do_action( 'action_scheduler_canceled_action', $action_id ); + add_filter( 'pre_wp_unique_post_slug', array( $this, 'set_unique_post_slug' ), 10, 5 ); + wp_trash_post( $action_id ); + remove_filter( 'pre_wp_unique_post_slug', array( $this, 'set_unique_post_slug' ), 10 ); + } + + /** + * Delete action. + * + * @param int $action_id Action ID. + * @return void + * @throws InvalidArgumentException If action is not identified. + */ + public function delete_action( $action_id ) { + $post = get_post( $action_id ); + if ( empty( $post ) || ( self::POST_TYPE !== $post->post_type ) ) { + /* translators: %s is the action ID */ + throw new InvalidArgumentException( sprintf( __( 'Unidentified action %s', 'woocommerce' ), $action_id ) ); + } + do_action( 'action_scheduler_deleted_action', $action_id ); + + wp_delete_post( $action_id, true ); + } + + /** + * Get date for claim id. + * + * @param int $action_id Action ID. + * @return ActionScheduler_DateTime The date the action is schedule to run, or the date that it ran. + */ + public function get_date( $action_id ) { + $next = $this->get_date_gmt( $action_id ); + return ActionScheduler_TimezoneHelper::set_local_timezone( $next ); + } + + /** + * Get Date GMT. + * + * @param int $action_id Action ID. + * + * @throws InvalidArgumentException If $action_id is not identified. + * @return ActionScheduler_DateTime The date the action is schedule to run, or the date that it ran. + */ + public function get_date_gmt( $action_id ) { + $post = get_post( $action_id ); + if ( empty( $post ) || ( self::POST_TYPE !== $post->post_type ) ) { + /* translators: %s is the action ID */ + throw new InvalidArgumentException( sprintf( __( 'Unidentified action %s', 'woocommerce' ), $action_id ) ); + } + if ( 'publish' === $post->post_status ) { + return as_get_datetime_object( $post->post_modified_gmt ); + } else { + return as_get_datetime_object( $post->post_date_gmt ); + } + } + + /** + * Stake claim. + * + * @param int $max_actions Maximum number of actions. + * @param DateTime $before_date Jobs must be schedule before this date. Defaults to now. + * @param array $hooks Claim only actions with a hook or hooks. + * @param string $group Claim only actions in the given group. + * + * @return ActionScheduler_ActionClaim + * @throws RuntimeException When there is an error staking a claim. + * @throws InvalidArgumentException When the given group is not valid. + */ + public function stake_claim( $max_actions = 10, DateTime $before_date = null, $hooks = array(), $group = '' ) { + $this->claim_before_date = $before_date; + $claim_id = $this->generate_claim_id(); + $this->claim_actions( $claim_id, $max_actions, $before_date, $hooks, $group ); + $action_ids = $this->find_actions_by_claim_id( $claim_id ); + $this->claim_before_date = null; + + return new ActionScheduler_ActionClaim( $claim_id, $action_ids ); + } + + /** + * Get claim count. + * + * @return int + */ + public function get_claim_count() { + global $wpdb; + + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching + return $wpdb->get_var( + $wpdb->prepare( + "SELECT COUNT(DISTINCT post_password) FROM {$wpdb->posts} WHERE post_password != '' AND post_type = %s AND post_status IN ('in-progress','pending')", + array( self::POST_TYPE ) + ) + ); + } + + /** + * Generate claim id. + * + * @return string + */ + protected function generate_claim_id() { + $claim_id = md5( microtime( true ) . wp_rand( 0, 1000 ) ); + return substr( $claim_id, 0, 20 ); // to fit in db field with 20 char limit. + } + + /** + * Claim actions. + * + * @param string $claim_id Claim ID. + * @param int $limit Limit. + * @param DateTime $before_date Should use UTC timezone. + * @param array $hooks Claim only actions with a hook or hooks. + * @param string $group Claim only actions in the given group. + * + * @return int The number of actions that were claimed. + * @throws RuntimeException When there is a database error. + */ + protected function claim_actions( $claim_id, $limit, DateTime $before_date = null, $hooks = array(), $group = '' ) { + // Set up initial variables. + $date = null === $before_date ? as_get_datetime_object() : clone $before_date; + $limit_ids = ! empty( $group ); + $ids = $limit_ids ? $this->get_actions_by_group( $group, $limit, $date ) : array(); + + // If limiting by IDs and no posts found, then return early since we have nothing to update. + if ( $limit_ids && 0 === count( $ids ) ) { + return 0; + } + + /** + * Global wpdb object. + * + * @var wpdb $wpdb + */ + global $wpdb; + + /* + * Build up custom query to update the affected posts. Parameters are built as a separate array + * to make it easier to identify where they are in the query. + * + * We can't use $wpdb->update() here because of the "ID IN ..." clause. + */ + $update = "UPDATE {$wpdb->posts} SET post_password = %s, post_modified_gmt = %s, post_modified = %s"; + $params = array( + $claim_id, + current_time( 'mysql', true ), + current_time( 'mysql' ), + ); + + // Build initial WHERE clause. + $where = "WHERE post_type = %s AND post_status = %s AND post_password = ''"; + $params[] = self::POST_TYPE; + $params[] = ActionScheduler_Store::STATUS_PENDING; + + if ( ! empty( $hooks ) ) { + $placeholders = array_fill( 0, count( $hooks ), '%s' ); + $where .= ' AND post_title IN (' . join( ', ', $placeholders ) . ')'; + $params = array_merge( $params, array_values( $hooks ) ); + } + + /* + * Add the IDs to the WHERE clause. IDs not escaped because they came directly from a prior DB query. + * + * If we're not limiting by IDs, then include the post_date_gmt clause. + */ + if ( $limit_ids ) { + $where .= ' AND ID IN (' . join( ',', $ids ) . ')'; + } else { + $where .= ' AND post_date_gmt <= %s'; + $params[] = $date->format( 'Y-m-d H:i:s' ); + } + + // Add the ORDER BY clause and,ms limit. + $order = 'ORDER BY menu_order ASC, post_date_gmt ASC, ID ASC LIMIT %d'; + $params[] = $limit; + + // Run the query and gather results. + $rows_affected = $wpdb->query( $wpdb->prepare( "{$update} {$where} {$order}", $params ) ); // phpcs:ignore // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare + + if ( false === $rows_affected ) { + throw new RuntimeException( __( 'Unable to claim actions. Database error.', 'woocommerce' ) ); + } + + return (int) $rows_affected; + } + + /** + * Get IDs of actions within a certain group and up to a certain date/time. + * + * @param string $group The group to use in finding actions. + * @param int $limit The number of actions to retrieve. + * @param DateTime $date DateTime object representing cutoff time for actions. Actions retrieved will be + * up to and including this DateTime. + * + * @return array IDs of actions in the appropriate group and before the appropriate time. + * @throws InvalidArgumentException When the group does not exist. + */ + protected function get_actions_by_group( $group, $limit, DateTime $date ) { + // Ensure the group exists before continuing. + if ( ! term_exists( $group, self::GROUP_TAXONOMY ) ) { + /* translators: %s is the group name */ + throw new InvalidArgumentException( sprintf( __( 'The group "%s" does not exist.', 'woocommerce' ), $group ) ); + } + + // Set up a query for post IDs to use later. + $query = new WP_Query(); + $query_args = array( + 'fields' => 'ids', + 'post_type' => self::POST_TYPE, + 'post_status' => ActionScheduler_Store::STATUS_PENDING, + 'has_password' => false, + 'posts_per_page' => $limit * 3, + 'suppress_filters' => true, + 'no_found_rows' => true, + 'orderby' => array( + 'menu_order' => 'ASC', + 'date' => 'ASC', + 'ID' => 'ASC', + ), + 'date_query' => array( + 'column' => 'post_date_gmt', + 'before' => $date->format( 'Y-m-d H:i' ), + 'inclusive' => true, + ), + 'tax_query' => array( // phpcs:ignore WordPress.DB.SlowDBQuery + array( + 'taxonomy' => self::GROUP_TAXONOMY, + 'field' => 'slug', + 'terms' => $group, + 'include_children' => false, + ), + ), + ); + + return $query->query( $query_args ); + } + + /** + * Find actions by claim ID. + * + * @param string $claim_id Claim ID. + * @return array + */ + public function find_actions_by_claim_id( $claim_id ) { + /** + * Global wpdb object. + * + * @var wpdb $wpdb + */ + global $wpdb; + + $action_ids = array(); + $before_date = isset( $this->claim_before_date ) ? $this->claim_before_date : as_get_datetime_object(); + $cut_off = $before_date->format( 'Y-m-d H:i:s' ); + + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching + $results = $wpdb->get_results( + $wpdb->prepare( + "SELECT ID, post_date_gmt FROM {$wpdb->posts} WHERE post_type = %s AND post_password = %s", + array( + self::POST_TYPE, + $claim_id, + ) + ) + ); + + // Verify that the scheduled date for each action is within the expected bounds (in some unusual + // cases, we cannot depend on MySQL to honor all of the WHERE conditions we specify). + foreach ( $results as $claimed_action ) { + if ( $claimed_action->post_date_gmt <= $cut_off ) { + $action_ids[] = absint( $claimed_action->ID ); + } + } + + return $action_ids; + } + + /** + * Release claim. + * + * @param ActionScheduler_ActionClaim $claim Claim object to release. + * @return void + * @throws RuntimeException When the claim is not unlocked. + */ + public function release_claim( ActionScheduler_ActionClaim $claim ) { + $action_ids = $this->find_actions_by_claim_id( $claim->get_id() ); + if ( empty( $action_ids ) ) { + return; // nothing to do. + } + $action_id_string = implode( ',', array_map( 'intval', $action_ids ) ); + /** + * Global wpdb object. + * + * @var wpdb $wpdb + */ + global $wpdb; + + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching + $result = $wpdb->query( + $wpdb->prepare( + "UPDATE {$wpdb->posts} SET post_password = '' WHERE ID IN ($action_id_string) AND post_password = %s", //phpcs:ignore + array( + $claim->get_id(), + ) + ) + ); + if ( false === $result ) { + /* translators: %s: claim ID */ + throw new RuntimeException( sprintf( __( 'Unable to unlock claim %s. Database error.', 'woocommerce' ), $claim->get_id() ) ); + } + } + + /** + * Unclaim action. + * + * @param string $action_id Action ID. + * @throws RuntimeException When unable to unlock claim on action ID. + */ + public function unclaim_action( $action_id ) { + /** + * Global wpdb object. + * + * @var wpdb $wpdb + */ + global $wpdb; + + //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching + $result = $wpdb->query( + $wpdb->prepare( + "UPDATE {$wpdb->posts} SET post_password = '' WHERE ID = %d AND post_type = %s", + $action_id, + self::POST_TYPE + ) + ); + if ( false === $result ) { + /* translators: %s: action ID */ + throw new RuntimeException( sprintf( __( 'Unable to unlock claim on action %s. Database error.', 'woocommerce' ), $action_id ) ); + } + } + + /** + * Mark failure on action. + * + * @param int $action_id Action ID. + * + * @return void + * @throws RuntimeException When unable to mark failure on action ID. + */ + public function mark_failure( $action_id ) { + /** + * Global wpdb object. + * + * @var wpdb $wpdb + */ + global $wpdb; + + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching + $result = $wpdb->query( + $wpdb->prepare( "UPDATE {$wpdb->posts} SET post_status = %s WHERE ID = %d AND post_type = %s", self::STATUS_FAILED, $action_id, self::POST_TYPE ) + ); + if ( false === $result ) { + /* translators: %s: action ID */ + throw new RuntimeException( sprintf( __( 'Unable to mark failure on action %s. Database error.', 'woocommerce' ), $action_id ) ); + } + } + + /** + * Return an action's claim ID, as stored in the post password column + * + * @param int $action_id Action ID. + * @return mixed + */ + public function get_claim_id( $action_id ) { + return $this->get_post_column( $action_id, 'post_password' ); + } + + /** + * Return an action's status, as stored in the post status column + * + * @param int $action_id Action ID. + * + * @return mixed + * @throws InvalidArgumentException When the action ID is invalid. + */ + public function get_status( $action_id ) { + $status = $this->get_post_column( $action_id, 'post_status' ); + + if ( null === $status ) { + throw new InvalidArgumentException( __( 'Invalid action ID. No status found.', 'woocommerce' ) ); + } + + return $this->get_action_status_by_post_status( $status ); + } + + /** + * Get post column + * + * @param string $action_id Action ID. + * @param string $column_name Column Name. + * + * @return string|null + */ + private function get_post_column( $action_id, $column_name ) { + /** + * Global wpdb object. + * + * @var wpdb $wpdb + */ + global $wpdb; + + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching + return $wpdb->get_var( + $wpdb->prepare( + "SELECT {$column_name} FROM {$wpdb->posts} WHERE ID=%d AND post_type=%s", // phpcs:ignore + $action_id, + self::POST_TYPE + ) + ); + } + + /** + * Log Execution. + * + * @throws Exception If the action status cannot be updated to self::STATUS_RUNNING ('in-progress'). + * + * @param string $action_id Action ID. + */ + public function log_execution( $action_id ) { + /** + * Global wpdb object. + * + * @var wpdb $wpdb + */ + global $wpdb; + + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching + $status_updated = $wpdb->query( + $wpdb->prepare( + "UPDATE {$wpdb->posts} SET menu_order = menu_order+1, post_status=%s, post_modified_gmt = %s, post_modified = %s WHERE ID = %d AND post_type = %s", + self::STATUS_RUNNING, + current_time( 'mysql', true ), + current_time( 'mysql' ), + $action_id, + self::POST_TYPE + ) + ); + + if ( ! $status_updated ) { + throw new Exception( + sprintf( + /* translators: 1: action ID. 2: status slug. */ + __( 'Unable to update the status of action %1$d to %2$s.', 'woocommerce' ), + $action_id, + self::STATUS_RUNNING + ) + ); + } + } + + /** + * Record that an action was completed. + * + * @param string $action_id ID of the completed action. + * + * @throws InvalidArgumentException When the action ID is invalid. + * @throws RuntimeException When there was an error executing the action. + */ + public function mark_complete( $action_id ) { + $post = get_post( $action_id ); + if ( empty( $post ) || ( self::POST_TYPE !== $post->post_type ) ) { + /* translators: %s is the action ID */ + throw new InvalidArgumentException( sprintf( __( 'Unidentified action %s', 'woocommerce' ), $action_id ) ); + } + add_filter( 'wp_insert_post_data', array( $this, 'filter_insert_post_data' ), 10, 1 ); + add_filter( 'pre_wp_unique_post_slug', array( $this, 'set_unique_post_slug' ), 10, 5 ); + $result = wp_update_post( + array( + 'ID' => $action_id, + 'post_status' => 'publish', + ), + true + ); + remove_filter( 'wp_insert_post_data', array( $this, 'filter_insert_post_data' ), 10 ); + remove_filter( 'pre_wp_unique_post_slug', array( $this, 'set_unique_post_slug' ), 10 ); + if ( is_wp_error( $result ) ) { + throw new RuntimeException( $result->get_error_message() ); + } + + /** + * Fires after a scheduled action has been completed. + * + * @since 3.4.2 + * + * @param int $action_id Action ID. + */ + do_action( 'action_scheduler_completed_action', $action_id ); + } + + /** + * Mark action as migrated when there is an error deleting the action. + * + * @param int $action_id Action ID. + */ + public function mark_migrated( $action_id ) { + wp_update_post( + array( + 'ID' => $action_id, + 'post_status' => 'migrated', + ) + ); + } + + /** + * Determine whether the post store can be migrated. + * + * @param [type] $setting - Setting value. + * @return bool + */ + public function migration_dependencies_met( $setting ) { + global $wpdb; + + $dependencies_met = get_transient( self::DEPENDENCIES_MET ); + if ( empty( $dependencies_met ) ) { + $maximum_args_length = apply_filters( 'action_scheduler_maximum_args_length', 191 ); + $found_action = $wpdb->get_var( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching + $wpdb->prepare( + "SELECT ID FROM {$wpdb->posts} WHERE post_type = %s AND CHAR_LENGTH(post_content) > %d LIMIT 1", + $maximum_args_length, + self::POST_TYPE + ) + ); + $dependencies_met = $found_action ? 'no' : 'yes'; + set_transient( self::DEPENDENCIES_MET, $dependencies_met, DAY_IN_SECONDS ); + } + + return 'yes' === $dependencies_met ? $setting : false; + } + + /** + * InnoDB indexes have a maximum size of 767 bytes by default, which is only 191 characters with utf8mb4. + * + * Previously, AS wasn't concerned about args length, as we used the (unindex) post_content column. However, + * as we prepare to move to custom tables, and can use an indexed VARCHAR column instead, we want to warn + * developers of this impending requirement. + * + * @param ActionScheduler_Action $action Action object. + */ + protected function validate_action( ActionScheduler_Action $action ) { + try { + parent::validate_action( $action ); + } catch ( Exception $e ) { + /* translators: %s is the error message */ + $message = sprintf( __( '%s Support for strings longer than this will be removed in a future version.', 'woocommerce' ), $e->getMessage() ); + _doing_it_wrong( 'ActionScheduler_Action::$args', esc_html( $message ), '2.1.0' ); + } + } + + /** + * (@codeCoverageIgnore) + */ + public function init() { + add_filter( 'action_scheduler_migration_dependencies_met', array( $this, 'migration_dependencies_met' ) ); + + $post_type_registrar = new ActionScheduler_wpPostStore_PostTypeRegistrar(); + $post_type_registrar->register(); + + $post_status_registrar = new ActionScheduler_wpPostStore_PostStatusRegistrar(); + $post_status_registrar->register(); + + $taxonomy_registrar = new ActionScheduler_wpPostStore_TaxonomyRegistrar(); + $taxonomy_registrar->register(); + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpPostStore_PostStatusRegistrar.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpPostStore_PostStatusRegistrar.php new file mode 100644 index 00000000..aac99d96 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpPostStore_PostStatusRegistrar.php @@ -0,0 +1,59 @@ +post_status_args(), $this->post_status_running_labels() ) ); + register_post_status( ActionScheduler_Store::STATUS_FAILED, array_merge( $this->post_status_args(), $this->post_status_failed_labels() ) ); + } + + /** + * Build the args array for the post type definition + * + * @return array + */ + protected function post_status_args() { + $args = array( + 'public' => false, + 'exclude_from_search' => false, + 'show_in_admin_all_list' => true, + 'show_in_admin_status_list' => true, + ); + + return apply_filters( 'action_scheduler_post_status_args', $args ); + } + + /** + * Build the args array for the post type definition + * + * @return array + */ + protected function post_status_failed_labels() { + $labels = array( + 'label' => _x( 'Failed', 'post', 'woocommerce' ), + /* translators: %s: count */ + 'label_count' => _n_noop( 'Failed (%s)', 'Failed (%s)', 'woocommerce' ), + ); + + return apply_filters( 'action_scheduler_post_status_failed_labels', $labels ); + } + + /** + * Build the args array for the post type definition + * + * @return array + */ + protected function post_status_running_labels() { + $labels = array( + 'label' => _x( 'In-Progress', 'post', 'woocommerce' ), + /* translators: %s: count */ + 'label_count' => _n_noop( 'In-Progress (%s)', 'In-Progress (%s)', 'woocommerce' ), + ); + + return apply_filters( 'action_scheduler_post_status_running_labels', $labels ); + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpPostStore_PostTypeRegistrar.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpPostStore_PostTypeRegistrar.php new file mode 100644 index 00000000..c94925b2 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpPostStore_PostTypeRegistrar.php @@ -0,0 +1,51 @@ +post_type_args() ); + } + + /** + * Build the args array for the post type definition + * + * @return array + */ + protected function post_type_args() { + $args = array( + 'label' => __( 'Scheduled Actions', 'woocommerce' ), + 'description' => __( 'Scheduled actions are hooks triggered on a cetain date and time.', 'woocommerce' ), + 'public' => false, + 'map_meta_cap' => true, + 'hierarchical' => false, + 'supports' => array('title', 'editor','comments'), + 'rewrite' => false, + 'query_var' => false, + 'can_export' => true, + 'ep_mask' => EP_NONE, + 'labels' => array( + 'name' => __( 'Scheduled Actions', 'woocommerce' ), + 'singular_name' => __( 'Scheduled Action', 'woocommerce' ), + 'menu_name' => _x( 'Scheduled Actions', 'Admin menu name', 'woocommerce' ), + 'add_new' => __( 'Add', 'woocommerce' ), + 'add_new_item' => __( 'Add New Scheduled Action', 'woocommerce' ), + 'edit' => __( 'Edit', 'woocommerce' ), + 'edit_item' => __( 'Edit Scheduled Action', 'woocommerce' ), + 'new_item' => __( 'New Scheduled Action', 'woocommerce' ), + 'view' => __( 'View Action', 'woocommerce' ), + 'view_item' => __( 'View Action', 'woocommerce' ), + 'search_items' => __( 'Search Scheduled Actions', 'woocommerce' ), + 'not_found' => __( 'No actions found', 'woocommerce' ), + 'not_found_in_trash' => __( 'No actions found in trash', 'woocommerce' ), + ), + ); + + $args = apply_filters('action_scheduler_post_type_args', $args); + return $args; + } +} + \ No newline at end of file diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpPostStore_TaxonomyRegistrar.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpPostStore_TaxonomyRegistrar.php new file mode 100644 index 00000000..4b7f8517 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpPostStore_TaxonomyRegistrar.php @@ -0,0 +1,27 @@ +taxonomy_args() ); + } + + protected function taxonomy_args() { + $args = array( + 'label' => __( 'Action Group', 'woocommerce' ), + 'public' => false, + 'hierarchical' => false, + 'show_admin_column' => true, + 'query_var' => false, + 'rewrite' => false, + ); + + $args = apply_filters( 'action_scheduler_taxonomy_args', $args ); + return $args; + } +} + \ No newline at end of file diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/migration/ActionMigrator.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/migration/ActionMigrator.php new file mode 100644 index 00000000..3d1c7be5 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/migration/ActionMigrator.php @@ -0,0 +1,110 @@ +source = $source_store; + $this->destination = $destination_store; + $this->log_migrator = $log_migrator; + } + + /** + * Migrate an action. + * + * @param int $source_action_id Action ID. + * + * @return int 0|new action ID + */ + public function migrate( $source_action_id ) { + try { + $action = $this->source->fetch_action( $source_action_id ); + $status = $this->source->get_status( $source_action_id ); + } catch ( \Exception $e ) { + $action = null; + $status = ''; + } + + if ( is_null( $action ) || empty( $status ) || ! $action->get_schedule()->get_date() ) { + // null action or empty status means the fetch operation failed or the action didn't exist + // null schedule means it's missing vital data + // delete it and move on + try { + $this->source->delete_action( $source_action_id ); + } catch ( \Exception $e ) { + // nothing to do, it didn't exist in the first place + } + do_action( 'action_scheduler/no_action_to_migrate', $source_action_id, $this->source, $this->destination ); + + return 0; + } + + try { + + // Make sure the last attempt date is set correctly for completed and failed actions + $last_attempt_date = ( $status !== \ActionScheduler_Store::STATUS_PENDING ) ? $this->source->get_date( $source_action_id ) : null; + + $destination_action_id = $this->destination->save_action( $action, null, $last_attempt_date ); + } catch ( \Exception $e ) { + do_action( 'action_scheduler/migrate_action_failed', $source_action_id, $this->source, $this->destination ); + + return 0; // could not save the action in the new store + } + + try { + switch ( $status ) { + case \ActionScheduler_Store::STATUS_FAILED : + $this->destination->mark_failure( $destination_action_id ); + break; + case \ActionScheduler_Store::STATUS_CANCELED : + $this->destination->cancel_action( $destination_action_id ); + break; + } + + $this->log_migrator->migrate( $source_action_id, $destination_action_id ); + $this->source->delete_action( $source_action_id ); + + $test_action = $this->source->fetch_action( $source_action_id ); + if ( ! is_a( $test_action, 'ActionScheduler_NullAction' ) ) { + throw new \RuntimeException( sprintf( __( 'Unable to remove source migrated action %s', 'woocommerce' ), $source_action_id ) ); + } + do_action( 'action_scheduler/migrated_action', $source_action_id, $destination_action_id, $this->source, $this->destination ); + + return $destination_action_id; + } catch ( \Exception $e ) { + // could not delete from the old store + $this->source->mark_migrated( $source_action_id ); + do_action( 'action_scheduler/migrate_action_incomplete', $source_action_id, $destination_action_id, $this->source, $this->destination ); + do_action( 'action_scheduler/migrated_action', $source_action_id, $destination_action_id, $this->source, $this->destination ); + + return $destination_action_id; + } + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/migration/ActionScheduler_DBStoreMigrator.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/migration/ActionScheduler_DBStoreMigrator.php new file mode 100644 index 00000000..a0dee1bb --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/migration/ActionScheduler_DBStoreMigrator.php @@ -0,0 +1,48 @@ + $this->get_scheduled_date_string( $action, $last_attempt_date ), + 'last_attempt_local' => $this->get_scheduled_date_string_local( $action, $last_attempt_date ), + ]; + + $wpdb->update( $wpdb->actionscheduler_actions, $data, array( 'action_id' => $action_id ), array( '%s', '%s' ), array( '%d' ) ); + } + + return $action_id; + } catch ( \Exception $e ) { + throw new \RuntimeException( sprintf( __( 'Error saving action: %s', 'woocommerce' ), $e->getMessage() ), 0 ); + } + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/migration/BatchFetcher.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/migration/BatchFetcher.php new file mode 100644 index 00000000..7547bd49 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/migration/BatchFetcher.php @@ -0,0 +1,87 @@ +store = $source_store; + } + + /** + * Retrieve a list of actions. + * + * @param int $count The number of actions to retrieve + * + * @return int[] A list of action IDs + */ + public function fetch( $count = 10 ) { + foreach ( $this->get_query_strategies( $count ) as $query ) { + $action_ids = $this->store->query_actions( $query ); + if ( ! empty( $action_ids ) ) { + return $action_ids; + } + } + + return []; + } + + /** + * Generate a list of prioritized of action search parameters. + * + * @param int $count Number of actions to find. + * + * @return array + */ + private function get_query_strategies( $count ) { + $now = as_get_datetime_object(); + $args = [ + 'date' => $now, + 'per_page' => $count, + 'offset' => 0, + 'orderby' => 'date', + 'order' => 'ASC', + ]; + + $priorities = [ + Store::STATUS_PENDING, + Store::STATUS_FAILED, + Store::STATUS_CANCELED, + Store::STATUS_COMPLETE, + Store::STATUS_RUNNING, + '', // any other unanticipated status + ]; + + foreach ( $priorities as $status ) { + yield wp_parse_args( [ + 'status' => $status, + 'date_compare' => '<=', + ], $args ); + yield wp_parse_args( [ + 'status' => $status, + 'date_compare' => '>=', + ], $args ); + } + } +} \ No newline at end of file diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/migration/Config.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/migration/Config.php new file mode 100644 index 00000000..03717d40 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/migration/Config.php @@ -0,0 +1,169 @@ +source_store ) ) { + throw new \RuntimeException( __( 'Source store must be configured before running a migration', 'woocommerce' ) ); + } + + return $this->source_store; + } + + /** + * Set the configured source store. + * + * @param ActionScheduler_Store $store Source store object. + */ + public function set_source_store( Store $store ) { + $this->source_store = $store; + } + + /** + * Get the configured source loger. + * + * @return ActionScheduler_Logger + */ + public function get_source_logger() { + if ( empty( $this->source_logger ) ) { + throw new \RuntimeException( __( 'Source logger must be configured before running a migration', 'woocommerce' ) ); + } + + return $this->source_logger; + } + + /** + * Set the configured source logger. + * + * @param ActionScheduler_Logger $logger + */ + public function set_source_logger( Logger $logger ) { + $this->source_logger = $logger; + } + + /** + * Get the configured destination store. + * + * @return ActionScheduler_Store + */ + public function get_destination_store() { + if ( empty( $this->destination_store ) ) { + throw new \RuntimeException( __( 'Destination store must be configured before running a migration', 'woocommerce' ) ); + } + + return $this->destination_store; + } + + /** + * Set the configured destination store. + * + * @param ActionScheduler_Store $store + */ + public function set_destination_store( Store $store ) { + $this->destination_store = $store; + } + + /** + * Get the configured destination logger. + * + * @return ActionScheduler_Logger + */ + public function get_destination_logger() { + if ( empty( $this->destination_logger ) ) { + throw new \RuntimeException( __( 'Destination logger must be configured before running a migration', 'woocommerce' ) ); + } + + return $this->destination_logger; + } + + /** + * Set the configured destination logger. + * + * @param ActionScheduler_Logger $logger + */ + public function set_destination_logger( Logger $logger ) { + $this->destination_logger = $logger; + } + + /** + * Get flag indicating whether it's a dry run. + * + * @return bool + */ + public function get_dry_run() { + return $this->dry_run; + } + + /** + * Set flag indicating whether it's a dry run. + * + * @param bool $dry_run + */ + public function set_dry_run( $dry_run ) { + $this->dry_run = (bool) $dry_run; + } + + /** + * Get progress bar object. + * + * @return ActionScheduler\WPCLI\ProgressBar + */ + public function get_progress_bar() { + return $this->progress_bar; + } + + /** + * Set progress bar object. + * + * @param ActionScheduler\WPCLI\ProgressBar $progress_bar + */ + public function set_progress_bar( ProgressBar $progress_bar ) { + $this->progress_bar = $progress_bar; + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/migration/Controller.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/migration/Controller.php new file mode 100644 index 00000000..0009c4b1 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/migration/Controller.php @@ -0,0 +1,227 @@ +migration_scheduler = $migration_scheduler; + $this->store_classname = ''; + } + + /** + * Set the action store class name. + * + * @param string $class Classname of the store class. + * + * @return string + */ + public function get_store_class( $class ) { + if ( \ActionScheduler_DataController::is_migration_complete() ) { + return \ActionScheduler_DataController::DATASTORE_CLASS; + } elseif ( \ActionScheduler_Store::DEFAULT_CLASS !== $class ) { + $this->store_classname = $class; + return $class; + } else { + return 'ActionScheduler_HybridStore'; + } + } + + /** + * Set the action logger class name. + * + * @param string $class Classname of the logger class. + * + * @return string + */ + public function get_logger_class( $class ) { + \ActionScheduler_Store::instance(); + + if ( $this->has_custom_datastore() ) { + $this->logger_classname = $class; + return $class; + } else { + return \ActionScheduler_DataController::LOGGER_CLASS; + } + } + + /** + * Get flag indicating whether a custom datastore is in use. + * + * @return bool + */ + public function has_custom_datastore() { + return (bool) $this->store_classname; + } + + /** + * Set up the background migration process. + * + * @return void + */ + public function schedule_migration() { + $logging_tables = new ActionScheduler_LoggerSchema(); + $store_tables = new ActionScheduler_StoreSchema(); + + /* + * In some unusual cases, the expected tables may not have been created. In such cases + * we do not schedule a migration as doing so will lead to fatal error conditions. + * + * In such cases the user will likely visit the Tools > Scheduled Actions screen to + * investigate, and will see appropriate messaging (this step also triggers an attempt + * to rebuild any missing tables). + * + * @see https://github.com/woocommerce/action-scheduler/issues/653 + */ + if ( + ActionScheduler_DataController::is_migration_complete() + || $this->migration_scheduler->is_migration_scheduled() + || ! $store_tables->tables_exist() + || ! $logging_tables->tables_exist() + ) { + return; + } + + $this->migration_scheduler->schedule_migration(); + } + + /** + * Get the default migration config object + * + * @return ActionScheduler\Migration\Config + */ + public function get_migration_config_object() { + static $config = null; + + if ( ! $config ) { + $source_store = $this->store_classname ? new $this->store_classname() : new \ActionScheduler_wpPostStore(); + $source_logger = $this->logger_classname ? new $this->logger_classname() : new \ActionScheduler_wpCommentLogger(); + + $config = new Config(); + $config->set_source_store( $source_store ); + $config->set_source_logger( $source_logger ); + $config->set_destination_store( new \ActionScheduler_DBStoreMigrator() ); + $config->set_destination_logger( new \ActionScheduler_DBLogger() ); + + if ( defined( 'WP_CLI' ) && WP_CLI ) { + $config->set_progress_bar( new ProgressBar( '', 0 ) ); + } + } + + return apply_filters( 'action_scheduler/migration_config', $config ); + } + + /** + * Hook dashboard migration notice. + */ + public function hook_admin_notices() { + if ( ! $this->allow_migration() || \ActionScheduler_DataController::is_migration_complete() ) { + return; + } + add_action( 'admin_notices', array( $this, 'display_migration_notice' ), 10, 0 ); + } + + /** + * Show a dashboard notice that migration is in progress. + */ + public function display_migration_notice() { + printf( '

            %s

            ', esc_html__( 'Action Scheduler migration in progress. The list of scheduled actions may be incomplete.', 'woocommerce' ) ); + } + + /** + * Add store classes. Hook migration. + */ + private function hook() { + add_filter( 'action_scheduler_store_class', array( $this, 'get_store_class' ), 100, 1 ); + add_filter( 'action_scheduler_logger_class', array( $this, 'get_logger_class' ), 100, 1 ); + add_action( 'init', array( $this, 'maybe_hook_migration' ) ); + add_action( 'wp_loaded', array( $this, 'schedule_migration' ) ); + + // Action Scheduler may be displayed as a Tools screen or WooCommerce > Status administration screen + add_action( 'load-tools_page_action-scheduler', array( $this, 'hook_admin_notices' ), 10, 0 ); + add_action( 'load-woocommerce_page_wc-status', array( $this, 'hook_admin_notices' ), 10, 0 ); + } + + /** + * Possibly hook the migration scheduler action. + * + * @author Jeremy Pry + */ + public function maybe_hook_migration() { + if ( ! $this->allow_migration() || \ActionScheduler_DataController::is_migration_complete() ) { + return; + } + + $this->migration_scheduler->hook(); + } + + /** + * Allow datastores to enable migration to AS tables. + */ + public function allow_migration() { + if ( ! \ActionScheduler_DataController::dependencies_met() ) { + return false; + } + + if ( null === $this->migrate_custom_store ) { + $this->migrate_custom_store = apply_filters( 'action_scheduler_migrate_data_store', false ); + } + + return ( ! $this->has_custom_datastore() ) || $this->migrate_custom_store; + } + + /** + * Proceed with the migration if the dependencies have been met. + */ + public static function init() { + if ( \ActionScheduler_DataController::dependencies_met() ) { + self::instance()->hook(); + } + } + + /** + * Singleton factory. + */ + public static function instance() { + if ( ! isset( self::$instance ) ) { + self::$instance = new static( new Scheduler() ); + } + + return self::$instance; + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/migration/DryRun_ActionMigrator.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/migration/DryRun_ActionMigrator.php new file mode 100644 index 00000000..bee36caa --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/migration/DryRun_ActionMigrator.php @@ -0,0 +1,29 @@ +source = $source_logger; + $this->destination = $destination_Logger; + } + + /** + * Migrate an action log. + * + * @param int $source_action_id Source logger object. + * @param int $destination_action_id Destination logger object. + */ + public function migrate( $source_action_id, $destination_action_id ) { + $logs = $this->source->get_logs( $source_action_id ); + foreach ( $logs as $log ) { + if ( $log->get_action_id() == $source_action_id ) { + $this->destination->log( $destination_action_id, $log->get_message(), $log->get_date() ); + } + } + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/migration/Runner.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/migration/Runner.php new file mode 100644 index 00000000..d0bea0a0 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/migration/Runner.php @@ -0,0 +1,137 @@ +source_store = $config->get_source_store(); + $this->destination_store = $config->get_destination_store(); + $this->source_logger = $config->get_source_logger(); + $this->destination_logger = $config->get_destination_logger(); + + $this->batch_fetcher = new BatchFetcher( $this->source_store ); + if ( $config->get_dry_run() ) { + $this->log_migrator = new DryRun_LogMigrator( $this->source_logger, $this->destination_logger ); + $this->action_migrator = new DryRun_ActionMigrator( $this->source_store, $this->destination_store, $this->log_migrator ); + } else { + $this->log_migrator = new LogMigrator( $this->source_logger, $this->destination_logger ); + $this->action_migrator = new ActionMigrator( $this->source_store, $this->destination_store, $this->log_migrator ); + } + + if ( defined( 'WP_CLI' ) && WP_CLI ) { + $this->progress_bar = $config->get_progress_bar(); + } + } + + /** + * Run migration batch. + * + * @param int $batch_size Optional batch size. Default 10. + * + * @return int Size of batch processed. + */ + public function run( $batch_size = 10 ) { + $batch = $this->batch_fetcher->fetch( $batch_size ); + $batch_size = count( $batch ); + + if ( ! $batch_size ) { + return 0; + } + + if ( $this->progress_bar ) { + /* translators: %d: amount of actions */ + $this->progress_bar->set_message( sprintf( _n( 'Migrating %d action', 'Migrating %d actions', $batch_size, 'woocommerce' ), $batch_size ) ); + $this->progress_bar->set_count( $batch_size ); + } + + $this->migrate_actions( $batch ); + + return $batch_size; + } + + /** + * Migration a batch of actions. + * + * @param array $action_ids List of action IDs to migrate. + */ + public function migrate_actions( array $action_ids ) { + do_action( 'action_scheduler/migration_batch_starting', $action_ids ); + + \ActionScheduler::logger()->unhook_stored_action(); + $this->destination_logger->unhook_stored_action(); + + foreach ( $action_ids as $source_action_id ) { + $destination_action_id = $this->action_migrator->migrate( $source_action_id ); + if ( $destination_action_id ) { + $this->destination_logger->log( $destination_action_id, sprintf( + /* translators: 1: source action ID 2: source store class 3: destination action ID 4: destination store class */ + __( 'Migrated action with ID %1$d in %2$s to ID %3$d in %4$s', 'woocommerce' ), + $source_action_id, + get_class( $this->source_store ), + $destination_action_id, + get_class( $this->destination_store ) + ) ); + } + + if ( $this->progress_bar ) { + $this->progress_bar->tick(); + } + } + + if ( $this->progress_bar ) { + $this->progress_bar->finish(); + } + + \ActionScheduler::logger()->hook_stored_action(); + + do_action( 'action_scheduler/migration_batch_complete', $action_ids ); + } + + /** + * Initialize destination store and logger. + */ + public function init_destination() { + $this->destination_store->init(); + $this->destination_logger->init(); + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/migration/Scheduler.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/migration/Scheduler.php new file mode 100644 index 00000000..8050e8e9 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/migration/Scheduler.php @@ -0,0 +1,129 @@ +get_migration_runner(); + $count = $migration_runner->run( $this->get_batch_size() ); + + if ( $count === 0 ) { + $this->mark_complete(); + } else { + $this->schedule_migration( time() + $this->get_schedule_interval() ); + } + } + + /** + * Mark the migration complete. + */ + public function mark_complete() { + $this->unschedule_migration(); + + \ActionScheduler_DataController::mark_migration_complete(); + do_action( 'action_scheduler/migration_complete' ); + } + + /** + * Get a flag indicating whether the migration is scheduled. + * + * @return bool Whether there is a pending action in the store to handle the migration + */ + public function is_migration_scheduled() { + $next = as_next_scheduled_action( self::HOOK ); + + return ! empty( $next ); + } + + /** + * Schedule the migration. + * + * @param int $when Optional timestamp to run the next migration batch. Defaults to now. + * + * @return string The action ID + */ + public function schedule_migration( $when = 0 ) { + $next = as_next_scheduled_action( self::HOOK ); + + if ( ! empty( $next ) ) { + return $next; + } + + if ( empty( $when ) ) { + $when = time() + MINUTE_IN_SECONDS; + } + + return as_schedule_single_action( $when, self::HOOK, array(), self::GROUP ); + } + + /** + * Remove the scheduled migration action. + */ + public function unschedule_migration() { + as_unschedule_action( self::HOOK, null, self::GROUP ); + } + + /** + * Get migration batch schedule interval. + * + * @return int Seconds between migration runs. Defaults to 0 seconds to allow chaining migration via Async Runners. + */ + private function get_schedule_interval() { + return (int) apply_filters( 'action_scheduler/migration_interval', 0 ); + } + + /** + * Get migration batch size. + * + * @return int Number of actions to migrate in each batch. Defaults to 250. + */ + private function get_batch_size() { + return (int) apply_filters( 'action_scheduler/migration_batch_size', 250 ); + } + + /** + * Get migration runner object. + * + * @return Runner + */ + private function get_migration_runner() { + $config = Controller::instance()->get_migration_config_object(); + + return new Runner( $config ); + } + +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/schedules/ActionScheduler_CanceledSchedule.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/schedules/ActionScheduler_CanceledSchedule.php new file mode 100644 index 00000000..091513e6 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/schedules/ActionScheduler_CanceledSchedule.php @@ -0,0 +1,58 @@ +__wakeup() for details. + **/ + private $timestamp = NULL; + + /** + * @param DateTime $after + * + * @return DateTime|null + */ + public function calculate_next( DateTime $after ) { + return null; + } + + /** + * Cancelled actions should never have a next schedule, even if get_next() + * is called with $after < $this->scheduled_date. + * + * @param DateTime $after + * @return DateTime|null + */ + public function get_next( DateTime $after ) { + return null; + } + + /** + * @return bool + */ + public function is_recurring() { + return false; + } + + /** + * Unserialize recurring schedules serialized/stored prior to AS 3.0.0 + * + * Prior to Action Scheduler 3.0.0, schedules used different property names to refer + * to equivalent data. For example, ActionScheduler_IntervalSchedule::start_timestamp + * was the same as ActionScheduler_SimpleSchedule::timestamp. Action Scheduler 3.0.0 + * aligned properties and property names for better inheritance. To maintain backward + * compatibility with schedules serialized and stored prior to 3.0, we need to correctly + * map the old property names with matching visibility. + */ + public function __wakeup() { + if ( ! is_null( $this->timestamp ) ) { + $this->scheduled_timestamp = $this->timestamp; + unset( $this->timestamp ); + } + parent::__wakeup(); + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/schedules/ActionScheduler_CronSchedule.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/schedules/ActionScheduler_CronSchedule.php new file mode 100644 index 00000000..5851b0e7 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/schedules/ActionScheduler_CronSchedule.php @@ -0,0 +1,103 @@ +__wakeup() for details. + **/ + private $start_timestamp = NULL; + + /** + * Deprecated property @see $this->__wakeup() for details. + **/ + private $cron = NULL; + + /** + * Wrapper for parent constructor to accept a cron expression string and map it to a CronExpression for this + * objects $recurrence property. + * + * @param DateTime $start The date & time to run the action at or after. If $start aligns with the CronSchedule passed via $recurrence, it will be used. If it does not align, the first matching date after it will be used. + * @param CronExpression|string $recurrence The CronExpression used to calculate the schedule's next instance. + * @param DateTime|null $first (Optional) The date & time the first instance of this interval schedule ran. Default null, meaning this is the first instance. + */ + public function __construct( DateTime $start, $recurrence, DateTime $first = null ) { + if ( ! is_a( $recurrence, 'CronExpression' ) ) { + $recurrence = CronExpression::factory( $recurrence ); + } + + // For backward compatibility, we need to make sure the date is set to the first matching cron date, not whatever date is passed in. Importantly, by passing true as the 3rd param, if $start matches the cron expression, then it will be used. This was previously handled in the now deprecated next() method. + $date = $recurrence->getNextRunDate( $start, 0, true ); + + // parent::__construct() will set this to $date by default, but that may be different to $start now. + $first = empty( $first ) ? $start : $first; + + parent::__construct( $date, $recurrence, $first ); + } + + /** + * Calculate when an instance of this schedule would start based on a given + * date & time using its the CronExpression. + * + * @param DateTime $after + * @return DateTime + */ + protected function calculate_next( DateTime $after ) { + return $this->recurrence->getNextRunDate( $after, 0, false ); + } + + /** + * @return string + */ + public function get_recurrence() { + return strval( $this->recurrence ); + } + + /** + * Serialize cron schedules with data required prior to AS 3.0.0 + * + * Prior to Action Scheduler 3.0.0, reccuring schedules used different property names to + * refer to equivalent data. For example, ActionScheduler_IntervalSchedule::start_timestamp + * was the same as ActionScheduler_SimpleSchedule::timestamp. Action Scheduler 3.0.0 + * aligned properties and property names for better inheritance. To guard against the + * possibility of infinite loops if downgrading to Action Scheduler < 3.0.0, we need to + * also store the data with the old property names so if it's unserialized in AS < 3.0, + * the schedule doesn't end up with a null recurrence. + * + * @return array + */ + public function __sleep() { + + $sleep_params = parent::__sleep(); + + $this->start_timestamp = $this->scheduled_timestamp; + $this->cron = $this->recurrence; + + return array_merge( $sleep_params, array( + 'start_timestamp', + 'cron' + ) ); + } + + /** + * Unserialize cron schedules serialized/stored prior to AS 3.0.0 + * + * For more background, @see ActionScheduler_Abstract_RecurringSchedule::__wakeup(). + */ + public function __wakeup() { + if ( is_null( $this->scheduled_timestamp ) && ! is_null( $this->start_timestamp ) ) { + $this->scheduled_timestamp = $this->start_timestamp; + unset( $this->start_timestamp ); + } + + if ( is_null( $this->recurrence ) && ! is_null( $this->cron ) ) { + $this->recurrence = $this->cron; + unset( $this->cron ); + } + parent::__wakeup(); + } +} + diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/schedules/ActionScheduler_IntervalSchedule.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/schedules/ActionScheduler_IntervalSchedule.php new file mode 100644 index 00000000..4124f2a6 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/schedules/ActionScheduler_IntervalSchedule.php @@ -0,0 +1,82 @@ +__wakeup() for details. + **/ + private $start_timestamp = NULL; + + /** + * Deprecated property @see $this->__wakeup() for details. + **/ + private $interval_in_seconds = NULL; + + /** + * Calculate when this schedule should start after a given date & time using + * the number of seconds between recurrences. + * + * @param DateTime $after + * @return DateTime + */ + protected function calculate_next( DateTime $after ) { + $after->modify( '+' . (int) $this->get_recurrence() . ' seconds' ); + return $after; + } + + /** + * @return int + */ + public function interval_in_seconds() { + _deprecated_function( __METHOD__, '3.0.0', '(int)ActionScheduler_Abstract_RecurringSchedule::get_recurrence()' ); + return (int) $this->get_recurrence(); + } + + /** + * Serialize interval schedules with data required prior to AS 3.0.0 + * + * Prior to Action Scheduler 3.0.0, reccuring schedules used different property names to + * refer to equivalent data. For example, ActionScheduler_IntervalSchedule::start_timestamp + * was the same as ActionScheduler_SimpleSchedule::timestamp. Action Scheduler 3.0.0 + * aligned properties and property names for better inheritance. To guard against the + * possibility of infinite loops if downgrading to Action Scheduler < 3.0.0, we need to + * also store the data with the old property names so if it's unserialized in AS < 3.0, + * the schedule doesn't end up with a null/false/0 recurrence. + * + * @return array + */ + public function __sleep() { + + $sleep_params = parent::__sleep(); + + $this->start_timestamp = $this->scheduled_timestamp; + $this->interval_in_seconds = $this->recurrence; + + return array_merge( $sleep_params, array( + 'start_timestamp', + 'interval_in_seconds' + ) ); + } + + /** + * Unserialize interval schedules serialized/stored prior to AS 3.0.0 + * + * For more background, @see ActionScheduler_Abstract_RecurringSchedule::__wakeup(). + */ + public function __wakeup() { + if ( is_null( $this->scheduled_timestamp ) && ! is_null( $this->start_timestamp ) ) { + $this->scheduled_timestamp = $this->start_timestamp; + unset( $this->start_timestamp ); + } + + if ( is_null( $this->recurrence ) && ! is_null( $this->interval_in_seconds ) ) { + $this->recurrence = $this->interval_in_seconds; + unset( $this->interval_in_seconds ); + } + parent::__wakeup(); + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/schedules/ActionScheduler_NullSchedule.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/schedules/ActionScheduler_NullSchedule.php new file mode 100644 index 00000000..34f1b801 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/schedules/ActionScheduler_NullSchedule.php @@ -0,0 +1,32 @@ +scheduled_date = null; + } + + /** + * This schedule has no scheduled DateTime, so we need to override the parent __sleep() + * @return array + */ + public function __sleep() { + return array(); + } + + public function __wakeup() { + $this->scheduled_date = null; + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/schedules/ActionScheduler_Schedule.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/schedules/ActionScheduler_Schedule.php new file mode 100644 index 00000000..78a9899a --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/schedules/ActionScheduler_Schedule.php @@ -0,0 +1,19 @@ +__wakeup() for details. + **/ + private $timestamp = NULL; + + /** + * @param DateTime $after + * + * @return DateTime|null + */ + public function calculate_next( DateTime $after ) { + return null; + } + + /** + * @return bool + */ + public function is_recurring() { + return false; + } + + /** + * Serialize schedule with data required prior to AS 3.0.0 + * + * Prior to Action Scheduler 3.0.0, schedules used different property names to refer + * to equivalent data. For example, ActionScheduler_IntervalSchedule::start_timestamp + * was the same as ActionScheduler_SimpleSchedule::timestamp. Action Scheduler 3.0.0 + * aligned properties and property names for better inheritance. To guard against the + * scheduled date for single actions always being seen as "now" if downgrading to + * Action Scheduler < 3.0.0, we need to also store the data with the old property names + * so if it's unserialized in AS < 3.0, the schedule doesn't end up with a null recurrence. + * + * @return array + */ + public function __sleep() { + + $sleep_params = parent::__sleep(); + + $this->timestamp = $this->scheduled_timestamp; + + return array_merge( $sleep_params, array( + 'timestamp', + ) ); + } + + /** + * Unserialize recurring schedules serialized/stored prior to AS 3.0.0 + * + * Prior to Action Scheduler 3.0.0, schedules used different property names to refer + * to equivalent data. For example, ActionScheduler_IntervalSchedule::start_timestamp + * was the same as ActionScheduler_SimpleSchedule::timestamp. Action Scheduler 3.0.0 + * aligned properties and property names for better inheritance. To maintain backward + * compatibility with schedules serialized and stored prior to 3.0, we need to correctly + * map the old property names with matching visibility. + */ + public function __wakeup() { + + if ( is_null( $this->scheduled_timestamp ) && ! is_null( $this->timestamp ) ) { + $this->scheduled_timestamp = $this->timestamp; + unset( $this->timestamp ); + } + parent::__wakeup(); + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/schema/ActionScheduler_LoggerSchema.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/schema/ActionScheduler_LoggerSchema.php new file mode 100644 index 00000000..566a014c --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/schema/ActionScheduler_LoggerSchema.php @@ -0,0 +1,91 @@ +tables = [ + self::LOG_TABLE, + ]; + } + + /** + * Performs additional setup work required to support this schema. + */ + public function init() { + add_action( 'action_scheduler_before_schema_update', array( $this, 'update_schema_3_0' ), 10, 2 ); + } + + protected function get_table_definition( $table ) { + global $wpdb; + $table_name = $wpdb->$table; + $charset_collate = $wpdb->get_charset_collate(); + switch ( $table ) { + + case self::LOG_TABLE: + + $default_date = ActionScheduler_StoreSchema::DEFAULT_DATE; + return "CREATE TABLE $table_name ( + log_id bigint(20) unsigned NOT NULL auto_increment, + action_id bigint(20) unsigned NOT NULL, + message text NOT NULL, + log_date_gmt datetime NULL default '{$default_date}', + log_date_local datetime NULL default '{$default_date}', + PRIMARY KEY (log_id), + KEY action_id (action_id), + KEY log_date_gmt (log_date_gmt) + ) $charset_collate"; + + default: + return ''; + } + } + + /** + * Update the logs table schema, allowing datetime fields to be NULL. + * + * This is needed because the NOT NULL constraint causes a conflict with some versions of MySQL + * configured with sql_mode=NO_ZERO_DATE, which can for instance lead to tables not being created. + * + * Most other schema updates happen via ActionScheduler_Abstract_Schema::update_table(), however + * that method relies on dbDelta() and this change is not possible when using that function. + * + * @param string $table Name of table being updated. + * @param string $db_version The existing schema version of the table. + */ + public function update_schema_3_0( $table, $db_version ) { + global $wpdb; + + if ( 'actionscheduler_logs' !== $table || version_compare( $db_version, '3', '>=' ) ) { + return; + } + + // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared + $table_name = $wpdb->prefix . 'actionscheduler_logs'; + $table_list = $wpdb->get_col( "SHOW TABLES LIKE '{$table_name}'" ); + $default_date = ActionScheduler_StoreSchema::DEFAULT_DATE; + + if ( ! empty( $table_list ) ) { + $query = " + ALTER TABLE {$table_name} + MODIFY COLUMN log_date_gmt datetime NULL default '{$default_date}', + MODIFY COLUMN log_date_local datetime NULL default '{$default_date}' + "; + $wpdb->query( $query ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared + } + // phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/schema/ActionScheduler_StoreSchema.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/schema/ActionScheduler_StoreSchema.php new file mode 100644 index 00000000..033a3ba6 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/classes/schema/ActionScheduler_StoreSchema.php @@ -0,0 +1,132 @@ +tables = [ + self::ACTIONS_TABLE, + self::CLAIMS_TABLE, + self::GROUPS_TABLE, + ]; + } + + /** + * Performs additional setup work required to support this schema. + */ + public function init() { + add_action( 'action_scheduler_before_schema_update', array( $this, 'update_schema_5_0' ), 10, 2 ); + } + + protected function get_table_definition( $table ) { + global $wpdb; + $table_name = $wpdb->$table; + $charset_collate = $wpdb->get_charset_collate(); + $max_index_length = 191; // @see wp_get_db_schema() + $hook_status_scheduled_date_gmt_max_index_length = $max_index_length - 20 - 8; // - status, - scheduled_date_gmt + $default_date = self::DEFAULT_DATE; + switch ( $table ) { + + case self::ACTIONS_TABLE: + + return "CREATE TABLE {$table_name} ( + action_id bigint(20) unsigned NOT NULL auto_increment, + hook varchar(191) NOT NULL, + status varchar(20) NOT NULL, + scheduled_date_gmt datetime NULL default '{$default_date}', + scheduled_date_local datetime NULL default '{$default_date}', + priority tinyint unsigned NOT NULL default '10', + args varchar($max_index_length), + schedule longtext, + group_id bigint(20) unsigned NOT NULL default '0', + attempts int(11) NOT NULL default '0', + last_attempt_gmt datetime NULL default '{$default_date}', + last_attempt_local datetime NULL default '{$default_date}', + claim_id bigint(20) unsigned NOT NULL default '0', + extended_args varchar(8000) DEFAULT NULL, + PRIMARY KEY (action_id), + KEY hook_status_scheduled_date_gmt (hook($hook_status_scheduled_date_gmt_max_index_length), status, scheduled_date_gmt), + KEY status_scheduled_date_gmt (status, scheduled_date_gmt), + KEY scheduled_date_gmt (scheduled_date_gmt), + KEY args (args($max_index_length)), + KEY group_id (group_id), + KEY last_attempt_gmt (last_attempt_gmt), + KEY `claim_id_status_scheduled_date_gmt` (`claim_id`, `status`, `scheduled_date_gmt`) + ) $charset_collate"; + + case self::CLAIMS_TABLE: + + return "CREATE TABLE {$table_name} ( + claim_id bigint(20) unsigned NOT NULL auto_increment, + date_created_gmt datetime NULL default '{$default_date}', + PRIMARY KEY (claim_id), + KEY date_created_gmt (date_created_gmt) + ) $charset_collate"; + + case self::GROUPS_TABLE: + + return "CREATE TABLE {$table_name} ( + group_id bigint(20) unsigned NOT NULL auto_increment, + slug varchar(255) NOT NULL, + PRIMARY KEY (group_id), + KEY slug (slug($max_index_length)) + ) $charset_collate"; + + default: + return ''; + } + } + + /** + * Update the actions table schema, allowing datetime fields to be NULL. + * + * This is needed because the NOT NULL constraint causes a conflict with some versions of MySQL + * configured with sql_mode=NO_ZERO_DATE, which can for instance lead to tables not being created. + * + * Most other schema updates happen via ActionScheduler_Abstract_Schema::update_table(), however + * that method relies on dbDelta() and this change is not possible when using that function. + * + * @param string $table Name of table being updated. + * @param string $db_version The existing schema version of the table. + */ + public function update_schema_5_0( $table, $db_version ) { + global $wpdb; + + if ( 'actionscheduler_actions' !== $table || version_compare( $db_version, '5', '>=' ) ) { + return; + } + + // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared + $table_name = $wpdb->prefix . 'actionscheduler_actions'; + $table_list = $wpdb->get_col( "SHOW TABLES LIKE '{$table_name}'" ); + $default_date = self::DEFAULT_DATE; + + if ( ! empty( $table_list ) ) { + $query = " + ALTER TABLE {$table_name} + MODIFY COLUMN scheduled_date_gmt datetime NULL default '{$default_date}', + MODIFY COLUMN scheduled_date_local datetime NULL default '{$default_date}', + MODIFY COLUMN last_attempt_gmt datetime NULL default '{$default_date}', + MODIFY COLUMN last_attempt_local datetime NULL default '{$default_date}' + "; + $wpdb->query( $query ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared + } + // phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/deprecated/ActionScheduler_Abstract_QueueRunner_Deprecated.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/deprecated/ActionScheduler_Abstract_QueueRunner_Deprecated.php new file mode 100644 index 00000000..6f271688 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/deprecated/ActionScheduler_Abstract_QueueRunner_Deprecated.php @@ -0,0 +1,28 @@ +get_date(); + $replacement_method = 'get_date()'; + } else { + $return_value = $this->get_next( $after ); + $replacement_method = 'get_next( $after )'; + } + + _deprecated_function( __METHOD__, '3.0.0', __CLASS__ . '::' . $replacement_method ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + + return $return_value; + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/deprecated/ActionScheduler_Store_Deprecated.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/deprecated/ActionScheduler_Store_Deprecated.php new file mode 100644 index 00000000..eaf15b72 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/deprecated/ActionScheduler_Store_Deprecated.php @@ -0,0 +1,50 @@ +mark_failure( $action_id ); + } + + /** + * Add base hooks + * + * @since 2.2.6 + */ + protected static function hook() { + _deprecated_function( __METHOD__, '3.0.0' ); + } + + /** + * Remove base hooks + * + * @since 2.2.6 + */ + protected static function unhook() { + _deprecated_function( __METHOD__, '3.0.0' ); + } + + /** + * Get the site's local time. + * + * @deprecated 2.1.0 + * @return DateTimeZone + */ + protected function get_local_timezone() { + _deprecated_function( __FUNCTION__, '2.1.0', 'ActionScheduler_TimezoneHelper::set_local_timezone()' ); + return ActionScheduler_TimezoneHelper::get_local_timezone(); + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/deprecated/functions.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/deprecated/functions.php new file mode 100644 index 00000000..56953362 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/deprecated/functions.php @@ -0,0 +1,127 @@ + '' - the name of the action that will be triggered + * 'args' => NULL - the args array that will be passed with the action + * 'date' => NULL - the scheduled date of the action. Expects a DateTime object, a unix timestamp, or a string that can parsed with strtotime(). Used in UTC timezone. + * 'date_compare' => '<=' - operator for testing "date". accepted values are '!=', '>', '>=', '<', '<=', '=' + * 'modified' => NULL - the date the action was last updated. Expects a DateTime object, a unix timestamp, or a string that can parsed with strtotime(). Used in UTC timezone. + * 'modified_compare' => '<=' - operator for testing "modified". accepted values are '!=', '>', '>=', '<', '<=', '=' + * 'group' => '' - the group the action belongs to + * 'status' => '' - ActionScheduler_Store::STATUS_COMPLETE or ActionScheduler_Store::STATUS_PENDING + * 'claimed' => NULL - TRUE to find claimed actions, FALSE to find unclaimed actions, a string to find a specific claim ID + * 'per_page' => 5 - Number of results to return + * 'offset' => 0 + * 'orderby' => 'date' - accepted values are 'hook', 'group', 'modified', or 'date' + * 'order' => 'ASC' + * @param string $return_format OBJECT, ARRAY_A, or ids + * + * @deprecated 2.1.0 + * + * @return array + */ +function wc_get_scheduled_actions( $args = array(), $return_format = OBJECT ) { + _deprecated_function( __FUNCTION__, '2.1.0', 'as_get_scheduled_actions()' ); + return as_get_scheduled_actions( $args, $return_format ); +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/functions.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/functions.php new file mode 100644 index 00000000..1b02c489 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/functions.php @@ -0,0 +1,494 @@ +create( + array( + 'type' => 'async', + 'hook' => $hook, + 'arguments' => $args, + 'group' => $group, + 'unique' => $unique, + 'priority' => $priority, + ) + ); +} + +/** + * Schedule an action to run one time + * + * @param int $timestamp When the job will run. + * @param string $hook The hook to trigger. + * @param array $args Arguments to pass when the hook triggers. + * @param string $group The group to assign this job to. + * @param bool $unique Whether the action should be unique. + * @param int $priority Lower values take precedence over higher values. Defaults to 10, with acceptable values falling in the range 0-255. + * + * @return int The action ID. Zero if there was an error scheduling the action. + */ +function as_schedule_single_action( $timestamp, $hook, $args = array(), $group = '', $unique = false, $priority = 10 ) { + if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) { + return 0; + } + + /** + * Provides an opportunity to short-circuit the default process for enqueuing single + * actions. + * + * Returning a value other than null from the filter will short-circuit the normal + * process. The expectation in such a scenario is that callbacks will return an integer + * representing the scheduled action ID (scheduled using some alternative process) or else + * zero. + * + * @param int|null $pre_option The value to return instead of the option value. + * @param int $timestamp When the action will run. + * @param string $hook Action hook. + * @param array $args Action arguments. + * @param string $group Action group. + * @param int $priorities Action priority. + */ + $pre = apply_filters( 'pre_as_schedule_single_action', null, $timestamp, $hook, $args, $group, $priority ); + if ( null !== $pre ) { + return is_int( $pre ) ? $pre : 0; + } + + return ActionScheduler::factory()->create( + array( + 'type' => 'single', + 'hook' => $hook, + 'arguments' => $args, + 'when' => $timestamp, + 'group' => $group, + 'unique' => $unique, + 'priority' => $priority, + ) + ); +} + +/** + * Schedule a recurring action + * + * @param int $timestamp When the first instance of the job will run. + * @param int $interval_in_seconds How long to wait between runs. + * @param string $hook The hook to trigger. + * @param array $args Arguments to pass when the hook triggers. + * @param string $group The group to assign this job to. + * @param bool $unique Whether the action should be unique. + * @param int $priority Lower values take precedence over higher values. Defaults to 10, with acceptable values falling in the range 0-255. + * + * @return int The action ID. Zero if there was an error scheduling the action. + */ +function as_schedule_recurring_action( $timestamp, $interval_in_seconds, $hook, $args = array(), $group = '', $unique = false, $priority = 10 ) { + if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) { + return 0; + } + + $interval = (int) $interval_in_seconds; + + // We expect an integer and allow it to be passed using float and string types, but otherwise + // should reject unexpected values. + if ( ! is_numeric( $interval_in_seconds ) || $interval_in_seconds != $interval ) { + _doing_it_wrong( + __METHOD__, + sprintf( + /* translators: 1: provided value 2: provided type. */ + esc_html__( 'An integer was expected but "%1$s" (%2$s) was received.', 'woocommerce' ), + esc_html( $interval_in_seconds ), + esc_html( gettype( $interval_in_seconds ) ) + ), + '3.6.0' + ); + + return 0; + } + + /** + * Provides an opportunity to short-circuit the default process for enqueuing recurring + * actions. + * + * Returning a value other than null from the filter will short-circuit the normal + * process. The expectation in such a scenario is that callbacks will return an integer + * representing the scheduled action ID (scheduled using some alternative process) or else + * zero. + * + * @param int|null $pre_option The value to return instead of the option value. + * @param int $timestamp When the action will run. + * @param int $interval_in_seconds How long to wait between runs. + * @param string $hook Action hook. + * @param array $args Action arguments. + * @param string $group Action group. + * @param int $priority Action priority. + */ + $pre = apply_filters( 'pre_as_schedule_recurring_action', null, $timestamp, $interval_in_seconds, $hook, $args, $group, $priority ); + if ( null !== $pre ) { + return is_int( $pre ) ? $pre : 0; + } + + return ActionScheduler::factory()->create( + array( + 'type' => 'recurring', + 'hook' => $hook, + 'arguments' => $args, + 'when' => $timestamp, + 'pattern' => $interval_in_seconds, + 'group' => $group, + 'unique' => $unique, + 'priority' => $priority, + ) + ); +} + +/** + * Schedule an action that recurs on a cron-like schedule. + * + * @param int $timestamp The first instance of the action will be scheduled + * to run at a time calculated after this timestamp matching the cron + * expression. This can be used to delay the first instance of the action. + * @param string $schedule A cron-link schedule string. + * @see http://en.wikipedia.org/wiki/Cron + * * * * * * * + * ┬ ┬ ┬ ┬ ┬ ┬ + * | | | | | | + * | | | | | + year [optional] + * | | | | +----- day of week (0 - 7) (Sunday=0 or 7) + * | | | +---------- month (1 - 12) + * | | +--------------- day of month (1 - 31) + * | +-------------------- hour (0 - 23) + * +------------------------- min (0 - 59) + * @param string $hook The hook to trigger. + * @param array $args Arguments to pass when the hook triggers. + * @param string $group The group to assign this job to. + * @param bool $unique Whether the action should be unique. + * @param int $priority Lower values take precedence over higher values. Defaults to 10, with acceptable values falling in the range 0-255. + * + * @return int The action ID. Zero if there was an error scheduling the action. + */ +function as_schedule_cron_action( $timestamp, $schedule, $hook, $args = array(), $group = '', $unique = false, $priority = 10 ) { + if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) { + return 0; + } + + /** + * Provides an opportunity to short-circuit the default process for enqueuing cron + * actions. + * + * Returning a value other than null from the filter will short-circuit the normal + * process. The expectation in such a scenario is that callbacks will return an integer + * representing the scheduled action ID (scheduled using some alternative process) or else + * zero. + * + * @param int|null $pre_option The value to return instead of the option value. + * @param int $timestamp When the action will run. + * @param string $schedule Cron-like schedule string. + * @param string $hook Action hook. + * @param array $args Action arguments. + * @param string $group Action group. + * @param int $priority Action priority. + */ + $pre = apply_filters( 'pre_as_schedule_cron_action', null, $timestamp, $schedule, $hook, $args, $group, $priority ); + if ( null !== $pre ) { + return is_int( $pre ) ? $pre : 0; + } + + return ActionScheduler::factory()->create( + array( + 'type' => 'cron', + 'hook' => $hook, + 'arguments' => $args, + 'when' => $timestamp, + 'pattern' => $schedule, + 'group' => $group, + 'unique' => $unique, + 'priority' => $priority, + ) + ); +} + +/** + * Cancel the next occurrence of a scheduled action. + * + * While only the next instance of a recurring or cron action is unscheduled by this method, that will also prevent + * all future instances of that recurring or cron action from being run. Recurring and cron actions are scheduled in + * a sequence instead of all being scheduled at once. Each successive occurrence of a recurring action is scheduled + * only after the former action is run. If the next instance is never run, because it's unscheduled by this function, + * then the following instance will never be scheduled (or exist), which is effectively the same as being unscheduled + * by this method also. + * + * @param string $hook The hook that the job will trigger. + * @param array $args Args that would have been passed to the job. + * @param string $group The group the job is assigned to. + * + * @return int|null The scheduled action ID if a scheduled action was found, or null if no matching action found. + */ +function as_unschedule_action( $hook, $args = array(), $group = '' ) { + if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) { + return 0; + } + $params = array( + 'hook' => $hook, + 'status' => ActionScheduler_Store::STATUS_PENDING, + 'orderby' => 'date', + 'order' => 'ASC', + 'group' => $group, + ); + if ( is_array( $args ) ) { + $params['args'] = $args; + } + + $action_id = ActionScheduler::store()->query_action( $params ); + + if ( $action_id ) { + try { + ActionScheduler::store()->cancel_action( $action_id ); + } catch ( Exception $exception ) { + ActionScheduler::logger()->log( + $action_id, + sprintf( + /* translators: %1$s is the name of the hook to be cancelled, %2$s is the exception message. */ + __( 'Caught exception while cancelling action "%1$s": %2$s', 'woocommerce' ), + $hook, + $exception->getMessage() + ) + ); + + $action_id = null; + } + } + + return $action_id; +} + +/** + * Cancel all occurrences of a scheduled action. + * + * @param string $hook The hook that the job will trigger. + * @param array $args Args that would have been passed to the job. + * @param string $group The group the job is assigned to. + */ +function as_unschedule_all_actions( $hook, $args = array(), $group = '' ) { + if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) { + return; + } + if ( empty( $args ) ) { + if ( ! empty( $hook ) && empty( $group ) ) { + ActionScheduler_Store::instance()->cancel_actions_by_hook( $hook ); + return; + } + if ( ! empty( $group ) && empty( $hook ) ) { + ActionScheduler_Store::instance()->cancel_actions_by_group( $group ); + return; + } + } + do { + $unscheduled_action = as_unschedule_action( $hook, $args, $group ); + } while ( ! empty( $unscheduled_action ) ); +} + +/** + * Check if there is an existing action in the queue with a given hook, args and group combination. + * + * An action in the queue could be pending, in-progress or async. If the is pending for a time in + * future, its scheduled date will be returned as a timestamp. If it is currently being run, or an + * async action sitting in the queue waiting to be processed, in which case boolean true will be + * returned. Or there may be no async, in-progress or pending action for this hook, in which case, + * boolean false will be the return value. + * + * @param string $hook Name of the hook to search for. + * @param array $args Arguments of the action to be searched. + * @param string $group Group of the action to be searched. + * + * @return int|bool The timestamp for the next occurrence of a pending scheduled action, true for an async or in-progress action or false if there is no matching action. + */ +function as_next_scheduled_action( $hook, $args = null, $group = '' ) { + if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) { + return false; + } + + $params = array( + 'hook' => $hook, + 'orderby' => 'date', + 'order' => 'ASC', + 'group' => $group, + ); + + if ( is_array( $args ) ) { + $params['args'] = $args; + } + + $params['status'] = ActionScheduler_Store::STATUS_RUNNING; + $action_id = ActionScheduler::store()->query_action( $params ); + if ( $action_id ) { + return true; + } + + $params['status'] = ActionScheduler_Store::STATUS_PENDING; + $action_id = ActionScheduler::store()->query_action( $params ); + if ( null === $action_id ) { + return false; + } + + $action = ActionScheduler::store()->fetch_action( $action_id ); + $scheduled_date = $action->get_schedule()->get_date(); + if ( $scheduled_date ) { + return (int) $scheduled_date->format( 'U' ); + } elseif ( null === $scheduled_date ) { // pending async action with NullSchedule. + return true; + } + + return false; +} + +/** + * Check if there is a scheduled action in the queue but more efficiently than as_next_scheduled_action(). + * + * It's recommended to use this function when you need to know whether a specific action is currently scheduled + * (pending or in-progress). + * + * @since 3.3.0 + * + * @param string $hook The hook of the action. + * @param array $args Args that have been passed to the action. Null will matches any args. + * @param string $group The group the job is assigned to. + * + * @return bool True if a matching action is pending or in-progress, false otherwise. + */ +function as_has_scheduled_action( $hook, $args = null, $group = '' ) { + if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) { + return false; + } + + $query_args = array( + 'hook' => $hook, + 'status' => array( ActionScheduler_Store::STATUS_RUNNING, ActionScheduler_Store::STATUS_PENDING ), + 'group' => $group, + 'orderby' => 'none', + ); + + if ( null !== $args ) { + $query_args['args'] = $args; + } + + $action_id = ActionScheduler::store()->query_action( $query_args ); + + return null !== $action_id; +} + +/** + * Find scheduled actions + * + * @param array $args Possible arguments, with their default values. + * 'hook' => '' - the name of the action that will be triggered. + * 'args' => NULL - the args array that will be passed with the action. + * 'date' => NULL - the scheduled date of the action. Expects a DateTime object, a unix timestamp, or a string that can parsed with strtotime(). Used in UTC timezone. + * 'date_compare' => '<=' - operator for testing "date". accepted values are '!=', '>', '>=', '<', '<=', '='. + * 'modified' => NULL - the date the action was last updated. Expects a DateTime object, a unix timestamp, or a string that can parsed with strtotime(). Used in UTC timezone. + * 'modified_compare' => '<=' - operator for testing "modified". accepted values are '!=', '>', '>=', '<', '<=', '='. + * 'group' => '' - the group the action belongs to. + * 'status' => '' - ActionScheduler_Store::STATUS_COMPLETE or ActionScheduler_Store::STATUS_PENDING. + * 'claimed' => NULL - TRUE to find claimed actions, FALSE to find unclaimed actions, a string to find a specific claim ID. + * 'per_page' => 5 - Number of results to return. + * 'offset' => 0. + * 'orderby' => 'date' - accepted values are 'hook', 'group', 'modified', 'date' or 'none'. + * 'order' => 'ASC'. + * + * @param string $return_format OBJECT, ARRAY_A, or ids. + * + * @return array + */ +function as_get_scheduled_actions( $args = array(), $return_format = OBJECT ) { + if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) { + return array(); + } + $store = ActionScheduler::store(); + foreach ( array( 'date', 'modified' ) as $key ) { + if ( isset( $args[ $key ] ) ) { + $args[ $key ] = as_get_datetime_object( $args[ $key ] ); + } + } + $ids = $store->query_actions( $args ); + + if ( 'ids' === $return_format || 'int' === $return_format ) { + return $ids; + } + + $actions = array(); + foreach ( $ids as $action_id ) { + $actions[ $action_id ] = $store->fetch_action( $action_id ); + } + + if ( ARRAY_A == $return_format ) { + foreach ( $actions as $action_id => $action_object ) { + $actions[ $action_id ] = get_object_vars( $action_object ); + } + } + + return $actions; +} + +/** + * Helper function to create an instance of DateTime based on a given + * string and timezone. By default, will return the current date/time + * in the UTC timezone. + * + * Needed because new DateTime() called without an explicit timezone + * will create a date/time in PHP's timezone, but we need to have + * assurance that a date/time uses the right timezone (which we almost + * always want to be UTC), which means we need to always include the + * timezone when instantiating datetimes rather than leaving it up to + * the PHP default. + * + * @param mixed $date_string A date/time string. Valid formats are explained in http://php.net/manual/en/datetime.formats.php. + * @param string $timezone A timezone identifier, like UTC or Europe/Lisbon. The list of valid identifiers is available http://php.net/manual/en/timezones.php. + * + * @return ActionScheduler_DateTime + */ +function as_get_datetime_object( $date_string = null, $timezone = 'UTC' ) { + if ( is_object( $date_string ) && $date_string instanceof DateTime ) { + $date = new ActionScheduler_DateTime( $date_string->format( 'Y-m-d H:i:s' ), new DateTimeZone( $timezone ) ); + } elseif ( is_numeric( $date_string ) ) { + $date = new ActionScheduler_DateTime( '@' . $date_string, new DateTimeZone( $timezone ) ); + } else { + $date = new ActionScheduler_DateTime( null === $date_string ? 'now' : $date_string, new DateTimeZone( $timezone ) ); + } + return $date; +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/lib/WP_Async_Request.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/lib/WP_Async_Request.php new file mode 100644 index 00000000..f41641a4 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/lib/WP_Async_Request.php @@ -0,0 +1,192 @@ +identifier = $this->prefix . '_' . $this->action; + + add_action( 'wp_ajax_' . $this->identifier, array( $this, 'maybe_handle' ) ); + add_action( 'wp_ajax_nopriv_' . $this->identifier, array( $this, 'maybe_handle' ) ); + } + + /** + * Set data used during the request + * + * @param array $data Data. + * + * @return $this + */ + public function data( $data ) { + $this->data = $data; + + return $this; + } + + /** + * Dispatch the async request + * + * @return array|WP_Error + */ + public function dispatch() { + $url = add_query_arg( $this->get_query_args(), $this->get_query_url() ); + $args = $this->get_post_args(); + + return wp_remote_post( esc_url_raw( $url ), $args ); + } + + /** + * Get query args + * + * @return array + */ + protected function get_query_args() { + if ( property_exists( $this, 'query_args' ) ) { + return $this->query_args; + } + + $args = array( + 'action' => $this->identifier, + 'nonce' => wp_create_nonce( $this->identifier ), + ); + + /** + * Filters the post arguments used during an async request. + * + * @param array $url + */ + return apply_filters( $this->identifier . '_query_args', $args ); + } + + /** + * Get query URL + * + * @return string + */ + protected function get_query_url() { + if ( property_exists( $this, 'query_url' ) ) { + return $this->query_url; + } + + $url = admin_url( 'admin-ajax.php' ); + + /** + * Filters the post arguments used during an async request. + * + * @param string $url + */ + return apply_filters( $this->identifier . '_query_url', $url ); + } + + /** + * Get post args + * + * @return array + */ + protected function get_post_args() { + if ( property_exists( $this, 'post_args' ) ) { + return $this->post_args; + } + + $args = array( + 'timeout' => 0.01, + 'blocking' => false, + 'body' => $this->data, + 'cookies' => $_COOKIE, + 'sslverify' => apply_filters( 'https_local_ssl_verify', false ), + ); + + /** + * Filters the post arguments used during an async request. + * + * @param array $args + */ + return apply_filters( $this->identifier . '_post_args', $args ); + } + + /** + * Maybe handle + * + * Check for correct nonce and pass to handler. + */ + public function maybe_handle() { + // Don't lock up other requests while processing + session_write_close(); + + check_ajax_referer( $this->identifier, 'nonce' ); + + $this->handle(); + + wp_die(); + } + + /** + * Handle + * + * Override this method to perform any actions required + * during the async request. + */ + abstract protected function handle(); + + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/lib/cron-expression/CronExpression.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/lib/cron-expression/CronExpression.php new file mode 100644 index 00000000..eabb8df0 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/lib/cron-expression/CronExpression.php @@ -0,0 +1,319 @@ + + * @link http://en.wikipedia.org/wiki/Cron + */ +class CronExpression +{ + const MINUTE = 0; + const HOUR = 1; + const DAY = 2; + const MONTH = 3; + const WEEKDAY = 4; + const YEAR = 5; + + /** + * @var array CRON expression parts + */ + private $cronParts; + + /** + * @var CronExpression_FieldFactory CRON field factory + */ + private $fieldFactory; + + /** + * @var array Order in which to test of cron parts + */ + private static $order = array(self::YEAR, self::MONTH, self::DAY, self::WEEKDAY, self::HOUR, self::MINUTE); + + /** + * Factory method to create a new CronExpression. + * + * @param string $expression The CRON expression to create. There are + * several special predefined values which can be used to substitute the + * CRON expression: + * + * @yearly, @annually) - Run once a year, midnight, Jan. 1 - 0 0 1 1 * + * @monthly - Run once a month, midnight, first of month - 0 0 1 * * + * @weekly - Run once a week, midnight on Sun - 0 0 * * 0 + * @daily - Run once a day, midnight - 0 0 * * * + * @hourly - Run once an hour, first minute - 0 * * * * + * +*@param CronExpression_FieldFactory $fieldFactory (optional) Field factory to use + * + * @return CronExpression + */ + public static function factory($expression, CronExpression_FieldFactory $fieldFactory = null) + { + $mappings = array( + '@yearly' => '0 0 1 1 *', + '@annually' => '0 0 1 1 *', + '@monthly' => '0 0 1 * *', + '@weekly' => '0 0 * * 0', + '@daily' => '0 0 * * *', + '@hourly' => '0 * * * *' + ); + + if (isset($mappings[$expression])) { + $expression = $mappings[$expression]; + } + + return new self($expression, $fieldFactory ? $fieldFactory : new CronExpression_FieldFactory()); + } + + /** + * Parse a CRON expression + * + * @param string $expression CRON expression (e.g. '8 * * * *') + * @param CronExpression_FieldFactory $fieldFactory Factory to create cron fields + */ + public function __construct($expression, CronExpression_FieldFactory $fieldFactory) + { + $this->fieldFactory = $fieldFactory; + $this->setExpression($expression); + } + + /** + * Set or change the CRON expression + * + * @param string $value CRON expression (e.g. 8 * * * *) + * + * @return CronExpression + * @throws InvalidArgumentException if not a valid CRON expression + */ + public function setExpression($value) + { + $this->cronParts = preg_split('/\s/', $value, -1, PREG_SPLIT_NO_EMPTY); + if (count($this->cronParts) < 5) { + throw new InvalidArgumentException( + $value . ' is not a valid CRON expression' + ); + } + + foreach ($this->cronParts as $position => $part) { + $this->setPart($position, $part); + } + + return $this; + } + + /** + * Set part of the CRON expression + * + * @param int $position The position of the CRON expression to set + * @param string $value The value to set + * + * @return CronExpression + * @throws InvalidArgumentException if the value is not valid for the part + */ + public function setPart($position, $value) + { + if (!$this->fieldFactory->getField($position)->validate($value)) { + throw new InvalidArgumentException( + 'Invalid CRON field value ' . $value . ' as position ' . $position + ); + } + + $this->cronParts[$position] = $value; + + return $this; + } + + /** + * Get a next run date relative to the current date or a specific date + * + * @param string|DateTime $currentTime (optional) Relative calculation date + * @param int $nth (optional) Number of matches to skip before returning a + * matching next run date. 0, the default, will return the current + * date and time if the next run date falls on the current date and + * time. Setting this value to 1 will skip the first match and go to + * the second match. Setting this value to 2 will skip the first 2 + * matches and so on. + * @param bool $allowCurrentDate (optional) Set to TRUE to return the + * current date if it matches the cron expression + * + * @return DateTime + * @throws RuntimeException on too many iterations + */ + public function getNextRunDate($currentTime = 'now', $nth = 0, $allowCurrentDate = false) + { + return $this->getRunDate($currentTime, $nth, false, $allowCurrentDate); + } + + /** + * Get a previous run date relative to the current date or a specific date + * + * @param string|DateTime $currentTime (optional) Relative calculation date + * @param int $nth (optional) Number of matches to skip before returning + * @param bool $allowCurrentDate (optional) Set to TRUE to return the + * current date if it matches the cron expression + * + * @return DateTime + * @throws RuntimeException on too many iterations + * @see CronExpression::getNextRunDate + */ + public function getPreviousRunDate($currentTime = 'now', $nth = 0, $allowCurrentDate = false) + { + return $this->getRunDate($currentTime, $nth, true, $allowCurrentDate); + } + + /** + * Get multiple run dates starting at the current date or a specific date + * + * @param int $total Set the total number of dates to calculate + * @param string|DateTime $currentTime (optional) Relative calculation date + * @param bool $invert (optional) Set to TRUE to retrieve previous dates + * @param bool $allowCurrentDate (optional) Set to TRUE to return the + * current date if it matches the cron expression + * + * @return array Returns an array of run dates + */ + public function getMultipleRunDates($total, $currentTime = 'now', $invert = false, $allowCurrentDate = false) + { + $matches = array(); + for ($i = 0; $i < max(0, $total); $i++) { + $matches[] = $this->getRunDate($currentTime, $i, $invert, $allowCurrentDate); + } + + return $matches; + } + + /** + * Get all or part of the CRON expression + * + * @param string $part (optional) Specify the part to retrieve or NULL to + * get the full cron schedule string. + * + * @return string|null Returns the CRON expression, a part of the + * CRON expression, or NULL if the part was specified but not found + */ + public function getExpression($part = null) + { + if (null === $part) { + return implode(' ', $this->cronParts); + } elseif (array_key_exists($part, $this->cronParts)) { + return $this->cronParts[$part]; + } + + return null; + } + + /** + * Helper method to output the full expression. + * + * @return string Full CRON expression + */ + public function __toString() + { + return $this->getExpression(); + } + + /** + * Determine if the cron is due to run based on the current date or a + * specific date. This method assumes that the current number of + * seconds are irrelevant, and should be called once per minute. + * + * @param string|DateTime $currentTime (optional) Relative calculation date + * + * @return bool Returns TRUE if the cron is due to run or FALSE if not + */ + public function isDue($currentTime = 'now') + { + if ('now' === $currentTime) { + $currentDate = date('Y-m-d H:i'); + $currentTime = strtotime($currentDate); + } elseif ($currentTime instanceof DateTime) { + $currentDate = $currentTime->format('Y-m-d H:i'); + $currentTime = strtotime($currentDate); + } else { + $currentTime = new DateTime($currentTime); + $currentTime->setTime($currentTime->format('H'), $currentTime->format('i'), 0); + $currentDate = $currentTime->format('Y-m-d H:i'); + $currentTime = (int)($currentTime->getTimestamp()); + } + + return $this->getNextRunDate($currentDate, 0, true)->getTimestamp() == $currentTime; + } + + /** + * Get the next or previous run date of the expression relative to a date + * + * @param string|DateTime $currentTime (optional) Relative calculation date + * @param int $nth (optional) Number of matches to skip before returning + * @param bool $invert (optional) Set to TRUE to go backwards in time + * @param bool $allowCurrentDate (optional) Set to TRUE to return the + * current date if it matches the cron expression + * + * @return DateTime + * @throws RuntimeException on too many iterations + */ + protected function getRunDate($currentTime = null, $nth = 0, $invert = false, $allowCurrentDate = false) + { + if ($currentTime instanceof DateTime) { + $currentDate = $currentTime; + } else { + $currentDate = new DateTime($currentTime ? $currentTime : 'now'); + $currentDate->setTimezone(new DateTimeZone(date_default_timezone_get())); + } + + $currentDate->setTime($currentDate->format('H'), $currentDate->format('i'), 0); + $nextRun = clone $currentDate; + $nth = (int) $nth; + + // Set a hard limit to bail on an impossible date + for ($i = 0; $i < 1000; $i++) { + + foreach (self::$order as $position) { + $part = $this->getExpression($position); + if (null === $part) { + continue; + } + + $satisfied = false; + // Get the field object used to validate this part + $field = $this->fieldFactory->getField($position); + // Check if this is singular or a list + if (strpos($part, ',') === false) { + $satisfied = $field->isSatisfiedBy($nextRun, $part); + } else { + foreach (array_map('trim', explode(',', $part)) as $listPart) { + if ($field->isSatisfiedBy($nextRun, $listPart)) { + $satisfied = true; + break; + } + } + } + + // If the field is not satisfied, then start over + if (!$satisfied) { + $field->increment($nextRun, $invert); + continue 2; + } + } + + // Skip this match if needed + if ((!$allowCurrentDate && $nextRun == $currentDate) || --$nth > -1) { + $this->fieldFactory->getField(0)->increment($nextRun, $invert); + continue; + } + + return $nextRun; + } + + // @codeCoverageIgnoreStart + throw new RuntimeException('Impossible CRON expression'); + // @codeCoverageIgnoreEnd + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_AbstractField.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_AbstractField.php new file mode 100644 index 00000000..546c9d55 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_AbstractField.php @@ -0,0 +1,101 @@ + + */ +abstract class CronExpression_AbstractField implements CronExpression_FieldInterface +{ + /** + * Check to see if a field is satisfied by a value + * + * @param string $dateValue Date value to check + * @param string $value Value to test + * + * @return bool + */ + public function isSatisfied($dateValue, $value) + { + if ($this->isIncrementsOfRanges($value)) { + return $this->isInIncrementsOfRanges($dateValue, $value); + } elseif ($this->isRange($value)) { + return $this->isInRange($dateValue, $value); + } + + return $value == '*' || $dateValue == $value; + } + + /** + * Check if a value is a range + * + * @param string $value Value to test + * + * @return bool + */ + public function isRange($value) + { + return strpos($value, '-') !== false; + } + + /** + * Check if a value is an increments of ranges + * + * @param string $value Value to test + * + * @return bool + */ + public function isIncrementsOfRanges($value) + { + return strpos($value, '/') !== false; + } + + /** + * Test if a value is within a range + * + * @param string $dateValue Set date value + * @param string $value Value to test + * + * @return bool + */ + public function isInRange($dateValue, $value) + { + $parts = array_map('trim', explode('-', $value, 2)); + + return $dateValue >= $parts[0] && $dateValue <= $parts[1]; + } + + /** + * Test if a value is within an increments of ranges (offset[-to]/step size) + * + * @param string $dateValue Set date value + * @param string $value Value to test + * + * @return bool + */ + public function isInIncrementsOfRanges($dateValue, $value) + { + $parts = array_map('trim', explode('/', $value, 2)); + $stepSize = isset($parts[1]) ? $parts[1] : 0; + if ($parts[0] == '*' || $parts[0] === '0') { + return (int) $dateValue % $stepSize == 0; + } + + $range = explode('-', $parts[0], 2); + $offset = $range[0]; + $to = isset($range[1]) ? $range[1] : $dateValue; + // Ensure that the date value is within the range + if ($dateValue < $offset || $dateValue > $to) { + return false; + } + + for ($i = $offset; $i <= $to; $i+= $stepSize) { + if ($i == $dateValue) { + return true; + } + } + + return false; + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_DayOfMonthField.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_DayOfMonthField.php new file mode 100644 index 00000000..a7d0c4ba --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_DayOfMonthField.php @@ -0,0 +1,111 @@ + + */ +class CronExpression_DayOfMonthField extends CronExpression_AbstractField +{ + /** + * Get the nearest day of the week for a given day in a month + * + * @param int $currentYear Current year + * @param int $currentMonth Current month + * @param int $targetDay Target day of the month + * + * @return DateTime Returns the nearest date + */ + private static function getNearestWeekday($currentYear, $currentMonth, $targetDay) + { + $tday = str_pad($targetDay, 2, '0', STR_PAD_LEFT); + $target = new DateTime("$currentYear-$currentMonth-$tday"); + $currentWeekday = (int) $target->format('N'); + + if ($currentWeekday < 6) { + return $target; + } + + $lastDayOfMonth = $target->format('t'); + + foreach (array(-1, 1, -2, 2) as $i) { + $adjusted = $targetDay + $i; + if ($adjusted > 0 && $adjusted <= $lastDayOfMonth) { + $target->setDate($currentYear, $currentMonth, $adjusted); + if ($target->format('N') < 6 && $target->format('m') == $currentMonth) { + return $target; + } + } + } + } + + /** + * {@inheritdoc} + */ + public function isSatisfiedBy(DateTime $date, $value) + { + // ? states that the field value is to be skipped + if ($value == '?') { + return true; + } + + $fieldValue = $date->format('d'); + + // Check to see if this is the last day of the month + if ($value == 'L') { + return $fieldValue == $date->format('t'); + } + + // Check to see if this is the nearest weekday to a particular value + if (strpos($value, 'W')) { + // Parse the target day + $targetDay = substr($value, 0, strpos($value, 'W')); + // Find out if the current day is the nearest day of the week + return $date->format('j') == self::getNearestWeekday( + $date->format('Y'), + $date->format('m'), + $targetDay + )->format('j'); + } + + return $this->isSatisfied($date->format('d'), $value); + } + + /** + * {@inheritdoc} + */ + public function increment(DateTime $date, $invert = false) + { + if ($invert) { + $date->modify('previous day'); + $date->setTime(23, 59); + } else { + $date->modify('next day'); + $date->setTime(0, 0); + } + + return $this; + } + + /** + * {@inheritdoc} + */ + public function validate($value) + { + return (bool) preg_match('/[\*,\/\-\?LW0-9A-Za-z]+/', $value); + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_DayOfWeekField.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_DayOfWeekField.php new file mode 100644 index 00000000..164c532d --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_DayOfWeekField.php @@ -0,0 +1,125 @@ + + */ +class CronExpression_DayOfWeekField extends CronExpression_AbstractField +{ + /** + * {@inheritdoc} + */ + public function isSatisfiedBy(DateTime $date, $value) + { + if ($value == '?') { + return true; + } + + // Convert text day of the week values to integers + $value = str_ireplace( + array('SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT'), + range(0, 6), + $value + ); + + $currentYear = $date->format('Y'); + $currentMonth = $date->format('m'); + $lastDayOfMonth = $date->format('t'); + + // Find out if this is the last specific weekday of the month + if (strpos($value, 'L')) { + $weekday = str_replace('7', '0', substr($value, 0, strpos($value, 'L'))); + $tdate = clone $date; + $tdate->setDate($currentYear, $currentMonth, $lastDayOfMonth); + while ($tdate->format('w') != $weekday) { + $tdate->setDate($currentYear, $currentMonth, --$lastDayOfMonth); + } + + return $date->format('j') == $lastDayOfMonth; + } + + // Handle # hash tokens + if (strpos($value, '#')) { + list($weekday, $nth) = explode('#', $value); + // Validate the hash fields + if ($weekday < 1 || $weekday > 5) { + throw new InvalidArgumentException("Weekday must be a value between 1 and 5. {$weekday} given"); + } + if ($nth > 5) { + throw new InvalidArgumentException('There are never more than 5 of a given weekday in a month'); + } + // The current weekday must match the targeted weekday to proceed + if ($date->format('N') != $weekday) { + return false; + } + + $tdate = clone $date; + $tdate->setDate($currentYear, $currentMonth, 1); + $dayCount = 0; + $currentDay = 1; + while ($currentDay < $lastDayOfMonth + 1) { + if ($tdate->format('N') == $weekday) { + if (++$dayCount >= $nth) { + break; + } + } + $tdate->setDate($currentYear, $currentMonth, ++$currentDay); + } + + return $date->format('j') == $currentDay; + } + + // Handle day of the week values + if (strpos($value, '-')) { + $parts = explode('-', $value); + if ($parts[0] == '7') { + $parts[0] = '0'; + } elseif ($parts[1] == '0') { + $parts[1] = '7'; + } + $value = implode('-', $parts); + } + + // Test to see which Sunday to use -- 0 == 7 == Sunday + $format = in_array(7, str_split($value)) ? 'N' : 'w'; + $fieldValue = $date->format($format); + + return $this->isSatisfied($fieldValue, $value); + } + + /** + * {@inheritdoc} + */ + public function increment(DateTime $date, $invert = false) + { + if ($invert) { + $date->modify('-1 day'); + $date->setTime(23, 59, 0); + } else { + $date->modify('+1 day'); + $date->setTime(0, 0, 0); + } + + return $this; + } + + /** + * {@inheritdoc} + */ + public function validate($value) + { + return (bool) preg_match('/[\*,\/\-0-9A-Z]+/', $value); + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_FieldFactory.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_FieldFactory.php new file mode 100644 index 00000000..29a427b7 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_FieldFactory.php @@ -0,0 +1,56 @@ + + * @link http://en.wikipedia.org/wiki/Cron + */ +class CronExpression_FieldFactory +{ + /** + * @var array Cache of instantiated fields + */ + private $fields = array(); + + /** + * Get an instance of a field object for a cron expression position + * + * @param int $position CRON expression position value to retrieve + * + * @return CronExpression_FieldInterface + * @throws InvalidArgumentException if a position is not valid + */ + public function getField($position) + { + if (!isset($this->fields[$position])) { + switch ($position) { + case 0: + $this->fields[$position] = new CronExpression_MinutesField(); + break; + case 1: + $this->fields[$position] = new CronExpression_HoursField(); + break; + case 2: + $this->fields[$position] = new CronExpression_DayOfMonthField(); + break; + case 3: + $this->fields[$position] = new CronExpression_MonthField(); + break; + case 4: + $this->fields[$position] = new CronExpression_DayOfWeekField(); + break; + case 5: + $this->fields[$position] = new CronExpression_YearField(); + break; + default: + throw new InvalidArgumentException( + $position . ' is not a valid position' + ); + } + } + + return $this->fields[$position]; + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_FieldInterface.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_FieldInterface.php new file mode 100644 index 00000000..8105042c --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_FieldInterface.php @@ -0,0 +1,40 @@ + + */ +interface CronExpression_FieldInterface +{ + /** + * Check if the respective value of a DateTime field satisfies a CRON exp + * + * @param DateTime $date DateTime object to check + * @param string $value CRON expression to test against + * + * @return bool Returns TRUE if satisfied, FALSE otherwise + */ + public function isSatisfiedBy(DateTime $date, $value); + + /** + * When a CRON expression is not satisfied, this method is used to increment + * or decrement a DateTime object by the unit of the cron field + * + * @param DateTime $date DateTime object to change + * @param bool $invert (optional) Set to TRUE to decrement + * + * @return CronExpression_FieldInterface + */ + public function increment(DateTime $date, $invert = false); + + /** + * Validates a CRON expression for a given field + * + * @param string $value CRON expression value to validate + * + * @return bool Returns TRUE if valid, FALSE otherwise + */ + public function validate($value); +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_HoursField.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_HoursField.php new file mode 100644 index 00000000..731a6997 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_HoursField.php @@ -0,0 +1,48 @@ + + */ +class CronExpression_HoursField extends CronExpression_AbstractField +{ + /** + * {@inheritdoc} + */ + public function isSatisfiedBy(DateTime $date, $value) + { + return $this->isSatisfied($date->format('H'), $value); + } + + /** + * {@inheritdoc} + */ + public function increment(DateTime $date, $invert = false) + { + // Change timezone to UTC temporarily. This will + // allow us to go back or forwards and hour even + // if DST will be changed between the hours. + $timezone = $date->getTimezone(); + $date->setTimezone(new DateTimeZone('UTC')); + if ($invert) { + $date->modify('-1 hour'); + $date->setTime($date->format('H'), 59); + } else { + $date->modify('+1 hour'); + $date->setTime($date->format('H'), 0); + } + $date->setTimezone($timezone); + + return $this; + } + + /** + * {@inheritdoc} + */ + public function validate($value) + { + return (bool) preg_match('/[\*,\/\-0-9]+/', $value); + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_MinutesField.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_MinutesField.php new file mode 100644 index 00000000..5e6fd8b6 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_MinutesField.php @@ -0,0 +1,40 @@ + + */ +class CronExpression_MinutesField extends CronExpression_AbstractField +{ + /** + * {@inheritdoc} + */ + public function isSatisfiedBy(DateTime $date, $value) + { + return $this->isSatisfied($date->format('i'), $value); + } + + /** + * {@inheritdoc} + */ + public function increment(DateTime $date, $invert = false) + { + if ($invert) { + $date->modify('-1 minute'); + } else { + $date->modify('+1 minute'); + } + + return $this; + } + + /** + * {@inheritdoc} + */ + public function validate($value) + { + return (bool) preg_match('/[\*,\/\-0-9]+/', $value); + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_MonthField.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_MonthField.php new file mode 100644 index 00000000..e9a5e386 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_MonthField.php @@ -0,0 +1,56 @@ + + */ +class CronExpression_MonthField extends CronExpression_AbstractField +{ + /** + * {@inheritdoc} + */ + public function isSatisfiedBy(DateTime $date, $value) + { + // Convert text month values to integers + $value = str_ireplace( + array( + 'JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', + 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC' + ), + range(1, 12), + $value + ); + + return $this->isSatisfied($date->format('m'), $value); + } + + /** + * {@inheritdoc} + */ + public function increment(DateTime $date, $invert = false) + { + if ($invert) { + // $date->modify('last day of previous month'); // remove for php 5.2 compat + $date->modify('previous month'); + $date->modify($date->format('Y-m-t')); + $date->setTime(23, 59); + } else { + //$date->modify('first day of next month'); // remove for php 5.2 compat + $date->modify('next month'); + $date->modify($date->format('Y-m-01')); + $date->setTime(0, 0); + } + + return $this; + } + + /** + * {@inheritdoc} + */ + public function validate($value) + { + return (bool) preg_match('/[\*,\/\-0-9A-Z]+/', $value); + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_YearField.php b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_YearField.php new file mode 100644 index 00000000..1403f7f1 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_YearField.php @@ -0,0 +1,44 @@ + + */ +class CronExpression_YearField extends CronExpression_AbstractField +{ + /** + * {@inheritdoc} + */ + public function isSatisfiedBy(DateTime $date, $value) + { + return $this->isSatisfied($date->format('Y'), $value); + } + + /** + * {@inheritdoc} + */ + public function increment(DateTime $date, $invert = false) + { + if ($invert) { + $date->modify('-1 year'); + $date->setDate($date->format('Y'), 12, 31); + $date->setTime(23, 59, 0); + } else { + $date->modify('+1 year'); + $date->setDate($date->format('Y'), 1, 1); + $date->setTime(0, 0, 0); + } + + return $this; + } + + /** + * {@inheritdoc} + */ + public function validate($value) + { + return (bool) preg_match('/[\*,\/\-0-9]+/', $value); + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/lib/cron-expression/LICENSE b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/lib/cron-expression/LICENSE new file mode 100644 index 00000000..c6d88ac6 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/lib/cron-expression/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2011 Michael Dowling and contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/license.txt b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/license.txt new file mode 100644 index 00000000..f288702d --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/license.txt @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/readme.txt b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/readme.txt new file mode 100644 index 00000000..ba7d0143 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/includes/libraries/action-scheduler/readme.txt @@ -0,0 +1,177 @@ +=== Action Scheduler === +Contributors: Automattic, wpmuguru, claudiosanches, peterfabian1000, vedjain, jamosova, obliviousharmony, konamiman, sadowski, royho, barryhughes-1 +Tags: scheduler, cron +Stable tag: 3.7.0 +License: GPLv3 +Tested up to: 6.4 + +Action Scheduler - Job Queue for WordPress + +== Description == + +Action Scheduler is a scalable, traceable job queue for background processing large sets of actions in WordPress. It's specially designed to be distributed in WordPress plugins. + +Action Scheduler works by triggering an action hook to run at some time in the future. Each hook can be scheduled with unique data, to allow callbacks to perform operations on that data. The hook can also be scheduled to run on one or more occassions. + +Think of it like an extension to `do_action()` which adds the ability to delay and repeat a hook. + +## Battle-Tested Background Processing + +Every month, Action Scheduler processes millions of payments for [Subscriptions](https://woocommerce.com/products/woocommerce-subscriptions/), webhooks for [WooCommerce](https://wordpress.org/plugins/woocommerce/), as well as emails and other events for a range of other plugins. + +It's been seen on live sites processing queues in excess of 50,000 jobs and doing resource intensive operations, like processing payments and creating orders, at a sustained rate of over 10,000 / hour without negatively impacting normal site operations. + +This is all on infrastructure and WordPress sites outside the control of the plugin author. + +If your plugin needs background processing, especially of large sets of tasks, Action Scheduler can help. + +## Learn More + +To learn more about how to Action Scheduler works, and how to use it in your plugin, check out the docs on [ActionScheduler.org](https://actionscheduler.org). + +There you will find: + +* [Usage guide](https://actionscheduler.org/usage/): instructions on installing and using Action Scheduler +* [WP CLI guide](https://actionscheduler.org/wp-cli/): instructions on running Action Scheduler at scale via WP CLI +* [API Reference](https://actionscheduler.org/api/): complete reference guide for all API functions +* [Administration Guide](https://actionscheduler.org/admin/): guide to managing scheduled actions via the administration screen +* [Guide to Background Processing at Scale](https://actionscheduler.org/perf/): instructions for running Action Scheduler at scale via the default WP Cron queue runner + +## Credits + +Action Scheduler is developed and maintained by [Automattic](http://automattic.com/) with significant early development completed by [Flightless](https://flightless.us/). + +Collaboration is cool. We'd love to work with you to improve Action Scheduler. [Pull Requests](https://github.com/woocommerce/action-scheduler/pulls) welcome. + +== Changelog == + += 3.7.0 - 2023-11-20 = +* Add extended indexes for hook_status_scheduled_date_gmt and status_sheduled_date_gmt. +* Catch and log exceptions thrown when actions can't be created, e.g. under a corrupt database schema. +* Release/3.6.4. +* Tweak - WP 6.4 compatibility. +* Update unit tests for upcoming dependency version policy. +* make sure hook action_scheduler_failed_execution can access original exception object. +* mention dependency version policy in usage.md. + += 3.6.4 - 2023-10-11 = +* Performance improvements when bulk cancelling actions. +* Dev-related fixes. + += 3.6.3 - 2023-09-13 = +* Use `_doing_it_wrong` in initialization check. + += 3.6.2 - 2023-08-09 = +* Add guidance about passing arguments. +* Atomic option locking. +* Improve bulk delete handling. +* Include database error in the exception message. +* Tweak - WP 6.3 compatibility. + += 3.6.1 - 2023-06-14 = +* Document new optional `$priority` arg for various API functions. +* Document the new `--exclude-groups` WP CLI option. +* Document the new `action_scheduler_init` hook. +* Ensure actions within each claim are executed in the expected order. +* Fix incorrect text domain. +* Remove SHOW TABLES usage when checking if tables exist. + += 3.6.0 - 2023-05-10 = +* Add $unique parameter to function signatures. +* Add a cast-to-int for extra safety before forming new DateTime object. +* Add a hook allowing exceptions for consistently failing recurring actions. +* Add action priorities. +* Add init hook. +* Always raise the time limit. +* Bump minimatch from 3.0.4 to 3.0.8. +* Bump yaml from 2.2.1 to 2.2.2. +* Defensive coding relating to gaps in declared schedule types. +* Do not process an action if it cannot be set to `in-progress`. +* Filter view labels (status names) should be translatable | #919. +* Fix WPCLI progress messages. +* Improve data-store initialization flow. +* Improve error handling across all supported PHP versions. +* Improve logic for flushing the runtime cache. +* Support exclusion of multiple groups. +* Update lint-staged and Node/NPM requirements. +* add CLI clean command. +* add CLI exclude-group filter. +* exclude past-due from list table all filter count. +* throwing an exception if as_schedule_recurring_action interval param is not of type integer. + += 3.5.4 - 2023-01-17 = +* Add pre filters during action registration. +* Async scheduling. +* Calculate timeouts based on total actions. +* Correctly order the parameters for `ActionScheduler_ActionFactory`'s calls to `single_unique`. +* Fetch action in memory first before releasing claim to avoid deadlock. +* PHP 8.2: declare property to fix creation of dynamic property warning. +* PHP 8.2: fix "Using ${var} in strings is deprecated, use {$var} instead". +* Prevent `undefined variable` warning for `$num_pastdue_actions`. + += 3.5.3 - 2022-11-09 = +* Query actions with partial match. + += 3.5.2 - 2022-09-16 = +* Fix - erroneous 3.5.1 release. + += 3.5.1 - 2022-09-13 = +* Maintenance on A/S docs. +* fix: PHP 8.2 deprecated notice. + += 3.5.0 - 2022-08-25 = +* Add - The active view link within the "Tools > Scheduled Actions" screen is now clickable. +* Add - A warning when there are past-due actions. +* Enhancement - Added the ability to schedule unique actions via an atomic operation. +* Enhancement - Improvements to cache invalidation when processing batches (when running on WordPress 6.0+). +* Enhancement - If a recurring action is found to be consistently failing, it will stop being rescheduled. +* Enhancement - Adds a new "Past Due" view to the scheduled actions list table. + += 3.4.2 - 2022-06-08 = +* Fix - Change the include for better linting. +* Fix - update: Added Action scheduler completed action hook. + += 3.4.1 - 2022-05-24 = +* Fix - Change the include for better linting. +* Fix - Fix the documented return type. + += 3.4.0 - 2021-10-29 = +* Enhancement - Number of items per page can now be set for the Scheduled Actions view (props @ovidiul). #771 +* Fix - Do not lower the max_execution_time if it is already set to 0 (unlimited) (props @barryhughes). #755 +* Fix - Avoid triggering autoloaders during the version resolution process (props @olegabr). #731 & #776 +* Dev - ActionScheduler_wcSystemStatus PHPCS fixes (props @ovidiul). #761 +* Dev - ActionScheduler_DBLogger.php PHPCS fixes (props @ovidiul). #768 +* Dev - Fixed phpcs for ActionScheduler_Schedule_Deprecated (props @ovidiul). #762 +* Dev - Improve actions table indicies (props @glagonikas). #774 & #777 +* Dev - PHPCS fixes for ActionScheduler_DBStore.php (props @ovidiul). #769 & #778 +* Dev - PHPCS Fixes for ActionScheduler_Abstract_ListTable (props @ovidiul). #763 & #779 +* Dev - Adds new filter action_scheduler_claim_actions_order_by to allow tuning of the claim query (props @glagonikas). #773 +* Dev - PHPCS fixes for ActionScheduler_WpPostStore class (props @ovidiul). #780 + += 3.3.0 - 2021-09-15 = +* Enhancement - Adds as_has_scheduled_action() to provide a performant way to test for existing actions. #645 +* Fix - Improves compatibility with environments where NO_ZERO_DATE is enabled. #519 +* Fix - Adds safety checks to guard against errors when our database tables cannot be created. #645 +* Dev - Now supports queries that use multiple statuses. #649 +* Dev - Minimum requirements for WordPress and PHP bumped (to 5.2 and 5.6 respectively). #723 + += 3.2.1 - 2021-06-21 = +* Fix - Add extra safety/account for different versions of AS and different loading patterns. #714 +* Fix - Handle hidden columns (Tools → Scheduled Actions) | #600. + += 3.2.0 - 2021-06-03 = +* Fix - Add "no ordering" option to as_next_scheduled_action(). +* Fix - Add secondary scheduled date checks when claiming actions (DBStore) | #634. +* Fix - Add secondary scheduled date checks when claiming actions (wpPostStore) | #634. +* Fix - Adds a new index to the action table, reducing the potential for deadlocks (props: @glagonikas). +* Fix - Fix unit tests infrastructure and adapt tests to PHP 8. +* Fix - Identify in-use data store. +* Fix - Improve test_migration_is_scheduled. +* Fix - PHP notice on list table. +* Fix - Speed up clean up and batch selects. +* Fix - Update pending dependencies. +* Fix - [PHP 8.0] Only pass action arg values through to do_action_ref_array(). +* Fix - [PHP 8] Set the PHP version to 7.1 in composer.json for PHP 8 compatibility. +* Fix - add is_initialized() to docs. +* Fix - fix file permissions. +* Fix - fixes #664 by replacing __ with esc_html__. diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-de_DE-035dc61797ac8bfb6d6ed258fe72ad8c.json b/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-de_DE-035dc61797ac8bfb6d6ed258fe72ad8c.json new file mode 100644 index 00000000..a789f0b2 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-de_DE-035dc61797ac8bfb6d6ed258fe72ad8c.json @@ -0,0 +1 @@ +{"translation-revision-date":"2024-03-11 09:52+0000","generator":"WP-CLI\/2.10.0","source":"blocks\/src\/js\/send-coupon-form\/block.js","domain":"messages","locale_data":{"messages":{"":{"domain":"messages","lang":"de-DE","plural-forms":"nplurals=2; plural=(n != 1);"},"Frontend\u0004Send coupons to...":[""],"Frontend\u0004Your order contains coupons. What would you like to do?":[""],"Frontend\u0004Send to me":[""],"Frontend\u0004Gift to someone else":[""],"Frontend\u0004Send to one person":[""],"Frontend\u0004Send to different people":[""],"Frontend\u0004Deliver coupon":[""],"Frontend\u0004Receiver email address":[""],"Frontend\u0004Enter recipient e-mail address":[""],"Frontend\u0004Message for receiver":[""],"Frontend\u0004Write a message":[""]}}} \ No newline at end of file diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-de_DE-0fac2f3b919d34656822c41cb1ed8c2c.json b/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-de_DE-0fac2f3b919d34656822c41cb1ed8c2c.json new file mode 100644 index 00000000..97d93ab4 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-de_DE-0fac2f3b919d34656822c41cb1ed8c2c.json @@ -0,0 +1 @@ +{"translation-revision-date":"2024-03-11 09:52+0000","generator":"WP-CLI\/2.10.0","source":"blocks\/build\/woocommerce-smart-coupons-send-coupon-form-block-frontend.js","domain":"messages","locale_data":{"messages":{"":{"domain":"messages","lang":"de-DE","plural-forms":"nplurals=2; plural=(n != 1);"},"Frontend\u0004Send coupons to...":[""],"Frontend\u0004Your order contains coupons. What would you like to do?":[""],"Frontend\u0004Send to me":[""],"Frontend\u0004Gift to someone else":[""],"Frontend\u0004Send to one person":[""],"Frontend\u0004Send to different people":[""],"Frontend\u0004Deliver coupon":[""],"Frontend\u0004Receiver email address":[""],"Frontend\u0004Enter recipient e-mail address":[""],"Frontend\u0004Message for receiver":[""],"Frontend\u0004Write a message":[""]}}} \ No newline at end of file diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-de_DE-88ba117fdcd48887044ec0ca59856410.json b/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-de_DE-88ba117fdcd48887044ec0ca59856410.json new file mode 100644 index 00000000..06ea3737 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-de_DE-88ba117fdcd48887044ec0ca59856410.json @@ -0,0 +1 @@ +{"translation-revision-date":"2024-03-11 09:52+0000","generator":"WP-CLI\/2.10.0","source":"blocks\/build\/woocommerce-smart-coupons-available-coupons-block.js","domain":"messages","locale_data":{"messages":{"":{"domain":"messages","lang":"de-DE","plural-forms":"nplurals=2; plural=(n != 1);"},"Block editor\u0004Available Coupons (click on a coupon to use it)":[""]}}} \ No newline at end of file diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-de_DE-9b3491f4c368ce2ad4994aa24713559a.json b/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-de_DE-9b3491f4c368ce2ad4994aa24713559a.json new file mode 100644 index 00000000..174b317d --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-de_DE-9b3491f4c368ce2ad4994aa24713559a.json @@ -0,0 +1 @@ +{"translation-revision-date":"2024-03-11 09:52+0000","generator":"WP-CLI\/2.10.0","source":"blocks\/src\/js\/available-coupons\/edit.js","domain":"messages","locale_data":{"messages":{"":{"domain":"messages","lang":"de-DE","plural-forms":"nplurals=2; plural=(n != 1);"},"Block editor\u0004Available Coupons (click on a coupon to use it)":[""]}}} \ No newline at end of file diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-de_DE-b8d31255012dc50a25232a24e5b093ad.json b/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-de_DE-b8d31255012dc50a25232a24e5b093ad.json new file mode 100644 index 00000000..bdfcc231 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-de_DE-b8d31255012dc50a25232a24e5b093ad.json @@ -0,0 +1 @@ +{"translation-revision-date":"2024-03-11 09:52+0000","generator":"WP-CLI\/2.10.0","source":"blocks\/src\/js\/send-coupon-form\/edit.js","domain":"messages","locale_data":{"messages":{"":{"domain":"messages","lang":"de-DE","plural-forms":"nplurals=2; plural=(n != 1);"},"Block editor\u0004Send coupons to...":[""],"Block editor\u0004Your order contains coupons. What would you like to do?":[""],"Block editor\u0004Send to me":[""],"Block editor\u0004Gift to someone else":[""],"Block editor\u0004Send to one person":[""],"Block editor\u0004Send to different people":[""],"Block editor\u0004Deliver coupon":[""],"Block editor\u0004now":[""],"Block editor\u0004later":[""],"Block editor\u0004Receiver email address":[""],"Block editor\u0004Enter recipient e-mail address":[""],"Block editor\u0004Message for receiver":[""],"Block editor\u0004Write a message":[""]}}} \ No newline at end of file diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-de_DE-d811137fe50d78464704a484441a64be.json b/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-de_DE-d811137fe50d78464704a484441a64be.json new file mode 100644 index 00000000..852fe6ed --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-de_DE-d811137fe50d78464704a484441a64be.json @@ -0,0 +1 @@ +{"translation-revision-date":"2024-03-11 09:52+0000","generator":"WP-CLI\/2.10.0","source":"includes\/blocks\/sc-gutenberg-block.js","domain":"messages","locale_data":{"messages":{"":{"domain":"messages","lang":"de-DE","plural-forms":"nplurals=2; plural=(n != 1);"},"Smart Coupons":[""]}}} \ No newline at end of file diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-de_DE-fd0f2ef4bb9ad5ddc0e7e6898a11a573.json b/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-de_DE-fd0f2ef4bb9ad5ddc0e7e6898a11a573.json new file mode 100644 index 00000000..65a4c186 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-de_DE-fd0f2ef4bb9ad5ddc0e7e6898a11a573.json @@ -0,0 +1 @@ +{"translation-revision-date":"2024-03-11 09:52+0000","generator":"WP-CLI\/2.10.0","source":"blocks\/build\/woocommerce-smart-coupons-send-coupon-form-block.js","domain":"messages","locale_data":{"messages":{"":{"domain":"messages","lang":"de-DE","plural-forms":"nplurals=2; plural=(n != 1);"},"Block editor\u0004Send coupons to...":[""],"Block editor\u0004Your order contains coupons. What would you like to do?":[""],"Block editor\u0004Send to me":[""],"Block editor\u0004Gift to someone else":[""],"Block editor\u0004Send to one person":[""],"Block editor\u0004Send to different people":[""],"Block editor\u0004Deliver coupon":[""],"Block editor\u0004now":[""],"Block editor\u0004later":[""],"Block editor\u0004Receiver email address":[""],"Block editor\u0004Enter recipient e-mail address":[""],"Block editor\u0004Message for receiver":[""],"Block editor\u0004Write a message":[""]}}} \ No newline at end of file diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-de_DE.mo b/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-de_DE.mo new file mode 100644 index 0000000000000000000000000000000000000000..4bbab8f7b2b6f216ef0af8b98a83c86caf7f595c GIT binary patch literal 5003 zcma);ON<;x8Gs8&cx-?`3?YyRYLPeICEGLmupPTsKJ3dI#}6#;+QtzO^~}`Hv}dM! z($&3_-QbfE5&|JE5y4UmUz!2995LXlU2 za*hi>37^QvPeD1a1?9Xx4B0oho6VL@Hl)2UW1Qt=vUzlxDEdUPrzpoF7~_zKMQ{a#jk&Y;)lQG z<9Fc!#s_f1=inhIdM!bjUx%Vk6N;a=p@j66oUcOB^ED`P-hiKiZ$Uol?|gj${uiEt z509ZE0W?tZ;A=Qj{Nh2Tln*tGq2$l=kdOLV&R;|E$M2xz!J815tGD1hd%=qFm5rpVCu%-LV;q@im~;`@5O!?xT-kLRjbeTFwG*|RU;OuH4~V~i%lcf z$*Q$bZ-j^u;Z~jM_Cho(hG&emx?y6Bv+9g*@!n>!6EDXt<447F-EaBzmiSh;ye*@n zTv@#tgkRZ(iWe0_>YOQ#ieQmW{b9-5k%&@!hdC+2T` zvS&H&$j@TEXtzgW4t@?-o2O$x?wD&Xz73ibxTNDrQMBV4Zyp-1MunTxs`Q+tTA1kR z!0Vc8QcSLzdhDEPIG0RhrKsxLMo%BB%+6P4#x5ACn9f<-^c&7n(zMP-=<3pK{eC4) z1FzS!l`v{nZPJqs)p{7j9>Nk^9XrFdb2dmZi`rr2YG#6FLh*ApjMsJbnu)qzFn0FT z+0}t+vq;C>7?(I3+dbpz*gP9odmYaY7Bnxl$eQ@X#f_8BvB5eKvS}h`HQ-i~xUN1{ z^W(AeU*2#icd65y6bMBGD?%d2{Ge_L{85TPi%oZsg1|w^a zIx~;!na9(GGcz-#5iZ5sSy>%B-$^2`j~9C@qBalX0zt;;wg17dh)bXNHeXIu0|;i+evhg#5*RK zQkPjAw8N;DtE$S4QgR2Q!LOl7SwhnwhYkrGUb;kg(Ta>;OUM(IdBas}yEi+r-_$kV zx@sTmvmV1Y5pR-GAETa1QYQ{(f+11bPx}rwnLu4Of#1ZND?@#Uk=n)FV7pFuUvYQw zNWO5I9?$5NM4PDPbtF*qb#X;!9!$fSd9XYr^=i5)6D7X2re%VPI_F_J{Y*^zVOj%a zPIH7_taXTggEG_2I*@j3)M~f4x%)D2iL3`fycej&T2^5sypkH!N-UH^hMl9g%HY#` zw8EZ)idpK=d`J`sb35HzK9Lh^k(Z#Nu>-%{^>YH5%OD9n=}cmAr-&oV+i7cpN0~vn zEOT|=kLXk`cGF1aw*ymllFshy*g37+X|krS4sakZ^rqzeWH2?*Q1UMAThepVlr94z zDPEkWn|>`7R6doRybwtiJ;?n2?#tw8nhTs|i_6I`i4;2`-41(_S!sIEteb!vi$~>7 zrwtD48WNE}FXc_mZB)z5lq_lQz8a0#XmZp&rY2qS(BnJ%Cp~PBe+IXi+LQJNM)MYIBqVf}iFA;b9FuE#+dhUXCpS&} zOCM8)3ww);s796q62zKmOFt3peN=8Qcb6;D7?q=P;Xn>u&MjtSQ~TEMbTNlgZAziS#S4~fT}XCi@0RzU%E6kW28A6MC1RUXuQV& literal 0 HcmV?d00001 diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-de_DE.po b/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-de_DE.po new file mode 100644 index 00000000..4971ff13 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-de_DE.po @@ -0,0 +1,4549 @@ +msgid "" +msgstr "" +"Project-Id-Version: WooCommerce Smart Coupons 8.13.0\n" +"Report-Msgid-Bugs-To: https://www.storeapps.org/support/contact-us/\n" +"Last-Translator: \n" +"Language-Team: German\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"POT-Creation-Date: 2024-01-12T12:54:20+05:30\n" +"PO-Revision-Date: 2024-06-07 07:20+0000\n" +"Language: de-DE\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"X-Generator: Loco https://localise.biz/\n" +"X-Domain: woocommerce-smart-coupons\n" +"X-Loco-Version: 2.6.6; wp-6.4.3\n" + +#. translators: Add more detail to coupon description +#: includes/class-wc-sc-display-coupons.php:649 +msgid " &" +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:278 +#: includes/class-wc-sc-display-coupons.php:869 +#: includes/class-wc-sc-display-coupons.php:2410 +#: includes/class-wc-sc-shortcode.php:540 +#: includes/class-wc-smart-coupons.php:4893 +#: templates/combined-email.php:125 +#: templates/email.php:123 +#: templates/print-coupons-default.php:142 +msgid " & " +msgstr " & " + +#: templates/plain/combined-email.php:88 +#: templates/plain/email.php:83 +msgid " & " +msgstr " & " + +#. translators: 1. Discount type 2. Discount Type Label +#: includes/class-wc-sc-product-fields.php:114 +#: includes/class-wc-sc-product-fields.php:175 +msgid " ( %1$s: %2$s )" +msgstr "" + +#. translators: 1: email heading 2: suffix +#: includes/emails/class-wc-sc-email-coupon.php:460 +msgid " coupon" +msgstr " Gutschein" + +#: includes/class-wc-sc-display-coupons.php:634 +msgid " discount" +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:610 +#: includes/class-wc-sc-display-coupons.php:619 +msgid " discount on " +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:601 +msgid " discount on your entire purchase" +msgstr " Rabatt auf den gesamten Einkauf" + +#: includes/class-wc-sc-display-coupons.php:634 +msgid " on " +msgstr "" + +#. translators: %s: Maximum coupon discount amount +#: includes/class-wc-sc-display-coupons.php:632 +#: includes/class-wc-smart-coupons.php:1168 +#: includes/emails/class-wc-sc-email-coupon.php:439 +msgid " upto %s" +msgstr "" + +#: includes/class-wc-sc-admin-notifications.php:243 +msgid "! If things aren't going quite as expected, we're happy to help -- please reach out to" +msgstr "" + +#: includes/class-wc-sc-settings.php:647 +msgid "\"Coupons with Product\" description" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:414 +msgid "\"Store Credit Receiver detail\" form not appearing on checkout page?" +msgstr "" + +#: includes/class-wc-smart-coupons.php:6022 +msgid "$coupon is not an object of WC_Coupon" +msgstr "" + +#: includes/class-wc-smart-coupons.php:6024 +msgid "$coupon is: " +msgstr "" + +#: includes/class-wc-smart-coupons.php:6642 +#: includes/class-wc-smart-coupons.php:6690 +msgid "$item is not an object of WC_Order_Item" +msgstr "" + +#: includes/class-wc-smart-coupons.php:6644 +#: includes/class-wc-smart-coupons.php:6692 +msgid "$item is: " +msgstr "" + +#: includes/class-wc-smart-coupons.php:6768 +msgid "$item_id is required" +msgstr "" + +#: includes/class-wc-smart-coupons.php:6509 +#: includes/class-wc-smart-coupons.php:6563 +#: includes/class-wc-smart-coupons.php:6592 +#: includes/class-wc-smart-coupons.php:6616 +#: includes/class-wc-smart-coupons.php:6770 +msgid "$item_id is: " +msgstr "" + +#: includes/class-wc-smart-coupons.php:6510 +#: includes/class-wc-smart-coupons.php:6564 +#: includes/class-wc-smart-coupons.php:6593 +#: includes/class-wc-smart-coupons.php:6617 +msgid "$item_key is: " +msgstr "" + +#: includes/class-wc-smart-coupons.php:6395 +#: includes/class-wc-smart-coupons.php:6450 +msgid "$key is required" +msgstr "" + +#: includes/class-wc-smart-coupons.php:6397 +#: includes/class-wc-smart-coupons.php:6452 +msgid "$key is: " +msgstr "" + +#: includes/class-wc-smart-coupons.php:6125 +#: includes/class-wc-smart-coupons.php:6240 +#: includes/class-wc-smart-coupons.php:6354 +msgid "$meta_key is: " +msgstr "" + +#: includes/class-wc-smart-coupons.php:6124 +#: includes/class-wc-smart-coupons.php:6239 +#: includes/class-wc-smart-coupons.php:6353 +msgid "$post_id is: " +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:1006 +msgid "%" +msgstr "" + +#. translators: 1. Product/s 2. Product names 3. is/are 4. Coupons code +#: includes/class-wc-sc-coupon-actions.php:504 +msgid "%1$s %2$s %3$s removed because coupon %4$s is removed." +msgstr "" + +#. translators: 1. The coupon code, 2. The discount type +#: includes/class-wc-sc-ajax.php:252 +#: includes/class-wc-sc-settings.php:332 +msgid "%1$s (Type: %2$s)" +msgstr "" + +#. translators: 1. Discount type 2. Discount amount +#. translators: 1: coupon type 2: coupon amount +#: includes/class-wc-sc-display-coupons.php:641 +#: includes/emails/class-wc-sc-email-coupon.php:452 +msgid "%1$s coupon of %2$s" +msgstr "" + +#. translators: 1: email heading 2: suffix +#: includes/emails/class-wc-sc-email-coupon.php:460 +msgid "%1$s Free Shipping%2$s" +msgstr "%1$s Kostenloser Versand%2$s" + +#. translators: 1. amount of store credit 2. store credit label 3. coupon code +#: includes/class-wc-sc-coupon-process.php:776 +msgid "%1$s worth of %2$s restored to coupon %3$s." +msgstr "" + +#. translators: 1. amount of store credit 2. coupon code +#: includes/class-wc-sc-coupon-process.php:779 +msgid "%1$s worth of Store Credit restored to coupon %2$s." +msgstr "" + +#. translators: 1: HTML small tag start 2: HTML small tag end +#: includes/class-wc-sc-admin-pages.php:1268 +msgid "%1$s(This will add the same coupon description in all the bulk generated coupons)%2$s" +msgstr "" + +#. translators: 1: plugin name 2: page based text 3: Label for store credit 4: Hide notice text +#: includes/class-wc-sc-settings.php:903 +#: includes/class-wc-sc-settings.php:906 +msgid "%1$s: %2$s to avoid issues related to missing data for %3$s. %4$s" +msgstr "" + +#. translators: 1. Error title 2. The bulk process +#: includes/class-wc-sc-background-coupon-importer.php:385 +msgid "%1$s: The coupon bulk %2$s process stopped. Please review the coupons list to check the status." +msgstr "" + +#. translators: 1. Important 2. Upload path +#: includes/class-wc-sc-background-coupon-importer.php:333 +msgid "%1$s: To allow bulk generation of coupons, please make sure %2$s directory is writable." +msgstr "" + +#. translators: 1: WooCommerce Smart Coupons 2: Link for the Smart Coupons settings +#: includes/class-wc-sc-admin-notifications.php:256 +msgid "%1$s: You are using a custom coupon style which is planned to be removed from the plugin in upcoming versions. New, improved styles & colors are added in the version 4.9.0. We would request you to choose a color scheme & a style for coupon from the newly added colors & styles. You can do this from %2$s." +msgstr "" + +#. translators: 1$-2$: opening and closing tags, 3$-4$: link tags, takes to woocommerce plugin on wp.org, 5$-6$: opening and closing link tags, leads to plugins.php in admin. +#: woocommerce-smart-coupons.php:61 +msgid "%1$sWooCommerce Smart Coupons is inactive.%2$s The %3$sWooCommerce plugin%4$s must be active for the Smart Coupons to work. Please %5$sinstall & activate WooCommerce »%6$s" +msgstr "" + +#. translators: Plugin's name +#: includes/class-wc-sc-privacy.php:53 +msgid "%s - Coupon Personal Data Eraser" +msgstr "" + +#. translators: Plugin's name +#: includes/class-wc-sc-privacy.php:51 +msgid "%s - Coupon Personal Data Exporter" +msgstr "" + +#. translators: Plugin's name +#: includes/class-wc-sc-privacy.php:58 +msgid "%s - Order Personal Data Eraser" +msgstr "" + +#. translators: Plugin's name +#: includes/class-wc-sc-privacy.php:56 +msgid "%s - Order Personal Data Exporter" +msgstr "" + +#. translators: Plugin's name +#: includes/class-wc-sc-privacy.php:63 +msgid "%s - User Personal Data Eraser" +msgstr "" + +#. translators: Plugin's name +#: includes/class-wc-sc-privacy.php:61 +msgid "%s - User Personal Data Exporter" +msgstr "" + +#. translators: 1. Coupon type +#: includes/class-wc-sc-background-coupon-importer.php:400 +msgid "%s are being" +msgstr "" + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-order-fields.php:501 +msgid "%s Balance " +msgstr "%s Guthaben " + +#. translators: Order notes +#: includes/class-wc-sc-coupon-process.php:787 +msgid "%s Because PayPal doesn't accept discount on shipping & tax." +msgstr "" + +#. translators: %s: Plugin name +#: includes/class-wc-sc-admin-notifications.php:467 +msgid "%s database update completed. Thank you for updating to the latest version!" +msgstr "" + +#. translators: %s: Plugin name +#: includes/class-wc-sc-admin-notifications.php:416 +msgid "%s database update required" +msgstr "" + +#. translators: %s: Label for store credit +#: includes/class-wc-sc-settings.php:758 +msgid "%s discount is inclusive of tax" +msgstr "" + +#. translators: 1. The discount text +#: includes/class-wc-smart-coupons.php:1617 +msgid "%s discount on anything you want." +msgstr "" + +#. translators: 1. The discount text +#: includes/class-wc-smart-coupons.php:1619 +msgid "%s discount on entire store." +msgstr "" + +#. translators: Add more detail to coupon description +#: includes/class-wc-sc-display-coupons.php:649 +msgid "%s Free Shipping" +msgstr "" + +#. translators: 1. Product title +#: includes/class-wc-sc-coupon-actions.php:421 +msgid "%s has been added to your cart!" +msgstr "" + +#. translators: %s: Label for store credit +#: includes/class-wc-sc-settings.php:756 +msgid "%s include tax?" +msgstr "" + +#. translators: %s: Plugin name +#: includes/class-wc-sc-admin-notifications.php:454 +msgid "%s is updating the database in the background. The database update process may take a little while, so please be patient." +msgstr "" + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-display-coupons.php:591 +msgid "%s of " +msgstr "" + +#. translators: %s: Label for store credit +#: includes/class-wc-sc-settings.php:624 +msgid "%s product CTA" +msgstr "" + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-admin-pages.php:672 +msgid "%s sent successfully." +msgstr "" + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-order-fields.php:197 +msgid "%s Used" +msgstr "%s Verwendet" + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-order-fields.php:254 +msgid "%s Used:" +msgstr "%s Verwendet:" + +#. translators: 1: email heading 2: suffix +#: includes/emails/class-wc-sc-email-coupon.php:460 +msgid "&" +msgstr "&" + +#: includes/class-wc-sc-admin-pages.php:1194 +msgid "(Add to store and email generated coupons to recipients)" +msgstr "" + +#: includes/class-wc-sc-admin-coupons-dashboard-actions.php:199 +msgid "(Copy)" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:1184 +msgid "(Does not add to store, but creates a .csv file, that you can" +msgstr "" + +#. translators: %s: Note for admin +#: includes/class-wc-sc-settings.php:557 +msgid "(Note: It's recommended to keep it Disabled)" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:815 +#: includes/class-wc-sc-admin-pages.php:1229 +msgid "(optional)" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:445 +msgid "(Used only for auto-generated coupons)" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:484 +msgid "(We recommend up to three letters for prefix/suffix)" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:406 +msgid "--:--:--" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:365 +msgid ". If still the issue persist, temporarily de-activate all plugins except WooCommerce & Smart Coupons. Re-check the issue, if the issue still persists, contact us (from the link at the end of this page). If the issue goes away, re-activate other plugins one-by-one & re-checking the fields, to find out which plugin is conflicting." +msgstr "" + +#. translators: Documentation link for 'How to Apply Single or Multiple Coupons on Click of a Link' +#: includes/class-wc-sc-admin-welcome.php:382 +msgid ". Replace www.mysite.com with your own site URL and replace discount5 with the your coupon code." +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:784 +#: includes/class-wc-sc-coupon-fields.php:1004 +msgid "0.00" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:999 +msgid "1" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:1160 +msgid "10" +msgstr "" + +#. Description of the plugin +#: woocommerce-smart-coupons.php +msgid "WooCommerce Smart Coupons lets customers buy gift certificates, store credits or coupons easily. They can use purchased credits themselves or gift to someone else." +msgstr "" + +#. translators: 1: Singular name for post type 2: Email +#: includes/class-wc-sc-admin-pages.php:1551 +msgid "[%1$s restricted with email: %2$s]" +msgstr "" + +#. translators: %s: Preview link +#: includes/class-wc-sc-settings.php:501 +#: includes/class-wc-sc-settings.php:510 +#: includes/class-wc-sc-settings.php:519 +#: includes/class-wc-sc-settings.php:528 +#: includes/class-wc-sc-settings.php:537 +#: includes/class-wc-sc-settings.php:625 +#: includes/class-wc-sc-settings.php:637 +#: includes/class-wc-sc-settings.php:648 +#: includes/class-wc-sc-settings.php:658 +#: includes/class-wc-sc-settings.php:668 +#: includes/class-wc-sc-settings.php:689 +#: includes/class-wc-sc-settings.php:698 +#: includes/class-wc-sc-settings.php:708 +#: includes/class-wc-sc-settings.php:717 +msgid "[Preview]" +msgstr "" + +#. translators: %s: Label for store credit, 1: : Label for store credit, 2: Label for store credit, 3: Label for store credit +#: includes/class-wc-sc-settings.php:575 +#: includes/class-wc-sc-settings.php:586 +#: includes/class-wc-sc-settings.php:606 +msgid "[Read More]" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:87 +msgid "About Smart Coupons" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5873 +msgid "Account endpoints > Coupons" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5864 +msgid "Acknowledgement email" +msgstr "" + +#: includes/class-wc-smart-coupons.php:1611 +msgid "Act before the offer expires." +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:1153 +msgid "Action" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:934 +msgid "Actions" +msgstr "" + +#: includes/compat/class-wcs-sc-compatibility.php:1072 +msgid "Active for x payments" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:551 +msgid "Add Coupon" +msgstr "" + +#: includes/class-wc-sc-coupon-categories.php:96 +msgid "Add new coupon category" +msgstr "" + +#: includes/class-wc-sc-coupon-actions.php:580 +msgid "Add product details" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:964 +msgid "Add products to cart" +msgstr "" + +#: includes/class-wc-sc-coupons-by-taxonomy.php:146 +#: includes/class-wc-sc-coupons-by-taxonomy.php:219 +msgid "Add taxonomy restriction" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:1166 +msgid "Add to store" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:586 +#: includes/class-wc-sc-background-coupon-importer.php:595 +msgid "added" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:578 +#: includes/class-wc-sc-background-coupon-importer.php:582 +msgid "added & emailed" +msgstr "" + +#: includes/class-wc-smart-coupons.php:7377 +msgid "Added by coupon" +msgstr "" + +#: includes/class-wc-sc-settings.php:711 +msgid "Additional text below the title." +msgstr "" + +#: includes/class-wc-sc-coupons-by-location.php:196 +msgid "Address to look in" +msgstr "" + +#: includes/class-wc-sc-coupon-categories.php:89 +msgctxt "Admin menu name" +msgid "Categories" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:264 +msgid "Advanced restrictions - payment, shipping, location, user roles, product attributes" +msgstr "" + +#. translators: Link for the plugin 'Aelia Currency Switcher for WooCommerce' +#: includes/class-wc-sc-admin-welcome.php:449 +msgid "Aelia Currency Switcher for WooCommerce" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:962 +msgid "After applying the coupon do these also" +msgstr "" + +#: includes/class-wc-sc-coupon-categories.php:91 +msgid "All coupon categories" +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:608 +#: includes/class-wc-sc-display-coupons.php:617 +msgid "all products" +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:936 +msgid "All set, Begin import?" +msgstr "" + +#: includes/class-wc-sc-settings.php:716 +#: includes/class-wc-smart-coupons.php:5860 +msgid "Allow schedule sending of coupons?" +msgstr "" + +#. translators: %s: Label for store credit, 1: : Label for store credit, 2: Label for store credit, 3: Label for store credit +#: includes/class-wc-sc-settings.php:586 +msgid "Allow selling %s at discounted price" +msgstr "" + +#: includes/class-wc-sc-settings.php:688 +#: includes/class-wc-smart-coupons.php:5859 +msgid "Allow sending of coupons to others" +msgstr "" + +#: includes/class-wc-sc-settings.php:689 +msgid "Allow the buyer to send coupons to someone else." +msgstr "" + +#: includes/class-wc-sc-coupons-by-excluded-email.php:468 +msgid "Allowed emails" +msgstr "" + +#: includes/class-wc-sc-coupons-by-user-role.php:116 +msgid "Allowed user roles" +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:1077 +msgid "Already uploaded CSV to the server?" +msgstr "" + +#: includes/class-wc-sc-settings.php:359 +msgid "Amaranth red" +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:2495 +msgid "Amount" +msgstr "Summe" + +#: includes/class-wc-smart-coupons.php:986 +msgid "An error has occurred. Please try again later." +msgstr "" + +#: includes/class-wc-sc-coupons-by-payment-method.php:411 +msgid "An error occurred:" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:267 +msgid "and a lot more…" +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:1037 +msgid "and create your CSV based on that." +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:497 +msgid "and my account?" +msgstr "" + +#. translators: 1: Affiliate For WooCommerce 2: Smart Manager 3: Smart Offers +#: includes/class-wc-sc-admin-welcome.php:287 +msgid "any amount" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:1344 +msgid "Apply" +msgstr "" + +#: includes/class-wc-sc-settings.php:741 +msgid "Apply before tax" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:263 +msgid "Apply multiple coupons via URL" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:215 +msgid "Are you sure you want to remove the selected items? If you have previously reduced this item's stock, or this order was submitted by a customer, you will need to manually restore the item's stock." +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:272 +msgid "Are you sure you want to revoke access to this download?" +msgstr "" + +#. translators: 1. The bulk process +#: includes/class-wc-sc-background-coupon-importer.php:551 +msgid "Are you sure you want to stop the coupon bulk %s process? Click OK to stop." +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:218 +#: includes/class-wc-sc-coupon-refund-process.php:566 +msgid "Are you sure you wish to delete this refund? This action cannot be undone." +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:219 +msgid "Are you sure you wish to delete this tax column? This action cannot be undone." +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:217 +msgid "Are you sure you wish to process this refund? This action cannot be undone." +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:300 +msgid "Attach a gift of any value (free or paid product) to a particular coupon. Here, instead of a discount, a product is redeemed for the coupon code." +msgstr "" + +#: includes/class-wc-smart-coupons.php:1608 +msgid "Attention!" +msgstr "" + +#: includes/class-wc-sc-coupons-by-product-attribute.php:167 +msgid "Attribute=" +msgstr "" + +#: includes/class-wc-sc-settings.php:545 +msgid "Auto apply coupons" +msgstr "" + +#: includes/class-wc-sc-auto-apply-coupon.php:120 +#: includes/class-wc-sc-auto-apply-coupon.php:186 +msgid "Auto apply?" +msgstr "" + +#: includes/class-wc-smart-coupons.php:4650 +msgid "Auto Generate Coupon" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:459 +msgid "Auto generate new coupons with each item" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5862 +msgid "Auto generated coupon email" +msgstr "" + +#: includes/class-wc-sc-coupon-refund-process.php:225 +msgid "Auto-fill refund amount" +msgstr "" + +#: includes/class-wc-sc-settings.php:555 +#: includes/class-wc-smart-coupons.php:5853 +msgid "Automatic deletion" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:271 +msgid "Automatic payment for subscription renewals" +msgstr "" + +#. translators: %s: plural name for store credit +#. translators: %s: Label for store credit +#: includes/class-wc-sc-display-coupons.php:749 +#: includes/class-wc-sc-display-coupons.php:940 +#: includes/class-wc-sc-settings.php:673 +msgid "Available Coupons & %s" +msgstr "" + +#. translators: %s: plural name for store credit +#: includes/class-wc-sc-display-coupons.php:749 +#: includes/class-wc-sc-display-coupons.php:940 +msgid "Available Coupons & Store Credits" +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:342 +#: includes/class-wc-sc-display-coupons.php:735 +#: includes/class-wc-sc-settings.php:662 +msgid "Available Coupons (click on a coupon to use it)" +msgstr "Verfügbare Gutscheine (Klicke, um einen zu nutzen)" + +#: includes/class-wc-sc-admin-welcome.php:398 +msgid "Available coupons are not visible on Cart, Checkout & My Account page?" +msgstr "" + +#. translators: %s: list of placeholders +#: includes/emails/class-wc-sc-email.php:97 +msgid "Available placeholders: %s" +msgstr "" + +#: includes/class-wc-sc-admin-notifications.php:243 +msgid "Awesome, you successfully auto-generated a coupon! Are you having a great experience with" +msgstr "" + +#: includes/class-wc-sc-settings.php:408 +msgid "Basic" +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:1061 +msgid "Before you can upload your import file, you will need to fix the following error:" +msgstr "" + +#: includes/class-wc-sc-coupons-by-location.php:199 +msgid "Billing" +msgstr "" + +#: includes/class-wc-sc-coupons-by-location.php:478 +msgid "billing address" +msgstr "" + +#: includes/class-wc-sc-coupons-by-location.php:494 +msgid "Billing Locations" +msgstr "" + +#: blocks/build/js/available-coupons/block.json +#: blocks/src/js/available-coupons/block.json +msgctxt "block description" +msgid "Displays available coupons." +msgstr "" + +#: blocks/build/js/send-coupon-form/block.json +#: blocks/src/js/send-coupon-form/block.json +msgctxt "block description" +msgid "Displays Send coupon form." +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-available-coupons-block.js:7 +#: blocks/src/js/available-coupons/edit.js:19 +msgctxt "Block editor" +msgid "Available Coupons (click on a coupon to use it)" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block.js:1 +#: blocks/src/js/send-coupon-form/edit.js:59 +#: blocks/src/js/send-coupon-form/edit.js:63 +msgctxt "Block editor" +msgid "Deliver coupon" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block.js:1 +#: blocks/src/js/send-coupon-form/edit.js:84 +msgctxt "Block editor" +msgid "Enter recipient e-mail address" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block.js:1 +#: blocks/src/js/send-coupon-form/edit.js:39 +msgctxt "Block editor" +msgid "Gift to someone else" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block.js:1 +#: blocks/src/js/send-coupon-form/edit.js:71 +msgctxt "Block editor" +msgid "later" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block.js:1 +#: blocks/src/js/send-coupon-form/edit.js:88 +msgctxt "Block editor" +msgid "Message for receiver" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block.js:1 +#: blocks/src/js/send-coupon-form/edit.js:67 +msgctxt "Block editor" +msgid "now" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block.js:1 +#: blocks/src/js/send-coupon-form/edit.js:80 +msgctxt "Block editor" +msgid "Receiver email address" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block.js:1 +#: blocks/src/js/send-coupon-form/edit.js:30 +msgctxt "Block editor" +msgid "Send coupons to..." +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block.js:1 +#: blocks/src/js/send-coupon-form/edit.js:53 +msgctxt "Block editor" +msgid "Send to different people" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block.js:1 +#: blocks/src/js/send-coupon-form/edit.js:35 +msgctxt "Block editor" +msgid "Send to me" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block.js:1 +#: blocks/src/js/send-coupon-form/edit.js:49 +msgctxt "Block editor" +msgid "Send to one person" +msgstr "" + +#: blocks/blocks.php:51 +msgctxt "Block editor" +msgid "WooCommerce Smart Coupons" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block.js:1 +#: blocks/src/js/send-coupon-form/edit.js:92 +msgctxt "Block editor" +msgid "Write a message" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block.js:1 +#: blocks/src/js/send-coupon-form/edit.js:31 +msgctxt "Block editor" +msgid "Your order contains coupons. What would you like to do?" +msgstr "" + +#: blocks/class-wc-sc-blocks-integration.php:423 +msgctxt "Block editor & frontend" +msgid "Available Coupons (click on a coupon to use it)" +msgstr "" + +#: blocks/class-wc-sc-blocks-integration.php:600 +msgctxt "Block editor & frontend" +msgid "coupon" +msgstr "" + +#: blocks/class-wc-sc-blocks-integration.php:653 +msgctxt "Block editor & frontend" +msgid "Deliver coupon" +msgstr "" + +#: blocks/class-wc-sc-blocks-integration.php:654 +msgctxt "Block editor & frontend" +msgid "Enter recipient e-mail address" +msgstr "" + +#: blocks/class-wc-sc-blocks-integration.php:597 +msgctxt "Block editor & frontend" +msgid "Free Shipping coupon" +msgstr "" + +#: blocks/class-wc-sc-blocks-integration.php:629 +msgctxt "Block editor & frontend" +msgid "Gift to someone else" +msgstr "" + +#: blocks/class-wc-sc-blocks-integration.php:649 +msgctxt "Block editor & frontend" +msgid "later" +msgstr "" + +#: blocks/class-wc-sc-blocks-integration.php:645 +msgctxt "Block editor & frontend" +msgid "now" +msgstr "" + +#: blocks/class-wc-sc-blocks-integration.php:604 +msgctxt "Block editor & frontend" +msgid "of" +msgstr "" + +#: blocks/class-wc-sc-blocks-integration.php:604 +msgctxt "Block editor & frontend" +msgid "Send" +msgstr "" + +#: blocks/class-wc-sc-blocks-integration.php:515 +#: blocks/class-wc-sc-blocks-integration.php:516 +msgctxt "Block editor & frontend" +msgid "Send Coupons to..." +msgstr "" + +#: blocks/class-wc-sc-blocks-integration.php:639 +msgctxt "Block editor & frontend" +msgid "Send to different people" +msgstr "" + +#: blocks/class-wc-sc-blocks-integration.php:625 +msgctxt "Block editor & frontend" +msgid "Send to me" +msgstr "" + +#: blocks/class-wc-sc-blocks-integration.php:635 +msgctxt "Block editor & frontend" +msgid "Send to one person" +msgstr "" + +#: blocks/class-wc-sc-blocks-integration.php:621 +msgctxt "Block editor & frontend" +msgid "Your order contains coupons. What would you like to do?" +msgstr "" + +#: blocks/build/js/available-coupons/block.json +#: blocks/src/js/available-coupons/block.json +msgctxt "block title" +msgid "Available coupons" +msgstr "" + +#: blocks/build/js/send-coupon-form/block.json +#: blocks/src/js/send-coupon-form/block.json +msgctxt "block title" +msgid "Send coupon form" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5874 +msgid "Block-enabled Cart" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5875 +msgid "Block-enabled Checkout" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:292 +msgid "Bulk create unique coupons & email them" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:124 +#: includes/class-wc-sc-admin-pages.php:556 +#: includes/class-wc-sc-admin-pages.php:1594 +msgid "Bulk Generate" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:262 +msgid "Bulk generate coupons" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:338 +msgid "Bulk generation is disabled since uploads directory is not writable. Please ensure uploads directory is writable before starting bulk generate process." +msgstr "" + +#. translators: 1. The discount text +#: includes/class-wc-smart-coupons.php:1623 +msgid "Buy as much as you want. Flat %s off everything." +msgstr "" + +#: includes/class-wc-sc-settings.php:684 +msgid "Buyers can send purchased coupons to anyone – right while they're checking out." +msgstr "" + +#: includes/class-wc-smart-coupons.php:5872 +msgid "Calculate coupon discounts sequentially" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:231 +msgid "Calculate line taxes? This will calculate taxes based on the customers country. If no billing/shipping is set it will use the store base country." +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:230 +msgid "Calculate totals based on order items, discounts, and shipping?" +msgstr "" + +#: includes/class-wc-sc-settings.php:601 +msgid "Call it something else! Use these to quickly change text labels through your store. Use translations for complete control." +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:376 +msgid "Can coupon code have any spaces in the name? / My Store Credit/Gift Certificate is not working (not generating new coupon code)." +msgstr "" + +#: includes/class-wc-sc-shortcode.php:944 +msgid "Cancel" +msgstr "" + +#: includes/class-wc-sc-settings.php:360 +msgid "Carolina Blue" +msgstr "" + +#: includes/class-wc-sc-coupons-by-product-quantity.php:120 +msgid "Cart" +msgstr "" + +#: includes/class-wc-sc-ajax.php:337 +#: includes/class-wc-sc-ajax.php:352 +#: includes/class-wc-smart-coupons.php:1148 +#: includes/class-wc-smart-coupons.php:1163 +msgid "Cart Discount" +msgstr "Warenkorb Rabatt" + +#: includes/class-wc-sc-coupons-by-product-quantity.php:191 +#: includes/class-wc-sc-coupons-by-product-quantity.php:208 +#: includes/class-wc-sc-coupons-by-product-quantity.php:253 +#: includes/class-wc-sc-coupons-by-product-quantity.php:263 +msgid "Categories" +msgstr "" + +#: includes/class-wc-sc-coupon-categories.php:88 +msgid "Category" +msgstr "" + +#: includes/class-wc-smart-coupons.php:71 +msgid "Cheatin’ huh?" +msgstr "" + +#: includes/class-wc-sc-coupon-message.php:134 +msgid "Check this box to include above message in order confirmation email" +msgstr "" + +#: includes/class-wc-sc-product-fields.php:129 +#: includes/class-wc-sc-product-fields.php:185 +msgid "Check this box to send above coupons on each renewal order." +msgstr "" + +#. translators: 1. The coupon code 2. The text 'payment method/s' 3. List of payment method names 4. Link to the checkout page +#: includes/class-wc-sc-coupons-by-payment-method.php:210 +#: includes/class-wc-sc-coupons-by-payment-method.php:214 +msgid "Checkout" +msgstr "" + +#: includes/class-wc-sc-settings.php:368 +msgid "Chocolate" +msgstr "" + +#: includes/class-wc-sc-settings.php:355 +msgid "Choose a color scheme for coupons." +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:1070 +msgid "Choose a CSV file" +msgstr "" + +#: includes/class-wc-sc-settings.php:395 +msgid "Choose a style for coupon on the website." +msgstr "" + +#: includes/class-wc-sc-settings.php:456 +msgid "Choose order status which will trigger the auto-generation of coupon, if the order contains product which will generate the coupon." +msgstr "" + +#: includes/class-wc-sc-coupons-by-product-quantity.php:127 +msgid "Choose whether to validate the quantity, cart-wise or product-wise" +msgstr "" + +#: includes/emails/class-wc-sc-email.php:109 +msgid "Choose which format of email to send." +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:1020 +msgid "Chosen" +msgstr "" + +#: includes/class-wc-smart-coupons.php:3275 +msgid "Clear Smart Coupons Cache" +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:1037 +msgid "Click here to download a sample" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:146 +#: includes/class-wc-sc-coupon-fields.php:1434 +msgid "Click to copy" +msgstr "" + +#: includes/class-wc-sc-shortcode.php:825 +msgid "Click to select coupon code." +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:224 +msgid "Click to toggle" +msgstr "" + +#: includes/class-wc-sc-shortcode.php:607 +#: templates/combined-email.php:195 +#: templates/email.php:182 +msgid "Click to visit store. This coupon will be applied automatically." +msgstr "" + +#: includes/class-wc-sc-settings.php:407 +msgid "Clipper" +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:2494 +msgid "Code" +msgstr "Gutscheincode" + +#: includes/class-wc-sc-settings.php:351 +msgid "Colors" +msgstr "" + +#: includes/class-wc-sc-settings.php:726 +#: includes/class-wc-smart-coupons.php:5861 +msgid "Combine emails" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5863 +msgid "Combined auto generated coupons email" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:1432 +#: includes/class-wc-sc-coupon-fields.php:1447 +msgid "Copied!" +msgstr "" + +#: includes/class-wc-sc-admin-coupons-dashboard-actions.php:116 +msgid "Copy" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:232 +msgid "Copy billing information to shipping information? This will remove any currently entered shipping information." +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:1439 +#: includes/class-wc-sc-coupon-fields.php:1449 +msgid "Copy coupon code" +msgstr "" + +#: includes/class-wc-sc-admin-coupons-dashboard-actions.php:118 +msgid "Copy coupon shareable link and apply via URL" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:139 +msgid "Copy the following link and share it to apply this coupon via URL." +msgstr "" + +#: includes/class-wc-sc-admin-coupons-dashboard-actions.php:116 +msgid "Copy this coupon code" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:271 +msgid "Could not grant access - the user may already have permission for this file or billing email is not set. Ensure the billing email is set, and the order has been saved." +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:1312 +msgid "Could not locate WooCommerce" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:605 +#: includes/class-wc-sc-purchase-credit.php:991 +#: includes/emails/class-wc-sc-email-coupon.php:488 +msgid "coupon" +msgstr "" + +#: includes/class-wc-sc-privacy.php:384 +#: includes/emails/class-wc-sc-acknowledgement-email.php:342 +#: templates/acknowledgement-email.php:66 +#: templates/coupon-design/basic.php:39 +#: templates/coupon-design/clipper.php:38 +#: templates/coupon-design/cutout.php:55 +#: templates/coupon-design/deal.php:29 +#: templates/coupon-design/deliver.php:34 +#: templates/coupon-design/shipment.php:33 +#: templates/coupon-design/special.php:58 +#: templates/coupon-design/ticket.php:40 +#: templates/plain/acknowledgement-email.php:56 +msgid "Coupon" +msgid_plural "Coupons" +msgstr[0] "Gutschein" +msgstr[1] "Gutscheine" + +#. translators: The coupon code +#: includes/class-wc-smart-coupons.php:3319 +msgid "Coupon %s is valid for a new user only, hence removed." +msgstr "" + +#: includes/class-wc-sc-privacy.php:602 +#: includes/class-wc-smart-coupons.php:5009 +msgid "Coupon Amount" +msgstr "" + +#: includes/class-wc-sc-privacy.php:122 +msgid "Coupon amount, email & message entered for gift card receiver" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:581 +#: includes/class-wc-sc-background-coupon-importer.php:594 +msgid "Coupon bulk generation" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:1298 +#: includes/class-wc-sc-coupon-categories.php:87 +#: includes/class-wc-sc-coupon-categories.php:225 +msgid "Coupon categories" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5031 +msgid "Coupon Category" +msgstr "" + +#: includes/class-wc-sc-privacy.php:599 +#: includes/class-wc-smart-coupons.php:4997 +msgid "Coupon Code" +msgstr "" + +#: includes/class-wc-sc-shortcode.php:879 +msgid "Coupon code" +msgstr "" + +#. translators: 1. The coupon code 2. The text 'payment method/s' 3. List of payment method names 4. Link to the checkout page +#: includes/class-wc-sc-coupons-by-payment-method.php:210 +msgid "Coupon code %1$s has been removed. It is valid only for %2$s: %3$s. You can change the payment method from the %4$s page." +msgstr "" + +#. translators: 1. The coupon code 2. The text 'payment method/s' 3. List of payment method names 4. Link to the checkout page +#: includes/class-wc-sc-coupons-by-payment-method.php:214 +msgid "Coupon code %1$s is valid only for %2$s: %3$s. You can change payment method from the %4$s page." +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:480 +msgid "Coupon code format" +msgstr "" + +#: includes/class-wc-sc-privacy.php:120 +msgid "Coupon code generated for you" +msgstr "" + +#: includes/class-wc-sc-privacy.php:121 +msgid "Coupon code passed via URL" +msgstr "" + +#: templates/plain/combined-email.php:97 +#: templates/plain/email.php:92 +msgid "Coupon Code:" +msgstr "Gutscheincode:" + +#. translators: %d: Post ID +#: includes/class-wc-sc-admin-coupons-dashboard-actions.php:288 +msgid "Coupon creation failed, could not find original coupon: %d" +msgstr "" + +#. translators: %s: coupon id +#: includes/class-wc-sc-admin-coupons-dashboard-actions.php:311 +msgid "Coupon creation failed, could not find original coupon: %s" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:1288 +msgid "Coupon Data" +msgstr "" + +#. translators: %s: field name +#: includes/class-wc-sc-purchase-credit.php:1427 +msgid "Coupon delivery date and time is a required field." +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:1266 +msgid "Coupon Description " +msgstr "" + +#: includes/class-wc-sc-settings.php:565 +#: includes/class-wc-smart-coupons.php:5854 +msgid "Coupon emails" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:391 +#: includes/class-wc-smart-coupons.php:4661 +msgid "Coupon expiry time" +msgstr "" + +#: includes/class-wc-sc-privacy.php:605 +msgid "Coupon For" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:577 +#: includes/class-wc-sc-background-coupon-importer.php:585 +msgid "Coupon import" +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:857 +msgid "Coupon Import Error" +msgstr "" + +#: includes/class-wc-sc-coupons-by-location.php:478 +msgid "Coupon is not valid for the" +msgstr "" + +#: includes/class-wc-smart-coupons.php:4655 +msgid "Coupon Is Visible Storewide" +msgstr "" + +#: includes/class-wc-sc-coupon-message.php:418 +#: includes/class-wc-sc-coupon-message.php:435 +msgid "Coupon Message" +msgstr "" + +#: includes/class-wc-sc-privacy.php:401 +msgid "Coupon passed in URL" +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:2167 +msgid "Coupon Received" +msgstr "Deine Gutscheine" + +#: includes/class-wc-sc-settings.php:682 +msgid "Coupon Receiver Details during Checkout" +msgstr "" + +#. translators: The coupon code +#: includes/class-wc-smart-coupons.php:3378 +msgid "Coupon removed. There is no credit remaining in %s." +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:101 +msgid "Coupon shareable link" +msgstr "" + +#: includes/class-wc-smart-coupons.php:4651 +msgid "Coupon Title Prefix" +msgstr "" + +#: includes/class-wc-smart-coupons.php:4652 +msgid "Coupon Title Suffix" +msgstr "" + +#: includes/class-wc-smart-coupons.php:4648 +msgid "Coupon Validity" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:452 +msgid "Coupon value same as product's price?" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:123 +#: includes/class-wc-sc-admin-pages.php:550 +#: includes/class-wc-sc-admin-pages.php:555 +#: includes/class-wc-sc-admin-pages.php:1620 +#: includes/class-wc-sc-background-coupon-importer.php:396 +#: includes/class-wc-sc-display-coupons.php:791 +#: includes/class-wc-sc-display-coupons.php:828 +#: includes/class-wc-sc-display-coupons.php:1940 +#: includes/class-wc-sc-product-fields.php:99 +#: includes/class-wc-sc-product-fields.php:159 +msgid "Coupons" +msgstr "Gutscheine" + +#: includes/class-wc-sc-background-coupon-importer.php:606 +msgid "coupons" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:261 +msgid "Create and gift Store Credit / Gift Cards" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:627 +msgid "CSV file has been generated. You can download it from " +msgstr "" + +#. translators: Link for the plugin 'Aelia Currency Switcher for WooCommerce' +#: includes/class-wc-sc-admin-welcome.php:449 +msgid "Currently, Smart Coupons is compatible with %s. But it is not compatible with any other multi-currency plugin or with WPML." +msgstr "" + +#: includes/class-wc-sc-settings.php:384 +msgid "Custom colors" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5286 +msgid "Custom Style" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5020 +msgid "Customer Email" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:436 +msgid "Customers can apply store credit on a subscription during purchase of subscription. If the same store credit has sufficient balance, it'll keep applying it to renewals till the remainder in store credit is higher than renewal price. Customers will be able to apply store credit only during signup. They will not get an option to apply store credit in renewals. But if the store credit will not have sufficient balance to pay for the renewals, then the order will go into pending mode. Now when the customer will go to pay for this renewal order, they'll get an option to apply store credit again. To activate the subscription again, the customer will have to pay for the renewals. When the customer is paying for the renewals from their account, then in that process they can use the same store credit which didn't have the sufficient balance, again & pay for the remaining amount." +msgstr "" + +#: includes/class-wc-sc-settings.php:380 +msgid "Customize color scheme for coupons." +msgstr "" + +#: includes/class-wc-sc-settings.php:376 +msgid "Customize colors" +msgstr "" + +#: includes/class-wc-sc-settings.php:405 +msgid "Cutout" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:440 +msgid "Days" +msgstr "" + +#: includes/class-wc-sc-settings.php:409 +msgid "Deal" +msgstr "" + +#: includes/class-wc-sc-settings.php:742 +#: includes/class-wc-smart-coupons.php:5851 +msgid "Deduct credit/gift before doing tax calculations" +msgstr "" + +#. translators: 1: plugin name 2: page based text 3: Label for store credit 4: Hide notice text +#: includes/class-wc-sc-settings.php:903 +msgid "Delete Gift / Credit, when credit is used up" +msgstr "" + +#. translators: %s: Note for admin +#: includes/class-wc-sc-settings.php:557 +msgid "Delete the %1$s when entire credit amount is used up %2$s" +msgstr "" + +#: includes/class-wc-sc-settings.php:406 +msgid "Deliver" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:854 +msgid "Deliver coupon" +msgstr "" + +#: includes/class-wc-sc-settings.php:707 +msgid "Description" +msgstr "" + +#: templates/plain/combined-email.php:103 +#: templates/plain/email.php:98 +msgid "Description:" +msgstr "Beschreibung:" + +#: includes/class-wc-smart-coupons.php:4654 +msgid "Disable Email Restriction" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:536 +msgid "Disable email restriction?" +msgstr "" + +#. translators: %s: Explanation of the setting +#: includes/class-wc-sc-settings.php:547 +msgid "Disabling this, no coupons will be auto-applied - even if any coupon has \"Auto apply?\" enabled." +msgstr "" + +#: includes/class-wc-sc-ajax.php:352 +#: includes/class-wc-sc-settings.php:1051 +#: includes/class-wc-smart-coupons.php:1163 +msgid "Discount" +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:1213 +msgid "Discount Coupons" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5008 +msgid "Discount Type" +msgstr "" + +#: includes/class-wc-sc-order-fields.php:280 +#: templates/plain/combined-email.php:83 +#: templates/plain/email.php:78 +msgid "Discount:" +msgstr "Rabatt:" + +#. translators: %s: Preview link +#: includes/class-wc-sc-settings.php:537 +msgid "Display coupon description along with coupon code (on site as well as in emails) %s" +msgstr "" + +#: includes/class-wc-sc-coupon-message.php:125 +msgid "Display message" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5868 +msgid "Display prices during cart and checkout" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5867 +msgid "Display prices in the shop" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5870 +msgid "Display tax totals" +msgstr "" + +#: includes/class-wc-sc-settings.php:499 +msgid "Displaying coupons" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:537 +msgid "Do not restrict auto-generated coupons to buyer/receiver email, anyone with coupon code can use it" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:385 +msgid "Do not want to tie store credit to be used by only one customer? / Can a customer send a gift certificate to themselves to pass on to someone else?" +msgstr "" + +#: includes/class-wc-sc-admin-notifications.php:101 +#: includes/class-wc-sc-admin-welcome.php:198 +msgid "Docs" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:418 +msgid "Does Smart Coupons allow printing of coupon as Gift Card?" +msgstr "" + +#: includes/class-wc-smart-coupons.php:1612 +msgid "Don't Miss Out." +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:857 +msgid "Download a sample.csv to confirm" +msgstr "" + +#: includes/class-wc-sc-admin-coupons-dashboard-actions.php:123 +msgid "Duplicate" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:998 +msgid "each with quantity" +msgstr "" + +#: includes/class-wc-sc-coupon-categories.php:94 +msgid "Edit coupon category" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:386 +msgid "Edit the main coupon which is entered in \"Coupons\" field of the product edit page, then go to \"Usage Restrictions\" > \"Disable Email Restriction\" and disable this setting and save the coupon." +msgstr "" + +#: includes/class-wc-sc-coupon-process.php:322 +msgid "Email address" +msgstr "" + +#: includes/emails/class-wc-sc-email-coupon.php:35 +msgid "Email auto generated coupon to recipients. One email per coupon." +msgstr "" + +#: includes/class-wc-sc-settings.php:566 +msgid "Email auto generated coupons to recipients" +msgstr "" + +#: includes/class-wc-sc-settings.php:424 +msgid "Email coupon" +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:951 +msgid "Email coupon to recipients" +msgstr "" + +#: includes/emails/class-wc-sc-email.php:124 +msgid "Email heading" +msgstr "" + +#: includes/class-wc-sc-coupon-message.php:133 +msgid "Email message?" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:1212 +msgid "Email to " +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:1192 +msgid "Email to recipients" +msgstr "" + +#: includes/emails/class-wc-sc-email.php:107 +msgid "Email type" +msgstr "" + +#: includes/class-wc-sc-admin-notifications.php:176 +msgid "Enable" +msgstr "" + +#: includes/class-wc-sc-settings.php:575 +msgid "Enable feature to allow printing of coupons" +msgstr "" + +#: includes/class-wc-sc-settings.php:470 +msgid "Enable store notice for the coupon" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5865 +msgid "Enable taxes" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5871 +msgid "Enable the use of coupon codes" +msgstr "" + +#: includes/emails/class-wc-sc-email.php:103 +msgid "Enable this email notification" +msgstr "" + +#: includes/class-wc-sc-settings.php:717 +msgid "Enable this to allow buyers to select date & time for delivering the coupon." +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:951 +msgid "Enable this to send coupon to recipient's email addresses, provided in imported file." +msgstr "" + +#: includes/emails/class-wc-sc-email.php:101 +msgid "Enable/Disable" +msgstr "" + +#: includes/class-wc-smart-coupons.php:1605 +msgid "Ending Soon!" +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:1941 +msgid "Endpoint for the My Account → Coupons page" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:1045 +#: includes/class-wc-smart-coupons.php:5140 +msgctxt "enhanced select" +msgid "%qty% results are available, use up and down arrow keys to navigate." +msgstr "" + +#: includes/class-wc-smart-coupons.php:5142 +msgctxt "enhanced select" +msgid "Loading failed" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:1054 +#: includes/class-wc-smart-coupons.php:5149 +msgctxt "enhanced select" +msgid "Loading more results…" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:1046 +#: includes/class-wc-smart-coupons.php:5141 +msgctxt "enhanced select" +msgid "No matches found" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:1044 +#: includes/class-wc-smart-coupons.php:5139 +msgctxt "enhanced select" +msgid "One result is available, press enter to select it." +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:1051 +#: includes/class-wc-smart-coupons.php:5146 +msgctxt "enhanced select" +msgid "Please delete %qty% characters" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:1050 +#: includes/class-wc-smart-coupons.php:5145 +msgctxt "enhanced select" +msgid "Please delete 1 character" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:1049 +#: includes/class-wc-smart-coupons.php:5144 +msgctxt "enhanced select" +msgid "Please enter %qty% or more characters" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:1048 +#: includes/class-wc-smart-coupons.php:5143 +msgctxt "enhanced select" +msgid "Please enter 1 or more characters" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:1047 +#: includes/class-wc-sc-coupon-fields.php:1055 +#: includes/class-wc-smart-coupons.php:5150 +msgctxt "enhanced select" +msgid "Searching…" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:1053 +#: includes/class-wc-smart-coupons.php:5148 +msgctxt "enhanced select" +msgid "You can only select %qty% items" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:1052 +#: includes/class-wc-smart-coupons.php:5147 +msgctxt "enhanced select" +msgid "You can only select 1 item" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:229 +msgid "Enter a name for the new attribute term:" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:158 +msgid "Enter a numeric value." +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:1077 +msgid "Enter location on the server" +msgstr "" + +#: includes/class-wc-sc-shortcode.php:809 +msgid "Enter more than one character to search." +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:887 +#: includes/class-wc-sc-purchase-credit.php:998 +msgid "Enter recipient e-mail address" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:226 +msgid "Enter some text, or some attributes by pipe (|) separating values." +msgstr "" + +#. translators: 1: Path to setting 2: Setting to set email address 3: Setting for number of coupons to generate +#: includes/class-wc-sc-admin-pages.php:1200 +msgid "Enter the email addresses of the recipients separated by comma under %1$1s. Make sure to match the count of email addresses in %2$2s to %3$3s" +msgstr "" + +#: includes/class-wc-sc-coupons-by-location.php:306 +msgid "Entered location not found. On pressing \"Enter\" button, a new custom location will be saved as: " +msgstr "" + +#. translators: 1. Error title 2. The bulk process +#: includes/class-wc-sc-background-coupon-importer.php:385 +msgid "Error" +msgstr "" + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-coupon-process.php:352 +msgid "Error: %s Receiver’s E-mail address is invalid." +msgstr "" + +#: includes/class-wc-sc-coupon-process.php:354 +msgid "Error: Gift Card Receiver’s E-mail address is invalid." +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:1257 +msgid "Every 5 Seconds" +msgstr "" + +#: includes/class-wc-sc-coupons-by-taxonomy.php:104 +#: includes/class-wc-sc-coupons-by-taxonomy.php:291 +msgid "Exclude" +msgstr "" + +#: includes/class-wc-sc-coupons-by-product-attribute.php:546 +msgid "Exclude Attributes" +msgstr "" + +#: includes/class-wc-sc-coupons-by-product-attribute.php:200 +msgid "Exclude attributes" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5019 +msgid "Exclude Product categories" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5017 +msgid "Exclude product IDs" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5015 +msgid "Exclude Sale Items" +msgstr "" + +#: includes/class-wc-sc-coupons-by-user-role.php:244 +msgid "Exclude User Role" +msgstr "" + +#: includes/class-wc-sc-coupons-by-user-role.php:133 +msgid "Exclude user roles" +msgstr "" + +#: includes/class-wc-sc-coupons-by-excluded-email.php:105 +#: includes/class-wc-sc-coupons-by-excluded-email.php:341 +#: includes/class-wc-sc-coupons-by-excluded-email.php:469 +msgid "Excluded emails" +msgstr "" + +#. translators: Discount amount applied on tax +#: includes/class-wc-smart-coupons.php:2777 +msgid "excludes -%s on tax" +msgstr "" + +#: templates/plain/combined-email.php:108 +#: templates/plain/email.php:103 +msgid "Expires on:" +msgstr "Gültig bis:" + +#: includes/class-wc-sc-admin-pages.php:800 +msgid "Expiry Date" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5011 +msgid "Expiry date" +msgstr "" + +#. translators: 1: The expiry date +#: includes/class-wc-smart-coupons.php:1278 +msgid "Expiry: %s" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:206 +#: includes/class-wc-smart-coupons.php:4257 +msgid "Export" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:1172 +msgid "Export to CSV" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:743 +#: includes/class-wc-sc-background-coupon-importer.php:760 +msgid "Failed to create export file." +msgstr "" + +#. translators: 1. Receiver email 2. Coupon code 3. Order id +#: includes/class-wc-sc-coupon-process.php:1081 +#: includes/class-wc-smart-coupons.php:873 +msgid "Failed to schedule email to \"%1$s\" for coupon \"%2$s\" received from order #%3$s." +msgstr "" + +#. translators: 1. Receiver email 2. Coupon code +#: includes/class-wc-sc-coupon-import.php:669 +msgid "Failed to schedule email to \"%1$s\" for coupon \"%2$s\"." +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:1324 +#: includes/compat/class-wc-sc-kco-compatibility.php:123 +msgid "Failed to update coupon receiver details in session." +msgstr "" + +#: includes/class-wc-sc-coupon-refund-process.php:502 +msgid "Failed to update store credit refund details." +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:349 +msgid "FAQ / Common Problems" +msgstr "" + +#: includes/class-wc-sc-admin-notifications.php:100 +#: includes/class-wc-sc-admin-pages.php:159 +#: includes/class-wc-sc-admin-pages.php:608 +#: includes/class-wc-sc-admin-welcome.php:223 +msgid "FAQ's" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:235 +msgid "Featured" +msgstr "" + +#: includes/class-wc-sc-admin-notifications.php:177 +msgid "features." +msgstr "" + +#: includes/class-wc-sc-settings.php:402 +msgid "Festive" +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:941 +msgid "File format seems OK" +msgstr "" + +#. translators: File path +#: includes/class-wc-smart-coupons.php:5317 +#: includes/class-wc-smart-coupons.php:5325 +msgid "File not found %s" +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:940 +msgid "File uploaded OK" +msgstr "" + +#: includes/class-wc-smart-coupons.php:4224 +msgid "Filter by category" +msgstr "" + +#. translators: Email address of users +#: includes/class-wc-smart-coupons.php:7070 +msgid "Find coupons restricted to %s" +msgstr "" + +#: includes/class-wc-sc-settings.php:399 +msgid "Flat" +msgstr "" + +#. translators: 1. The discount text +#: includes/class-wc-smart-coupons.php:1625 +msgid "Flat %s discount on everything today." +msgstr "" + +#: includes/emails/class-wc-sc-email-coupon.php:410 +#: includes/emails/class-wc-sc-email-coupon.php:421 +msgid "for all products" +msgstr "für alle Produkte" + +#: includes/emails/class-wc-sc-email-coupon.php:432 +msgid "for entire purchase" +msgstr "für den gesamten Einkauf" + +#. translators: Documentation link for 'How to Apply Single or Multiple Coupons on Click of a Link' +#: includes/class-wc-sc-admin-welcome.php:382 +msgid "For more details you can refer to this article: %s" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:422 +#: includes/class-wc-smart-coupons.php:4656 +#: includes/class-wc-smart-coupons.php:5026 +msgid "For new user only?" +msgstr "" + +#: includes/emails/class-wc-sc-email-coupon.php:408 +#: includes/emails/class-wc-sc-email-coupon.php:419 +#: includes/emails/class-wc-sc-email-coupon.php:430 +msgid "for some products" +msgstr "für einige Produkte" + +#: includes/class-wc-sc-display-coupons.php:280 +#: includes/class-wc-sc-display-coupons.php:871 +#: includes/class-wc-sc-display-coupons.php:2412 +#: includes/class-wc-sc-shortcode.php:542 +#: includes/class-wc-smart-coupons.php:4895 +#: templates/combined-email.php:127 +#: templates/email.php:125 +#: templates/plain/combined-email.php:93 +#: templates/plain/email.php:88 +#: templates/print-coupons-default.php:144 +msgid "Free Shipping" +msgstr "Kostenloser Versand" + +#: includes/class-wc-smart-coupons.php:5010 +msgid "Free shipping" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:988 +msgid "Free Shipping coupon" +msgstr "" + +#: includes/emails/class-wc-sc-combined-email-coupon.php:144 +#: includes/emails/class-wc-sc-combined-email-coupon.php:221 +#: includes/emails/class-wc-sc-email-coupon.php:202 +#: includes/emails/class-wc-sc-email-coupon.php:281 +msgid "from" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:424 +msgid "From version 4.11.0, you can add/link coupons to product variations as well. This feature is not available in a version lower than 4.11.0." +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block-frontend.js:1 +#: blocks/src/js/send-coupon-form/block.js:235 +#: blocks/src/js/send-coupon-form/block.js:239 +msgctxt "Frontend" +msgid "Deliver coupon" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block-frontend.js:1 +#: blocks/src/js/send-coupon-form/block.js:262 +#: blocks/src/js/send-coupon-form/block.js:287 +msgctxt "Frontend" +msgid "Enter recipient e-mail address" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block-frontend.js:1 +#: blocks/src/js/send-coupon-form/block.js:207 +msgctxt "Frontend" +msgid "Gift to someone else" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block-frontend.js:1 +#: blocks/src/js/send-coupon-form/block.js:267 +#: blocks/src/js/send-coupon-form/block.js:294 +msgctxt "Frontend" +msgid "Message for receiver" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block-frontend.js:1 +#: blocks/src/js/send-coupon-form/block.js:259 +#: blocks/src/js/send-coupon-form/block.js:284 +msgctxt "Frontend" +msgid "Receiver email address" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block-frontend.js:1 +#: blocks/src/js/send-coupon-form/block.js:195 +msgctxt "Frontend" +msgid "Send coupons to..." +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block-frontend.js:1 +#: blocks/src/js/send-coupon-form/block.js:225 +msgctxt "Frontend" +msgid "Send to different people" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block-frontend.js:1 +#: blocks/src/js/send-coupon-form/block.js:202 +msgctxt "Frontend" +msgid "Send to me" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block-frontend.js:1 +#: blocks/src/js/send-coupon-form/block.js:220 +msgctxt "Frontend" +msgid "Send to one person" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block-frontend.js:1 +#: blocks/src/js/send-coupon-form/block.js:271 +#: blocks/src/js/send-coupon-form/block.js:298 +msgctxt "Frontend" +msgid "Write a message" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block-frontend.js:1 +#: blocks/src/js/send-coupon-form/block.js:197 +msgctxt "Frontend" +msgid "Your order contains coupons. What would you like to do?" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:366 +#: includes/class-wc-sc-background-coupon-importer.php:371 +msgid "generate" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:284 +msgid "Generate coupon code" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:1164 +msgid "Generate coupons and" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:460 +msgid "Generate exact copy of this coupon with unique coupon code for each purchased product (needs this coupon to be linked with that product)" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:370 +#: includes/class-wc-sc-background-coupon-importer.php:595 +msgid "generated" +msgstr "" + +#. translators: %s: Label for store credit +#: includes/class-wc-sc-settings.php:489 +msgid "Generated %s amount" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:365 +msgid "generated & sent" +msgstr "" + +#: includes/class-wc-sc-privacy.php:390 +msgid "Generated Coupon Data" +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:2595 +msgid "Generated coupons" +msgstr "Generierte Gutscheine" + +#. translators: 1. Link to jump to 'Order actions' metabox 2. Text 'Order actions' 3. Text 'arrow' +#: includes/class-wc-sc-display-coupons.php:2107 +msgctxt "Generated coupons metabox - Order edit admin page" +msgid "arrow" +msgstr "" + +#. translators: 1. Link to jump to 'Order actions' metabox 2. Text 'Order actions' 3. Text 'arrow' +#: includes/class-wc-sc-display-coupons.php:2107 +msgctxt "Generated coupons metabox - Order edit admin page" +msgid "Coupons are not generated for this order. You can regenerate it from %1$s. Select an appropriate action from the %2$s dropdown menu and hit the %3$s button next to it." +msgstr "" + +#. translators: 1. Link to jump to 'Order actions' metabox 2. Text 'Order actions' 3. Text 'arrow' +#: includes/class-wc-sc-display-coupons.php:2107 +msgctxt "Generated coupons metabox - Order edit admin page" +msgid "Order actions" +msgstr "" + +#. translators: 1. Label for Order action for regenerating coupons +#: includes/class-wc-sc-display-coupons.php:2120 +msgctxt "Generated coupons metabox - Order edit admin page" +msgid "Select %s to only regenerate coupons. No email will be sent for this." +msgstr "" + +#. translators: 1. Label for Order action for regenerating & resending coupons +#: includes/class-wc-sc-display-coupons.php:2130 +msgctxt "Generated coupons metabox - Order edit admin page" +msgid "Select %s to regenerate as well as resend coupons to the recipients via email." +msgstr "" + +#: includes/class-wc-sc-admin-coupons-dashboard-actions.php:118 +msgid "Get shareable link" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:389 +msgid "Getting 'Page Not Found Error' when accessing Coupons tab from My Account Page?" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:298 +msgid "Gift a product via coupon" +msgstr "" + +#: includes/emails/class-wc-sc-email-coupon.php:355 +#: includes/emails/class-wc-sc-email-coupon.php:479 +msgid "Gift Card" +msgstr "" + +#: includes/emails/class-wc-sc-acknowledgement-email.php:336 +#: templates/acknowledgement-email.php:61 +#: templates/plain/acknowledgement-email.php:51 +msgid "Gift card" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5852 +msgid "Gift Card discount is inclusive of tax" +msgstr "" + +#: includes/emails/class-wc-sc-acknowledgement-email.php:337 +#: templates/acknowledgement-email.php:62 +#: templates/plain/acknowledgement-email.php:52 +msgid "Gift cards" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:847 +msgid "Gift to someone else" +msgstr "" + +#: includes/class-wc-sc-settings.php:610 +msgid "Give alternate singular name to Store Credit / Gift Certificate. This label will only rename Store Credit / Gift Certificate used in the Smart Coupons plugin." +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:432 +msgid "Give away a discount or credit on signing up a subscription, give away recurring discount or credits, apply credit during sign up, automatic payment for renewals from credit (Note: When using PayPal Standard Gateway, store credit can be applied only during sign up. Automatic payment for renewals by credit will not work for PayPal Standard Gateway)." +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:314 +msgid "Give bigger discounts without hurting your profits. Offer a percentage off coupon upto a particular value. Example - Flat 50% off upto $100." +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:306 +msgid "Give discounts to customers for next purchase" +msgstr "" + +#: includes/class-wc-sc-settings.php:617 +msgid "Give plural name for the above singular name." +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:179 +msgid "Glad to have you onboard. We hope WooCommerce Smart Coupons adds to your desired success 🏆" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:183 +msgid "Go To Coupons" +msgstr "Zu den Gutscheinen" + +#: includes/class-wc-sc-admin-welcome.php:390 +msgid "Go to WordPress -> Settings -> Permalinks and click on Save Settings once." +msgstr "" + +#: includes/class-wc-sc-settings.php:363 +msgid "Gold" +msgstr "" + +#: includes/class-wc-smart-coupons.php:1603 +msgid "Great News!" +msgstr "" + +#. translators: %s: link to submit idea for Smart Coupons on WooCommerce idea board +#: includes/class-wc-sc-admin-notifications.php:330 +msgid "Have a feature request? Submit it %s." +msgstr "" + +#. translators: %s: link to submit idea for Smart Coupons on WooCommerce idea board +#. translators: 1. File name 2. File download link +#: includes/class-wc-sc-admin-notifications.php:330 +#: includes/class-wc-sc-admin-welcome.php:361 +#: includes/class-wc-sc-admin-welcome.php:369 +#: includes/class-wc-sc-admin-welcome.php:395 +#: includes/class-wc-sc-background-coupon-importer.php:627 +#: includes/class-wc-sc-print-coupon.php:278 +msgid "here" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:392 +msgid "HH:MM" +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:1036 +msgid "Hi there! Upload a CSV file with coupons details to import them into your shop." +msgstr "" + +#. translators: 1: plugin name 2: page based text 3: Label for store credit 4: Hide notice text +#: includes/class-wc-sc-settings.php:903 +#: includes/class-wc-sc-settings.php:906 +msgid "Hide this notice" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:402 +msgid "How can I resend gift card coupon bought by customers?" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:435 +msgid "How does automatic payment by store credit work with Subscriptions?" +msgstr "" + +#: includes/class-wc-sc-settings.php:432 +msgid "How many coupons (at max) should be shown on cart, checkout & my account page? If set to 0 (zero) then coupons will not be displayed at all on the website." +msgstr "" + +#. translators: Documentation link for 'How to Apply Single or Multiple Coupons on Click of a Link' +#: includes/class-wc-sc-admin-welcome.php:382 +msgid "How to Apply Single or Multiple Coupons on Click of a Link" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:372 +msgid "How to change texts of the emails sent from Smart Coupons?" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:373 +msgid "How to override email template" +msgstr "" + +#. translators: Documentation link for 'How to Print Coupons' +#: includes/class-wc-sc-admin-welcome.php:420 +msgid "How to Print Coupons" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:368 +msgid "How to translate texts from Smart Coupons?" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:280 +msgid "How to use Smart Coupons the best way" +msgstr "" + +#. Plugin URI of the plugin +#: woocommerce-smart-coupons.php +msgid "https://woocommerce.com/products/smart-coupons/" +msgstr "https://woocommerce.com/products/smart-coupons/" + +#. Author URI of the plugin +#: woocommerce-smart-coupons.php +msgid "https://www.storeapps.org/" +msgstr "" + +#: includes/class-wc-sc-settings.php:1052 +msgid "Hurry. Going fast! On the entire range of products." +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:447 +msgid "I'm using WPML & WPML provides support for multi-currency, but Smart Coupons only changes currency symbol & the price value remains same. Can Smart Coupons change the currency symbol and the price value associated with it?" +msgstr "" + +#. translators: 1: ID who refunded +#: includes/class-wc-sc-coupon-refund-process.php:671 +msgid "ID: %d" +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:945 +msgid "If enabled, existing coupons that match by coupon code will be updated. Coupons that do not exist will be skipped." +msgstr "" + +#: includes/class-wc-sc-privacy.php:116 +msgid "If you are a visitor: We access your billing email address entered during purchase" +msgstr "" + +#. translators: WooCommerce My Account support link +#: includes/class-wc-sc-admin-welcome.php:476 +msgid "If you are facing any issues, please %s from your WooCommerce account." +msgstr "" + +#: includes/class-wc-sc-privacy.php:115 +msgid "If you are logged in: We access your billing email address saved in your account & billing email address entered during purchase" +msgstr "" + +#. translators: 1. File name 2. File download link +#: includes/class-wc-sc-admin-welcome.php:395 +msgid "If you want to import coupon through file, the file should be like" +msgstr "" + +#. translators: WooCommerce Subscriptions product link +#: includes/class-wc-sc-admin-welcome.php:275 +msgid "If your store is using %s and your customer has purchased a subscription using a Store Credit. If that store credit has balance left in it, store will automatically use it for renewing that subscription." +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:205 +#: includes/class-wc-sc-coupon-import.php:955 +msgid "Import" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:1184 +#: includes/class-wc-sc-background-coupon-importer.php:360 +msgid "import" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:385 +msgid "Import coupons to your store via a csv file." +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:294 +msgid "Import and export unique coupons in bulk via CSV. Share coupon codes to deal sites or email them to your customers." +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:320 +msgid "Import complete - imported" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:133 +#: includes/class-wc-sc-admin-pages.php:566 +#: includes/class-wc-sc-admin-pages.php:1587 +msgid "Import Coupons" +msgstr "Gutscheine importieren" + +#. translators: 1. Important 2. Upload path +#. translators: 1. Coupon type +#: includes/class-wc-sc-admin-notifications.php:165 +#: includes/class-wc-sc-background-coupon-importer.php:333 +#: includes/class-wc-sc-background-coupon-importer.php:400 +#: includes/class-wc-smart-coupons.php:5409 +msgid "Important" +msgstr "" + +#. translators: 1: plugin name 2: page based text 3: Label for store credit 4: Hide notice text +#: includes/class-wc-sc-settings.php:906 +msgid "Important setting" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:359 +msgid "imported" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:402 +msgid "in the background. You will be notified when it is completed." +msgstr "" + +#: includes/class-wc-sc-coupons-by-taxonomy.php:103 +#: includes/class-wc-sc-coupons-by-taxonomy.php:290 +msgid "Include" +msgstr "" + +#. translators: %s: Preview link +#: includes/class-wc-sc-settings.php:501 +msgid "Include coupon details on product's page, for products that issue coupons %s" +msgstr "" + +#. translators: %s: Preview link +#: includes/class-wc-sc-settings.php:519 +msgid "Include coupons received from other people on My Account > Coupons page %s" +msgstr "" + +#. translators: %s: Label for store credit +#: includes/class-wc-sc-settings.php:491 +msgid "Include tax in the amount of the generated %s" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5850 +msgid "Include tax in the amount of the generated gift card" +msgstr "" + +#. translators: Discount amount applied on tax +#: includes/class-wc-smart-coupons.php:2780 +msgid "includes -%s on tax" +msgstr "" + +#. translators: 1. Coupon code 2. Expiry date +#: includes/class-wc-sc-coupon-parser.php:416 +msgid "Incorrect format for expiry date of coupon \"%1$s\". Entered date is %2$s. Expected date format: YYYY-MM-DD" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5014 +msgid "Individual USe" +msgstr "" + +#: includes/class-wc-sc-shortcode.php:941 +msgid "Insert Shortcode" +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:1245 +msgid "Invalid / Used Coupons" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:790 +#: includes/class-wc-sc-purchase-credit.php:156 +msgid "Invalid amount." +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:857 +msgid "Invalid CSV file. Make sure your CSV file contains all columns, header row, and data in correct format." +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:770 +msgid "Invalid email address." +msgstr "" + +#. translators: 1. Product/s 2. Product names 3. is/are 4. Coupons code +#: includes/class-wc-sc-coupon-actions.php:504 +msgid "is" +msgid_plural "are" +msgstr[0] "" +msgstr[1] "" + +#: includes/class-wc-smart-coupons.php:5409 +msgid "is active but it will only work with WooCommerce 3.0.0+." +msgstr "" + +#: includes/class-wc-sc-coupon-message.php:436 +msgid "Is Email Coupon Message" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:423 +msgid "Is it possible to have a coupon for each variation of the variable product?" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:439 +msgid "Is it possible to partially pay for a subscription with store credit and the remainder by another method?" +msgstr "" + +#: includes/class-wc-smart-coupons.php:4653 +msgid "Is Pick Price of Product" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:427 +msgid "Is Smart Coupons compatible with WooCommerce Subscriptions?" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:443 +msgid "Is Smart Coupons WPML compatible?" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:393 +msgid "Is there any reference file for creating an import file for coupons?" +msgstr "" + +#: includes/class-wc-sc-admin-notifications.php:177 +msgid "it to use" +msgstr "" + +#: includes/class-wc-sc-settings.php:361 +msgid "Keppel" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:214 +msgid "Know Smart Coupons" +msgstr "" + +#: includes/class-wc-sc-settings.php:599 +msgid "Labels" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:545 +msgid "Later" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:1184 +msgid "later" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:365 +msgid "latest version of Smart Coupons" +msgstr "" + +#: includes/class-wc-sc-admin-notifications.php:243 +msgid "leaving a review" +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:2218 +#: includes/class-wc-sc-display-coupons.php:2229 +msgid "Less details" +msgstr "Weniger Details" + +#. translators: 1: Affiliate For WooCommerce 2: Smart Manager 3: Smart Offers +#: includes/class-wc-sc-admin-welcome.php:287 +msgid "Let customers purchase gift cards from you or you issue store credit that your users can redeem on the current or next purchase. See how: %1$s or %2$s" +msgstr "" + +#. translators: %s: link to review WooCommerce Smart Coupons +#: includes/class-wc-sc-admin-notifications.php:304 +msgid "Liked WooCommerce Smart Coupons? Leave us a %s. A huge thank you from WooCommerce & StoreApps in advance!" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5023 +msgid "Limit Usage to X Items" +msgstr "" + +#: includes/class-wc-smart-coupons.php:1606 +msgid "Limited Time Offer!" +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:2168 +msgid "List of coupons & their details which you have received from the store. Click on the coupon to see the details." +msgstr "Liste aller Gutscheine und deren Details, die Du erhalten hast. Klicke auf einen Gutschein, um die Details zu sehen." + +#: includes/class-wc-sc-display-coupons.php:978 +msgid "List of coupons which are valid & available for use. Click on the coupon to use it. The coupon discount will be visible only when at least one product is present in the cart." +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:1260 +msgid "List of coupons which can not be used. The reason can be based on its usage restrictions, usage limits, expiry date." +msgstr "" + +#: includes/class-wc-sc-coupons-by-excluded-email.php:107 +msgid "List of excluded billing emails to check against when an order is placed. Separate email addresses with commas. You can also use an asterisk (*) to match parts of an email. For example \"*@gmail.com\" would match all gmail addresses." +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:233 +msgid "Load the customer's billing information? This will remove any currently entered billing information." +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:234 +msgid "Load the customer's shipping information? This will remove any currently entered shipping information." +msgstr "" + +#: includes/class-wc-sc-coupons-by-location.php:207 +msgid "Locations" +msgstr "" + +#: includes/class-wc-sc-coupons-by-location.php:493 +msgid "Locations lookup in" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:369 +msgid "Loco Translate" +msgstr "" + +#: includes/class-wc-sc-settings.php:364 +msgid "Majorelle Blue" +msgstr "" + +#: includes/class-wc-sc-admin-coupons-dashboard-actions.php:123 +msgid "Make a duplicate from this coupon" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:318 +msgid "Make customer's coupon usage, easy & simple" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:355 +msgid "Make sure use of coupon is enabled in your store. You can find this setting" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:365 +msgid "Make sure you are using the " +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:1302 +#: includes/class-wc-sc-coupon-categories.php:105 +#: includes/class-wc-sc-coupon-categories.php:165 +#: includes/class-wc-smart-coupons.php:4261 +msgid "Manage coupon categories" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:1615 +msgid "Marketing" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:407 +#: includes/class-wc-smart-coupons.php:4657 +msgid "Max discount" +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:1075 +msgid "Maximum file size" +msgstr "" + +#: includes/class-wc-sc-coupons-by-product-quantity.php:135 +msgid "Maximum quantity" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5013 +msgid "Maximum Spend" +msgstr "" + +#: includes/class-wc-sc-settings.php:362 +msgid "McDonald" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5001 +msgid "Menu Order" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:815 +#: includes/class-wc-sc-admin-pages.php:1229 +#: includes/class-wc-sc-display-coupons.php:2464 +#: includes/class-wc-sc-display-coupons.php:2497 +#: includes/class-wc-sc-privacy.php:608 +msgid "Message" +msgstr "" + +#: templates/plain/combined-email.php:75 +#: templates/plain/email.php:26 +msgid "Message:" +msgstr "Nachricht:" + +#: includes/class-wc-sc-coupons-by-product-quantity.php:131 +msgid "Minimum quantity" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5012 +msgid "Minimum Spend" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:442 +msgid "Months" +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:2220 +#: includes/class-wc-sc-display-coupons.php:2232 +#: includes/class-wc-sc-display-coupons.php:2335 +msgid "More details" +msgstr "Mehr Details" + +#: includes/class-wc-sc-settings.php:667 +msgid "My Account page" +msgstr "" + +#: includes/class-wc-sc-privacy.php:820 +msgid "N/A" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:222 +msgid "Name" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:1109 +msgid "Need a lot of coupons? You can easily do that with Smart Coupons." +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:297 +#: includes/class-wc-sc-display-coupons.php:885 +#: includes/class-wc-sc-display-coupons.php:2442 +#: includes/class-wc-sc-shortcode.php:572 +#: includes/class-wc-smart-coupons.php:4922 +#: includes/emails/class-wc-sc-email-coupon.php:173 +#: templates/combined-email.php:158 +#: templates/email.php:156 +#: templates/plain/combined-email.php:125 +#: templates/plain/email.php:120 +#: templates/print-coupons-default.php:176 +msgid "Never expires" +msgstr "Kein Ablaufdatum" + +#: includes/class-wc-sc-admin-notifications.php:240 +#: includes/class-wc-sc-print-coupon.php:275 +msgid "Never show again" +msgstr "" + +#: includes/class-wc-sc-coupon-categories.php:97 +msgid "New coupon category name" +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:945 +msgid "New feature" +msgstr "" + +#: includes/class-wc-sc-coupon-categories.php:98 +msgid "No coupon categories found" +msgstr "" + +#: includes/class-wc-sc-shortcode.php:827 +msgid "No coupon code found." +msgstr "" + +#: includes/class-wc-sc-admin-coupons-dashboard-actions.php:266 +msgid "No coupon to duplicate has been supplied!" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:238 +msgid "No customer selected" +msgstr "" + +#: includes/class-wc-sc-coupons-by-product-quantity.php:136 +#: includes/class-wc-sc-coupons-by-product-quantity.php:158 +#: includes/class-wc-sc-coupons-by-product-quantity.php:196 +#: includes/class-wc-sc-coupons-by-product-quantity.php:226 +#: includes/class-wc-sc-coupons-by-product-quantity.php:238 +msgid "No maximum" +msgstr "" + +#: includes/class-wc-sc-coupons-by-product-quantity.php:132 +#: includes/class-wc-sc-coupons-by-product-quantity.php:157 +#: includes/class-wc-sc-coupons-by-product-quantity.php:195 +#: includes/class-wc-sc-coupons-by-product-quantity.php:225 +#: includes/class-wc-sc-coupons-by-product-quantity.php:237 +msgid "No minimum" +msgstr "" + +#: includes/class-wc-sc-coupons-by-payment-method.php:105 +msgid "No payment methods" +msgstr "" + +#: includes/class-wc-sc-coupons-by-product-attribute.php:182 +#: includes/class-wc-sc-coupons-by-product-attribute.php:201 +msgid "No product attributes" +msgstr "" + +#: includes/class-wc-sc-coupons-by-excluded-email.php:106 +msgid "No restrictions" +msgstr "" + +#: includes/class-wc-sc-shortcode.php:805 +#: includes/class-wc-sc-shortcode.php:846 +#: includes/class-wc-sc-shortcode.php:883 +msgid "No search term specified." +msgstr "" + +#: includes/class-wc-sc-coupons-by-shipping-method.php:107 +msgid "No shipping methods" +msgstr "" + +#: includes/class-wc-sc-coupons-by-user-role.php:117 +#: includes/class-wc-sc-coupons-by-user-role.php:134 +msgid "No user roles" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:440 +msgid "No, this is possible only in those cases where subscription amount is more than store credit's balance. If store credit's balance is more than subscription's total then your bank account or credit card will not be charged." +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:377 +msgid "No. Coupon code should not have any spaces in the name, Eg, Coupon code should be “gift-certificate” & not “gift certificate”." +msgstr "" + +#: includes/class-wc-sc-coupon-refund-process.php:513 +msgid "Nonce verification failed for action \"wc_sc_refund_store_credit\"." +msgstr "" + +#. translators: Excluded product names +#: includes/class-wc-smart-coupons.php:1251 +msgid "Not valid for %s" +msgstr "" + +#. translators: 1: The category names excluded +#: includes/class-wc-smart-coupons.php:1265 +msgid "Not valid for category %s" +msgid_plural "Not valid for categories %s" +msgstr[0] "" +msgstr[1] "" + +#. translators: Formatted maximum amount +#: includes/class-wc-smart-coupons.php:1239 +msgid "Not valid for sale items" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:444 +msgid "Not yet, but this is being worked on. You will find this in later versions." +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:1038 +msgid "Note: If any coupon from the CSV file already exists in the store, it will not update the existing coupon, instead a new coupon will be imported & the previous coupon with the same code will become inactive." +msgstr "" + +#: includes/class-wc-sc-admin-notifications.php:456 +msgid "Note: WP CRON has been disabled on your install which may prevent this update from completing." +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:535 +msgid "Now" +msgstr "" + +#: includes/class-wc-sc-settings.php:440 +#: includes/class-wc-smart-coupons.php:5848 +msgid "Number of characters in auto-generated coupon code" +msgstr "" + +#: includes/class-wc-sc-settings.php:441 +msgid "Number of characters in auto-generated coupon code will be restricted to this number excluding prefix and/or suffix. The default length will be 13. It is recommended to keep this number between 10 to 15 to avoid coupon code duplication." +msgstr "" + +#. translators: 1: Path to setting 2: Setting to set email address 3: Setting for number of coupons to generate +#: includes/class-wc-sc-admin-pages.php:1159 +#: includes/class-wc-sc-admin-pages.php:1200 +msgid "Number of coupons to generate" +msgstr "" + +#: includes/class-wc-sc-settings.php:431 +#: includes/class-wc-smart-coupons.php:5847 +msgid "Number of coupons to show" +msgstr "" + +#: includes/class-wc-sc-settings.php:369 +msgid "Ocean" +msgstr "" + +#. translators: 1. Coupon type 2. Coupon amount +#: includes/class-wc-sc-purchase-credit.php:997 +msgid "of" +msgstr "" + +#: templates/acknowledgement-email.php:53 +msgid "on" +msgstr "an" + +#: includes/class-wc-sc-settings.php:657 +msgid "On Cart/Checkout pages" +msgstr "" + +#: includes/class-wc-sc-product-columns.php:235 +msgid "Open in a new tab" +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:1076 +msgid "OR" +msgstr "" + +#: includes/class-wc-sc-coupon-process.php:1850 +msgctxt "Order edit admin page" +msgid "Coupon details manually sent." +msgstr "" + +#: includes/class-wc-sc-coupon-process.php:1845 +msgctxt "Order edit admin page" +msgid "Coupons manually regenerated & sent." +msgstr "" + +#: includes/class-wc-sc-coupon-process.php:1843 +msgctxt "Order edit admin page" +msgid "Coupons manually regenerated." +msgstr "" + +#: includes/class-wc-sc-coupon-process.php:1816 +msgctxt "Order edit admin page" +msgid "Regenerate & resend coupon emails" +msgstr "" + +#: includes/class-wc-sc-coupon-process.php:1815 +msgctxt "Order edit admin page" +msgid "Regenerate coupons" +msgstr "" + +#: includes/class-wc-sc-coupon-process.php:1813 +msgctxt "Order edit admin page" +msgid "Resend coupon emails" +msgstr "" + +#. translators: %s: singular name for store credit +#: includes/compat/class-wcs-sc-compatibility.php:894 +msgid "Order paid by %s" +msgstr "" + +#. translators: %s: singular name for store credit +#: includes/compat/class-wcs-sc-compatibility.php:894 +msgid "Order paid by store credit." +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:1633 +msgid "Original amount" +msgstr "" + +#: includes/class-wc-sc-admin-notifications.php:243 +msgid "our support team" +msgstr "" + +#: includes/class-wc-sc-print-coupon.php:123 +msgctxt "Page slug" +msgid "wc-sc-coupons-terms" +msgstr "" + +#: includes/class-wc-sc-print-coupon.php:124 +msgctxt "Page title" +msgid "Smart Coupons Terms" +msgstr "" + +#: includes/class-wc-sc-coupon-categories.php:92 +msgid "Parent coupon category" +msgstr "" + +#: includes/class-wc-sc-coupon-categories.php:93 +msgid "Parent coupon category:" +msgstr "" + +#. translators: 1. The coupon code 2. The text 'payment method/s' 3. List of payment method names 4. Link to the checkout page +#: includes/class-wc-sc-coupons-by-payment-method.php:210 +#: includes/class-wc-sc-coupons-by-payment-method.php:214 +msgid "payment method" +msgid_plural "payment methods" +msgstr[0] "" +msgstr[1] "" + +#: includes/class-wc-sc-coupons-by-payment-method.php:104 +#: includes/class-wc-sc-coupons-by-payment-method.php:233 +msgid "Payment methods" +msgstr "" + +#: includes/class-wc-sc-coupons-by-payment-method.php:115 +msgid "Payment methods that must be selected during checkout for this coupon to be valid." +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:890 +#: includes/class-wc-sc-purchase-credit.php:1003 +msgid "Pick a delivery date & time" +msgstr "" + +#. translators: 1. The discount text +#: includes/class-wc-smart-coupons.php:1621 +msgid "Pick any item today for %s off." +msgstr "" + +#: includes/class-wc-sc-admin-notifications.php:243 +msgid "Please consider" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:1028 +msgid "Please enter a valid value for Number of Coupons to Generate" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:201 +msgid "Please enter in a value less than the regular price." +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:200 +msgid "Please enter in country code with two capital letters." +msgstr "" + +#. translators: Decimal point +#: includes/class-wc-sc-admin-pages.php:197 +msgid "Please enter in decimal (%s) format without thousand separators." +msgstr "" + +#. translators: Decimal point +#: includes/class-wc-sc-admin-pages.php:199 +msgid "Please enter in monetary decimal (%s) format without thousand separators and currency symbols." +msgstr "" + +#: includes/class-wc-smart-coupons.php:4244 +msgid "Please select at least one coupon to print." +msgstr "" + +#: includes/class-wc-sc-coupons-by-product-quantity.php:210 +#: includes/class-wc-sc-coupons-by-product-quantity.php:255 +msgid "Please select some categories" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:216 +msgid "Please select some items." +msgstr "" + +#: includes/class-wc-sc-coupons-by-product-quantity.php:171 +#: includes/class-wc-sc-coupons-by-product-quantity.php:247 +msgid "Please select some products" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:677 +msgid "Please try again later." +msgstr "" + +#: includes/class-wc-smart-coupons.php:5409 +msgid "Please update WooCommerce to the latest version" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:369 +msgid "plugin and then following steps listed " +msgstr "" + +#: includes/class-wc-sc-settings.php:618 +msgid "Plural name" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5002 +msgid "Post Date" +msgstr "" + +#: includes/class-wc-smart-coupons.php:4998 +msgid "Post Excerpt" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5000 +msgid "Post Parent" +msgstr "" + +#: includes/class-wc-smart-coupons.php:4999 +msgid "Post Status" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:481 +msgid "Prefix" +msgstr "" + +#: includes/class-wc-sc-settings.php:209 +#: includes/class-wc-sc-shortcode.php:892 +msgid "Preview" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:830 +#: includes/class-wc-sc-admin-pages.php:1244 +msgid "Preview Email" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5866 +msgid "Prices entered with tax" +msgstr "" + +#: includes/class-wc-smart-coupons.php:4259 +msgid "Print" +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:1120 +#: templates/combined-email.php:228 +#: templates/email.php:209 +msgid "Print coupon" +msgid_plural "Print coupons" +msgstr[0] "" +msgstr[1] "" + +#: includes/class-wc-smart-coupons.php:4259 +msgid "Print selected coupons" +msgstr "" + +#: includes/class-wc-sc-settings.php:574 +#: includes/class-wc-smart-coupons.php:5855 +msgid "Printing coupons" +msgstr "" + +#. translators: 1. Product/s 2. Product names 3. is/are 4. Coupons code +#: includes/class-wc-sc-coupon-actions.php:504 +#: includes/class-wc-sc-coupons-by-product-quantity.php:124 +msgid "Product" +msgid_plural "Products" +msgstr[0] "" +msgstr[1] "" + +#. translators: 1. Singular/plural label for product(s) 2. Excluded product names +#: includes/class-wc-sc-coupons-by-product-attribute.php:525 +#: includes/class-wc-sc-coupons-by-taxonomy.php:729 +msgid "product" +msgid_plural "products" +msgstr[0] "" +msgstr[1] "" + +#: includes/class-wc-sc-coupons-by-product-attribute.php:545 +msgid "Product Attributes" +msgstr "" + +#: includes/class-wc-sc-coupons-by-product-attribute.php:181 +msgid "Product attributes" +msgstr "" + +#. translators: Non product type coupon labels +#: includes/class-wc-sc-coupons-by-product-attribute.php:193 +msgid "Product attributes that the coupon will be applied to, or that need to be in the cart in order for the %s to be applied." +msgstr "" + +#. translators: Non product type coupon labels +#: includes/class-wc-sc-coupons-by-product-attribute.php:212 +msgid "Product attributes that the coupon will not be applied to, or that cannot be in the cart in order for the %s to be applied." +msgstr "" + +#: includes/class-wc-smart-coupons.php:5018 +msgid "Product categories" +msgstr "" + +#: includes/class-wc-sc-ajax.php:342 +#: includes/class-wc-sc-ajax.php:347 +#: includes/class-wc-smart-coupons.php:1153 +#: includes/class-wc-smart-coupons.php:1158 +msgid "Product Discount" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5016 +msgid "Product IDs" +msgstr "" + +#: includes/class-wc-sc-coupons-by-product-quantity.php:115 +#: includes/class-wc-sc-coupons-by-product-quantity.php:663 +msgid "Product quantity based restrictions" +msgstr "" + +#: includes/class-wc-sc-coupons-by-taxonomy.php:183 +msgid "Product taxonomies that the coupon will be applicable for, or its availability in the cart in order for the \"Fixed cart discount\" to be applied, based on whether the taxonomies are included or excluded." +msgstr "" + +#: includes/class-wc-sc-coupons-by-taxonomy.php:142 +msgid "Product taxonomies that the coupon will be applicable for, or its availability in the cart in order for the \"Fixed cart discount\" to be applied, based on whether the taxonomies are included or excluded. All the taxonomies selected here, should be valid, for this coupon to be valid." +msgstr "" + +#: includes/class-wc-sc-coupons-by-product-quantity.php:153 +#: includes/class-wc-sc-coupons-by-product-quantity.php:169 +#: includes/class-wc-sc-coupons-by-product-quantity.php:245 +#: includes/class-wc-sc-coupons-by-product-quantity.php:260 +msgid "Products" +msgstr "Produkte" + +#: includes/class-wc-sc-background-coupon-importer.php:405 +msgid "Progress" +msgstr "" + +#: includes/class-wc-sc-settings.php:400 +msgid "Promotion" +msgstr "" + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-purchase-credit.php:218 +msgid "Purchase %s worth" +msgstr "" + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-purchase-credit.php:218 +#: includes/class-wc-sc-settings.php:642 +msgid "Purchase credit worth" +msgstr "" + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-admin-pages.php:727 +msgid "Quickly create and email %s to one or more people." +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:729 +msgid "Quickly create and email Store Credit or Gift Card to one or more people." +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:1039 +msgid "Ready to import? Choose a .csv file, then click \"Upload file\"." +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:2462 +#: includes/class-wc-sc-display-coupons.php:2496 +msgid "Receiver" +msgstr "Empfänger" + +#: includes/compat/class-wcs-sc-compatibility.php:951 +msgid "Recurring subscriptions" +msgstr "" + +#. translators: 1: refund id 2: refund date +#: includes/class-wc-sc-coupon-refund-process.php:678 +msgid "Refund %1$s - %2$s" +msgstr "" + +#. translators: 1: refund id 2: refund date 3: username +#: includes/class-wc-sc-coupon-refund-process.php:665 +msgid "Refund %1$s - %2$s by %3$s" +msgstr "" + +#: includes/class-wc-sc-coupon-refund-process.php:213 +msgid "Refund to Store Credit" +msgstr "" + +#: includes/class-wc-sc-admin-notifications.php:239 +msgid "Remind me after a month" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:223 +msgid "Remove" +msgstr "" + +#: includes/class-wc-sc-coupons-by-taxonomy.php:219 +msgid "Remove taxonomy restriction" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:221 +msgid "Remove this attribute?" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:220 +msgid "Remove this item meta?" +msgstr "" + +#: includes/class-wc-sc-privacy.php:324 +msgid "Removed Coupon Personal Data" +msgstr "" + +#: includes/class-wc-sc-privacy.php:734 +msgid "Removed Order Personal Data" +msgstr "" + +#: includes/class-wc-sc-privacy.php:443 +msgid "Removed User Personal Data" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5858 +#: includes/compat/class-wcs-sc-compatibility.php:961 +msgid "Renewal orders should not generate coupons even when they include a product that issues coupons" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:1159 +msgid "Required" +msgstr "" + +#: blocks/class-wc-sc-extend-store-endpoint.php:133 +msgctxt "REST API" +msgid "Coupons scheduled date & time" +msgstr "" + +#: blocks/class-wc-sc-extend-store-endpoint.php:118 +msgctxt "REST API" +msgid "Email address of recipients" +msgstr "" + +#: blocks/class-wc-sc-extend-store-endpoint.php:148 +msgctxt "REST API" +msgid "Message for coupon recipient" +msgstr "" + +#: blocks/class-wc-sc-extend-store-endpoint.php:106 +msgctxt "REST API" +msgid "Whether to send coupons now or schedule for later." +msgstr "" + +#: blocks/class-wc-sc-extend-store-endpoint.php:94 +msgctxt "REST API" +msgid "Whether to send coupons to only one person or multiple people." +msgstr "" + +#: blocks/class-wc-sc-extend-store-endpoint.php:81 +msgctxt "REST API" +msgid "Whether to send coupons to someone else." +msgstr "" + +#: includes/class-wc-sc-privacy.php:816 +msgid "Retain Store Credit/Gift Certificate" +msgstr "" + +#: includes/class-wc-sc-admin-notifications.php:103 +msgid "Review" +msgstr "" + +#: includes/class-wc-sc-coupons-by-user-role.php:145 +msgid "Role of the users for whom this coupon is not valid. Keep empty if you want this coupon to be valid for users with any role." +msgstr "" + +#: includes/class-wc-sc-coupons-by-user-role.php:128 +msgid "Role of the users for whom this coupon is valid. Keep empty if you want this coupon to be valid for users with any role." +msgstr "" + +#: includes/class-wc-sc-settings.php:365 +msgid "Rose Pink" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5869 +msgid "Rounding" +msgstr "" + +#: includes/emails/class-wc-sc-acknowledgement-email.php:116 +msgid "Scheduled email heading" +msgstr "" + +#: includes/emails/class-wc-sc-acknowledgement-email.php:108 +msgid "Scheduled email subject" +msgstr "" + +#: includes/class-wc-sc-settings.php:474 +msgid "Search & select a coupon which you want to display as store notice. The selected coupon's description will be displayed along with the coupon code (if it is set) otherwise, a description will be generated automatically. To disable the feature, keep this field empty." +msgstr "" + +#: includes/class-wc-sc-coupon-categories.php:90 +msgid "Search coupon categories" +msgstr "" + +#: includes/class-wc-sc-shortcode.php:879 +msgid "Search coupon..." +msgstr "" + +#: includes/class-wc-sc-product-fields.php:100 +#: includes/class-wc-sc-product-fields.php:161 +msgid "Search for a coupon…" +msgstr "" + +#: includes/class-wc-sc-settings.php:480 +msgid "Search for a coupon..." +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:967 +#: includes/class-wc-sc-coupon-fields.php:994 +msgid "Search for a product…" +msgstr "" + +#: includes/class-wc-sc-settings.php:211 +msgid "See coupon search limitations" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:294 +#: includes/class-wc-sc-admin-welcome.php:300 +#: includes/class-wc-sc-admin-welcome.php:308 +#: includes/class-wc-sc-admin-welcome.php:403 +msgid "See how" +msgstr "" + +#: includes/class-wc-sc-coupons-by-location.php:282 +msgid "Select Additional Locations" +msgstr "" + +#: includes/class-wc-sc-coupons-by-location.php:219 +msgid "Select location" +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:722 +#: includes/class-wc-sc-settings.php:630 +#: includes/class-wc-smart-coupons.php:296 +msgid "Select options" +msgstr "" + +#: includes/class-wc-sc-settings.php:465 +msgid "Select order status…" +msgstr "" + +#. translators: %s: Label for store credit +#: includes/class-wc-sc-settings.php:584 +msgid "Sell %s at less price?" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5856 +msgid "Sell gift cards at less price?" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:283 +msgid "Sell or issue store credit / gift cards" +msgstr "" + +#. translators: 1. Coupon type 2. Coupon amount +#: includes/class-wc-sc-admin-pages.php:824 +#: includes/class-wc-sc-purchase-credit.php:997 +msgid "Send" +msgstr "" + +#. translators: %s: singular name for store credit +#. translators: Store Credit label +#: includes/class-wc-sc-admin-pages.php:143 +#: includes/class-wc-sc-admin-pages.php:579 +#: includes/class-wc-sc-admin-pages.php:1591 +msgid "Send %s" +msgstr "" + +#: includes/emails/class-wc-sc-acknowledgement-email.php:42 +msgid "Send an acknowledgement email to the purchaser. One email per customer." +msgstr "" + +#: includes/class-wc-sc-product-fields.php:127 +#: includes/class-wc-sc-product-fields.php:186 +msgid "Send coupons on renewals?" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:820 +#: includes/class-wc-sc-settings.php:702 +msgid "Send Coupons to..." +msgstr "" + +#: includes/class-wc-sc-settings.php:727 +msgid "Send only one email instead of multiple emails when multiple coupons are generated for same recipient" +msgstr "" + +#: includes/emails/class-wc-sc-combined-email-coupon.php:35 +msgid "Send only one email instead of multiple emails when multiple coupons are generated per recipient." +msgstr "" + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-admin-pages.php:143 +#: includes/class-wc-sc-admin-pages.php:579 +msgid "Send Store Credit" +msgstr "" + +#. translators: 1: Path to setting 2: Setting to set email address 3: Setting for number of coupons to generate +#: includes/class-wc-sc-admin-pages.php:762 +#: includes/class-wc-sc-admin-pages.php:1200 +#: includes/class-wc-sc-admin-pages.php:1218 +msgid "Send to" +msgstr "Senden an" + +#: includes/class-wc-sc-purchase-credit.php:850 +msgid "Send to different people" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:845 +msgid "Send to me" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:849 +msgid "Send to one person" +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:2461 +#: includes/class-wc-sc-display-coupons.php:2498 +msgid "Sender" +msgstr "Absender" + +#: includes/class-wc-sc-background-coupon-importer.php:590 +msgid "sent" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:312 +msgid "Set a maximum discount limit" +msgstr "" + +#: includes/class-wc-sc-settings.php:347 +msgid "Set up Smart Coupons the way you like. Use these options to configure/change the way Smart Coupons works." +msgstr "" + +#. translators: 1: plugin name 2: page based text 3: Label for store credit 4: Hide notice text +#: includes/class-wc-sc-settings.php:903 +#: includes/class-wc-sc-settings.php:906 +msgid "Setting" +msgstr "" + +#: includes/class-wc-sc-admin-notifications.php:165 +msgid "Setting \"Enable the use of coupon codes\" is disabled." +msgstr "" + +#: includes/class-wc-sc-admin-notifications.php:99 +#: includes/class-wc-sc-admin-welcome.php:197 +msgid "Settings" +msgstr "" + +#: includes/class-wc-sc-settings.php:404 +msgid "Shipment" +msgstr "" + +#: includes/class-wc-sc-coupons-by-location.php:203 +msgid "Shipping" +msgstr "" + +#: includes/class-wc-sc-coupons-by-location.php:478 +msgid "shipping address" +msgstr "" + +#: includes/class-wc-sc-coupons-by-location.php:495 +msgid "Shipping Locations" +msgstr "" + +#: includes/class-wc-sc-coupons-by-shipping-method.php:106 +#: includes/class-wc-sc-coupons-by-shipping-method.php:224 +msgid "Shipping methods" +msgstr "Versandarten" + +#: includes/class-wc-sc-coupons-by-shipping-method.php:117 +msgid "Shipping methods that must be selected during checkout for this coupon to be valid." +msgstr "" + +#. translators: %s: Preview link +#: includes/class-wc-sc-settings.php:510 +msgid "Show coupons available to customers on their My Account > Coupons page %s" +msgstr "" + +#. translators: %s: Preview link +#: includes/class-wc-sc-settings.php:528 +msgid "Show invalid or used coupons in My Account > Coupons %s" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:497 +msgid "Show on cart, checkout" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:320 +msgid "Show only valid coupons to your customer (if logged in) on cart, checkout & My Account page. Coupons can be applied with single click. So, no need to remember the coupon code or copy-pasting." +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:369 +msgid "Simplest method is by installing" +msgstr "" + +#: includes/class-wc-sc-settings.php:609 +msgid "Singular name" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:617 +msgid "Skipped" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:320 +msgid "skipped" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:521 +#: includes/class-wc-sc-admin-pages.php:523 +msgid "Smart Coupon" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:364 +msgid "Smart Coupon's fields are broken?" +msgstr "" + +#: includes/class-wc-sc-settings.php:94 +#: includes/blocks/sc-gutenberg-block.js:43 +msgid "Smart Coupons" +msgstr "" + +#: includes/emails/class-wc-sc-acknowledgement-email.php:41 +msgid "Smart Coupons - Acknowledgement email" +msgstr "" + +#: includes/emails/class-wc-sc-email-coupon.php:34 +msgid "Smart Coupons - Auto generated coupon email" +msgstr "" + +#: includes/emails/class-wc-sc-combined-email-coupon.php:34 +msgid "Smart Coupons - Combined auto generated coupons email" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:255 +msgid "Smart Coupons enable coupons to become an automatic/interactive system." +msgstr "" + +#: includes/class-wc-sc-print-coupon.php:278 +msgid "Smart Coupons has created a coupon's terms page (used during coupon printing) for you. Please edit it as required from" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:254 +msgid "Smart Coupons is a powerful extension, built on top of WooCommerce coupons. It adds a new discount type - Store Credit - and advanced functionality to the default coupons." +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:410 +msgid "Smart Coupons is not sending emails." +msgstr "" + +#: includes/class-wc-smart-coupons.php:5883 +msgid "Smart Coupons related settings" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:411 +msgid "Smart Coupons sends email only after order completion. So make sure that order complete email is enabled and sending. If enabled, then make sure all settings of coupons, products are in place. Also check by switching your theme." +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:152 +#: includes/class-wc-sc-admin-pages.php:595 +#: includes/class-wc-sc-settings.php:345 +msgid "Smart Coupons Settings" +msgstr "" + +#: includes/class-wc-sc-admin-notifications.php:266 +msgid "Smart Coupons settings" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:399 +msgid "Smart Coupons uses hooks of Cart, Checkout & My Account page to display available coupons. If your theme is not using those hooks in cart, checkout & my-account template, coupons will not be displayed." +msgstr "" + +#: includes/class-wc-sc-admin-notifications.php:243 +msgid "so far?" +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:606 +#: includes/class-wc-sc-display-coupons.php:615 +#: includes/class-wc-sc-display-coupons.php:624 +msgid "some products" +msgstr "" + +#: includes/class-wc-smart-coupons.php:6507 +#: includes/class-wc-smart-coupons.php:6561 +#: includes/class-wc-smart-coupons.php:6590 +#: includes/class-wc-smart-coupons.php:6614 +msgid "Some values required for $item_id & $item_key" +msgstr "" + +#: includes/class-wc-smart-coupons.php:6122 +#: includes/class-wc-smart-coupons.php:6237 +#: includes/class-wc-smart-coupons.php:6351 +msgid "Some values required for $post_id & $meta_key" +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:925 +#: includes/class-wc-sc-display-coupons.php:981 +msgid "Sorry, No coupons available for you." +msgstr "Keine Gutscheine verfügbar." + +#: includes/class-wc-sc-coupon-import.php:702 +#: includes/class-wc-sc-coupon-import.php:758 +#: includes/class-wc-sc-coupon-import.php:770 +msgid "Sorry, there has been an error." +msgstr "" + +#: includes/class-wc-sc-coupons-by-product-attribute.php:491 +#: includes/class-wc-sc-coupons-by-taxonomy.php:700 +msgid "Sorry, this coupon is not applicable to selected products." +msgstr "" + +#. translators: 1. Singular/plural label for product(s) 2. Excluded product names +#: includes/class-wc-sc-coupons-by-product-attribute.php:525 +#: includes/class-wc-sc-coupons-by-taxonomy.php:729 +msgid "Sorry, this coupon is not applicable to the %1$s: %2$s." +msgstr "" + +#: includes/class-wc-sc-settings.php:367 +msgid "Spanish Orange" +msgstr "" + +#: includes/class-wc-sc-settings.php:403 +msgid "Special" +msgstr "" + +#. translators: Formatted minimum amount +#: includes/class-wc-smart-coupons.php:1231 +msgid "Spend at least %s" +msgstr "" + +#. translators: Formatted maximum amount +#: includes/class-wc-smart-coupons.php:1235 +msgid "Spend up to %s" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:407 +msgid "Stop" +msgstr "" + +#. translators: Store Credit label +#: includes/class-wc-sc-admin-pages.php:1426 +#: includes/class-wc-sc-admin-pages.php:1436 +#: includes/class-wc-sc-admin-pages.php:1591 +#: includes/class-wc-sc-ajax.php:332 +#: includes/class-wc-sc-coupon-refund-process.php:666 +#: includes/class-wc-sc-coupon-refund-process.php:679 +#: includes/class-wc-smart-coupons.php:1143 +#: includes/emails/class-wc-sc-email-coupon.php:357 +#: includes/emails/class-wc-sc-email-coupon.php:481 +msgid "Store Credit" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:589 +msgid "Store credit" +msgstr "" + +#: includes/class-wc-sc-settings.php:301 +#: includes/compat/class-wcs-sc-compatibility.php:947 +msgid "store credit" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:602 +msgid "store credit / gift card" +msgstr "" + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-order-fields.php:501 +msgid "Store Credit / Gift Card Balance" +msgstr "Shop-Guthaben / Geschenkkarten-Guthaben" + +#: includes/class-wc-sc-coupon-fields.php:1359 +#: includes/class-wc-sc-settings.php:605 +msgid "Store Credit / Gift Certificate" +msgstr "" + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-admin-pages.php:672 +msgid "Store Credit / Gift Certificate sent successfully." +msgstr "" + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-display-coupons.php:591 +msgid "Store Credit of " +msgstr "" + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-order-fields.php:197 +msgid "Store Credit Used" +msgstr "Verbrauchtes Gutschein-Guthaben" + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-order-fields.php:254 +msgid "Store Credit Used:" +msgstr "Verbrauchtes Gutschein-Guthaben:" + +#: includes/class-wc-sc-admin-welcome.php:407 +msgid "Store Credit's default behavior is auto-generate because, when using a store credit, it's balance keeps reducing. Therefore it should be uniquely created for every user automatically." +msgstr "" + +#: includes/class-wc-sc-privacy.php:112 +#: includes/class-wc-sc-privacy.php:324 +#: includes/class-wc-sc-privacy.php:443 +#: includes/class-wc-sc-privacy.php:734 +msgid "Store Credit/Gift Certificate" +msgstr "" + +#: includes/class-wc-sc-privacy.php:247 +msgid "Store Credit/Gift Certificate - Coupon Data" +msgstr "" + +#: includes/class-wc-sc-privacy.php:618 +msgid "Store Credit/Gift Certificate - Order Data" +msgstr "" + +#: includes/class-wc-sc-privacy.php:817 +msgid "Store Credit/Gift Certificate that are stored for customers via coupons. If erased, the customer will not be able to use the coupons." +msgstr "" + +#: includes/class-wc-sc-order-fields.php:341 +msgid "Store Credit:" +msgstr "Guthaben:" + +#: includes/class-wc-sc-display-coupons.php:1185 +msgid "Store Credits" +msgstr "" + +#: includes/class-wc-sc-settings.php:302 +#: includes/class-wc-sc-settings.php:896 +msgid "store credits" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:394 +msgid "Store Credits / Gift Cards" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:603 +msgid "store credits / gift cards" +msgstr "" + +#. Author of the plugin +#: woocommerce-smart-coupons.php +msgid "StoreApps" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5280 +msgid "Style 1" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5281 +msgid "Style 2" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5282 +msgid "Style 3" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5283 +msgid "Style 4" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5284 +msgid "Style 5" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5285 +msgid "Style 6" +msgstr "" + +#: includes/class-wc-sc-settings.php:420 +msgid "Style for coupon in email." +msgstr "" + +#: includes/class-wc-sc-settings.php:416 +msgid "Style for email" +msgstr "" + +#: includes/class-wc-sc-settings.php:391 +msgid "Styles" +msgstr "" + +#: includes/emails/class-wc-sc-email.php:116 +msgid "Subject" +msgstr "" + +#. translators: WooCommerce My Account support link +#: includes/class-wc-sc-admin-welcome.php:476 +msgid "submit a ticket" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:614 +msgid "Successfully" +msgstr "" + +#: includes/class-wc-sc-act-deact.php:268 +msgid "Successfully cleared WooCommerce Smart Coupons cache!" +msgstr "" + +#: includes/class-wc-sc-coupon-refund-process.php:500 +msgid "Successfully updated store credit refund details." +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:483 +msgid "Suffix" +msgstr "" + +#: includes/class-wc-smart-coupons.php:1604 +msgid "Super Savings!" +msgstr "" + +#: includes/class-wc-sc-admin-notifications.php:102 +msgid "Support" +msgstr "" + +#: includes/class-wc-sc-coupons-by-taxonomy.php:141 +#: includes/class-wc-sc-coupons-by-taxonomy.php:182 +msgid "Taxonomy" +msgstr "" + +#: includes/class-wc-sc-coupons-by-taxonomy.php:871 +msgid "Taxonomy based restrictions" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:177 +msgid "Thank you for installing WooCommerce Smart Coupons" +msgstr "" + +#: includes/class-wc-sc-rest-coupons-controller.php:147 +msgid "The coupon code already exists" +msgstr "" + +#: includes/class-wc-sc-settings.php:717 +msgid "The coupons will be sent to the recipients via email on the selected date & time" +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:1037 +msgid "The CSV must adhere to a specific format and include a header row." +msgstr "" + +#: includes/class-wc-sc-admin-notifications.php:417 +msgid "The database update process runs in the background and may take a little while, so please be patient." +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:703 +msgid "The file does not exist, please try again." +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:409 +msgid "The maximum discount this coupon can give on a cart." +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:807 +msgid "The store credit will expire at 00:00:00 of this date." +msgstr "" + +#: includes/class-wc-sc-settings.php:701 +msgid "The title for coupon receiver details block." +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:163 +msgid "The value should not be greater than" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:161 +msgid "The value should not be less than" +msgstr "" + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-admin-pages.php:676 +msgid "There has been an error in sending %s." +msgstr "" + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-admin-pages.php:676 +msgid "There has been an error in sending Store Credit / Gift Certificate." +msgstr "" + +#. translators: 1. File name 2. File download link +#: includes/class-wc-sc-admin-welcome.php:395 +msgid "There is one file which is located inside the plugin. You can download the %1$s file from %2$s." +msgstr "" + +#: includes/class-wc-sc-product-fields.php:123 +#: includes/class-wc-sc-product-fields.php:160 +msgid "These coupon/s will be given to customers who buy this product. The coupon code will be automatically sent to their email address on purchase." +msgstr "" + +#: includes/class-wc-smart-coupons.php:977 +msgid "This coupon has pending emails to be sent. Deleting it will delete those emails also. Are you sure to delete this coupon?" +msgstr "" + +#: includes/class-wc-sc-coupons-by-shipping-method.php:200 +#: includes/class-wc-sc-coupons-by-shipping-method.php:205 +msgid "This coupon is not valid for selected shipping method." +msgstr "" + +#: includes/class-wc-sc-coupons-by-excluded-email.php:239 +#: includes/class-wc-sc-coupons-by-excluded-email.php:253 +#: includes/class-wc-sc-coupons-by-user-role.php:220 +#: includes/class-wc-sc-coupons-by-user-role.php:227 +msgid "This coupon is not valid for you." +msgstr "" + +#: includes/class-wc-smart-coupons.php:3416 +msgid "This coupon is valid for the first order only." +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:415 +msgid "This form is displayed using a hook which is available in My Account template. Make sure your theme's my-account template contains all hooks required for that template. Update your theme if it is not updated." +msgstr "" + +#: includes/class-wc-sc-settings.php:651 +msgid "This is the heading above coupon details displayed on products that issue coupons." +msgstr "" + +#: includes/class-wc-sc-settings.php:661 +msgid "This is the title for the list of available coupons, shown on Cart and Checkout pages." +msgstr "" + +#: includes/class-wc-sc-order-fields.php:199 +msgid "This is the total credit used." +msgstr "Das ist der Gesamtkredit, der verwendet wird." + +#. translators: %s: Label for store credit +#: includes/class-wc-sc-settings.php:629 +msgid "This is what will be shown instead of \"Add to Cart\" for products that sell %s." +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:1000 +msgid "This much quantity of each product, selected above, will be added to cart." +msgstr "" + +#. translators: %s: $coupon_code coupon code +#: includes/class-wc-sc-url-coupon.php:347 +msgctxt "This notice will be shown on the cart or the checkout page if the coupon is already applied." +msgid "Coupon code \"%s\" already applied! Please add some products to the cart to see the discount." +msgstr "" + +#. translators: %s: $coupon_code coupon code +#: includes/class-wc-sc-url-coupon.php:343 +msgctxt "This notice will be shown on the cart or the checkout page if the coupon will be applied successfully." +msgid "Coupon code \"%s\" applied successfully. Please add some products to the cart to see the discount." +msgstr "" + +#: includes/class-wc-smart-coupons.php:5883 +msgid "This section shows settings that affects Smart Coupons' functionalities." +msgstr "" + +#: includes/class-wc-smart-coupons.php:3276 +msgid "This tool will clear the cache created by WooCommerce Smart Coupons." +msgstr "" + +#: includes/class-wc-smart-coupons.php:1607 +msgid "This Week Only!" +msgstr "" + +#: includes/class-wc-smart-coupons.php:1610 +msgid "This will be over soon! Hurry." +msgstr "" + +#. translators: %s: list of placeholders +#: includes/emails/class-wc-sc-acknowledgement-email.php:104 +msgid "This will be used when the setting \"WooCommerce > Settings > Smart Coupons > Allow schedule sending of coupons?\" is enabled. Available placeholders: %s." +msgstr "" + +#: includes/class-wc-sc-settings.php:401 +msgid "Ticket" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:393 +msgid "Time after which coupon will be expired. This will work in conjunction with Coupon expiry date." +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:352 +msgctxt "Timepicker on the admin side" +msgid "Choose Time" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:286 +msgctxt "Timepicker on the admin side" +msgid "Done" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:350 +msgctxt "Timepicker on the admin side" +msgid "HH:mm" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:354 +msgctxt "Timepicker on the admin side" +msgid "Hour" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:358 +msgctxt "Timepicker on the admin side" +msgid "Microsecond" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:357 +msgctxt "Timepicker on the admin side" +msgid "Millisecond" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:355 +msgctxt "Timepicker on the admin side" +msgid "Minute" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:285 +msgctxt "Timepicker on the admin side" +msgid "Now" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:356 +msgctxt "Timepicker on the admin side" +msgid "Second" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:353 +msgctxt "Timepicker on the admin side" +msgid "Time" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:359 +msgctxt "Timepicker on the admin side" +msgid "Time Zone" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:682 +msgctxt "Timepicker on the frontend side" +msgid "Choose Time" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:616 +msgctxt "Timepicker on the frontend side" +msgid "Done" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:680 +msgctxt "Timepicker on the frontend side" +msgid "HH:mm" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:684 +msgctxt "Timepicker on the frontend side" +msgid "Hour" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:688 +msgctxt "Timepicker on the frontend side" +msgid "Microsecond" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:687 +msgctxt "Timepicker on the frontend side" +msgid "Millisecond" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:685 +msgctxt "Timepicker on the frontend side" +msgid "Minute" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:615 +msgctxt "Timepicker on the frontend side" +msgid "Now" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:686 +msgctxt "Timepicker on the frontend side" +msgid "Second" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:683 +msgctxt "Timepicker on the frontend side" +msgid "Time" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:689 +msgctxt "Timepicker on the frontend side" +msgid "Time Zone" +msgstr "" + +#: includes/class-wc-sc-settings.php:697 +msgid "Title" +msgstr "" + +#: includes/class-wc-sc-product-columns.php:102 +msgctxt "Title for coupon column on the products page" +msgid "Linked coupons" +msgstr "" + +#: includes/class-wc-sc-settings.php:671 +msgid "Title of available coupons list on My Account page." +msgstr "" + +#: templates/acknowledgement-email.php:71 +msgid "to" +msgstr "bis" + +#: templates/combined-email.php:82 +msgid "To redeem your discount click on the following coupon(s):" +msgstr "Um den Rabatt einzulösen, klicke auf nachfolgende(n) Gutscheincode(s):" + +#: templates/plain/combined-email.php:22 +msgid "To redeem your discount use below coupon codes during checkout or copy and paste the below URLs and hit enter in your browser" +msgstr "Um deinen Gutschein einzulösen gib den Gutscheincode %s im Warenkorb während deines Einkaufes ein oder kopiere die untenstehenden URLs in deinen Browser" + +#. translators: %s: Coupon code +#: templates/email.php:85 +msgid "To redeem your discount use coupon code %s during checkout or click on the following coupon:" +msgstr "Um deinen Gutschein einlösen zu können, gib den Gutscheincode %s auf der Kasse-Seite ein oder klicke auf den folgenden Gutschein:" + +#. translators: %s: Coupon code +#: templates/plain/email.php:23 +msgid "To redeem your discount use coupon code %s during checkout or copy and paste the below URL and hit enter in your browser:" +msgstr "Um Deinen Gutschein einzulösen gebe den Gutscheincode %s im Warenkorb während Deines Einkaufes ein:" + +#: includes/class-wc-sc-admin-welcome.php:259 +msgid "Top Smart Coupons features" +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:1194 +msgid "Total Credit Amount" +msgstr "" + +#. translators: 1. Discount type 2. Discount Type Label +#: includes/class-wc-sc-ajax.php:132 +#: includes/class-wc-sc-product-fields.php:114 +#: includes/class-wc-sc-product-fields.php:175 +msgid "Type" +msgstr "" + +#. translators: 1: plugin name 2: page based text 3: Label for store credit 4: Hide notice text +#: includes/class-wc-sc-settings.php:903 +msgid "Uncheck" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:406 +msgid "Uncheck \"Auto-generate\" option in Store Credit is not saving? Is it always checked?" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:408 +msgid "Unlimited discount" +msgstr "" + +#: includes/class-wc-sc-coupon-categories.php:95 +msgid "Update coupon category" +msgstr "" + +#: includes/class-wc-sc-admin-notifications.php:430 +msgid "Update database" +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:945 +msgid "Update existing coupons" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:586 +msgid "updated" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:578 +msgid "updated & emailed" +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:1079 +msgid "Upload file" +msgstr "" + +#. translators: %s: Maximum coupon discount amount +#: includes/class-wc-sc-ajax.php:357 +msgid "upto %s" +msgstr "" + +#. translators: Documentation link for 'How to Apply Single or Multiple Coupons on Click of a Link' +#: includes/class-wc-sc-admin-welcome.php:382 +msgid "URL of coupon should be like this:" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5024 +msgid "Usage Count" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5021 +msgid "Usage Limit" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5022 +msgid "Usage Limit Per User" +msgstr "" + +#. translators: %s: Label for store credit +#: includes/compat/class-wcs-sc-compatibility.php:953 +msgid "Use %s applied in first subscription order for subsequent renewals until credit reaches zero" +msgstr "" + +#: includes/class-wc-smart-coupons.php:1637 +msgid "Use code" +msgstr "" + +#. translators: 1. The coupon code +#: includes/class-wc-smart-coupons.php:1654 +msgid "Use code: %s" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:773 +#: includes/class-wc-sc-admin-pages.php:1224 +msgid "Use comma \",\" to separate multiple email addresses" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5857 +msgid "Use gift card applied in first subscription order for subsequent renewals until credit reaches zero" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5025 +msgid "Used By" +msgstr "" + +#: includes/class-wc-sc-print-coupon.php:420 +msgid "Used during coupon printing" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:228 +msgid "Used for variations" +msgstr "" + +#: includes/class-wc-sc-coupon-columns.php:128 +msgid "Used in orders" +msgstr "" + +#: includes/class-wc-sc-coupons-by-user-role.php:243 +msgid "User Role" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:437 +msgid "Valid for" +msgstr "" + +#. translators: Product names +#: includes/class-wc-smart-coupons.php:1245 +msgid "Valid for %s" +msgstr "" + +#. translators: 1: The category names +#: includes/class-wc-smart-coupons.php:1258 +msgid "Valid for category %s" +msgid_plural "Valid for categories %s" +msgstr[0] "" +msgstr[1] "" + +#: includes/class-wc-smart-coupons.php:1287 +msgid "Valid on entire range of products. Buy anything in the store." +msgstr "Gültig für alle Produkte." + +#: includes/class-wc-sc-settings.php:455 +#: includes/class-wc-smart-coupons.php:5849 +msgid "Valid order status for auto-generating coupon" +msgstr "" + +#: includes/class-wc-sc-coupons-by-product-quantity.php:117 +msgid "Validate quantity of" +msgstr "" + +#: includes/class-wc-smart-coupons.php:4649 +msgid "Validity Suffix" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:225 +msgid "Value(s)" +msgstr "" + +#: includes/class-wc-sc-coupons-by-product-attribute.php:167 +msgid "Value=" +msgstr "" + +#. translators: 1: Affiliate For WooCommerce 2: Smart Manager 3: Smart Offers +#: includes/class-wc-sc-admin-welcome.php:287 +msgid "variable but fixed amount" +msgstr "" + +#: includes/class-wc-sc-admin-notifications.php:458 +msgid "View status" +msgstr "" + +#: includes/class-wc-sc-settings.php:366 +msgid "Vintage" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:227 +msgid "Visible on the product page" +msgstr "" + +#: templates/combined-email.php:209 +#: templates/email.php:194 +#: templates/plain/combined-email.php:131 +#: templates/plain/email.php:124 +msgid "Visit store" +msgstr "Shop besuchen" + +#: includes/class-wc-sc-background-coupon-importer.php:487 +msgid "We are processing coupons in background. Please wait before starting new process." +msgstr "" + +#: includes/class-wc-sc-privacy.php:124 +msgid "We store these data so that we can process it for you whenever required." +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:441 +msgid "Weeks" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:88 +msgid "Welcome to Smart Coupons" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:252 +msgid "What is Smart Coupons?" +msgstr "" + +#: includes/class-wc-sc-privacy.php:113 +msgid "What we access?" +msgstr "" + +#: includes/class-wc-sc-privacy.php:118 +msgid "What we store & why?" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:380 +msgid "What's the URL to a coupon, so it's automatically inserted when visiting?" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:453 +msgid "When checked, generated coupon's value will be same as product's price" +msgstr "" + +#: includes/class-wc-sc-auto-apply-coupon.php:121 +msgid "When checked, this coupon will be applied automatically, if it is valid. If enabled in more than 5 coupons, only 5 coupons will be applied automatically, rest will be ignored." +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:423 +msgid "When checked, this coupon will be valid for the user's first order on the store." +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:498 +msgid "When checked, this coupon will be visible on cart/checkout page for everyone" +msgstr "" + +#. translators: %s: Explanation of the setting +#: includes/class-wc-sc-settings.php:547 +msgid "When enabled, each coupon will have the option to enable auto-apply for that coupon %s" +msgstr "" + +#. translators: %s: Label for store credit, 1: : Label for store credit, 2: Label for store credit, 3: Label for store credit +#: includes/class-wc-sc-settings.php:586 +msgid "When selling %1$s, if Regular and Sale price is found for the product, then coupon will be created with product's Regular Price but customer will pay product's Sale price. This setting will also make sure if any discount coupon is applied on the %2$s while purchasing, then customer will get %3$s in their picked price" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:1009 +msgid "When this coupon will be applied, selected products will be added to cart with set discount. If discount is not set, this coupon's discount will be applied to these products." +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:354 +msgid "When trying to add coupon/Smart Coupon, I get \"Invalid post type\" message." +msgstr "" + +#. translators: %s: Label for store credit +#: includes/class-wc-sc-settings.php:641 +msgid "When you opt to allow people to buy %s of any amount, this label will be used." +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:431 +msgid "Which features of Smart Coupons work with Subscriptions?" +msgstr "" + +#. translators: %s: Label for store credit +#: includes/class-wc-sc-settings.php:636 +msgid "While purchasing %s" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:1003 +msgid "with discount of" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:1610 +msgid "WooCommerce" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5876 +msgid "WooCommerce Account Connected" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:385 +msgid "WooCommerce Coupons (CSV)" +msgstr "" + +#. Plugin Name of the plugin +#. translators: 1: plugin name 2: page based text 3: Label for store credit 4: Hide notice text +#: woocommerce-smart-coupons.php +#: includes/class-wc-sc-admin-notifications.php:177 +#: includes/class-wc-sc-admin-notifications.php:243 +#: includes/class-wc-sc-admin-notifications.php:257 +#: includes/class-wc-sc-settings.php:903 +#: includes/class-wc-sc-settings.php:906 +msgid "WooCommerce Smart Coupons" +msgstr "WooCommerce Smart Coupons" + +#: includes/class-wc-smart-coupons.php:3274 +msgid "WooCommerce Smart Coupons Cache" +msgstr "" + +#. translators: WooCommerce Subscriptions product link +#: includes/class-wc-sc-admin-welcome.php:275 +msgid "WooCommerce Subscriptions" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:779 +msgid "Worth" +msgstr "" + +#. translators: 1: coupon amount 2: discount for text +#: includes/emails/class-wc-sc-email-coupon.php:414 +msgid "worth %1$s (%2$s) " +msgstr "im Wert von %1$s (%2$s) " + +#. translators: 1: coupon amount 2: max discount text 3: discount for text +#: includes/emails/class-wc-sc-email-coupon.php:443 +msgid "worth %1$s%% %2$s (%3$s) " +msgstr "im Wert von %1$s%% %2$s (%3$s) " + +#. translators: 1: coupon amount 2: discount for text +#: includes/emails/class-wc-sc-email-coupon.php:425 +msgid "worth %1$s%% (%2$s) " +msgstr "im Wert von %1$s%% (%2$s) " + +#. translators: %s coupon amount +#: includes/emails/class-wc-sc-email-coupon.php:398 +msgid "worth %s " +msgstr "im Wert von %s " + +#. translators: %s: coupon amount +#: includes/emails/class-wc-sc-email-coupon.php:403 +msgid "worth %s (for entire purchase) " +msgstr "im Wert von %s (für den gesamten Einkauf) " + +#: includes/class-wc-sc-purchase-credit.php:894 +#: includes/class-wc-sc-purchase-credit.php:1009 +msgid "Write a message" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:443 +msgid "Years" +msgstr "" + +#. translators: Documentation link for 'How to Print Coupons' +#: includes/class-wc-sc-admin-welcome.php:420 +msgid "Yes, Smart Coupons does provide a feature for printing coupons. For more details, check this article: %s" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:428 +msgid "Yes, Smart Coupons does work with WooCommerce Subscriptions." +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:150 +msgid "You can also apply multiple coupon codes via a single URL. For example:" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:411 +msgid "You can continue with other work. But for bulk generating or importing new coupons, wait for the current process to complete." +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:373 +msgid "You can do this by overriding the email template." +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:308 +msgid "You can give a coupon to your customer after every purchase, which can encourage them to purchase again from you." +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:403 +msgid "You can resend them from order admin edit page." +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:273 +msgid "You cannot add the same tax rate twice!" +msgstr "" + +#: includes/class-wc-smart-coupons.php:1609 +msgid "You don't want to miss this..." +msgstr "" + +#: templates/combined-email.php:237 +msgid "You got these coupons " +msgstr "Du hast diese Gutscheine erhalten " + +#. translators: %s: singular name for store credit +#: templates/email.php:219 +#: templates/plain/combined-email.php:137 +#: templates/plain/email.php:130 +msgid "You got this %s" +msgstr "Du hast diesen %s bekommen" + +#. translators: %s: singular name for store credit +#: templates/email.php:219 +#: templates/plain/combined-email.php:137 +#: templates/plain/email.php:130 +msgid "You got this gift card" +msgstr "Du hast diesen Gutschein erhalten" + +#. translators: 1: email heading 2: suffix +#: includes/emails/class-wc-sc-email-coupon.php:460 +msgid "You have received a" +msgstr "Du hast einen" + +#: includes/emails/class-wc-sc-email-coupon.php:73 +msgid "You have received a {coupon_type} {coupon_value}" +msgstr "" + +#: includes/emails/class-wc-sc-combined-email-coupon.php:70 +msgid "You have received coupons." +msgstr "Du hast Gutscheine erhalten." + +#. translators: 1. Receiver's count 2. Gift Card/s 3. Receiver name 4. Receiver details +#: templates/acknowledgement-email.php:37 +msgid "You have scheduled to send %1$d %2$s %3$s %4$s" +msgstr "" + +#. translators: 1. Receiver's count 2. Gift Card/s 3. Receiver name 4. Receiver details +#: templates/plain/acknowledgement-email.php:27 +msgid "You have scheduled to send %1$d %2$s to %3$s (%4$s)" +msgstr "" + +#. translators: 1. Receiver's count 2. Singular/Plural label for store credit(s) 3. Receiver name 4. Receiver details +#: templates/acknowledgement-email.php:34 +msgid "You have successfully sent %1$d %2$s %3$s %4$s" +msgstr "" + +#. translators: 1. Receiver's count 2. Singular/Plural label for store credit(s) 3. Receiver name 4. Receiver details +#: templates/plain/acknowledgement-email.php:24 +msgid "You have successfully sent %1$d %2$s to %3$s (%4$s)" +msgstr "" + +#: includes/class-wc-sc-settings.php:652 +msgid "You will get following coupon(s) when you buy this item" +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:540 +msgid "You will get following coupon(s) when you buy this item:" +msgstr "" + +#: includes/class-wc-sc-coupons-by-product-quantity.php:559 +#: includes/class-wc-sc-coupons-by-product-quantity.php:561 +#: includes/class-wc-sc-coupons-by-product-quantity.php:563 +msgid "Your cart does not meet the product quantity requirement." +msgstr "" + +#: includes/class-wc-sc-coupons-by-product-quantity.php:523 +msgid "Your cart does not meet the quantity requirement." +msgstr "" + +#. translators: 1. Number of quantity 2. Singular or plural text based on number of quantities +#: includes/class-wc-sc-coupons-by-product-quantity.php:537 +msgid "Your cart should have a maximum of %1$d %2$s in total." +msgstr "" + +#. translators: 1. Number of quantity 2. Singular or plural text based on number of quantities +#: includes/class-wc-sc-coupons-by-product-quantity.php:541 +msgid "Your cart should have a minimum of %1$d %2$s in total." +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:626 +msgid "your entire purchase" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:843 +msgid "Your order contains coupons. What would you like to do?" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:832 +msgid "Your order contains coupons. You will receive them after completion of this order." +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:274 +msgid "Your product has variations! Before changing the product type, it is a good idea to delete the variations to avoid errors in the stock reports." +msgstr "" + +#: includes/emails/class-wc-sc-acknowledgement-email.php:95 +msgid "{coupon_type} has been successfully scheduled" +msgstr "" + +#: includes/emails/class-wc-sc-acknowledgement-email.php:77 +msgid "{coupon_type} sent successfully" +msgstr "" + +#: includes/emails/class-wc-sc-email-coupon.php:64 +msgid "{site_title}: Congratulations! You've received a {coupon_type} from {sender_name}" +msgstr "" + +#: includes/emails/class-wc-sc-combined-email-coupon.php:61 +msgid "{site_title}: Congratulations! You've received coupons from {sender_name}" +msgstr "{site_title}: Herzlichen Glückwunsch! Du hast einen Gutschein von {sender_name} erhalten" + +#: includes/emails/class-wc-sc-acknowledgement-email.php:86 +msgid "{site_title}: {coupon_type} has been successfully scheduled" +msgstr "" + +#: includes/emails/class-wc-sc-acknowledgement-email.php:68 +msgid "{site_title}: {coupon_type} sent successfully" +msgstr "" diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-fr_FR-035dc61797ac8bfb6d6ed258fe72ad8c.json b/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-fr_FR-035dc61797ac8bfb6d6ed258fe72ad8c.json new file mode 100644 index 00000000..e86cab29 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-fr_FR-035dc61797ac8bfb6d6ed258fe72ad8c.json @@ -0,0 +1 @@ +{"translation-revision-date":"2024-03-11 09:49+0000","generator":"WP-CLI\/2.10.0","source":"blocks\/src\/js\/send-coupon-form\/block.js","domain":"messages","locale_data":{"messages":{"":{"domain":"messages","lang":"fr-FR","plural-forms":"nplurals=2; plural=(n > 1);"},"Frontend\u0004Send coupons to...":[""],"Frontend\u0004Your order contains coupons. What would you like to do?":[""],"Frontend\u0004Send to me":[""],"Frontend\u0004Gift to someone else":[""],"Frontend\u0004Send to one person":[""],"Frontend\u0004Send to different people":[""],"Frontend\u0004Deliver coupon":[""],"Frontend\u0004Receiver email address":[""],"Frontend\u0004Enter recipient e-mail address":[""],"Frontend\u0004Message for receiver":[""],"Frontend\u0004Write a message":[""]}}} \ No newline at end of file diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-fr_FR-0fac2f3b919d34656822c41cb1ed8c2c.json b/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-fr_FR-0fac2f3b919d34656822c41cb1ed8c2c.json new file mode 100644 index 00000000..711b60ed --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-fr_FR-0fac2f3b919d34656822c41cb1ed8c2c.json @@ -0,0 +1 @@ +{"translation-revision-date":"2024-03-11 09:49+0000","generator":"WP-CLI\/2.10.0","source":"blocks\/build\/woocommerce-smart-coupons-send-coupon-form-block-frontend.js","domain":"messages","locale_data":{"messages":{"":{"domain":"messages","lang":"fr-FR","plural-forms":"nplurals=2; plural=(n > 1);"},"Frontend\u0004Send coupons to...":[""],"Frontend\u0004Your order contains coupons. What would you like to do?":[""],"Frontend\u0004Send to me":[""],"Frontend\u0004Gift to someone else":[""],"Frontend\u0004Send to one person":[""],"Frontend\u0004Send to different people":[""],"Frontend\u0004Deliver coupon":[""],"Frontend\u0004Receiver email address":[""],"Frontend\u0004Enter recipient e-mail address":[""],"Frontend\u0004Message for receiver":[""],"Frontend\u0004Write a message":[""]}}} \ No newline at end of file diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-fr_FR-88ba117fdcd48887044ec0ca59856410.json b/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-fr_FR-88ba117fdcd48887044ec0ca59856410.json new file mode 100644 index 00000000..8a0bbc54 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-fr_FR-88ba117fdcd48887044ec0ca59856410.json @@ -0,0 +1 @@ +{"translation-revision-date":"2024-03-11 09:49+0000","generator":"WP-CLI\/2.10.0","source":"blocks\/build\/woocommerce-smart-coupons-available-coupons-block.js","domain":"messages","locale_data":{"messages":{"":{"domain":"messages","lang":"fr-FR","plural-forms":"nplurals=2; plural=(n > 1);"},"Block editor\u0004Available Coupons (click on a coupon to use it)":[""]}}} \ No newline at end of file diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-fr_FR-9b3491f4c368ce2ad4994aa24713559a.json b/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-fr_FR-9b3491f4c368ce2ad4994aa24713559a.json new file mode 100644 index 00000000..89c973ba --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-fr_FR-9b3491f4c368ce2ad4994aa24713559a.json @@ -0,0 +1 @@ +{"translation-revision-date":"2024-03-11 09:49+0000","generator":"WP-CLI\/2.10.0","source":"blocks\/src\/js\/available-coupons\/edit.js","domain":"messages","locale_data":{"messages":{"":{"domain":"messages","lang":"fr-FR","plural-forms":"nplurals=2; plural=(n > 1);"},"Block editor\u0004Available Coupons (click on a coupon to use it)":[""]}}} \ No newline at end of file diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-fr_FR-b8d31255012dc50a25232a24e5b093ad.json b/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-fr_FR-b8d31255012dc50a25232a24e5b093ad.json new file mode 100644 index 00000000..fb8bd7df --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-fr_FR-b8d31255012dc50a25232a24e5b093ad.json @@ -0,0 +1 @@ +{"translation-revision-date":"2024-03-11 09:49+0000","generator":"WP-CLI\/2.10.0","source":"blocks\/src\/js\/send-coupon-form\/edit.js","domain":"messages","locale_data":{"messages":{"":{"domain":"messages","lang":"fr-FR","plural-forms":"nplurals=2; plural=(n > 1);"},"Block editor\u0004Send coupons to...":[""],"Block editor\u0004Your order contains coupons. What would you like to do?":[""],"Block editor\u0004Send to me":[""],"Block editor\u0004Gift to someone else":[""],"Block editor\u0004Send to one person":[""],"Block editor\u0004Send to different people":[""],"Block editor\u0004Deliver coupon":[""],"Block editor\u0004now":[""],"Block editor\u0004later":[""],"Block editor\u0004Receiver email address":[""],"Block editor\u0004Enter recipient e-mail address":[""],"Block editor\u0004Message for receiver":[""],"Block editor\u0004Write a message":[""]}}} \ No newline at end of file diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-fr_FR-d811137fe50d78464704a484441a64be.json b/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-fr_FR-d811137fe50d78464704a484441a64be.json new file mode 100644 index 00000000..5078ace8 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-fr_FR-d811137fe50d78464704a484441a64be.json @@ -0,0 +1 @@ +{"translation-revision-date":"2024-03-11 09:49+0000","generator":"WP-CLI\/2.10.0","source":"includes\/blocks\/sc-gutenberg-block.js","domain":"messages","locale_data":{"messages":{"":{"domain":"messages","lang":"fr-FR","plural-forms":"nplurals=2; plural=(n > 1);"},"Smart Coupons":["Smart Coupons"]}}} \ No newline at end of file diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-fr_FR-fd0f2ef4bb9ad5ddc0e7e6898a11a573.json b/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-fr_FR-fd0f2ef4bb9ad5ddc0e7e6898a11a573.json new file mode 100644 index 00000000..43d6b87d --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-fr_FR-fd0f2ef4bb9ad5ddc0e7e6898a11a573.json @@ -0,0 +1 @@ +{"translation-revision-date":"2024-03-11 09:49+0000","generator":"WP-CLI\/2.10.0","source":"blocks\/build\/woocommerce-smart-coupons-send-coupon-form-block.js","domain":"messages","locale_data":{"messages":{"":{"domain":"messages","lang":"fr-FR","plural-forms":"nplurals=2; plural=(n > 1);"},"Block editor\u0004Send coupons to...":[""],"Block editor\u0004Your order contains coupons. What would you like to do?":[""],"Block editor\u0004Send to me":[""],"Block editor\u0004Gift to someone else":[""],"Block editor\u0004Send to one person":[""],"Block editor\u0004Send to different people":[""],"Block editor\u0004Deliver coupon":[""],"Block editor\u0004now":[""],"Block editor\u0004later":[""],"Block editor\u0004Receiver email address":[""],"Block editor\u0004Enter recipient e-mail address":[""],"Block editor\u0004Message for receiver":[""],"Block editor\u0004Write a message":[""]}}} \ No newline at end of file diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-fr_FR.mo b/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons-fr_FR.mo new file mode 100644 index 0000000000000000000000000000000000000000..9284c8fc89d72cb70802f0e6263ca870387efdf7 GIT binary patch literal 89265 zcmdSCd7Rx+@!v@TWDwvx84NUPw|QWvyXt5$2R`|^Fh-tTih%gh9^-|z2_pAXDy z&gb(v+xxuFdppbh+7bJ_D&c?KPfn5(z*~<~DoMV-EXODD=MPBpN%A9bfAA;ZVc@Sr z`ry-(!2`f8;1%Grz`5Z2!G7>dU>A7&8A);$cmnuTa0_@0 zSObp)p9h`>-T{&&`53qj{1LbcTz6)YYzJQqUJ3p?xP*c)pwN``^=Es%uK-UX{XuXJ z_%L`P_%kpCk2xnv4g${x&jb6x!@-+C_5bCd`tv&QVDPQrCE)wOr-Q!&RsON(diiIA zqVLt9o=bnX@EzcOVA_`?hk^^hqrtO4nxAX{DKfbf)ORleSAc&CE(Sjb&If-1 zLW(3^o+Jl?+d#GRTJT~Ds)N^({s5iQxExI(9{`UBMc)U(r-R=DRsZk6XMjha@AaMz zs{ehU-meB#&sE^DU=>t3&jpVHZwH?Sz8w^uJ`SefXTT%C?}5jIzXi8|$E~FA;3%l_ zUj=IX-wldi?gvi+|1G2synyi~-3_X|=YS`J*Mq9>RiNngR1;8ozI;M+hw|1tP-@O+q8{r|^+{{pJtkAVk)zXBJ6`>%1j zE&)ZS4WQaP2%ZK`g6iknz&YT3U@!OxxDGsctcs1z;sD6A3yd3;IsBua8So3Bf zsCn22ik=sNqURX+8t^tybUX1v&wm-n6iMC!>ie&N>R)nEl0fR@72tQkFMv0J_pNuj zE{8a(XEnGFxGAK!fd`VVf(L*NP<$~7LXzaAAgq`?2uf}o1X0!Qqrti00&o#{F?b8u z0U>$vb8sHGe1q3t0god+44wqu45~eE1vTI91vSqe051Ul72F>@aih0)KDZz0(?HF; zWuVGm1?syYQ2lCx4X^`>Z@vXC27dyoU2|X#(RUDhCwK#>`sZHe<*o!p-%G(mz!!pt zfp>xjfo}s32HzLb9|J|NPk{%5kA(DhK+Vrzfro;}Zt`;Gg9}KX1uEZj0=B~Y+d!sr z@@i0g_7Es~e-BjszX8RMPr2OZ`w5`tWgn>aZUgnc8qyP>+Hor=e!mMm9sD3DI(!!t z9e)Rkj`KGAcy@#8=arz!9R$^n7I-rFN8sV$pMx5g4}qfp#{=FEE+PF%Q1t&fi0Dk_ zZSi`xgDP(bRKF%b)ps)}KDixKzjlM-%fACv-vgl9^EFWX_?M6JxDc#^$AGT@#pk=j^M3$Mo`RYehdwh&UItzc?hAe$ zJOlhUQ1k!zYn;AUfZ~%Kpy=8Fj|cxKq~8EOmGt{U`V*k~`%p;#JE-ygRlxn9<>@0q z(c>gg^f(n1{g#49gDXL`Ya1v%cMZtYN~S>Z$EQKH>kFX9>7PNh-XlQq z={!(;e`SmQ2DP9>Dxm3l>v8yFXsJUgX-6X&++zM1FF93LDA(FQ0;p)sBwP` zoDcp8JPtf|yFXtFs^7~&)w>RSP8a0#64& z3VsdzA*k{Cd@V_s;>p9{I&k5RB)JJ}f~&zFfu99WAM)>i2d*H!->~!V8n8`z3n+g2 zBq+K)3W~1Z2Q|LG1;zjS)xFwxBH=q^xbnqVVrCMNpz{3$)b~$nIX#X9RqpYi=)3@YGI%z)54ap$1zrFu|IMKC-vO$9Zvn*z_ko)K z4}*)q?}3^pN5d>?{=1dkwn0jTe{fSPA@@JR3$Q1!e9ybb(wQ1vZ_$Y+8pK-Jp@ zMXx^r9|XSwGG&vy$G!dgPhfkHJ_!6ics}?H@U%&Hh*h10H=N^>ii4H$d_2ub%I?&kMXChk#Gz`LUq*WD%(GTnVlRTj2TN$3V*u z+IZaL^_>8!AHAUZaWSa(6;N_u3Vb?v6R7uZ2>5>R1k#@Y_5M4c%6al1xgUHYsQR7{ zo&vrIRC(_K>00uBQ2k$Wv-e{+sPEqos{W4!d7?|^Fee}Z-Jpci?*aZvO4 zM$qUI@M8i09#lD>2gP^a1h;@c1~u;MUW{x4?*P@mPl0~}ejQA~H~+Eo_1}V;2cHM$ zfd3Mn{|1~#`k@D%W*KlS;)2J9m}2&&z01`h?l4DJs;28!`y z{tWB~Pka@zA8-IvyZ;MB6enG;_Hv#JD&Jp%J>Wy&KY~wwjm!Oqz$-{Ec&)eZ`QW9b z-w0j|ejmIDJo|NSkK6>RAAb+>D)~03d2{3IUC!JJ?yKkE>EM5W=Yl8x8Q*|cfzJZJ z1WtjczrpGLUhqiLp8_?{9|7lr-vmY1ectHv>0s~(($|8=fNfCyehDaf{`!FL2>6%a zQ9S=^@LAv&L5I!fmLt{RDJ&nN>2S7sCIR|*~j^4Q2cdDz#dS1aSqrG zt_4?s?U4QpQ1yQuR6BnHs{VcMa=IM?s@+F{sy78y??O<|*MOIUn?Q}jTS3wHd*IW+ z{{lsa1K;B1&jD56Qg9u(4tyW@GEjWC;;nAq{wa8V7xD$Xhv&z?-N*aWpvM2GKlk`o z6;%J<0IEIrg2#a$3-~4QB+@?$>BHaQ?K>4zf0u;x1>kw4*MS#;w}3Z-p9PnK>)(lv z0G|u?fA1zZBY20R}86nHxLEl_gn*xlZb%Ruqri$T?Q zKX?}SlYpna%fBB0H}m}U;O*cKK=I*?@Ah%O3ltsR1?~%e2voa128s_p2R;@2DyV$l z3-1qokL#NgL4Cgn+z&h#+#kFE6klHiZUwIaPXzA;7lRLiDfnw}HTaD8`h30?TtxbI z@J#R{p!)Yia1J;Njripy>D!Q0;yI)cpH8cmViqP~ZOm)b~FN z?+wW+1y%kr_qu(%095)^ zP<*gFq^qFX*9qw%+jq zNiPC59)02YMo{x=2vqx@2ddq-h3D@8yGegEJpV3uIq9eTrR)D|z~!X>9MpH;1et!x zVej|;J{8>fWaQ2l%zsPTOVD7yX=cqsT~Z~}Y` zTnauLB|8k>4yyj2gXe?41XcdIA9nj^BX}(7>p;z$n?a4|$3W%(CAbZ&egt0z{7Arc z_hE}r@E5@|cs}$o=gT*M%Se9#JRRKk<6iE$U?1r=D7xMQZUjFJ9u4mI*WTX~K=o%K zD0-X?svRpq_3Li%8Q?#I^TD5kCxR#ajoVGx_P1W{N#N5+_kg0y zh2UmzJ*fKL0IFSY2i5)`gKGEuPayNb3aD{-CwKt(0dP|n@k+2s`p`Yjx6cQEO!^k^ zIB??c+`qU3Oi6zLJPmvpRQtOA-s?XAJcjh)py;vy6d$bsPXc#>>hDXzMc}(Y_2(h* z6z~V&@!%2v;PmVUM@gRxsvqwJ=YfxcJ>UVKbh&yqsP+tl`tFtBdhkI|^gixW9tS)d z)c9Nr?hiJ>v%pEv#uZe5KMbn8FM!_xe+zB^ANw>m6nOe)kRjj)!0q56pLHAsVX@=^ zP;`FL=e*okg7Zng2|NM(d+=QFQBeIj;Q=47OF)hP3&8Wh*MMsOL*PR2$6zn`^v}Eh zehGLo=`Vmg!JmTa*T93Uoq*SY2Z8?rimu-Qj{u+akG@WFG&qO!Ht<*AB)9}@|C8&z zw}Tr<&;5eS#U}Vc(szUX;B&r6yWyX=g0CR`rH8!!`ok{Yt_Szy`3u0q!P`K!=QZGg z;M+j8>mG0b{51GXaPgO%KVJljpY8z92Hy#aufGny2|V)4KHvWmlwA1{sQRA%74O$v zu!r;-@JO%?itk@Bq?_LCMoILFu!LLGj7UK-Kda@GkI8 zpuSuA&mPa&3SLb5)u5h#6MQOk`YEXKI^YrS*JAK$(*5Ak;2Xi?!1sfq&ja8g;8#G= z;W6-d@HgOL;M4xq=gmS;5r`#ezP zzZz8ie*vof9|KPW{|VH0KLSGJ`KDXRQvx7JQI8msPZ2LH7>sa_XYR+rsKijGSWwY8^N{Uh2Wi_`tdKI z+WQ!&dVdXyt_M8o^Xiy@D?yFxFsSdE;Gy7iLDl;bumau*s=faMioc%nEw`i20c96o z1F9dB;A_A;z&C*lzwP|>NpLIa&w(mu&c8YTo(YP-t_4p4uLBjwxE)kGUjLZe|GU98 zqz^$jsb8Bxy&ndx-thd6kbVa!e)$`4fAB%@Jn+llx!_U%?snCs-~!Uug7d%^gH7-r za1uQ6yWZYcgGZ2l7brgeIH++w;6GeHtN@k&IpFEwt)Tet!{8S1LGTUW$=`E&|1Eeq z=}&@^H^+V7`?Uj9d!HB5w}Pto^`Q9jymh1T`;S2|gKo4=BF67kmNuE$~3F`k&se2B`6#0G0n0py21VEJg8PEM0at-f{;BJqwV>$nAyEAKAh;Dg>SyEu>)@r}mY+M{y%p>u{Tc8q zaNl3J9zPF!GVQz#)Ofw*m#**b1g|3fJMaVGRVc9bj1FN047>s?(Y$DRvne!Ln~dp-t=FCGR(zpf{BS-<*0)%yl;CwM$WkbJrgOu?6d zPXX@<_+e1>+z);Ndk1vP(GgPOn34EP-IS)>O*<^LN{ z-~SVMD)=a<@jB$7F5`!@z|%=@0@c1-LACqM0q+4-&&R=Iz=y$8!0&?^&!-;j?@tBa zM0z!-dGbwgE%-m+d~o?8T{a&EKvYTcSKuW0`a`=+&Kz-Am)Skf0Aayo8#ou-dU#hd z2b=_-1ilUwU%UYn-QNbPU7r9oK3@S<|F6UI!!bru(hES9cM&Lh?gYhW&j&@9{{UBl zM<3B;@^%~8Px?CWZ15hi4}1(%zvdj-W%FeS)boD^)z71k>N30QJW%b~0g7HP0at+U z0}ld!0IHq82zbcRPWL(B(L7%Qia*wY;)~0`qrfXcwSOeMe*xG_`o-V^@WY_S@f)DZ z{}rfwhaKbPp8~4>(?LC73BCZ_3f=)e1Zuo%$993*=jD6} z6u&+S9tM6NRQ0ZzIpybjOpvGq`;GLl4{f9u6{{>KT zRm6MPBjuY%&2!Dl#qc7mEmcY^N+Ukknt+;E~le+(4e zzXzTK{sa`C9d%Myat{4p1}-AKGxhep3OteYUx4cOKZ5%Hd!X9$lsP`X&jr=~3qg(V zD5!qi0_wXrf+v6vfQ!NZ0M7uAo$KSj0hB)83W`qKLCwFL!OOuv1DAn606SoMa#u1A zz6w;ngHG{$$AFsO=Ypc|MWFa$5EQ?Tfv*K$2`XRrye`vQ=Yaa|MFH;wH7;)k)sEeu z`g1>62Oj|^z;*L|o_`$FJUVj$?SPJ>;1bezEOh#O0u*072#Ow$gy#n@a(WyOp3n0O z!Oh@ppy>5ga0mEP@J{gAr*@%(h{J*!r%#{eeD>eqv#9r=#hxDS?n=5y-vpk{cQ^O= zcz+1Ig!Gp{$%DDQE{{Y-Y8jZ4 zUJpt>Uk4sQJDvyX`xh?t_PiC;_<98pZ?>`Ny-p4?V$4@}Xi{A#^ z52sb>LjxWY@Wg=gLCL2cQ2p8hYQEILeZetM<1zuB3f=;$yn8^&-4BKI1EA`E7!*Cf z4qgf#d4|(t030O!Lhwc4e}LkL)|oD6-v#!N{!eff_>8l>zU={D0(SHKgWziLTi|YR z{@G#Pf#Tcmffs|fGFdf`9t1A{e+~W=Tybt!ax-{FUzhD0{3}rP&R^b@RKRWER`9RD zE5U=$^Y#pas{b9}ec(f&=ydxEpJ%TIMX!U;?=rva2yg@GYr%Je?**s8t5I3IbT>wycvZKPY^m%&eg&jjzf$nCsef%PuvxW3EQ-M)3PkKYF_>9Y0q zQ#ZIh`ZiGX{52@Kchp9gZ)w0jQ2JqONOwT-!=HlE&#wa2&$~hK!M)&B;BP?LNmpFj zW&Y^@fVYzFz0B$M0q_FS`)~4jc@e1b8U;1pw}LAFo!~O?J}?D;0GiYb$vpoMD0zM#D1HAuPZE+ODx$wNo2hoKDsjP|$E?Y-}ne_i$}wEbZ=2$3|+Do3?6| z>Tuc|@9-{}+i%Tmr<3*0aJs4092~E9=B9(ScC}R>>(uGN+%26Z#r3ypgY{0jxmK;! zCu%J|=~U_?bJHEo)@a&jc2cUVRa$BiJ*p1ZsykK3SY@cTl2H+HoHp}L=dV_6v^h~5 zOb2S!$~cX3YNhke;9Wg?-Q(F7Zk-ydIb|35lXb0HE!{F)9~+}SQQRMgQkpxgCVw{B zY|*puh!dxQqU_sJmuJgEm7Zte)?wN^SsximD}xj}Tua-P(X2xSLZvQ1%_*|C*2g8VxnG~w6=Mkb~;jTi$#1Wyx`VXzWV6Gc{66Cx`3sFqy|jDvgE@=YUw-xoSs?45IVc$oLRs=fCl> zYI9TsgLm7s5?Wnan_QgMM`ob8e?L_PcCZ>GNt!k#H{a2 zC2XU*$0=a8*MEjQj#gz!}O^%cG{q7#O%G;hY2BO&^%xA>_C!q+g?3xspd=(ZD~&0W^H%p{rO~mDWhL-M&=e-g z>?QhwKGn!;3`-kLqf{%cjy27y9IUA}WU)!uyhHRRBST>Ifl77fPz$YPbSS(JWQtN` zw1R@s)UF^cIvt;wBelh8yBTLbvvRD`sncX@DP2|rC_suP?ccge$u_SM4~%fTy<>c2 zWU7a_)WTJgr%j0}hOE*UOlzZPoS9-%A0bcbW2&XSC|TIw9Ge2xz&Wm&3I#1jTy@ea zN{|7h-96RzM7pD{Mt6oQK8u-c$-+yU9dyq6&H{;D_+qrykT9UGoweFniYi=FZ%b|s zQkA%jv11a8St{e5X7^0#o-9OWWM#op&P-Be@EmiIxlQh|R&7UpS8scK2SC|PQ^S>! zMM-yepZ%Bg$QWpMq;$lLrXA8T3AT2Je$+;p+o)oiGg#}cR6F$vF}IYD3q%H~O@&bo6VwK6t)MDtAH@wLg(8XkV8#33r2d26Kn#^a`Mw^<{u%liZ z8Kfx;(~i1oW3XLWL{-pMGk1*Cp-N+@2U2dXp+xBaR;RwBUKQUm!E92%#@J+#B&rk!w$f(YCBAA?sno_e(kh%Hb*V*R`DeiMEUy zRMZ&4j6V!x)kWiwor|6$fZI?PALr3lJ z)Dd&EdvK70cHS~4N^CR-t^P^vrhkl_rPY;ii$ zq)*hmSOeEeTg?#-ckEiFLwgZmDsu-CLq_+=RAl~OR+ynslMOP`ZYHak_2EUJmbHkd z?Ha;jb?25B%S-WT%m$gD%3+e(_Vxc zN^}_750WrfY!y1R)q=^SIGfe#c#D^rE!@E_tqfHdOlkQRgDoQazZol|x9xE{IzG~= zV>Dz9pQu+PDUwxiylg@rBPE^_z;!GI7-3i zL7bq);_3R{J2BCe;y0b`G)JfpA}ci%kbQ3%X*Y_G0SZj%zKNLxQvWN{eq{5`^s-A- zs6L*p5%u=4UJuq}tT_SDn%FBV5qz`*EyNs>{F7&j4ZAb`9SMN#z!0f>*AQO z=4aX1Ji(@QP@cn#m`P)%9EM;zQ5hMpNtA^qg!Q0F+`^!^>RJUC5tL{)<|O>-f@ejt3hO4l zF!-*ST-HMqMhw0Fj^zze~ilRWPFeAi`6ZLjo4IpDbW4Ac%kFk>Z>BgxvYFH1PEBc8qd@1&)B>y0s+LA|RN0^Lt0|%!W zbrH;F6Kxu(C{{3AZG!J;N@A-b6SjTHYQ7>FG2IY!T{~H=cu3?aPq~TC#I56AXTo)U za01}fQU5Muv_R+5QwafyrC_OJ#;KF8F7&t%hS1Ptp@n`SInaUp1@IoFty z#rEh;cc!iS(6Cv%FcN(w4V7Irv9y9D9|@^OoD>>L4?D8OR1Y*nERV zGaYcQ>5Vp$1{Bjp&9hQ9<0QJ!6?E9V`B*}sMV)4c`JY$m`qI?y;=DhIM?_7mX{GXy zs3J`?M7dZQ(|C@e3aV58HWh)b?nH|cwrvdYLCYV$4Ux^KW^1R2wor+{YD(ui!Kzzi4XD;eXa~)yH!A6B z)Sglu`$w*}jVUQJ_+`R|KViFJgjl^X|KxL)Ej@dAIy^qiz)7akW*RckL>x6e>_XQn z1BCl9)7xzvP<6~XK~7=4B{c#+y5};p44Z~tKo}KquPL;kVZ1c@Gt8K3l=PR!1LNe& zpOhkm@_9m`mfbVWh#7|2GFcliPc;_ioj?Q;pbZYMO%Am7(2%TaCP*DUdg2~sc+YM)1ZC{UEQiufbxCuZF$JEm!W1yRQv*^V^ACT1qdh`q8(GZNoZUX>70 z_}WUB86L=QEJ2D;0q)m?tH>ZP3BWz8XL3IS1=xuh1grgNm$i0>H zGr{;rL1tidK%&z6nI%1IoG_FWnJw^TlStR#95Sm9{1Zha-0Y;&=&D;WK3aHQl*hpl z(L6U7sL?@+A$TBPE(D8((g{@;`YTCMde9!m#xdiHIZV(;R-0TWOdfZMEVo!9Hx05c zEwf}T4fk9&dqZ8JgwTNEo6rhH;!VoP*^6#Tx3MV-qJ^)6_6_c$yH~ZAt)W0FO+72p zbR&tNasvAWVTR7>N!PkTpgzp_$oy$_T5o+SWr5i?9-SE2Rt(fm^Yd$IAt0oeS}}AG zGnlT$FrWc8p{$`5lb+Tm1soT{?XqdY(uY+c6&*a?P)IH-z0kmeR)PNRi?yvGAfEl5 zF9N3V*}A3}*z&D+BXF%8>FilMy&{;mrXVKk#v=CpMi;s9)6Kq+I5;icO4r!JBG%cs zEhd^2#(Ih0ZB+n_O{Wka6we2-75 z6NB9rK{0cKlqXqmA{xU)frzgz1Lc- z(Z8(UAb+8-_@<$)dbPCOO3S`c86C0Ln#xo=SyQWw@QVH^wkB?$$%K}*j^ITCI;(07LMC6%rW&oh zs{~tt_b!pl{M_Q-eMwlKaN4As^U!1V#+ZuX&4Q9E^@?)Yt`Pr7KniwrcQA zGp$fu@ve*z^!DJmH`b@bLgt1A)Zvdw0*P{m;4EkHMe=Q_%gPL9T9!5*%0z?A31c8s zzwI`d{vCyi&h6nQbPq*p^xPSUkHpyCJSuLQ7KtP&*-QmRjE=IXWp9)d-gvnW=8oBJ ziei_|gU0TuLs+jOMgv(J3$9BTeU+`%Z>l4JXNyYm@Zyqy>~ERtd1TMM!w@$rEE7nR z()}3cC#9Kh{uZ`DA=J;PH>>J9mVPPR9~StbI{XQhGK*0omd#LQ$NE0~+~u8gBWqFV zW%4!Ggis(2b>quc+Gs?uw39V>)wZ0GtQFHoYPo?w-YnYqSjgW;vSqzsCV#Z!w`L}5O0g;s?5s$m z_=&{=vIHcA^$VOPC7Kmyba$zxGHp3b>ew5|03b87X4wq&g#-jN_Pu!|>=i(3T3ZMo zOOT4QOG9V9%?dN8ZCll0d<9$_!V<{QOq_u7-VeLUcd}_$_z2uCAL~NMWZ z{g?W#H_QN|Bg)#Bi_AYLuR?<9ndugGAv7?D*6w2e2xfJ_Gz-mVui`#F{Ov4S62IP3 z!Fpb=)uya~ZSs#cv(T75$ww%A6vgTKHF-uRYFMG#5Y9exIB~KUdFPz2D@+Df5!W6TPA?TjM+idC5 z8HVrY%F42BicyKo)#jTkAZ zAIg{8fx$E=v&BBk79;%=O#;|F48>HUXs`Vv7DAsOS;T;tKUwIPZVpz67_7r?)vPu; z%Me(Zl=nB4QlWePNp$^_3*$mfkYMJYOnbel@?X&~o9hK&#X@}B;$iNN{R!h1Ei~R^Uub6x=2Xr!*az-0m_a>cE*jg4 zu(%3~UyE^TV`k(fYu)PS%tF{^;Bl8wX7In;^&#z^RF`M7})^2tgr1klX(EjObl)#{=})n;#orkc~l;+2}7 z?CRZVZQV;F2tONn2Ru|7DdWqPxQ0ZOePIVr-NKeT*mHxSW;n~e7NCQKB9G>x4mf6{C@b&G82 z?87F}Et<{3XL6yfR$f}0Y|lw9x~OmCMs6GyXJ-~^*owO{-C}zn6irmP;-b1#eM{>$ zzKB_|jUpE9D|l*%;}CkH)nSQ~e50uG*lBr^Di4`w5=}-Z+g&cg2o~?ImoKeNEJJZR zM|NNnAVQFR<4_jO5TITP!y$tqoME9GWcSO!dE4#3#hAr60 zeBv**upuMlFcXE(*PBO?Ct*jI3`^U9f?K0uTaqrkq1I}$%fR9oK`dsIielkVIqC2K zRcfJ(8pL zEX=SqdiIj!RFvLWGX~J_?8})-ESA%k1)9}5GC3&ZI(xy^ufbFsOv09= z3Jzbz_AapS(Wl+-Ve5|x#d0h>7}42MLJ;AZ#3~fIqf(VN5(E1ghwR7zy5AVX$}fb; zBf~;}-z=q;jj%>T+v|-d*fI;p%fz?R;}n=bEvEkj`w=5KL1Y945SM->Wi0gIEARQN z9I5ZDg+AaW+2S?UgR4s!K8O)(T@)C$Xdh|FoGU5$kgrl&mkqmXnVltBVv7=C!~IB& zm0RdgM=tnBHp4Sruca%>R^TdE_Zl%X*@|Wc<6#Q|0n)hT)ycu)bKKyX$x`dGtRd{7 zun9XBlBp0c(})o){*w7=aYKvEs~nt&9!>>`A;KV7@IW$Xkif3R9Fah5KV|Z;vs1D? zwkA?p^V%0SvQ_f#pbXeQ=&x8|%Kt)!nMzC6YhOQpS-{wYs8bM*!NOH69AUfI2pXQr zLS~$NCwCwjx@%ftwiR8+ucFgJ7qCcbP3=FVf`YA@ZOgT~ibW{^%7{y%gg|qU$@#KG zq2ed-b*Ajp+9r|Z~nuoLAJ#YNUZ3?9Jhee0@IIhJP!vZ$h z;tQIINhb*_#l~s^n*lM96-a~PttKajG(l-~MZ_$38x{)HJAw1GGhUD@JSJ!`DpvIN zrE!Uj=bN;Uy-AyCr7}19TDdZm<-DmJaVmim{AHx}^e^(4?rRlA=`>q{yiD`4CMV0Z zL5->5`#|ED*=VxPjt**}EVRlTSjQeHPhe+j$F#C+qoT-#U zD34uK!RQj(Ye!C#ou;%}X}B3B!m=QLYC+VjJGB^hz@thSX!U&KnzbOzw3W#vHP+@w zl1tdYUZ!xe!FKWh@M*F^W^CMFz5zoi6C0U5p4)!80+Y;vy~6Y^buk_~;fN6|?7O{~ z55yRvIpzAB5WzIVA5q7qP)s}2v<_GDUXv%;fL<9aE-aTjv@+dLlhw>Vk&3M2bQS&$ zrVR~==baP}DY6MCLnNzLjg6VSt@v*CIn=~PV-YtESCeXsr^vtNw7Y?KuEFwq! zm24-dm;~bQwQyH|+Ut>38J)9i&quzg6Mbn*dPs8}tyE|yn-+=*vaQ>!-XMZylJBj# zaw+7%Vr$cea25-0=A56o8$8dp(CHY+xQztm$3qQBEPpnlks?))#Z<~hZKGObViZ#} zGp5d6rjdRJy%5|{w2;$1N znOS6*uu5Eya=Wt-u_6Oo-3wF-jAyiksFn5<4An-s5JS!5%;KAj_nhFYUmRRU1u;ye!QOaj%<)Vty)WXyS#o6hgflE3KV1g}nG=R~G0|qCPr4nr<1x zL(NhqCfh8BXHVjGtz=`Bb-l_6-|9@uWjbKMpSEuBt%-;4nIu*V-W^ z@7K?B@Ls^yTzG{!{-pGtlnc-#e_!=)o zKz71c*rH>4c%FJ%d=SIsGF)eU!w%4y@7h}2usyw&X-Ws2IL_1fk*8!W?S zrQ@Rm&`{GjE*-kRGxe|E z+YkoO#v)1ylpQq6>Eo`6@eK4<#_e(D=Cu=(()`W5 z!c=DRlph#3h5&g_qVLP9(Z&Ir0{Dn@cP;W?^-cUSKwmeUM8vdmz`~DLq2@{`S8Uxs&Z!J ziRC9JM>);UcjvoR^SHdl;j$KZjpkC?DTp|aVa(1XTB>aU}Sp~2_Ds) zw;6~XF%|@lO*>yOixUO%mr`wrMvD(^4%=^Mot^e_k=6nN93Gpb5D1 zsLNyvHm2^ph;uG(nVtR|uD*^1j%15%f>hYY_m;*zJ;7O0ye6&-B8hD?JA0$~9=`^85#gM6p8u|Q8GMQjRo5m&P4gl3?Tzv$`7z7#`5dd=r{ z!jbye^7wJ_-Ha@O{R??A3WRuw1v+hMLe*P%9JJlPtMWTtvKV1}Hxf>w$F$$Mq#`V< znTD#SnYaKXT#>`!i3& z>B6g$aI}wz7;|^m%xidL1c+ba`f+Q>L2>}w>{ZZC;FmmOyffVS{SIB501r*MuuaGb`; z4oD2K!@jq$i$nR!rD;nL4i?R@SZ}~|ZnhWRBzhi6rCdbIT*-$pyNMTuT(B5tMRn-h z{?M(O*&k_Pw!{Oa(Ti6ueH<3!f@%AI=f-bQyf)*OY?VfYiCd>+y+TaZj|#EmnJeB_ zQrLqnBM2pwb2b`s*36o2YJsh>6t_#o$2!ky;egmiT4v$0*t}GNINOneAf9F8RiSFd zz+*_(*Z&Hhi)l=4;X_TE;l-*So>YS~MBx%2)<$a!mxx$r87w%{$E(1l}{*&fh@^;5P=jtDgyVnkDV!=CuPo=P(9^bZ|zN4%84 z+{>NvaR2S>ALRF{{J!^^S4^(bMXJRH*k-75A=}W2edR|mR_THHB)&v4P-Bg-Zsw~= z#%w7^60-txhGWmpMC|Xe-g}foi(nKr5OyBw7FEeL&RR=5`MGn=>og*Fuw#C zg9j%YU0T#zWhq(JtuJ%PrMq$g8TuR_fT1`dK+;Z`Z4K9bCR_6@PGVtS-IN;IYXxNS z6<#xGD}yGLAU>S!Ywp#!#v;v;$7%9?f<0D5pozKZ<#po1YaKX2uOKvS8dHrVQRcTe zuejIc_HQoaZ1-eX>Qa-nFHv#cxYmpiwCf04;Qv! z)7G-H?c3RcixVL1b|}~vgEX1o{Y%(oopi~PKKoB<(3F8l z;Mr`=(iRZ{*&$)^Hw%zK`1?EkV@!G7R*?teAiv#;2PZLe8#X?(eUvTc=?f;;3|%EU zM>|KSP@ceNMVXV$(p>yo84Rj-t2gHt5l>cL!9ya1rz;AaHbDn^#Hq-Ok>N5cS5mad zez;i9ad9s^Llk2OY7V;h%36)_=7UCFR9!sTUn|(*aPmQN$g~{z_hI~p#!18GqRaIVqMI? z$P3jJ;>IxCDK{!*iG~8HlS4!1W-IWA1dIAm233d<@;*0zV3mSL7%i$9yOXJNw1y5H zotj~NL5aeKWjEY%rvW0E8p=!F<`>=S}9m}>Du!{x5PN(%ag+UzdJZ1InV+f{HO2W__Kp`1b8IfrQ!#5;3| zhnlWI)Ir}iL1mma>!$^9<+F!)N`>%Lm4(2P?psjuzX-R6Hg%dD7_yp7ecHg8n#?RH zJdnLAyiiDNsm@<<5S2R$Qa>T({19J@ve`NXUGRgpbBm=Hj{Naw$;~@ot8heGvNPLJ zT0+P$?kg=^6}&JcLFU7lUsbpbm3FgXzSaS<)gj;W8`v~9*)@pmrG@JD)Xvs11DQeB z1(%i=Y`ExmbFj2&)~=tT7F|L$8>a>yF3o3)@FZJx&xdX7wn@i)p=sJGQ{2*=UySDM zUf5pLx7VC90sUt3&`FE%&DbmllkjuSa+oOIaMu;4OtE;3IN#CRl?uf0sg$I%QVty{UxU`w{yF7bZxUif>1g{=L# z{jHTt`HC$*ux%J&^MIP|IX%SL;$2?HnAkiUH`ow!VFL_JMg~{EQEM7WUVbX-F+NjbG z?JKGoO6XCER@uRbO+S@drin!v#ZcPYtp1T{u{T*@P0_$(WT$ZTNZ1qgGwr>sK zy)8seD@MX8jAL$w%yv(y-33eE`J8&{C`tt-@`DTcy+CJ%@-WUU3Y(>WUj^D8m3_nQ z5)3u=S-IP@wb$BXgCedOM?BHlvI$;f?k7-S&WEzZSZ*u)Xq{DLfhLyzymd1E#DxkD z8l5(WEu2z8cCn6;UbOQoVZ=ZM4i91EAgtp6#=w@D9Qi25vNzcoK>N|6c#Obu>JVN2 zbzZxiJQ@&O3 z$G$RoX))3u)*N_|2!;lm*R&wesJA$w7jxf(`aL(E_T=Own`~J)nadKJos$VgNr<5M ztt`JW&5!I-wtRFfCz+BAiJun@O}9J5vxx$~+bq!!-$hGB*@`WKXu9jfIEnCD@t%k) zr;VaiO~Fnt{vGUIu9Dzv!=logQe}I8gZso>D!(r_hd0{rb|t_3hcJx9O0Fi{*XCa) zSE(ZV4Y)$r3hhSi6uQ}yTn(iq#f{@N!c)1`5RD`)gInAc+0O{W+}L$o!_Q>p>LVTE z>dVTJS6y!qAu^i!!Bf$=2es-7qI5GX{6ZS@TCsR*RB*aslFr7u_V1=-B zMHDOc!hXpImd0ZXH(?k@GBe!*%G~)ZhhOy*XEcSvdKlqxuKG%uhtFdeMTs}csneAEnTrYULX6ubv$~5bZvt$U( z@LpK?#YGl`Eq)wYfz3LSn2_CmG>*fiSvVcpwn&MeNcmmDF6>W9d(eKAO=oG?-j@~w&$P0JPz z5I$ZuXRs{Z6~`tuqsxDj6RrM9Vp42Zw#3>uU70YQYOlAU?wlsI@1!4*c&_f zX(C$!&EoeMja(7HZ_y!33I1FotAu2B63Qf&$q8S`e0Fk8ID)`m+U}d`ROYi2)35$7 z+ZioGZ7|UacW7}tk$vOmGG+cfdeb}Xi5o61VRQ;k3l6riT;_C-eKLwl^ZSKXl8*W< zi6@1r+V)EO5GG+H6N{o*^CQnCwFacrPhfdWZJ&A9cc$j4w;bGpjL^CgV?*}KX)JuC zYPEg>fY*dF*u97^4Urp_iTaQ&7ECWx2ck7vJM6N-8Fj|jW&($*v)zEx%VL##RF_Pm zYWy7O^bam$JGU2NjF7jUgKF$1^jHkd^$x=?Ju?~<&aecoagyZ6?S9YaOY@U?d;8Mc z;N_y$tlz)Ce9yI1itzX4@C~Ane6M8G+>~N64ZJ zmv&FHHPoB9JrRJp8Jzf{2b{?;qEX0uI}Pl5#RW~YEifVL%xBss>EoN3t<(9{<0Yq&-|Se-(PV^K)UtoEd&5Dg8767MB5wG#sc-;_sDZ?BydR70qoYaq zbxuuLw3L35A^vt0@k;gyXk~!ep9JbfY$sB^Nw%&N1xkA-`x2oPZqJSiKLS`DNO!lx zl6Nst+=81FUrnS+P(?#q>ARK5u6k^&6}+*_!NABK~x4FWW=eT4veGL7LeX`K0`{ zSwF=uljrJo_wBZ}b7LRwL}LgGPro3g6H#+gm~{a+kOXxr)lx3d%*f};tgN-R>)OH_ z|IiYHCh?mb9Tb!=IgsC? zg%i3rwukD2-K)ok+TB~5ed&Q4h}w6@`zv()8c*1&iJjiPmD$smauFaje){NNyB|< zPfz}o3wfdQE{t>ia#vs4-HjCCEVNF1ciJoB9fKT}?aMP=x#=Ri3aSscH2d|g@-K4r zj17-|j(MfVa0W40IJzUo1JaB2_7 zzIv`}ADE=``7h=FxarHmh4%Nw7h-r2KTuO^xuS(Df~og`$qZoGZ{_@g(yZqHrvJm;ia>N?8J#9^xf@g~Zp zLj7usP7vS;==VfYKE{sJ0eKjS_Uzd`F|Li<+`B~N5;@3nIvX0sxuHds>N+N!Jm<)z5m_!-_>uS4C`x(0bHx9--F}z&i!}Y|505Z&FPDZ zteX4Zy=KpDPKAxIa={Ox@e6)*$NFdw_Uvx#+0AA8b^rLI>eG(8jv!cnL^jA|JD9y% zR%Z~-s^$K>_(l1|G?)3l=J-mrx9X!16fYE76~-i$Pn;?OoPER(!^?G9DA5#0a*;pV zP@ia3>bmd9GzeP7RH47j2U;Xl?fzVS8>a_&^H4axld;{Yj57`>zfyzHsy#{JV>N~X z%Vf%PSFlJk7PD%-0}K1v7n*Xl5I@h{!doJ)wdY+7eepaO#TN1oB4WiXm^Wgl!e9>B zh|pF!0yq-z)}p+F&g^XYrgyLvR1uMF31DDk&)vixv6qy$BJOH77+fAPWadukL*=xq z&TTlHY{*cXHws75BvG-}m}u5Ti(=bigWM=->oZ0ZA8XIMm_j}26*ab5Zs!VGfN8MNGVIj7fFH-JZMYm#C)It`^7L%s8=b@7Y}?GD$IkGyBpjG)UvDV^7j?aF59+;lKs&>&XZr5iq3T_C)i1guS;fN`? z$-vgoHL~l+Cu$l}s~pa-+c(7Hbb`q?!p2;UI>H0CkT^4D)FUsOdnmlT^o*W!vF6!| zO}C6vgZTaWiDct^1RHvr^D^|aI=p8$OR?5djz_94>fIX!D*UFJ^}*T-7ucdxmQCsD zy@+juanu?(VgeFFT%;%Cg%};vN?taP858|<`q~{_9UJ&QWAQKoEYnbtHJN{06?i85 z(SScV*AuJCWnyUE6RfC|=ZRD!mT^AB^crvdA+^ntwXL5MPE`mr=FUXT7cOSm#O{X% z6=|7rj9Dw4CW^M$Q(8xTF*BWY$M)>TuF|%p`RI!_Mwg~cJDn-E_0-$FXLs>$<3-!(@SnmG_Zr2;;+{j$Zn_}fCA7!c&(i(oa_HeaU*!Rs1Yr$idl{(+b_xA+Hf zXoM+H&_09BNBOCFmLcqQr95xd7dJEL`PUl!D9pBJNX#QB4ks1Xc)h8Wzreg2t>W z9eZPeA1Oi*ej&d-S+9YYB80^-R)ev&a|$=Kcl1-!iy0BvsER1H{$UmkOE=jy2$~=^ zrY@!^&8`LuVjhQ9`&Jr*bcqf#xI^5yKwciSE!eVWH!av^dW3KMY=hhk*U0KkQPcW9 zjLZ~J<0T@qY9y`;wkbd5OT%?D5Iv41n(k5Xq1Ugx5($u;=w(J{$D*XWyU+ehI4&j8 zEph2agtTv4TASZTj_qeuHPB6rGA4r>o|!Km!GQ%tP6*7kAqWr221rr#c;Ql>l>FWv z4E65J4B$pZti!!FW}0!lkouyAP|zPP_W|WfH&s-XcT+D!b zK+KIPh;L-%dMx&b8mGfxVt9!sHfl-Wzz>AU?GsbZl98DF<=#Jr{GqZdQR&Gr8Bt++yB=Oem zBEd_f&hO!7cqK7pP_Rjlv2>fyrL>q<+=%KmV1WYfMUOCx{X=&jh|f-+q_7t|25dno zUC)nTBO&b4xU6L3bI6VEz;Yp~gss9n9^ch%7Bd#ixC}fu0IJ-$jLFTIir8jVF$gB} zH9|efo}0w8m~L7CNeDvUF*M6iN14ZjwA3_L$gIm1@^B)QVqL zlzka3$S5Y0t+HIro*ltLgni6hYfC`UaAJQNn^m^HV_F@lMO<9}H)}NM&$`x5Hs?*C zl@PgV9!qydG^WI^%-C4W;cAQTn8~h*`vD^Zq;M89(@4q)NmwWNDi*NuHZmluFvss! zJ(|I`3*`E7hP^bMqV>6Z2%E+PT@~++ouN2)uKM$#F%Hw%M4r-D(e8g2zW5wCPSGT@ zS78^A=UeNgx>vaa0%1&Un$N{J;_;5kg$@HB3ZIsNIyJWdK1=7B`Gf1tk~-7N7-5#e z%Oz@RWz&gT+>5DkgHh&v$>lW>VIM|?s}2{s{Ww!}vyV_=bfVYA#81}j*?k>tfYae5 ztuNu}*|nNxXezqWn!wiORvvyth0qMaCZ-`5)+$P(O{_31OQU>ZL}x@REz{#}9h(2A z?Ko3V7+Ec&iQl_{4Y-+%xy)>ce}xGyZgR^mf1`|bbAO6m*6BSB8d5vi^Ad)^{m%BD zkD3K5%TG*}dwn?97-1|FPzOUPoon_477zxL#17+Dv(RH4LNO+*53KcS+$6C*Kilqz zXw}@>1Oq(5fTwtD&x8Fwi z26I_1yCm2|YL`VTYMdv2oCXv}O}0OxkKnC@fkv+1>7m^gCs>y)|MybLZ;Ef?(m z%uEu+QR8QF;bEw_^@>&V8w2gJ<$qZD)7VYa5*ra6GQyYI{zS`P)gc5q41Y*Xxelg* z(snMs%v+R>3X!vgLG{E)ow$=dicHW&YDP)fi5-~(!drelr)(PT?Zd+JbRiN+GT7S_EyP912IORsq{Tc;6~zl+B9xzR;SE8F zLX3J-@R;xaDCR=pxioQ%U8_UIcPJDpAy$Slz;s2qM+Q zI3JHQ3gY^lSEdhSX+FqAScL{~?IHHJ0dS*-tF-ic7GkP|6)ce}S!ISO{3kzD8pc+s zb`VH~l3WG6rRIR~ml~s?ivePr9tfZiA5K^O zo^bQ5#hbQhgx$IN)fD$D_*M!$*oo$e??vgwuFK=VdxE^QQ8Gai$LtB|8e&eGuUzMA z`cDBTevd)p5Zt}!n3)TvF^hu`oWH{4hL<%{f^8_tXKO2p6yw?u4D#Bg9dJZyc3^QF zd1Br~G)q)FaYB!$XvbJIQ^GW{)q`>nxHvYZ&P;Qd=*5E=L4^d)MHCXeGBem0|J6oj zx(EMo>mUtEL55BtV?`R*c#v}lwOlpQS3C?W-Bxn+74bpwP%uhSZK^CIro|R2<5kmL zwLR|~@8!3p!`f9NOhJu1?N_Y6qgjDbB%)d@jcR12S)o}dlDE;{>M67umbDXVsy-T% zNI6o03Kl^ibJm2=Gg-QvNxcCcDbGgOhpZ4tl4x68=Wz362fx55ZK{P0hQlTGD0>2I z$)?4H)EKN9YC14d=U5?Dyof)&j=|d4IPoc$PFc6o^D5~u7bLHk8yD{j3+f7!^bR(w z{CahxGi}2Z=YhL9rWBXwYvslFUQUkTNU*J8?)CvI6CN8ddAby%tW1 z))Z1cBdvy>6;K}8RFJsS18NNh2F;00;O9zLH5y|4WHpm8?XR?&980O7=gqg@>}%Z$ z2Ka-br=9q8Wk0RfyP<)t z7uxa_0>I_A+OAMoT{n=+A|b6=71ZzEs))X&#;BiitAJjtn*% z>5sUMRggO2F-xkxk~hl=m(?+?305w}W%-ILfWbMB!a*TE{S0O)kNhD;YApO&AO%93 zH4JnLzdr!ked#zzL?@jTP%r{z_2sOU3~1O29tokT7!xq zJ1olJv9TG!nXaq>Fq_=`M@Hc_WuH4&D8%0?KSO5g3Qx%|(-Z~j(W>c{A>&Qx&wL|8 zGc0B2va4S_9_OXv6#SN9K2|0aD;`@wwW&|1g8`C;4M^fVJLWe|77I9DZTl z5Vjs_al}-*b@uo}ra0Y7DR>H$JH{RWxj?q^p=w1PQxk>XT{0n4FyU;SY?hBSrg;d? z9bks2)?mW{POmo65cINTFE&AB;Rortd}X^_Z@Eb56B}3{YT==b7BQoKY1uA8Doq8m zGMEsSm@1k+aEhr(oX1_j`nk0TJJfmM`8M}%TyN^k9#Aj2=_MO#~Y z-fiJ$BxwE+2kB1ZgJLL5Dn$Z7K`>V~AyGI4%`m5b#B`&oI-qL6iIQJq0H1-P3T2D)7##IMCJ6Ts_PA&L|sN7#(l zDy{-S$~bTA&mcf$AQooSJU7MF4rG%Jy4sM5=gj*qkdwG?SdL@SxXKh_?|^1sh!&Ow zC`J|Xr4(R~EwKh}vTbB}TeV!h22nycA!|_-m-lBC-=u}UTGNxY9;}p{EO=$EF*B-^ zDPbf)1j$=4LqpTeG-{MaN%(25Y0b*p4k<886>ZH{3(yDI8fiISX44n63ritlq+PV2 z*gxV9x_xW<(<`J*d{bTN>siME_HquKpIH`Ie3BhutfeUmO?6uWSy1ct*i?+}Fz=@+ zxxx^etP^{c#u#nJRzYo+lWH!twLrW~(t3;JWR=F1eMf3-kU1{Dv-(14=^_L^WOBJz zcW*k@7=KVU+DgS{mRZ3ToXnHJm^O{=Tvcc+wxe3(7Ae)a7>uly%?VcL%+=*w4tfjM z#a6u;G`=7VEQ3Ktovypt@VLS^VXzf`FHujYny^MRVYTq2MG4*q+rh2O!bmXIj2%K* zt7-%^^r{?Ba_bqh(1MZN_GSiHa7m#9J!V8)t4e(4d$DSnLRACJ`PJe^`~W+USvA{E zr)jLjFJKgMxhlokbUn_zlH*xRE>@U0;dd`NWWhsLVPt7aq>IsPd~<)l=)(Gv!xrB= z2{APF#NyFmkldfXEm1bSiDkZmgc>`E3IZHd3qfLO)&SdPS;#ROB8kD9gf_Dj;TtQn z9X*gzn>N(EqNpy4zvAC1@)BL4FgaF&x+K<$%Z+fP^oh^?$Nez-N{r(kPDyWQ@2CW* zJHX)!Dqn?Yl2NUi8BO9gVNXJFo+|)g3qz5A7siz*+3_rJU}cNQ!NbGlb2DubQ=?D= z@dhn3@r#CettM*V{48o97tL&y+-jfYbFV4){)?X!od2*$mGzO@igM#p_acqrHGVil zp>hZrm8E-Sr7SUEsX*rpOV(EU%R)FCmbA~lCrn27%8LXR2+ixQwUR3oj$H)z+m*4U@5>`s2t89`;UIP=DB7i!>3MPN$v##IOws*W^-{iK*$jOfhm z1Y)l>&1yR-c_n6z)y(f#M^M@^&MskI3gwEIvQV5gBWNg<%zzM*qGD~1Vp;5+m7Zj4 zzU&FtpQk zYqKE&*VFf%>Kw@EShlS^e9RUVO;Usxd>w+H2pMCYOqk;%Dzd|oIywerwOwU%KFv{s zWv;UwEZz3m;|Yh1x$JvX!(c&@V1uJ<38mew6(Fm>*1%t4!%|qi%)3m$B7lEy{Y zbi(8+emd(*t$S9uTpRXtTZFB-uw!_s@1z9u3x82ePSYVaO^Va(@yae*7-lw@+@a_W zd#zdY_GD)G6{V@zEj9tB3Jqj%qHj5)BZpPsnU@b*UM*5B2)d|6%Iu`^D9OE8r^l~K)#lU=<+A{yZTmLUFdBk* z5OEZs&>mZ};?SkVFapYiO(xOjw1XU>3nHKG;F#7Zh3cgPRi8Gbg?qrPUS*I*EejHB zgY#|FI5MD$%%>lv8fSwm{g1Oa2D;p_kmD1m(OZ~m$!g5G&Yln0@)z!%q6BLjgJaq+ z75Wioyr#0^m_*vbvRFF5#p<~NhTNRd$>c>CZ%x%?i{wg-lMxQhM%Pywvwb=0j&^40 z)JG|kg`#9o@++P?9DvNzgkokhXGP({3RG0pzDcA|jB9kU3e87UR6Dj0IBJ7zKN2Oo z?=g+Ig`%vTYceQ}XB~B0>NGMPr9gp#DJcIi}Y~%Q+0O%ywsR z7UXm+JM&8e^aWR6n$AqCVBD}Asd1avPS+F~o6bLZ=^1A&PjiP|3eMdVdhHIc7a2qm zWenJgJRIxij$F}{RQF6@2Zbrm*Y{wZNz9FqCxl7tyciaDKpT{7l(MG?pWyCik3`kr zl(ZAus8mu{;zFb*yIDDX`1^|2z^q>ri_5CeoJ{h7%}$OQOaqqVKUn@ z%j6=|R-Z|8Vzg$Z*&isF7>H$wEm^nfaxA7zaZ|4ZC5s1bJx})hF(R%CUr9R4_79?& z0>UDlDIKf9UiFlMU8r4FR>H}hT<(oy;}C%fc7S{i-?6G~vn8LwWQWe<*n5jkC>N|A zj(ez8VZ9(d*^VnQf0$8RIm`C1bz(n$^(}htd4P;fI*OBAc1f}>^rKWx0UogqcZb@S@K-y`&y>!kG)4kP+NtUW-cr8s>_c!b0~Hw1vsNb zGZh=mLSMaixgOSH!W?q737Hp`3mI(Unqswx;fYIYpk>1OO2VQnI+xpECSwZ0wxYM0 z+fU5={yd6X91f;)w1!JoaInF|5|EIV!+mY+K&hUAZvJfT|A~wm`%7u&w zpeT7rNQowCIe}pa&1Q?D!a?a`YcdQ3xd@P}JVJaI+X(Uy;hW?M@(B6(E0q}vQ zCwJzwIvB~#xTZax?LkB+3qnJ7gFt9h?03d_6!)0bv9{l@_*`E8rrm#^8gv!J$U7Bx zZN)nsB&Cq-iGDJ`!b$grtBwsxavTaJm=25eF9&9^IuGy#iH!J+ zSON4|g~@T?Mt{hZxWIZ#24bXZ!@R!Yo0%ZB`JaFL*MG))ugDk8XW)PNDR2CYKJQ3% z+gy2ja~GY5A_wf}mA64Kp8}S0MU<=;U=#+TjS`h$!%MEscC-hRb~Zrp4@ntZ-q8xB zjAI-K@b4@?`q5jrZwIvFC^$74S)~>!jRxr)u?zF#dM4sJkmUH^jyKGfTz)#BZAnxG zqTKJ|InIBnC5{~;9?sklR3IH13`x|)h=sJ)juqjuTsD$c0VwcD1B94ml60&)`mS8J z2$qP$7PxTbQ(=pRe6E05TZ*XZ+BOd<&?!YAw?^9hrSKhKN;_xQwuCr-=cU!C1HUDz zhY4Rs^~;MkUMFP|_4hjhZF3L4 zneI1yLLuj`Z7zQ;s((FVl*SQ5BLIdK%qcTVUS#Usqo6TZd0b-;TD+0vpHfe3EG4c1 zEo*BuJ!s#DN9NLesK(uZuQ`U%8YykR{0*C8Wj7#|>NZl4%qbi(Bz`9XQ>74(;BXhA z_xX&HSE)J=8u~bSjBSFYh`l82cELLT?B(yE#0UbVrg7#SX&wO?1T*#~HSgaeazuQ- zQU_qk{+cbw&Nn~1bNd##x&GleGr^NEIifJk(<7tdq3X1#>ZUUvXXG;%9u6T+QE^_| zuZV_c$@yU05s*8_ex`JFRm#d-KqV z-AM|ZdBT5=2FB&}{6tj`w9h|&*M%e=F84COLU@^z_#%$uoQg4M=o~C1C=e+xmfRR^ zTFM2Qu>qr3+^8uNn^Z%|jkzxcKZ&yA3?x^|@(cvvR*{5DqGQ9C!Iw@9w2Y#G3zViw z$bciF<>hZLpT4eH{=V~QY+jse;EXu}Ry;=Z2d+kf{GmLE2d_>+@Jtd}ly$2kh)$4v z-da@g{K0@=gb=-OyI2|t$4sLx%}n?NGZ3-mx`x95N2g#tHid3FSJkmdLk*V6SCbA! zY-g~wAZfmi#Cb28%p9p0k4YibiHLOW!O^lWD##qABJWug3m^K7p!+bhZPou+$+imc z)v{G`=fFgII%lKa8bMkEwSLIV-tKxAChs%rMyLUaqa|HriJ|Z;n1rcM|z z-$@6M4Ut=@3g~Lsl9nSiG}+$;5Mk^Ts_w`S@CY2)ej*_vmuPm7h6my1qp}J`$Zqh@ zmD{(ky!$SWIrQy0X1Cu zg~aaoEF9v%!(;Wkv3j>!kdiJU-ZEv$PMT0 zD8DB*WWr&Y`}jP6rU`EUYvW2XYbONwL6i zva2=zG^#2I7zs4m&O8w|u7qg`bzxcC^mczK?w%Yngcs5+uNlDSeq zqtbXu$}6^^3j`o*Gn7-6gRu3j6)1xNTwEo*7=TM=-QY&3%&aR24nf#ma`E^ zi=-X*$w&+H^*;O(E$l0p6>P@n0$UQ&gv-OzjJMbbn{c#&eSRdAYgZM|wXbzJo6d_> zr!mis5w0fk%0Bz^O7Xlk4JxcYtc46{)T9VRko9W%WAW<ajqFH@4u!VhcKmRDc| zb1d|1Vu)2+Ulm>6lz+PABEv_z|LdYQ!18-qci1elr!N>mcQ^dL{r493_da9}Zi&$n z?!tfKH_TSh8K~moN}l%>tE2kD%WW$4a3MIy{T(h8A`wwGI27_w!7%t}6xStJLKhCS zj7tzTbanPLEAeJ%OXv`2%VZjCVXpLoeu=e50h49&t%^o3ZcwDkv>)SRVoJhCqxsaw z=lW*U>Vefs@z+2SUYmOq@dU|G*970omKv5Wl z+N`Fp1M{JnGm=BW7O|BDTLheAnJtky$-|@NeHI+UNA&e6MJ5>E`|OTnV*pa8XN-YX z;Zp*J83eo1ccMlT^hK(;a{&*1Pc#~BK`Qa!NSXN!N?pX{cAB-M$QZCpQbkT<%tjc9 z#74do*6t9sLM-SVkbeeUyI+6i9@U>K?Ijy5S9&q#{MgYOYP3aDa4|CO8=S%lJz2Hc z*h9V@iFUSnCYyK6#$Es0#E)9@158XwMkH4=EJXv|hj zi_Rm`P4#A?u&N4MFb6izyK0ZwYfwmN|4u}(YH|r0S${SY#oi~Ny-pXt&SbY0p0N|a z;#gj9OlB`ASz<861ncOWJATPP_fbwBlgtJ3cWhINP52S^C6Rk5T~8nyyc!tC$b@uo zfil5X#}#Yrz|~lMzq8M(%%hUU$=#fEfz);UR5+PRC04Ef_D#RDIoiG@>q`_AU(-4EVxIZE)J zs?BDzJD4_VFg1arV)+~5($XrdD}Wpur!{DU1+cD}2O^?Vp_DERwPS(2&zLW(9FaJz zMhiybJW5W?E2QAVE6qY*ZrKgxAf9jes-SgQm?$X$LNbjAsCpjpEDBemZ!M=2I8I+& zMQP@fEEQ)x31juqxj|h7CX4kkDxIGpw|4wTQDVTQ_s0GUp1JDIa*GvF#6jx_m%I6mIjrXM#jL*c}$W zkE=J+&0%kY{2hFaGr^)+a7uk&9~aGy%V*z=KzcJ>2J5&_C95POKUF=NwNVf*@^ zfIQ*A70@+ge%jB6qNc6Y?-2~iz`|XD#;GJ+M+44r;rLYT-?MO@!f4VKrdTiBX(}iD z7y?8GsxUhBmoA4GS$i|-E|)KLqnT`4!&Z(34zQ=(BxrQ=-kRqWZynU&C_`OW1^T=8JAQet0%$ow>Vu5{`r&o0-1{rwhG3byW zeV#2@cwvKSHFAk+xmRRXXX&p&=!xWphBD~41lEWWNMuUQ+o>Zf##FHZ8K@TqLJpMZ zKEyIdMyg7Ec0*o$`0E`Xdoq}~6~h{aEQ@;RPO@W)HJqL)V^1GoDxc#yS9ZmFsHRW& zP+27ov=tP8|Nc#3;a>Ch%Pd&Nk0*To;1>!&t*B=Kq3VFu+>*p zO|?`3Nn&Qv)JUQw^Hnlwdbz&-{Jsz4l#4~NmIK|HMYYHp2kS~~&m6EMZh#1=_Sh5A zloYY34V(4gL?lE1ZPbFoM3`&I4Fj>rwVqme-)$ItyNgMzM$>q&v_6gIx#6WYCr3fe~AUp-msS2cpnp$ddf3*r-y=6yLF4XS=jC!4s*%p5c}= zl7*qDk}ieg;M9(7;e~iWd^saZ`iH|n=RKrtE`37DtsNT1Yp*X}2Mjbuh~nZHU9s8! z+lh4wnkHtADgn8eC7zdsSa>-QN*CV^QY7YGZL-nW2vaOO7@t z+s`ux3fK-(je>)+G4Hb}$l!*$)jOhvqvc)BY}Ke2cDwE@{ZA%|L>%U1FLJkFu zila0l9G&#VS$M((7yA&48>fbRD|zP)YY5BfRI0h+h&T z%o|BAe13o;hF5}9rh&u3vTkdum7!UCg|te@i1#xtHC? zODGQsxIOa%u(ub4|0(TH40>*&42F)DNRmt=aCu10JCGm^1dk~{u-ILMNwc5cxM<7* zVBto8oUwwkOY9*b$t;dNcM)4g#;rfg4X%{L!E8%Ju|?WxDRIflGBLsl*q_3#4t?7& za5J?*-C{*qmVtJ(zFu!CEEB8hns1f&E7FuJQUNr=_Z}VVLIJi*)YGD}XZU;Q3t4To zrNZvgt693${N82uow8-;kFTiu3o9;200@!bJ~~BGi_ebTy6FaI*il-=jI4&oO)s=E zCW%+HqydB)QM0-)!P^K@bgv6?J~g9`_>c@*)Uv^vho{U1 z%9=*8I~ysqx>Uc}mB=|^tlrLpk9Wo%^cv3_Ckap%1J_0f^i>*8r>cVdd|3rL{y z&t!7#tN5-d*dAk}z;Sl+dkwAkuDk}F-i#q?>*4AGHd916DzQe#Ae_^lBS9)_?{s#% z))P`<{A3{NhY)!`>)&+8_$-LSM^n`WvkUE`~4crSq1&QF*`NT+D+ z>}n5KB`x~+<-f!F2-(pE-&rm(1p)Q{lXmAC0mcl+I9e(f(CNA@F1xU+U8|Mr;O zwkVPb7l{=>h2{PfIso>b)++&8uSO4t6V{R+bYy z3`sSGhsA*(g66+vtX}IkY(=JKXj;ZYz|-2~H%t{b6Q|ZEt|bAziLg0UlPCMK%3)*_ zJ`@|#!mnFJTXU<_mumek>itfOXTnv6PP6N#mFsTavI0DUJUWaa$f~#?Cew)>38iy# zjJU`UJ(}2Z6~MK}Uy2RlLxp%l=@n%p@7Jz~gFr1RaR&+y*9Ce+0g|QRfGk9>UAgJy zXIXr=jn*!GJ*RR%K9v>|xjj=fn=u6|AQt4)Sq^S2J&5Q>TqTx}(-TuuzP-#rcbmQP z=g`AUahP*s{(w=fI;1p%L$CiKwFC!_V$nUE$})~bSRskWvk~%2mBb70tSuytt?VzUMO4-4WZIeSc&rhX$<({a!Ro1(K0J192@~_w0 z=Mn+_SYj$AgXtHj?QTmgoAzhDGV!)(By=A5O=UuN$U*cS_Ii3y*{OAf1F;5~LW8a4 zOI(CPM^3^^NGY8`z5AvtgB+yl@Xi$*ClhKr=oPPvZy|S!VO5m*qm7e z?Z|~hjb!+9zeR@r`cRA=jElm{@EGpem1mZAvFM0w42*$kzW78ZxF+M2gHSk1R%nMHa*O(_s_}<(NC>lu5?bz@&H41%Mi6g@-EcW9*_8~SWNWfa|IojsBP_s+BYp zc+dAiPM;AFubmOa7|h-OWg@-PmlF^bfGzy`SZ>M8WOcG<@4kiH8|PIiy9eXw+Si1b zO&y7hkF=186a&{wAt_8)vvF_3!OYUv8gVdo)p;cqtqwgLhV|3+0>Nl? zT`KQ- zL-o5@HF<}ZIZM|opuff1F1lHjaa1~q#nG1z>qjCD8KxEgKvStk+A`{#slz7Pg;~gX zOqv3_CcTxN3uk8Rg&Ki>MbvE6D!6v-E&nUaD)N@KoN~&>rGRzTHxDQbt(}nC`3))( zd(h!*)HydrN%SW2aE>61h(!BfYK2R$(ZUsMBnwP+I1LBG2I6OH1gLbQfBu;cJubXr=&Y<+@7H{!{k28!k z73$5?udaxaq`~iIF@U6G#e?B7+Mcv`L_ypn(F~!`-Qz~=SVYJ$ThdkBs^p=uI_P(5 zOOrv>88;)JJJRv-LsA-R(lE(LZ0txBrvxP&+MiRRk& zKuaq?LiKn8MhfGNXRIKlhhT4JcOI&5d9>CiYDUttxE`yd`=&g5wfKQt8wXMIf2%qHLoIad_aaz$J@or6>VfB`s+ZV!}CN9 z{yI2%6&3+#a4x^Eru|;#yql3nbI)+-KSFiF(dDtW0$VDT-PmVxBSu4< zmTP<=7pkq&fu3{OhlLs&+0&~71p}kM8W_F#{lzOI2CCILr6iQ9QTN2UzCao&hA9w_ zlt6TQ2z{4%v>3Hk?;fV>s>k*?Y8Wi*a56^Q+#wc9r%_*U2_41LuiI~7o@G&A4f%(y zD&xwY@3Y_-PI}@bAjcb36nXX@iSa(X$YV)Z$uKbkC%4}{en6N6a6%?~EVmV7Te4VU z^@2n-Np9p{JQ zZPW)k)&2m2V4%atN^EwO-py-or2IvGGD!yAz2B>Hywm$9LfkSlEwDwc0Hf^b8oMfF z0BKNE6p`tI|Bt&8^0^$J<#1CPT6vO^H@Z?LEvrA@HmH?tsI{Z9++)2Oi2k+(f|*qW zuL&yo5G4W9&dVnk{_K%v>_>fV=wu@Q^_LLKkcptZthU6NId5o3oQmC2TbmmW5mA~Q z>QlyNVGa-v$NkU$LUfIUk9kV^C#1n)-PKiZvgOor@Cu(1bg1UeD|VFrhMW?tX1Je? zX9~&D=8^Dr5|>CXfO3jI@&Vd zn>Z&mj>P8B&i58JlR5hGA4M4`U2x}Tfq8jE$DcEfn@=mz)gBg1 z1Vsxy)*C;?F8BCT7yyPgYYB69&V7NMj)%9ot7AaR+g&dMjV+!k-TQZG(Qou@UuqKGv}P4nP2J|do=@H@5X{D zpd1wfo>v_}bonNzA}R@A#}YAT^i~^d9#HGPzaaxevZY<>5wQcjG(beWXS~4v+Q?#H znkk#rH?e@Gv7(WL0~|5m1t^4SkZbfFJbxg>LwUohH6F*E#fb$xapb>OTD$^|fACzW zO_OoDg-6@DQDxf9B398!k(IzR8e$Ks)w^-!FMi5cGBI%w5FmG)N=5{lTjciJbT!p+& z0S_7TCBfS=dPGL1LC$JaDHJ4w+T>d{g`40}P_Q%9^48R_xRb0?DgIjMVDzqkaQ-DA zq*#tQSc*Hk#nMeGQDtMeQeJ0~ng#Ws`)CLoD0M_3!Y!nbj|*`%Xp+9YamCWbG95RWWQi;|=C~qdQg2EAW!*Dt6W~6xj>e01Uih_i zsKInD4Q@Srn@tfy&5Q8jxQT&9bxY4mn-K9w|WIi5=(2Wq~W0t@LQ^lYR#O86JXfqo0W-bKbnD)4ReU zZBUg1cm2ruvz@othhN5__()9aS31n~0eZsu>92NP*@2aNH+F$w-I$AH?1Mz~!w^cW zv<1%POW*qwsq0$Tl0~e+#ZXqu!-);|^+J_WwWlc^2OZ;iF*`DLQFCz^g%za0VvozG z>s_Agl5iB@`1|nrANGn-7`Y=VR4@zJn8C7$l#rxAq~xe^omGeP+dQOH21LmI7g_nZ z#Vl_|SZ}KIFgwydkE|ztn33U9CqrBsdCay>3G1A0l%1Bm&Dx5y(-Z33u+egQ$JrS2 zG0*}KQQ!xCB||gQNetnqrn@mM6#GWAr5sIWtFJ-_Q}iPxIl9u6)UBC17j_C{fYh6J z&a~3o4&K@dchK*tgQQYf@@!!Eh-9O0HqwrkpF4!fIfJK2m^cRE=8L$dUo1b*Tz7uE zC1C|6L6a{|f3c*VR6nJ`)^UP8rMGZtPO4ID7M^p7bXyluGDmqkd@Su1xe%OH!3n@! z98TH3BsOs)-=KDDjbB)2(cT`?IF|CFvUG%3yf_a|xag1tyYjCo@)r2FV$;kG#v`*_ z`iB=^T~ci4mRbeJtf5u&0ok7*Ucx)MdmFWgusQ^xR)(3x78x4lqCmkAJb|Ab{^%rB zQSWjy^HIz6>Rq<F}RNAauDSK-o&(F(ZX+k1Dz}_ z?6wo)b@A|gVE7(^52&%zg4moUxAWxKOnay$bG6y~aCQ+k&B0Jl^eFiVmXlKF@bjFs z>y0VrJUUQ)w0Ny{X*iZp75}J36gl-i8pU1WJ=LnhL2v4c!V6f0P5-IiK!h3uVDCeo zqU}PS`0~k%7oWX#_39U2d~x)}^XD%?#>L^oG`o=#qDuWp|**{W}I)h}%G4UYNQ zDI~BxdVcok>QdTP{zAuSLsPIzmZ?HDhwH`ld>p{W{xUgM_B(TLiWaC94vO;6$M zjXj?q`lSHakEqJ{hAY)x3;Rnb z1E+3{0!+Hc>(O07|oW9!_2@bsgDUA(m#+JVIxNA=d`8!gp!fX5EINQstL3tfd@ N 1);\n" +"X-Generator: Loco https://localise.biz/\n" +"X-Poedit-Basepath: ..\n" +"X-Poedit-Flags-xgettext: --add-comments=translators:\n" +"X-Poedit-WPHeader: woocommerce-smart-coupons.php\n" +"X-Poedit-SourceCharset: UTF-8\n" +"X-Poedit-KeywordsList: __;_e;_n:1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;esc_attr__;esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c;_n_noop:1,2;_nx_noop:3c,1,2;__ngettext_noop:1,2\n" +"X-Poedit-Bookmarks: -1,-1,-1,-1,182,-1,-1,-1,-1,-1\n" +"X-Poedit-SearchPath-0: .\n" +"X-Poedit-SearchPathExcluded-0: *.min.js\n" + +#. translators: Add more detail to coupon description +#: includes/class-wc-sc-display-coupons.php:649 +msgid " &" +msgstr " &" + +#: includes/class-wc-sc-display-coupons.php:278 +#: includes/class-wc-sc-display-coupons.php:869 +#: includes/class-wc-sc-display-coupons.php:2410 +#: includes/class-wc-sc-shortcode.php:540 +#: includes/class-wc-smart-coupons.php:4893 +#: templates/combined-email.php:125 +#: templates/email.php:123 +#: templates/print-coupons-default.php:142 +msgid " & " +msgstr " & " + +#: templates/plain/combined-email.php:88 +#: templates/plain/email.php:83 +msgid " & " +msgstr " & " + +#. translators: 1. Discount type 2. Discount Type Label +#: includes/class-wc-sc-product-fields.php:114 +#: includes/class-wc-sc-product-fields.php:175 +msgid " ( %1$s: %2$s )" +msgstr " ( %1$s : %2$s )" + +#. translators: 1: email heading 2: suffix +#: includes/emails/class-wc-sc-email-coupon.php:460 +msgid " coupon" +msgstr " code promo" + +#: includes/class-wc-sc-display-coupons.php:634 +msgid " discount" +msgstr " Remise" + +#: includes/class-wc-sc-display-coupons.php:610 +#: includes/class-wc-sc-display-coupons.php:619 +msgid " discount on " +msgstr " remise sur " + +#: includes/class-wc-sc-display-coupons.php:601 +msgid " discount on your entire purchase" +msgstr " de remise sur la totalité de votre achat" + +#: includes/class-wc-sc-display-coupons.php:634 +msgid " on " +msgstr " sur " + +#. translators: %s: Maximum coupon discount amount +#: includes/class-wc-sc-display-coupons.php:632 +#: includes/class-wc-smart-coupons.php:1168 +#: includes/emails/class-wc-sc-email-coupon.php:439 +msgid " upto %s" +msgstr " jusqu’à %s" + +#: includes/class-wc-sc-admin-notifications.php:243 +msgid "! If things aren't going quite as expected, we're happy to help -- please reach out to" +msgstr "! Si les choses ne se passent pas tout à fait comme prévu, nous serons heureux de vous aider — contactez-nous pour" + +#: includes/class-wc-sc-settings.php:647 +msgid "\"Coupons with Product\" description" +msgstr "Description des « Codes promo avec produit »" + +#: includes/class-wc-sc-admin-welcome.php:414 +msgid "\"Store Credit Receiver detail\" form not appearing on checkout page?" +msgstr "Formulaire «Détail du bon d’achat du bénéficiaire » ne figure pas sur la page « Commande » ?" + +#: includes/class-wc-smart-coupons.php:6022 +msgid "$coupon is not an object of WC_Coupon" +msgstr "" + +#: includes/class-wc-smart-coupons.php:6024 +msgid "$coupon is: " +msgstr "" + +#: includes/class-wc-smart-coupons.php:6642 +#: includes/class-wc-smart-coupons.php:6690 +msgid "$item is not an object of WC_Order_Item" +msgstr "" + +#: includes/class-wc-smart-coupons.php:6644 +#: includes/class-wc-smart-coupons.php:6692 +msgid "$item is: " +msgstr "" + +#: includes/class-wc-smart-coupons.php:6768 +msgid "$item_id is required" +msgstr "" + +#: includes/class-wc-smart-coupons.php:6509 +#: includes/class-wc-smart-coupons.php:6563 +#: includes/class-wc-smart-coupons.php:6592 +#: includes/class-wc-smart-coupons.php:6616 +#: includes/class-wc-smart-coupons.php:6770 +msgid "$item_id is: " +msgstr "" + +#: includes/class-wc-smart-coupons.php:6510 +#: includes/class-wc-smart-coupons.php:6564 +#: includes/class-wc-smart-coupons.php:6593 +#: includes/class-wc-smart-coupons.php:6617 +msgid "$item_key is: " +msgstr "" + +#: includes/class-wc-smart-coupons.php:6395 +#: includes/class-wc-smart-coupons.php:6450 +msgid "$key is required" +msgstr "" + +#: includes/class-wc-smart-coupons.php:6397 +#: includes/class-wc-smart-coupons.php:6452 +msgid "$key is: " +msgstr "" + +#: includes/class-wc-smart-coupons.php:6125 +#: includes/class-wc-smart-coupons.php:6240 +#: includes/class-wc-smart-coupons.php:6354 +msgid "$meta_key is: " +msgstr "" + +#: includes/class-wc-smart-coupons.php:6124 +#: includes/class-wc-smart-coupons.php:6239 +#: includes/class-wc-smart-coupons.php:6353 +msgid "$post_id is: " +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:1006 +msgid "%" +msgstr "%" + +#. translators: 1. Product/s 2. Product names 3. is/are 4. Coupons code +#: includes/class-wc-sc-coupon-actions.php:504 +msgid "%1$s %2$s %3$s removed because coupon %4$s is removed." +msgstr "%1$s %2$s %3$s supprimé car le code promo %4$s est supprimé." + +#. translators: 1. The coupon code, 2. The discount type +#: includes/class-wc-sc-ajax.php:252 +#: includes/class-wc-sc-settings.php:332 +msgid "%1$s (Type: %2$s)" +msgstr "%1$s (Type : %2$s)" + +#. translators: 1. Discount type 2. Discount amount +#. translators: 1: coupon type 2: coupon amount +#: includes/class-wc-sc-display-coupons.php:641 +#: includes/emails/class-wc-sc-email-coupon.php:452 +msgid "%1$s coupon of %2$s" +msgstr "%1$s code promo de %2$s" + +#. translators: 1: email heading 2: suffix +#: includes/emails/class-wc-sc-email-coupon.php:460 +msgid "%1$s Free Shipping%2$s" +msgstr "%1$s Livraison gratuite %2$s" + +#. translators: 1. amount of store credit 2. store credit label 3. coupon code +#: includes/class-wc-sc-coupon-process.php:776 +msgid "%1$s worth of %2$s restored to coupon %3$s." +msgstr "%1$s d’une valeur de %2$s restauré en code promo %3$s." + +#. translators: 1. amount of store credit 2. coupon code +#: includes/class-wc-sc-coupon-process.php:779 +msgid "%1$s worth of Store Credit restored to coupon %2$s." +msgstr "valeur de %1$s de bon d’achat restauré au code promo %2$s." + +#. translators: 1: HTML small tag start 2: HTML small tag end +#: includes/class-wc-sc-admin-pages.php:1268 +msgid "%1$s(This will add the same coupon description in all the bulk generated coupons)%2$s" +msgstr "%1$s(Ceci ajoutera la même description de code promo dans tous les codes promo générés en masse)%2$s" + +#. translators: 1: plugin name 2: page based text 3: Label for store credit 4: Hide notice text +#: includes/class-wc-sc-settings.php:903 +#: includes/class-wc-sc-settings.php:906 +msgid "%1$s: %2$s to avoid issues related to missing data for %3$s. %4$s" +msgstr "%1$s : %2$s pour éviter les problèmes liés aux données manquantes pour %3$s. %4$s" + +#. translators: 1. Error title 2. The bulk process +#: includes/class-wc-sc-background-coupon-importer.php:385 +msgid "%1$s: The coupon bulk %2$s process stopped. Please review the coupons list to check the status." +msgstr "%1$s : Le processus d’envoi de codes promo en masse %2$s s’est arrêté. Veuillez consulter la liste des codes promo pour vérifier le ." + +#. translators: 1. Important 2. Upload path +#: includes/class-wc-sc-background-coupon-importer.php:333 +msgid "%1$s: To allow bulk generation of coupons, please make sure %2$s directory is writable." +msgstr "%1$s: Pour permettre la génération en masse de codes promo, assurez-vous que le répertoire %2$s possède les autorisations d’écriture." + +#. translators: 1: WooCommerce Smart Coupons 2: Link for the Smart Coupons settings +#: includes/class-wc-sc-admin-notifications.php:256 +msgid "%1$s: You are using a custom coupon style which is planned to be removed from the plugin in upcoming versions. New, improved styles & colors are added in the version 4.9.0. We would request you to choose a color scheme & a style for coupon from the newly added colors & styles. You can do this from %2$s." +msgstr "%1$s : Vous utilisez un style de code promo personnalisé qu’il est prévu de supprimer de l’extension dans les prochaines versions. De nouveaux styles et couleurs améliorés ont été ajoutés dans la version 4.9.0. Nous vous demandons de choisir un schéma de couleurs et un style de code promo parmi les nouvelles couleurs et les nouveaux styles ajoutés. Vous pouvez le faire à partir de %2$s." + +#. translators: 1$-2$: opening and closing tags, 3$-4$: link tags, takes to woocommerce plugin on wp.org, 5$-6$: opening and closing link tags, leads to plugins.php in admin. +#: woocommerce-smart-coupons.php:61 +msgid "%1$sWooCommerce Smart Coupons is inactive.%2$s The %3$sWooCommerce plugin%4$s must be active for the Smart Coupons to work. Please %5$sinstall & activate WooCommerce »%6$s" +msgstr "" + +#. translators: Plugin's name +#: includes/class-wc-sc-privacy.php:53 +msgid "%s - Coupon Personal Data Eraser" +msgstr "%s - Effacer les données personnelles de code promo" + +#. translators: Plugin's name +#: includes/class-wc-sc-privacy.php:51 +msgid "%s - Coupon Personal Data Exporter" +msgstr "%s - Exporter les données personnelles de code promo" + +#. translators: Plugin's name +#: includes/class-wc-sc-privacy.php:58 +msgid "%s - Order Personal Data Eraser" +msgstr "%s - Effacer les données personnelles de commande" + +#. translators: Plugin's name +#: includes/class-wc-sc-privacy.php:56 +msgid "%s - Order Personal Data Exporter" +msgstr "%s - Exporter les données personnelles de commande" + +#. translators: Plugin's name +#: includes/class-wc-sc-privacy.php:63 +msgid "%s - User Personal Data Eraser" +msgstr "%s - Effacer les données personnelles de l’utilisateur" + +#. translators: Plugin's name +#: includes/class-wc-sc-privacy.php:61 +msgid "%s - User Personal Data Exporter" +msgstr "%s - Exporter les données personnelles de l’utilisateur" + +#. translators: 1. Coupon type +#: includes/class-wc-sc-background-coupon-importer.php:400 +msgid "%s are being" +msgstr "%s sont" + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-order-fields.php:501 +msgid "%s Balance " +msgstr "%s solde " + +#. translators: Order notes +#: includes/class-wc-sc-coupon-process.php:787 +msgid "%s Because PayPal doesn't accept discount on shipping & tax." +msgstr "%s parce que PayPal n’accepte pas les rabais sur l’expédition & fiscale." + +#. translators: %s: Plugin name +#: includes/class-wc-sc-admin-notifications.php:467 +msgid "%s database update completed. Thank you for updating to the latest version!" +msgstr "Mise à jour de la base de données %s terminée. Merci d’avoir mis à jour à la dernière version !" + +#. translators: %s: Plugin name +#: includes/class-wc-sc-admin-notifications.php:416 +msgid "%s database update required" +msgstr "%s mise à jour de la base de données de requise" + +#. translators: %s: Label for store credit +#: includes/class-wc-sc-settings.php:758 +msgid "%s discount is inclusive of tax" +msgstr "%s la remise inclus les taxes" + +#. translators: 1. The discount text +#: includes/class-wc-smart-coupons.php:1617 +msgid "%s discount on anything you want." +msgstr "%s rabais sur tout ce que vous voulez." + +#. translators: 1. The discount text +#: includes/class-wc-smart-coupons.php:1619 +msgid "%s discount on entire store." +msgstr "%s rabais sur tout le magasin." + +#. translators: Add more detail to coupon description +#: includes/class-wc-sc-display-coupons.php:649 +msgid "%s Free Shipping" +msgstr "%s Livraison gratuite" + +#. translators: 1. Product title +#: includes/class-wc-sc-coupon-actions.php:421 +msgid "%s has been added to your cart!" +msgstr "%s a été ajouté à votre panier !" + +#. translators: %s: Label for store credit +#: includes/class-wc-sc-settings.php:756 +msgid "%s include tax?" +msgstr "%s inclure les taxes ?" + +#. translators: %s: Plugin name +#: includes/class-wc-sc-admin-notifications.php:454 +msgid "%s is updating the database in the background. The database update process may take a little while, so please be patient." +msgstr "%s met à jour la base de données en arrière-plan. Le processus de mise à jour de la base de données peut prendre un peu de temps, alors soyez patient." + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-display-coupons.php:591 +msgid "%s of " +msgstr "%s de " + +#. translators: %s: Label for store credit +#: includes/class-wc-sc-settings.php:624 +msgid "%s product CTA" +msgstr "%s Produit CTA" + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-admin-pages.php:672 +msgid "%s sent successfully." +msgstr "%s envoyé avec succès." + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-order-fields.php:197 +msgid "%s Used" +msgstr "%s utilisé" + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-order-fields.php:254 +msgid "%s Used:" +msgstr "%s utilisé :" + +#. translators: 1: email heading 2: suffix +#: includes/emails/class-wc-sc-email-coupon.php:460 +msgid "&" +msgstr "&" + +#: includes/class-wc-sc-admin-pages.php:1194 +msgid "(Add to store and email generated coupons to recipients)" +msgstr "(Ajouter des codes promo automatiques et les envoyer par e-mail aux destinataires)" + +#: includes/class-wc-sc-admin-coupons-dashboard-actions.php:199 +msgid "(Copy)" +msgstr "(Copie)" + +#: includes/class-wc-sc-admin-pages.php:1184 +msgid "(Does not add to store, but creates a .csv file, that you can" +msgstr "(Ne s’ajoute pas à la boutique, mais crée un fichier .csv que vous pouvez" + +#. translators: %s: Note for admin +#: includes/class-wc-sc-settings.php:557 +msgid "(Note: It's recommended to keep it Disabled)" +msgstr "(Note: il est recommandé de le garder désactivé)" + +#: includes/class-wc-sc-admin-pages.php:815 +#: includes/class-wc-sc-admin-pages.php:1229 +msgid "(optional)" +msgstr "(facultatif)" + +#: includes/class-wc-sc-coupon-fields.php:445 +msgid "(Used only for auto-generated coupons)" +msgstr "(Utilisé uniquement pour les codes promo auto-générés)" + +#: includes/class-wc-sc-coupon-fields.php:484 +msgid "(We recommend up to three letters for prefix/suffix)" +msgstr "(Nous recommandons jusqu’à trois lettres pour le préfixe/suffixe)" + +#: includes/class-wc-sc-background-coupon-importer.php:406 +msgid "--:--:--" +msgstr "--:--:--" + +#: includes/class-wc-sc-admin-welcome.php:365 +msgid ". If still the issue persist, temporarily de-activate all plugins except WooCommerce & Smart Coupons. Re-check the issue, if the issue still persists, contact us (from the link at the end of this page). If the issue goes away, re-activate other plugins one-by-one & re-checking the fields, to find out which plugin is conflicting." +msgstr ". Si le problème persiste, désactivez temporairement tous les plugins, à l’exception de WooCommerce et de Smart Coupons. Re-vérifier, et si le problème persiste, contactez-nous (à partir du lien à la fin de cette page). Si le problème disparaît, réactiver les autres plugins un par un pour savoir quel plugin est en conflit." + +#. translators: Documentation link for 'How to Apply Single or Multiple Coupons on Click of a Link' +#: includes/class-wc-sc-admin-welcome.php:382 +msgid ". Replace www.mysite.com with your own site URL and replace discount5 with the your coupon code." +msgstr ". Remplacez  « www.mysite.com » par votre propre URL, et remplacez le « discount5 » par le code promo." + +#: includes/class-wc-sc-admin-pages.php:784 +#: includes/class-wc-sc-coupon-fields.php:1004 +msgid "0.00" +msgstr "0.00" + +#: includes/class-wc-sc-coupon-fields.php:999 +msgid "1" +msgstr "1. Sélectionnez la barre latérale" + +#: includes/class-wc-sc-admin-pages.php:1160 +msgid "10" +msgstr "10" + +#. Description of the plugin +#: woocommerce-smart-coupons.php +msgid "WooCommerce Smart Coupons lets customers buy gift certificates, store credits or coupons easily. They can use purchased credits themselves or gift to someone else." +msgstr "WooCommerce Smart Coupons permet aux clients d’utiliser des cartes cadeau, des bons d’achat ou des codes promo facilement. Ils peuvent utiliser les crédits achetés eux-mêmes ou en faire cadeau à quelqu’un d’autre." + +#. translators: 1: Singular name for post type 2: Email +#: includes/class-wc-sc-admin-pages.php:1551 +msgid "[%1$s restricted with email: %2$s]" +msgstr "[%1$s restreint avec e-mail: %2$s]" + +#. translators: %s: Preview link +#: includes/class-wc-sc-settings.php:501 +#: includes/class-wc-sc-settings.php:510 +#: includes/class-wc-sc-settings.php:519 +#: includes/class-wc-sc-settings.php:528 +#: includes/class-wc-sc-settings.php:537 +#: includes/class-wc-sc-settings.php:625 +#: includes/class-wc-sc-settings.php:637 +#: includes/class-wc-sc-settings.php:648 +#: includes/class-wc-sc-settings.php:658 +#: includes/class-wc-sc-settings.php:668 +#: includes/class-wc-sc-settings.php:689 +#: includes/class-wc-sc-settings.php:698 +#: includes/class-wc-sc-settings.php:708 +#: includes/class-wc-sc-settings.php:717 +msgid "[Preview]" +msgstr "[Aperçu]" + +#. translators: %s: Label for store credit, 1: : Label for store credit, 2: Label for store credit, 3: Label for store credit +#: includes/class-wc-sc-settings.php:575 +#: includes/class-wc-sc-settings.php:586 +#: includes/class-wc-sc-settings.php:606 +msgid "[Read More]" +msgstr "[Lire la suite]" + +#: includes/class-wc-sc-admin-welcome.php:87 +msgid "About Smart Coupons" +msgstr "À propos de Smart Coupon" + +#: includes/class-wc-smart-coupons.php:5873 +msgid "Account endpoints > Coupons" +msgstr "Points de terminaison > Codes promo" + +#: includes/class-wc-smart-coupons.php:5864 +msgid "Acknowledgement email" +msgstr "E-mail d’accusé de réception" + +#: includes/class-wc-smart-coupons.php:1611 +msgid "Act before the offer expires." +msgstr "Profitez-en avant que l’offre n’expire." + +#: includes/class-wc-sc-admin-pages.php:1153 +msgid "Action" +msgstr "Action" + +#: includes/class-wc-sc-coupon-fields.php:934 +msgid "Actions" +msgstr "Actions" + +#: includes/compat/class-wcs-sc-compatibility.php:1072 +msgid "Active for x payments" +msgstr "Actif pour x paiements" + +#: includes/class-wc-sc-admin-pages.php:551 +msgid "Add Coupon" +msgstr "Ajouter un code promo" + +#: includes/class-wc-sc-coupon-categories.php:96 +msgid "Add new coupon category" +msgstr "Ajouter une nouvelle catégorie de code promo" + +#: includes/class-wc-sc-coupon-actions.php:580 +msgid "Add product details" +msgstr "Ajouter les détails du produit" + +#: includes/class-wc-sc-coupon-fields.php:964 +msgid "Add products to cart" +msgstr "Ajouter des produits au panier" + +#: includes/class-wc-sc-coupons-by-taxonomy.php:146 +#: includes/class-wc-sc-coupons-by-taxonomy.php:219 +msgid "Add taxonomy restriction" +msgstr "Ajouter une restriction sur une taxonomie" + +#: includes/class-wc-sc-admin-pages.php:1166 +msgid "Add to store" +msgstr "Ajouter dans la boutique" + +#: includes/class-wc-sc-background-coupon-importer.php:586 +#: includes/class-wc-sc-background-coupon-importer.php:595 +msgid "added" +msgstr "ajouté" + +#: includes/class-wc-sc-background-coupon-importer.php:578 +#: includes/class-wc-sc-background-coupon-importer.php:582 +msgid "added & emailed" +msgstr "ajouté et envoyé par e-mail" + +#: includes/class-wc-smart-coupons.php:7377 +msgid "Added by coupon" +msgstr "" + +#: includes/class-wc-sc-settings.php:711 +msgid "Additional text below the title." +msgstr "Texte supplémentaire sous le titre." + +#: includes/class-wc-sc-coupons-by-location.php:196 +msgid "Address to look in" +msgstr "Adresse à rechercher dans" + +#: includes/class-wc-sc-coupon-categories.php:89 +msgctxt "Admin menu name" +msgid "Categories" +msgstr "Catégories" + +#: includes/class-wc-sc-admin-welcome.php:264 +msgid "Advanced restrictions - payment, shipping, location, user roles, product attributes" +msgstr "Restrictions avancées - paiement, expédition, localisation, rôles des utilisateurs, attributs des produits" + +#. translators: Link for the plugin 'Aelia Currency Switcher for WooCommerce' +#: includes/class-wc-sc-admin-welcome.php:449 +msgid "Aelia Currency Switcher for WooCommerce" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:962 +msgid "After applying the coupon do these also" +msgstr "Après avoir appliqué le code promo faire également ceci" + +#: includes/class-wc-sc-coupon-categories.php:91 +msgid "All coupon categories" +msgstr "Toutes les catégories de codes promo" + +#: includes/class-wc-sc-display-coupons.php:608 +#: includes/class-wc-sc-display-coupons.php:617 +msgid "all products" +msgstr "tous les produits" + +#: includes/class-wc-sc-coupon-import.php:936 +msgid "All set, Begin import?" +msgstr "Tout est prêt ! Commencer l’importation ?" + +#: includes/class-wc-sc-settings.php:716 +#: includes/class-wc-smart-coupons.php:5860 +msgid "Allow schedule sending of coupons?" +msgstr "Autoriser l’envoi programmé de codes promo ?" + +#. translators: %s: Label for store credit, 1: : Label for store credit, 2: Label for store credit, 3: Label for store credit +#: includes/class-wc-sc-settings.php:586 +msgid "Allow selling %s at discounted price" +msgstr "Autoriser les ventes de %s à prix réduit" + +#: includes/class-wc-sc-settings.php:688 +#: includes/class-wc-smart-coupons.php:5859 +msgid "Allow sending of coupons to others" +msgstr "Autoriser l’envoi de codes promo à d’autres personnes" + +#: includes/class-wc-sc-settings.php:689 +msgid "Allow the buyer to send coupons to someone else." +msgstr "Permettre au client d’envoyer des codes promo à quelqu’un d’autre." + +#: includes/class-wc-sc-coupons-by-excluded-email.php:468 +msgid "Allowed emails" +msgstr "" + +#: includes/class-wc-sc-coupons-by-user-role.php:116 +msgid "Allowed user roles" +msgstr "Rôles utilisateur autorisés" + +#: includes/class-wc-sc-coupon-import.php:1077 +msgid "Already uploaded CSV to the server?" +msgstr "Déjà téléchargé CSV sur le serveur?" + +#: includes/class-wc-sc-settings.php:359 +msgid "Amaranth red" +msgstr "Rouge amarante" + +#: includes/class-wc-sc-display-coupons.php:2495 +msgid "Amount" +msgstr "Montant" + +#: includes/class-wc-smart-coupons.php:986 +msgid "An error has occurred. Please try again later." +msgstr "Une erreur est apparue, merci de réessayer plus tard." + +#: includes/class-wc-sc-coupons-by-payment-method.php:411 +msgid "An error occurred:" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:267 +msgid "and a lot more…" +msgstr "et bien plus encore…" + +#: includes/class-wc-sc-coupon-import.php:1037 +msgid "and create your CSV based on that." +msgstr "et créer votre CSV basé sur cela." + +#: includes/class-wc-sc-coupon-fields.php:497 +msgid "and my account?" +msgstr "et « Mon compte » ?" + +#. translators: 1: Affiliate For WooCommerce 2: Smart Manager 3: Smart Offers +#: includes/class-wc-sc-admin-welcome.php:287 +msgid "any amount" +msgstr "n’importe quel montant" + +#: includes/class-wc-sc-admin-pages.php:1344 +msgid "Apply" +msgstr "Appliquer" + +#: includes/class-wc-sc-settings.php:741 +msgid "Apply before tax" +msgstr "Appliquer avant les taxes" + +#: includes/class-wc-sc-admin-welcome.php:263 +msgid "Apply multiple coupons via URL" +msgstr "Appliquer plusieurs codes promo via l’URL" + +#: includes/class-wc-sc-admin-pages.php:215 +msgid "Are you sure you want to remove the selected items? If you have previously reduced this item's stock, or this order was submitted by a customer, you will need to manually restore the item's stock." +msgstr "Êtes-vous sûr de vouloir supprimer ces articles ? Si vous avez précédemment réduit le stock de cet article, ou bien si cette commande a été envoyée par un client, vous devrez manuellement restaurer le stock de cet article." + +#: includes/class-wc-sc-admin-pages.php:272 +msgid "Are you sure you want to revoke access to this download?" +msgstr "Êtes-vous certain de vouloir supprimer l’accès à ce téléchargement ?" + +#. translators: 1. The bulk process +#: includes/class-wc-sc-background-coupon-importer.php:551 +msgid "Are you sure you want to stop the coupon bulk %s process? Click OK to stop." +msgstr "Êtes-vous sûr de vouloir arrêter le processus de génération de codes promo en masse %s ? Cliquez sur OK pour l’arrêter." + +#: includes/class-wc-sc-admin-pages.php:218 +#: includes/class-wc-sc-coupon-refund-process.php:566 +msgid "Are you sure you wish to delete this refund? This action cannot be undone." +msgstr "Êtes-vous sûr de vouloir supprimer ce remboursement ? Cette action est irréversible." + +#: includes/class-wc-sc-admin-pages.php:219 +msgid "Are you sure you wish to delete this tax column? This action cannot be undone." +msgstr "Êtes-vous sur de vouloir supprimer cette colonne de TVA ? Cette action est irréversible." + +#: includes/class-wc-sc-admin-pages.php:217 +msgid "Are you sure you wish to process this refund? This action cannot be undone." +msgstr "Êtes-vous sûr de vouloir procéder à ce remboursement ? Cette action est irréversible." + +#: includes/class-wc-sc-admin-welcome.php:300 +msgid "Attach a gift of any value (free or paid product) to a particular coupon. Here, instead of a discount, a product is redeemed for the coupon code." +msgstr "Attachez un cadeau de n’importe quelle valeur (produit gratuit ou payant) à un code promo particulier. Ici, au lieu d’une réduction, un produit est échangé contre le code promo." + +#: includes/class-wc-smart-coupons.php:1608 +msgid "Attention!" +msgstr "Attention !" + +#: includes/class-wc-sc-coupons-by-product-attribute.php:167 +msgid "Attribute=" +msgstr "Attribut=" + +#: includes/class-wc-sc-settings.php:545 +msgid "Auto apply coupons" +msgstr "" + +#: includes/class-wc-sc-auto-apply-coupon.php:120 +#: includes/class-wc-sc-auto-apply-coupon.php:186 +msgid "Auto apply?" +msgstr "Appliquer automatiquement ?" + +#: includes/class-wc-smart-coupons.php:4650 +msgid "Auto Generate Coupon" +msgstr "Génération automatique de code promo" + +#: includes/class-wc-sc-coupon-fields.php:459 +msgid "Auto generate new coupons with each item" +msgstr "Autogénérer de nouveaux codes promo avec chaque article" + +#: includes/class-wc-smart-coupons.php:5862 +msgid "Auto generated coupon email" +msgstr "E-mail de code promo généré automatiquement" + +#: includes/class-wc-sc-coupon-refund-process.php:225 +msgid "Auto-fill refund amount" +msgstr "Remplir automatiquement le montant du remboursement" + +#: includes/class-wc-sc-settings.php:555 +#: includes/class-wc-smart-coupons.php:5853 +msgid "Automatic deletion" +msgstr "Suppression automatique" + +#: includes/class-wc-sc-admin-welcome.php:271 +msgid "Automatic payment for subscription renewals" +msgstr "Paiement automatique pour les renouvellements d’abonnement" + +#. translators: %s: plural name for store credit +#. translators: %s: Label for store credit +#: includes/class-wc-sc-display-coupons.php:749 +#: includes/class-wc-sc-display-coupons.php:940 +#: includes/class-wc-sc-settings.php:673 +msgid "Available Coupons & %s" +msgstr "Codes promo et %s disponibles" + +#. translators: %s: plural name for store credit +#: includes/class-wc-sc-display-coupons.php:749 +#: includes/class-wc-sc-display-coupons.php:940 +msgid "Available Coupons & Store Credits" +msgstr "Codes promo & bons d’achat disponibles" + +#: includes/class-wc-sc-display-coupons.php:342 +#: includes/class-wc-sc-display-coupons.php:735 +#: includes/class-wc-sc-settings.php:662 +msgid "Available Coupons (click on a coupon to use it)" +msgstr "Codes promo disponibles (cliquer pour utiliser)" + +#: includes/class-wc-sc-admin-welcome.php:398 +msgid "Available coupons are not visible on Cart, Checkout & My Account page?" +msgstr "Les codes promo disponibles ne sont pas visibles sur la page « Panier », la page « Commande » et la page « Mon compte » ?" + +#. translators: %s: list of placeholders +#: includes/emails/class-wc-sc-email.php:97 +msgid "Available placeholders: %s" +msgstr "Espaces réservés disponibles : %s" + +#: includes/class-wc-sc-admin-notifications.php:243 +msgid "Awesome, you successfully auto-generated a coupon! Are you having a great experience with" +msgstr "Bravo, vous avez réussi à générer automatiquement un code promo ! Avez-vous une bonne expérience avec" + +#: includes/class-wc-sc-settings.php:408 +msgid "Basic" +msgstr "Basique" + +#: includes/class-wc-sc-coupon-import.php:1061 +msgid "Before you can upload your import file, you will need to fix the following error:" +msgstr "Avant de pouvoir transférer votre fichier d’importation, vous devez corriger les erreurs suivantes :" + +#: includes/class-wc-sc-coupons-by-location.php:199 +msgid "Billing" +msgstr "Facturation" + +#: includes/class-wc-sc-coupons-by-location.php:478 +msgid "billing address" +msgstr "adresse de facturation" + +#: includes/class-wc-sc-coupons-by-location.php:494 +msgid "Billing Locations" +msgstr "Emplacement de facturation" + +#: blocks/build/js/available-coupons/block.json +#: blocks/src/js/available-coupons/block.json +msgctxt "block description" +msgid "Displays available coupons." +msgstr "" + +#: blocks/build/js/send-coupon-form/block.json +#: blocks/src/js/send-coupon-form/block.json +msgctxt "block description" +msgid "Displays Send coupon form." +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-available-coupons-block.js:7 +#: blocks/src/js/available-coupons/edit.js:19 +msgctxt "Block editor" +msgid "Available Coupons (click on a coupon to use it)" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block.js:1 +#: blocks/src/js/send-coupon-form/edit.js:59 +#: blocks/src/js/send-coupon-form/edit.js:63 +msgctxt "Block editor" +msgid "Deliver coupon" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block.js:1 +#: blocks/src/js/send-coupon-form/edit.js:84 +msgctxt "Block editor" +msgid "Enter recipient e-mail address" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block.js:1 +#: blocks/src/js/send-coupon-form/edit.js:39 +msgctxt "Block editor" +msgid "Gift to someone else" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block.js:1 +#: blocks/src/js/send-coupon-form/edit.js:71 +msgctxt "Block editor" +msgid "later" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block.js:1 +#: blocks/src/js/send-coupon-form/edit.js:88 +msgctxt "Block editor" +msgid "Message for receiver" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block.js:1 +#: blocks/src/js/send-coupon-form/edit.js:67 +msgctxt "Block editor" +msgid "now" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block.js:1 +#: blocks/src/js/send-coupon-form/edit.js:80 +msgctxt "Block editor" +msgid "Receiver email address" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block.js:1 +#: blocks/src/js/send-coupon-form/edit.js:30 +msgctxt "Block editor" +msgid "Send coupons to..." +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block.js:1 +#: blocks/src/js/send-coupon-form/edit.js:53 +msgctxt "Block editor" +msgid "Send to different people" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block.js:1 +#: blocks/src/js/send-coupon-form/edit.js:35 +msgctxt "Block editor" +msgid "Send to me" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block.js:1 +#: blocks/src/js/send-coupon-form/edit.js:49 +msgctxt "Block editor" +msgid "Send to one person" +msgstr "" + +#: blocks/blocks.php:51 +msgctxt "Block editor" +msgid "WooCommerce Smart Coupons" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block.js:1 +#: blocks/src/js/send-coupon-form/edit.js:92 +msgctxt "Block editor" +msgid "Write a message" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block.js:1 +#: blocks/src/js/send-coupon-form/edit.js:31 +msgctxt "Block editor" +msgid "Your order contains coupons. What would you like to do?" +msgstr "" + +#: blocks/class-wc-sc-blocks-integration.php:423 +msgctxt "Block editor & frontend" +msgid "Available Coupons (click on a coupon to use it)" +msgstr "" + +#: blocks/class-wc-sc-blocks-integration.php:600 +msgctxt "Block editor & frontend" +msgid "coupon" +msgstr "" + +#: blocks/class-wc-sc-blocks-integration.php:653 +msgctxt "Block editor & frontend" +msgid "Deliver coupon" +msgstr "" + +#: blocks/class-wc-sc-blocks-integration.php:654 +msgctxt "Block editor & frontend" +msgid "Enter recipient e-mail address" +msgstr "" + +#: blocks/class-wc-sc-blocks-integration.php:597 +msgctxt "Block editor & frontend" +msgid "Free Shipping coupon" +msgstr "" + +#: blocks/class-wc-sc-blocks-integration.php:629 +msgctxt "Block editor & frontend" +msgid "Gift to someone else" +msgstr "" + +#: blocks/class-wc-sc-blocks-integration.php:649 +msgctxt "Block editor & frontend" +msgid "later" +msgstr "" + +#: blocks/class-wc-sc-blocks-integration.php:645 +msgctxt "Block editor & frontend" +msgid "now" +msgstr "" + +#: blocks/class-wc-sc-blocks-integration.php:604 +msgctxt "Block editor & frontend" +msgid "of" +msgstr "" + +#: blocks/class-wc-sc-blocks-integration.php:604 +msgctxt "Block editor & frontend" +msgid "Send" +msgstr "" + +#: blocks/class-wc-sc-blocks-integration.php:515 +#: blocks/class-wc-sc-blocks-integration.php:516 +msgctxt "Block editor & frontend" +msgid "Send Coupons to..." +msgstr "" + +#: blocks/class-wc-sc-blocks-integration.php:639 +msgctxt "Block editor & frontend" +msgid "Send to different people" +msgstr "" + +#: blocks/class-wc-sc-blocks-integration.php:625 +msgctxt "Block editor & frontend" +msgid "Send to me" +msgstr "" + +#: blocks/class-wc-sc-blocks-integration.php:635 +msgctxt "Block editor & frontend" +msgid "Send to one person" +msgstr "" + +#: blocks/class-wc-sc-blocks-integration.php:621 +msgctxt "Block editor & frontend" +msgid "Your order contains coupons. What would you like to do?" +msgstr "" + +#: blocks/build/js/available-coupons/block.json +#: blocks/src/js/available-coupons/block.json +msgctxt "block title" +msgid "Available coupons" +msgstr "" + +#: blocks/build/js/send-coupon-form/block.json +#: blocks/src/js/send-coupon-form/block.json +msgctxt "block title" +msgid "Send coupon form" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5874 +msgid "Block-enabled Cart" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5875 +msgid "Block-enabled Checkout" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:292 +msgid "Bulk create unique coupons & email them" +msgstr "Créez des codes promo uniques en lot et envoyez-les par e-mail" + +#: includes/class-wc-sc-admin-pages.php:124 +#: includes/class-wc-sc-admin-pages.php:556 +#: includes/class-wc-sc-admin-pages.php:1594 +msgid "Bulk Generate" +msgstr "Générer en masse" + +#: includes/class-wc-sc-admin-welcome.php:262 +msgid "Bulk generate coupons" +msgstr "Génère des codes promo en masse" + +#: includes/class-wc-sc-background-coupon-importer.php:338 +msgid "Bulk generation is disabled since uploads directory is not writable. Please ensure uploads directory is writable before starting bulk generate process." +msgstr "La génération en masse est désactivée car le répertoire de téléchargements n’a pas les autorisation d’écriture. Assurez-vous que le répertoire de téléchargements est inscriptible avant de commencer le processus de génération en masse." + +#. translators: 1. The discount text +#: includes/class-wc-smart-coupons.php:1623 +msgid "Buy as much as you want. Flat %s off everything." +msgstr "Achetez autant que vous voulez. %s net sur tout." + +#: includes/class-wc-sc-settings.php:684 +msgid "Buyers can send purchased coupons to anyone – right while they're checking out." +msgstr "Les clients peuvent acheter et envoyer des codes promo à la personne de leur choix pendant qu’ils effectuent une commande." + +#: includes/class-wc-smart-coupons.php:5872 +msgid "Calculate coupon discounts sequentially" +msgstr "Calculer les remises de coupon de manière séquentielle" + +#: includes/class-wc-sc-admin-pages.php:231 +msgid "Calculate line taxes? This will calculate taxes based on the customers country. If no billing/shipping is set it will use the store base country." +msgstr "Calculer la TVA en ligne ? Cela calculera la TVA basée sur le pays des clients. Si aucune reçu/livraison n’est paramétrée cela prendra le pays de base de la boutique." + +#: includes/class-wc-sc-admin-pages.php:230 +msgid "Calculate totals based on order items, discounts, and shipping?" +msgstr "Calculer le total des articles, les remises, et la livraison ?" + +#: includes/class-wc-sc-settings.php:601 +#, fuzzy +msgid "Call it something else! Use these to quickly change text labels through your store. Use translations for complete control." +msgstr "Appelez vos codes promo autrement ! Utilisez cette fonctionnalité pour modifier rapidement le libellé de vos codes promo depuis votre boutique. Utilisez les traductions pour un contrôle complet." + +#: includes/class-wc-sc-admin-welcome.php:376 +msgid "Can coupon code have any spaces in the name? / My Store Credit/Gift Certificate is not working (not generating new coupon code)." +msgstr "Le code promo peut-il avoir des espaces dans le nom ? / Mon bon d’achat/carte cadeau ne fonctionne pas (ne génère pas de nouveau code promo)." + +#: includes/class-wc-sc-shortcode.php:944 +msgid "Cancel" +msgstr "Annuler" + +#: includes/class-wc-sc-settings.php:360 +msgid "Carolina Blue" +msgstr "Bleu Carolina" + +#: includes/class-wc-sc-coupons-by-product-quantity.php:120 +msgid "Cart" +msgstr "Panier" + +#: includes/class-wc-sc-ajax.php:337 +#: includes/class-wc-sc-ajax.php:352 +#: includes/class-wc-smart-coupons.php:1148 +#: includes/class-wc-smart-coupons.php:1163 +msgid "Cart Discount" +msgstr "Remise du panier" + +#: includes/class-wc-sc-coupons-by-product-quantity.php:191 +#: includes/class-wc-sc-coupons-by-product-quantity.php:208 +#: includes/class-wc-sc-coupons-by-product-quantity.php:253 +#: includes/class-wc-sc-coupons-by-product-quantity.php:263 +msgid "Categories" +msgstr "Catégories" + +#: includes/class-wc-sc-coupon-categories.php:88 +msgid "Category" +msgstr "Catégorie" + +#: includes/class-wc-smart-coupons.php:71 +msgid "Cheatin’ huh?" +msgstr "Alors ’ on triche ?" + +#: includes/class-wc-sc-coupon-message.php:134 +msgid "Check this box to include above message in order confirmation email" +msgstr "Cochez cette case pour inclure le message ci-dessus dans l’e-mail de confirmation de la commande" + +#: includes/class-wc-sc-product-fields.php:129 +#: includes/class-wc-sc-product-fields.php:185 +msgid "Check this box to send above coupons on each renewal order." +msgstr "Cochez cette case pour envoyer les codes promo ci-dessus pour chaque commande renouvelée." + +#. translators: 1. The coupon code 2. The text 'payment method/s' 3. List of payment method names 4. Link to the checkout page +#: includes/class-wc-sc-coupons-by-payment-method.php:210 +#: includes/class-wc-sc-coupons-by-payment-method.php:214 +msgid "Checkout" +msgstr "" + +#: includes/class-wc-sc-settings.php:368 +msgid "Chocolate" +msgstr "Chocolat" + +#: includes/class-wc-sc-settings.php:355 +msgid "Choose a color scheme for coupons." +msgstr "Choisissez un schéma de couleurs pour les codes promo." + +#: includes/class-wc-sc-coupon-import.php:1070 +msgid "Choose a CSV file" +msgstr "Choisir un fichier CSV" + +#: includes/class-wc-sc-settings.php:395 +msgid "Choose a style for coupon on the website." +msgstr "Choisissez un style de codes promo sur le site web." + +#: includes/class-wc-sc-settings.php:456 +msgid "Choose order status which will trigger the auto-generation of coupon, if the order contains product which will generate the coupon." +msgstr "Choisissez l’état de la commande qui déclenchera la génération automatique du code promo, si la commande contient un produit générant des codes promo." + +#: includes/class-wc-sc-coupons-by-product-quantity.php:127 +msgid "Choose whether to validate the quantity, cart-wise or product-wise" +msgstr "Choisissez de valider la quantité, par panier ou par produit" + +#: includes/emails/class-wc-sc-email.php:109 +msgid "Choose which format of email to send." +msgstr "Choisissez quel format d’e-mail envoyer." + +#: includes/class-wc-sc-coupon-import.php:1020 +msgid "Chosen" +msgstr "Choisi" + +#: includes/class-wc-smart-coupons.php:3275 +msgid "Clear Smart Coupons Cache" +msgstr "Purger le cache des Smart Coupons" + +#: includes/class-wc-sc-coupon-import.php:1037 +msgid "Click here to download a sample" +msgstr "Cliquez ici pour télécharger un échantillon" + +#: includes/class-wc-sc-coupon-fields.php:146 +#: includes/class-wc-sc-coupon-fields.php:1434 +msgid "Click to copy" +msgstr "Cliquez pour copier" + +#: includes/class-wc-sc-shortcode.php:825 +msgid "Click to select coupon code." +msgstr "Cliquez pour sélectionner le code promo." + +#: includes/class-wc-sc-admin-pages.php:224 +msgid "Click to toggle" +msgstr "Cliquez ici pour basculer" + +#: includes/class-wc-sc-shortcode.php:607 +#: templates/combined-email.php:195 +#: templates/email.php:182 +msgid "Click to visit store. This coupon will be applied automatically." +msgstr "Cliquez ici pour visiter la boutique. Ce code promo sera automatiquement appliqué." + +#: includes/class-wc-sc-settings.php:407 +msgid "Clipper" +msgstr "Clipper" + +#: includes/class-wc-sc-display-coupons.php:2494 +msgid "Code" +msgstr "Code" + +#: includes/class-wc-sc-settings.php:351 +msgid "Colors" +msgstr "Couleurs" + +#: includes/class-wc-sc-settings.php:726 +#: includes/class-wc-smart-coupons.php:5861 +msgid "Combine emails" +msgstr "Combiner les e-mails" + +#: includes/class-wc-smart-coupons.php:5863 +msgid "Combined auto generated coupons email" +msgstr "E-mail regroupant plusieurs codes promo générés automatiquement" + +#: includes/class-wc-sc-coupon-fields.php:1432 +#: includes/class-wc-sc-coupon-fields.php:1447 +msgid "Copied!" +msgstr "Copié !" + +#: includes/class-wc-sc-admin-coupons-dashboard-actions.php:116 +msgid "Copy" +msgstr "Copier" + +#: includes/class-wc-sc-admin-pages.php:232 +msgid "Copy billing information to shipping information? This will remove any currently entered shipping information." +msgstr "Copier les informations de facturation vers les informations d’expédition ? Ceci enlèvera tout ce qui a été entré dans les informations d’expédition." + +#: includes/class-wc-sc-coupon-fields.php:1439 +#: includes/class-wc-sc-coupon-fields.php:1449 +msgid "Copy coupon code" +msgstr "Copier le code promo" + +#: includes/class-wc-sc-admin-coupons-dashboard-actions.php:118 +msgid "Copy coupon shareable link and apply via URL" +msgstr "Copier le lien partageable du code promo et l’appliquer par URL" + +#: includes/class-wc-sc-coupon-fields.php:139 +msgid "Copy the following link and share it to apply this coupon via URL." +msgstr "Copiez le lien suivant et partagez-le pour utiliser ce code promo via URL." + +#: includes/class-wc-sc-admin-coupons-dashboard-actions.php:116 +msgid "Copy this coupon code" +msgstr "Copier ce code promo" + +#: includes/class-wc-sc-admin-pages.php:271 +msgid "Could not grant access - the user may already have permission for this file or billing email is not set. Ensure the billing email is set, and the order has been saved." +msgstr "Impossible d’accorder l’accès - l’utilisateur peut déjà avoir la permission pour ce fichier ou l’e-mail de facturation n’est pas défini. Assurez-vous que l’e-mail de facturation est défini, et que l’adhésion a été sauvegardée." + +#: includes/class-wc-sc-coupon-fields.php:1312 +msgid "Could not locate WooCommerce" +msgstr "Impossible de localiser WooCommerce" + +#: includes/class-wc-sc-background-coupon-importer.php:605 +#: includes/class-wc-sc-purchase-credit.php:991 +#: includes/emails/class-wc-sc-email-coupon.php:488 +msgid "coupon" +msgstr "code promo" + +#: includes/class-wc-sc-privacy.php:384 +#: includes/emails/class-wc-sc-acknowledgement-email.php:342 +#: templates/acknowledgement-email.php:66 +#: templates/coupon-design/basic.php:39 +#: templates/coupon-design/clipper.php:38 +#: templates/coupon-design/cutout.php:55 +#: templates/coupon-design/deal.php:29 +#: templates/coupon-design/deliver.php:34 +#: templates/coupon-design/shipment.php:33 +#: templates/coupon-design/special.php:58 +#: templates/coupon-design/ticket.php:40 +#: templates/plain/acknowledgement-email.php:56 +msgid "Coupon" +msgid_plural "Coupons" +msgstr[0] "Code promo" +msgstr[1] "Codes promo" + +#. translators: The coupon code +#: includes/class-wc-smart-coupons.php:3319 +msgid "Coupon %s is valid for a new user only, hence removed." +msgstr "Le code promo %s n’est valable que pour les nouveaux utilisateurs, il est donc retiré." + +#: includes/class-wc-sc-privacy.php:602 +#: includes/class-wc-smart-coupons.php:5009 +msgid "Coupon Amount" +msgstr "Montant du code promo" + +#: includes/class-wc-sc-privacy.php:122 +msgid "Coupon amount, email & message entered for gift card receiver" +msgstr "Montant du code promo, e-mail & message entré pour le destinataire de la carte-cadeau" + +#: includes/class-wc-sc-background-coupon-importer.php:581 +#: includes/class-wc-sc-background-coupon-importer.php:594 +msgid "Coupon bulk generation" +msgstr "Générer des codes promo" + +#: includes/class-wc-sc-admin-pages.php:1298 +#: includes/class-wc-sc-coupon-categories.php:87 +#: includes/class-wc-sc-coupon-categories.php:225 +msgid "Coupon categories" +msgstr "Catégories de codes promo" + +#: includes/class-wc-smart-coupons.php:5031 +msgid "Coupon Category" +msgstr "Catégorie de codes promo" + +#: includes/class-wc-sc-privacy.php:599 +#: includes/class-wc-smart-coupons.php:4997 +msgid "Coupon Code" +msgstr "Code Promo" + +#: includes/class-wc-sc-shortcode.php:879 +msgid "Coupon code" +msgstr "Code promo" + +#. translators: 1. The coupon code 2. The text 'payment method/s' 3. List of payment method names 4. Link to the checkout page +#: includes/class-wc-sc-coupons-by-payment-method.php:210 +msgid "Coupon code %1$s has been removed. It is valid only for %2$s: %3$s. You can change the payment method from the %4$s page." +msgstr "" + +#. translators: 1. The coupon code 2. The text 'payment method/s' 3. List of payment method names 4. Link to the checkout page +#: includes/class-wc-sc-coupons-by-payment-method.php:214 +msgid "Coupon code %1$s is valid only for %2$s: %3$s. You can change payment method from the %4$s page." +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:480 +msgid "Coupon code format" +msgstr "Format du code promo" + +#: includes/class-wc-sc-privacy.php:120 +msgid "Coupon code generated for you" +msgstr "Code promo généré pour vous" + +#: includes/class-wc-sc-privacy.php:121 +msgid "Coupon code passed via URL" +msgstr "Code promo passé par URL" + +#: templates/plain/combined-email.php:97 +#: templates/plain/email.php:92 +msgid "Coupon Code:" +msgstr "Code promo :" + +#. translators: %d: Post ID +#: includes/class-wc-sc-admin-coupons-dashboard-actions.php:288 +msgid "Coupon creation failed, could not find original coupon: %d" +msgstr "" + +#. translators: %s: coupon id +#: includes/class-wc-sc-admin-coupons-dashboard-actions.php:311 +msgid "Coupon creation failed, could not find original coupon: %s" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:1288 +msgid "Coupon Data" +msgstr "Données du code promo" + +#. translators: %s: field name +#: includes/class-wc-sc-purchase-credit.php:1427 +msgid "Coupon delivery date and time is a required field." +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:1266 +msgid "Coupon Description " +msgstr "Description du code promo " + +#: includes/class-wc-sc-settings.php:565 +#: includes/class-wc-smart-coupons.php:5854 +msgid "Coupon emails" +msgstr "E-mails de code promo" + +#: includes/class-wc-sc-coupon-fields.php:391 +#: includes/class-wc-smart-coupons.php:4661 +msgid "Coupon expiry time" +msgstr "Heure d’expiration du code" + +#: includes/class-wc-sc-privacy.php:605 +msgid "Coupon For" +msgstr "Code promo pour" + +#: includes/class-wc-sc-background-coupon-importer.php:577 +#: includes/class-wc-sc-background-coupon-importer.php:585 +msgid "Coupon import" +msgstr "Importation de codes promo" + +#: includes/class-wc-sc-coupon-import.php:857 +msgid "Coupon Import Error" +msgstr "Erreur d’importation de code promo" + +#: includes/class-wc-sc-coupons-by-location.php:478 +msgid "Coupon is not valid for the" +msgstr "Le code promo n’est pas valide pour" + +#: includes/class-wc-smart-coupons.php:4655 +msgid "Coupon Is Visible Storewide" +msgstr "Le code promo est visible dans toute la boutique" + +#: includes/class-wc-sc-coupon-message.php:418 +#: includes/class-wc-sc-coupon-message.php:435 +msgid "Coupon Message" +msgstr "Message du code promo" + +#: includes/class-wc-sc-privacy.php:401 +msgid "Coupon passed in URL" +msgstr "Code promo passé dans l’URL" + +#: includes/class-wc-sc-display-coupons.php:2167 +msgid "Coupon Received" +msgstr "Code promo reçu" + +#: includes/class-wc-sc-settings.php:682 +msgid "Coupon Receiver Details during Checkout" +msgstr "Détails du destinataire du code promo pendant la commande" + +#. translators: The coupon code +#: includes/class-wc-smart-coupons.php:3378 +msgid "Coupon removed. There is no credit remaining in %s." +msgstr "Code promo retiré. Il n’y a aucun crédit restant dans %s." + +#: includes/class-wc-sc-coupon-fields.php:101 +msgid "Coupon shareable link" +msgstr "Lien partageable du code promo" + +#: includes/class-wc-smart-coupons.php:4651 +msgid "Coupon Title Prefix" +msgstr "Préfixe du code promo" + +#: includes/class-wc-smart-coupons.php:4652 +msgid "Coupon Title Suffix" +msgstr "Suffixe du code promo" + +#: includes/class-wc-smart-coupons.php:4648 +msgid "Coupon Validity" +msgstr "Validité du code promo" + +#: includes/class-wc-sc-coupon-fields.php:452 +msgid "Coupon value same as product's price?" +msgstr "Valeur du code promo identique au prix du produit ?" + +#: includes/class-wc-sc-admin-pages.php:123 +#: includes/class-wc-sc-admin-pages.php:550 +#: includes/class-wc-sc-admin-pages.php:555 +#: includes/class-wc-sc-admin-pages.php:1620 +#: includes/class-wc-sc-background-coupon-importer.php:396 +#: includes/class-wc-sc-display-coupons.php:791 +#: includes/class-wc-sc-display-coupons.php:828 +#: includes/class-wc-sc-display-coupons.php:1940 +#: includes/class-wc-sc-product-fields.php:99 +#: includes/class-wc-sc-product-fields.php:159 +msgid "Coupons" +msgstr "Codes promo" + +#: includes/class-wc-sc-background-coupon-importer.php:606 +msgid "coupons" +msgstr "codes promo" + +#: includes/class-wc-sc-admin-welcome.php:261 +msgid "Create and gift Store Credit / Gift Cards" +msgstr "Créer et offrir des bons d’achat/cartes cadeaux" + +#: includes/class-wc-sc-background-coupon-importer.php:627 +msgid "CSV file has been generated. You can download it from " +msgstr "Le fichier CSV a été généré. Vous pouvez le télécharger à partir de " + +#. translators: Link for the plugin 'Aelia Currency Switcher for WooCommerce' +#: includes/class-wc-sc-admin-welcome.php:449 +msgid "Currently, Smart Coupons is compatible with %s. But it is not compatible with any other multi-currency plugin or with WPML." +msgstr "" + +#: includes/class-wc-sc-settings.php:384 +msgid "Custom colors" +msgstr "Couleurs personnalisées" + +#: includes/class-wc-smart-coupons.php:5286 +msgid "Custom Style" +msgstr "Style personnalisé" + +#: includes/class-wc-smart-coupons.php:5020 +msgid "Customer Email" +msgstr "E-mail du client" + +#: includes/class-wc-sc-admin-welcome.php:436 +msgid "Customers can apply store credit on a subscription during purchase of subscription. If the same store credit has sufficient balance, it'll keep applying it to renewals till the remainder in store credit is higher than renewal price. Customers will be able to apply store credit only during signup. They will not get an option to apply store credit in renewals. But if the store credit will not have sufficient balance to pay for the renewals, then the order will go into pending mode. Now when the customer will go to pay for this renewal order, they'll get an option to apply store credit again. To activate the subscription again, the customer will have to pay for the renewals. When the customer is paying for the renewals from their account, then in that process they can use the same store credit which didn't have the sufficient balance, again & pay for the remaining amount." +msgstr "" + +#: includes/class-wc-sc-settings.php:380 +msgid "Customize color scheme for coupons." +msgstr "Personnalisez le schéma de couleurs des codes promo." + +#: includes/class-wc-sc-settings.php:376 +msgid "Customize colors" +msgstr "Personnaliser les couleurs" + +#: includes/class-wc-sc-settings.php:405 +msgid "Cutout" +msgstr "Découpe" + +#: includes/class-wc-sc-coupon-fields.php:440 +msgid "Days" +msgstr "Jours" + +#: includes/class-wc-sc-settings.php:409 +msgid "Deal" +msgstr "Offre" + +#: includes/class-wc-sc-settings.php:742 +#: includes/class-wc-smart-coupons.php:5851 +msgid "Deduct credit/gift before doing tax calculations" +msgstr "Déduisez la promotion avant de calculer les taxes" + +#. translators: 1: plugin name 2: page based text 3: Label for store credit 4: Hide notice text +#: includes/class-wc-sc-settings.php:903 +msgid "Delete Gift / Credit, when credit is used up" +msgstr "Supprimer la carte cadeau ou le bon d’achat lorsque le crédit est épuisé" + +#. translators: %s: Note for admin +#: includes/class-wc-sc-settings.php:557 +msgid "Delete the %1$s when entire credit amount is used up %2$s" +msgstr "Supprimez la %1$s lorsque le montant total du crédit est épuisé %2$s" + +#: includes/class-wc-sc-settings.php:406 +msgid "Deliver" +msgstr "Livraisons" + +#: includes/class-wc-sc-purchase-credit.php:854 +msgid "Deliver coupon" +msgstr "Envoyer le code promo" + +#: includes/class-wc-sc-settings.php:707 +msgid "Description" +msgstr "Description" + +#: templates/plain/combined-email.php:103 +#: templates/plain/email.php:98 +msgid "Description:" +msgstr "Description :" + +#: includes/class-wc-smart-coupons.php:4654 +msgid "Disable Email Restriction" +msgstr "Désactiver la restriction de l’e-mail" + +#: includes/class-wc-sc-coupon-fields.php:536 +msgid "Disable email restriction?" +msgstr "Désactiver la restriction d’e-mail ?" + +#. translators: %s: Explanation of the setting +#: includes/class-wc-sc-settings.php:547 +msgid "Disabling this, no coupons will be auto-applied - even if any coupon has \"Auto apply?\" enabled." +msgstr "" + +#: includes/class-wc-sc-ajax.php:352 +#: includes/class-wc-sc-settings.php:1051 +#: includes/class-wc-smart-coupons.php:1163 +msgid "Discount" +msgstr "Remise" + +#: includes/class-wc-sc-display-coupons.php:1213 +msgid "Discount Coupons" +msgstr "Codes promo" + +#: includes/class-wc-smart-coupons.php:5008 +msgid "Discount Type" +msgstr "Type de remise" + +#: includes/class-wc-sc-order-fields.php:280 +#: templates/plain/combined-email.php:83 +#: templates/plain/email.php:78 +msgid "Discount:" +msgstr "Remise :" + +#. translators: %s: Preview link +#: includes/class-wc-sc-settings.php:537 +msgid "Display coupon description along with coupon code (on site as well as in emails) %s" +msgstr "Afficher la description du code promo en plus du code (sur le site ainsi que dans les e-mails) %s" + +#: includes/class-wc-sc-coupon-message.php:125 +msgid "Display message" +msgstr "Afficher le message" + +#: includes/class-wc-smart-coupons.php:5868 +msgid "Display prices during cart and checkout" +msgstr "Afficher les prix sur le panier et la commande" + +#: includes/class-wc-smart-coupons.php:5867 +msgid "Display prices in the shop" +msgstr "Afficher les prix dans la boutique" + +#: includes/class-wc-smart-coupons.php:5870 +msgid "Display tax totals" +msgstr "Afficher le total des taxes" + +#: includes/class-wc-sc-settings.php:499 +msgid "Displaying coupons" +msgstr "Afficher les codes promo" + +#: includes/class-wc-sc-coupon-fields.php:537 +msgid "Do not restrict auto-generated coupons to buyer/receiver email, anyone with coupon code can use it" +msgstr "Ne pas restreindre l’utilisation des codes promo générés automatiquement au destinataire de l’e-mail : autoriser n’importe qui à l’utiliser" + +#: includes/class-wc-sc-admin-welcome.php:385 +msgid "Do not want to tie store credit to be used by only one customer? / Can a customer send a gift certificate to themselves to pass on to someone else?" +msgstr "Vous ne voulez pas lier le bon d’achat à un seul client ? / Un client peut-il s’envoyer une carte cadeau pour la transmettre à quelqu’un d’autre ?" + +#: includes/class-wc-sc-admin-notifications.php:101 +#: includes/class-wc-sc-admin-welcome.php:198 +msgid "Docs" +msgstr "Docs" + +#: includes/class-wc-sc-admin-welcome.php:418 +msgid "Does Smart Coupons allow printing of coupon as Gift Card?" +msgstr "Smart Coupons permet-il l’impression d’un code promo en tant que carte-cadeau ?" + +#: includes/class-wc-smart-coupons.php:1612 +msgid "Don't Miss Out." +msgstr "Ne manquez pas ça." + +#: includes/class-wc-sc-coupon-import.php:857 +msgid "Download a sample.csv to confirm" +msgstr "Télécharger un sample.csv pour confirmer" + +#: includes/class-wc-sc-admin-coupons-dashboard-actions.php:123 +msgid "Duplicate" +msgstr "Dupliquer" + +#: includes/class-wc-sc-coupon-fields.php:998 +msgid "each with quantity" +msgstr "chacun avec la quantité" + +#: includes/class-wc-sc-coupon-categories.php:94 +msgid "Edit coupon category" +msgstr "Modifier la catégorie de code promo" + +#: includes/class-wc-sc-admin-welcome.php:386 +msgid "Edit the main coupon which is entered in \"Coupons\" field of the product edit page, then go to \"Usage Restrictions\" > \"Disable Email Restriction\" and disable this setting and save the coupon." +msgstr "Modifiez le code promo principal saisi dans le champ « Code promo » de la page d’édition du produit, puis allez à « Restrictions d’utilisation » - « Désactiver la restriction d’e-mail » et désactiver ce paramètre puis enregistrer le code promo." + +#: includes/class-wc-sc-coupon-process.php:322 +msgid "Email address" +msgstr "Adresse e-mail" + +#: includes/emails/class-wc-sc-email-coupon.php:35 +msgid "Email auto generated coupon to recipients. One email per coupon." +msgstr "Envoyez le code promo généré automatiquement par e-mail aux destinataires. Un e-mail par coupon." + +#: includes/class-wc-sc-settings.php:566 +msgid "Email auto generated coupons to recipients" +msgstr "Envoyer des codes promo auto générés par e-mail aux destinataires" + +#: includes/class-wc-sc-settings.php:424 +msgid "Email coupon" +msgstr "Code promo d’e-mail" + +#: includes/class-wc-sc-coupon-import.php:951 +msgid "Email coupon to recipients" +msgstr "" + +#: includes/emails/class-wc-sc-email.php:124 +msgid "Email heading" +msgstr "Entête e-mail" + +#: includes/class-wc-sc-coupon-message.php:133 +msgid "Email message?" +msgstr "Message de l’e-mail ?" + +#: includes/class-wc-sc-admin-pages.php:1212 +msgid "Email to " +msgstr "Envoyer un e-mail à " + +#: includes/class-wc-sc-admin-pages.php:1192 +msgid "Email to recipients" +msgstr "E-mail aux destinataires" + +#: includes/emails/class-wc-sc-email.php:107 +msgid "Email type" +msgstr "Type d’e-mail" + +#: includes/class-wc-sc-admin-notifications.php:176 +msgid "Enable" +msgstr "Activer" + +#: includes/class-wc-sc-settings.php:575 +msgid "Enable feature to allow printing of coupons" +msgstr "Activer la fonction permettant l’impression de codes promo" + +#: includes/class-wc-sc-settings.php:470 +msgid "Enable store notice for the coupon" +msgstr "Activer la notification de la boutique pour le code promo" + +#: includes/class-wc-smart-coupons.php:5865 +msgid "Enable taxes" +msgstr "Activer les taxes" + +#: includes/class-wc-smart-coupons.php:5871 +msgid "Enable the use of coupon codes" +msgstr "Activer l’utilisation des codes promo" + +#: includes/emails/class-wc-sc-email.php:103 +msgid "Enable this email notification" +msgstr "Activer cette notification par e-mail" + +#: includes/class-wc-sc-settings.php:717 +msgid "Enable this to allow buyers to select date & time for delivering the coupon." +msgstr "Activez ceci pour permettre aux acheteurs de sélectionner la date et l’heure pour l’envoi des codes promo." + +#: includes/class-wc-sc-coupon-import.php:951 +msgid "Enable this to send coupon to recipient's email addresses, provided in imported file." +msgstr "Activez cette option pour envoyer un code promo aux adresses e-mail du destinataire, fournies dans le fichier importé." + +#: includes/emails/class-wc-sc-email.php:101 +msgid "Enable/Disable" +msgstr "Activer/Désactiver" + +#: includes/class-wc-smart-coupons.php:1605 +msgid "Ending Soon!" +msgstr "Bientôt la fin !" + +#: includes/class-wc-sc-display-coupons.php:1941 +msgid "Endpoint for the My Account → Coupons page" +msgstr "Endpoint pour la page « Mon compte » → onglet « Codes promo »" + +#: includes/class-wc-sc-coupon-fields.php:1045 +#: includes/class-wc-smart-coupons.php:5140 +msgctxt "enhanced select" +msgid "%qty% results are available, use up and down arrow keys to navigate." +msgstr "%qty% résultats sont disponibles, utilisez les flèches haut et bas pour naviguer." + +#: includes/class-wc-smart-coupons.php:5142 +msgctxt "enhanced select" +msgid "Loading failed" +msgstr "Échec du chargement" + +#: includes/class-wc-sc-coupon-fields.php:1054 +#: includes/class-wc-smart-coupons.php:5149 +msgctxt "enhanced select" +msgid "Loading more results…" +msgstr "Charger plus de résultats…" + +#: includes/class-wc-sc-coupon-fields.php:1046 +#: includes/class-wc-smart-coupons.php:5141 +msgctxt "enhanced select" +msgid "No matches found" +msgstr "Aucun résultat" + +#: includes/class-wc-sc-coupon-fields.php:1044 +#: includes/class-wc-smart-coupons.php:5139 +msgctxt "enhanced select" +msgid "One result is available, press enter to select it." +msgstr "Un résultat est disponible, appuyez sur Entrée pour le sélectionner." + +#: includes/class-wc-sc-coupon-fields.php:1051 +#: includes/class-wc-smart-coupons.php:5146 +msgctxt "enhanced select" +msgid "Please delete %qty% characters" +msgstr "Veuillez supprimer %qty% caractères" + +#: includes/class-wc-sc-coupon-fields.php:1050 +#: includes/class-wc-smart-coupons.php:5145 +msgctxt "enhanced select" +msgid "Please delete 1 character" +msgstr "Veuillez supprimer 1 caractère" + +#: includes/class-wc-sc-coupon-fields.php:1049 +#: includes/class-wc-smart-coupons.php:5144 +msgctxt "enhanced select" +msgid "Please enter %qty% or more characters" +msgstr "Veuillez saisir %qty% caractères ou plus" + +#: includes/class-wc-sc-coupon-fields.php:1048 +#: includes/class-wc-smart-coupons.php:5143 +msgctxt "enhanced select" +msgid "Please enter 1 or more characters" +msgstr "Veuillez saisir 1 caractère ou plus" + +#: includes/class-wc-sc-coupon-fields.php:1047 +#: includes/class-wc-sc-coupon-fields.php:1055 +#: includes/class-wc-smart-coupons.php:5150 +msgctxt "enhanced select" +msgid "Searching…" +msgstr "Recherche…" + +#: includes/class-wc-sc-coupon-fields.php:1053 +#: includes/class-wc-smart-coupons.php:5148 +msgctxt "enhanced select" +msgid "You can only select %qty% items" +msgstr "Vous ne pouvez sélectionner que %qty% articles" + +#: includes/class-wc-sc-coupon-fields.php:1052 +#: includes/class-wc-smart-coupons.php:5147 +msgctxt "enhanced select" +msgid "You can only select 1 item" +msgstr "Vous ne pouvez sélectionner qu’1 article" + +#: includes/class-wc-sc-admin-pages.php:229 +msgid "Enter a name for the new attribute term:" +msgstr "Saisissez un nom pour le nouvel attribut du terme :" + +#: includes/class-wc-sc-purchase-credit.php:158 +msgid "Enter a numeric value." +msgstr "Saisissez une valeur numérique." + +#: includes/class-wc-sc-coupon-import.php:1077 +msgid "Enter location on the server" +msgstr "Entrez l’emplacement sur le serveur" + +#: includes/class-wc-sc-shortcode.php:809 +msgid "Enter more than one character to search." +msgstr "Saisissez plus d’un caractère pour la recherche." + +#: includes/class-wc-sc-purchase-credit.php:887 +#: includes/class-wc-sc-purchase-credit.php:998 +msgid "Enter recipient e-mail address" +msgstr "E-mail du destinataire" + +#: includes/class-wc-sc-admin-pages.php:226 +msgid "Enter some text, or some attributes by pipe (|) separating values." +msgstr "Saisissez du texte, ou des attributs en les séparant avec une barre verticale (|)." + +#. translators: 1: Path to setting 2: Setting to set email address 3: Setting for number of coupons to generate +#: includes/class-wc-sc-admin-pages.php:1200 +msgid "Enter the email addresses of the recipients separated by comma under %1$1s. Make sure to match the count of email addresses in %2$2s to %3$3s" +msgstr "Entrez les adresses e-mail des destinataires séparées par des virgules %1$1s. Assurez-vous d’avoir le même nombre d’adresses e-mail en %2$2s à %3$3s" + +#: includes/class-wc-sc-coupons-by-location.php:306 +msgid "Entered location not found. On pressing \"Enter\" button, a new custom location will be saved as: " +msgstr "" + +#. translators: 1. Error title 2. The bulk process +#: includes/class-wc-sc-background-coupon-importer.php:385 +msgid "Error" +msgstr "Erreur" + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-coupon-process.php:352 +msgid "Error: %s Receiver’s E-mail address is invalid." +msgstr "Erreur: l’adresse de messagerie du %s Destinataire ’ s n’est pas valide." + +#: includes/class-wc-sc-coupon-process.php:354 +msgid "Error: Gift Card Receiver’s E-mail address is invalid." +msgstr "Erreur : l’e-mail du bénéficiaire de la carte cadeau n’est pas valide." + +#: includes/class-wc-sc-background-coupon-importer.php:1257 +msgid "Every 5 Seconds" +msgstr "Toutes les 5 secondes" + +#: includes/class-wc-sc-coupons-by-taxonomy.php:104 +#: includes/class-wc-sc-coupons-by-taxonomy.php:291 +msgid "Exclude" +msgstr "Exclure" + +#: includes/class-wc-sc-coupons-by-product-attribute.php:546 +msgid "Exclude Attributes" +msgstr "Exclure les attributs" + +#: includes/class-wc-sc-coupons-by-product-attribute.php:200 +msgid "Exclude attributes" +msgstr "Exclure les attributs" + +#: includes/class-wc-smart-coupons.php:5019 +msgid "Exclude Product categories" +msgstr "Exclure catégorie" + +#: includes/class-wc-smart-coupons.php:5017 +msgid "Exclude product IDs" +msgstr "Exclure les ID produit" + +#: includes/class-wc-smart-coupons.php:5015 +msgid "Exclude Sale Items" +msgstr "Exclure des produits" + +#: includes/class-wc-sc-coupons-by-user-role.php:244 +msgid "Exclude User Role" +msgstr "Rôle d’utilisateur à exclure" + +#: includes/class-wc-sc-coupons-by-user-role.php:133 +msgid "Exclude user roles" +msgstr "Exclure les rôles utilisateur" + +#: includes/class-wc-sc-coupons-by-excluded-email.php:105 +#: includes/class-wc-sc-coupons-by-excluded-email.php:341 +#: includes/class-wc-sc-coupons-by-excluded-email.php:469 +msgid "Excluded emails" +msgstr "" + +#. translators: Discount amount applied on tax +#: includes/class-wc-smart-coupons.php:2777 +msgid "excludes -%s on tax" +msgstr "" + +#: templates/plain/combined-email.php:108 +#: templates/plain/email.php:103 +msgid "Expires on:" +msgstr "Expire le :" + +#: includes/class-wc-sc-admin-pages.php:800 +msgid "Expiry Date" +msgstr "Date d’expiration" + +#: includes/class-wc-smart-coupons.php:5011 +msgid "Expiry date" +msgstr "Date d’expiration" + +#. translators: 1: The expiry date +#: includes/class-wc-smart-coupons.php:1278 +msgid "Expiry: %s" +msgstr "Expiration : %s" + +#: includes/class-wc-sc-admin-pages.php:206 +#: includes/class-wc-smart-coupons.php:4257 +msgid "Export" +msgstr "Exporter" + +#: includes/class-wc-sc-admin-pages.php:1172 +msgid "Export to CSV" +msgstr "Exporter au format CSV" + +#: includes/class-wc-sc-background-coupon-importer.php:743 +#: includes/class-wc-sc-background-coupon-importer.php:760 +msgid "Failed to create export file." +msgstr "Échec de la création du fichier d’exportation." + +#. translators: 1. Receiver email 2. Coupon code 3. Order id +#: includes/class-wc-sc-coupon-process.php:1081 +#: includes/class-wc-smart-coupons.php:873 +msgid "Failed to schedule email to \"%1$s\" for coupon \"%2$s\" received from order #%3$s." +msgstr "Impossible de planifier l’envoi du mail à « %1$s » pour le code promo « %2$s » reçu à partir de la commande #%3$s." + +#. translators: 1. Receiver email 2. Coupon code +#: includes/class-wc-sc-coupon-import.php:669 +msgid "Failed to schedule email to \"%1$s\" for coupon \"%2$s\"." +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:1324 +#: includes/compat/class-wc-sc-kco-compatibility.php:123 +msgid "Failed to update coupon receiver details in session." +msgstr "" + +#: includes/class-wc-sc-coupon-refund-process.php:502 +msgid "Failed to update store credit refund details." +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:349 +msgid "FAQ / Common Problems" +msgstr "FAQ / Problèmes connus" + +#: includes/class-wc-sc-admin-notifications.php:100 +#: includes/class-wc-sc-admin-pages.php:159 +#: includes/class-wc-sc-admin-pages.php:608 +#: includes/class-wc-sc-admin-welcome.php:223 +msgid "FAQ's" +msgstr "FAQ" + +#: includes/class-wc-sc-admin-pages.php:235 +msgid "Featured" +msgstr "En vedette" + +#: includes/class-wc-sc-admin-notifications.php:177 +msgid "features." +msgstr "caractéristiques." + +#: includes/class-wc-sc-settings.php:402 +msgid "Festive" +msgstr "Festive" + +#: includes/class-wc-sc-coupon-import.php:941 +msgid "File format seems OK" +msgstr "Format de fichier semble OK" + +#. translators: File path +#: includes/class-wc-smart-coupons.php:5317 +#: includes/class-wc-smart-coupons.php:5325 +msgid "File not found %s" +msgstr "Fichier non trouvé %s" + +#: includes/class-wc-sc-coupon-import.php:940 +msgid "File uploaded OK" +msgstr "Fichier téléchargé OK" + +#: includes/class-wc-smart-coupons.php:4224 +msgid "Filter by category" +msgstr "Filtrer par catégorie" + +#. translators: Email address of users +#: includes/class-wc-smart-coupons.php:7070 +msgid "Find coupons restricted to %s" +msgstr "" + +#: includes/class-wc-sc-settings.php:399 +msgid "Flat" +msgstr "Plat" + +#. translators: 1. The discount text +#: includes/class-wc-smart-coupons.php:1625 +msgid "Flat %s discount on everything today." +msgstr "%s de Remise sur tout aujourd’hui." + +#: includes/emails/class-wc-sc-email-coupon.php:410 +#: includes/emails/class-wc-sc-email-coupon.php:421 +msgid "for all products" +msgstr "pour tous les produits" + +#: includes/emails/class-wc-sc-email-coupon.php:432 +msgid "for entire purchase" +msgstr "pour la totalité de la commande" + +#. translators: Documentation link for 'How to Apply Single or Multiple Coupons on Click of a Link' +#: includes/class-wc-sc-admin-welcome.php:382 +msgid "For more details you can refer to this article: %s" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:422 +#: includes/class-wc-smart-coupons.php:4656 +#: includes/class-wc-smart-coupons.php:5026 +msgid "For new user only?" +msgstr "Pour les nouveaux utilisateurs seulement ?" + +#: includes/emails/class-wc-sc-email-coupon.php:408 +#: includes/emails/class-wc-sc-email-coupon.php:419 +#: includes/emails/class-wc-sc-email-coupon.php:430 +msgid "for some products" +msgstr "pour certains produits" + +#: includes/class-wc-sc-display-coupons.php:280 +#: includes/class-wc-sc-display-coupons.php:871 +#: includes/class-wc-sc-display-coupons.php:2412 +#: includes/class-wc-sc-shortcode.php:542 +#: includes/class-wc-smart-coupons.php:4895 +#: templates/combined-email.php:127 +#: templates/email.php:125 +#: templates/plain/combined-email.php:93 +#: templates/plain/email.php:88 +#: templates/print-coupons-default.php:144 +msgid "Free Shipping" +msgstr "Livraison gratuite" + +#: includes/class-wc-smart-coupons.php:5010 +msgid "Free shipping" +msgstr "Livraison gratuite" + +#: includes/class-wc-sc-purchase-credit.php:988 +msgid "Free Shipping coupon" +msgstr "Code promo de livraison gratuite" + +#: includes/emails/class-wc-sc-combined-email-coupon.php:144 +#: includes/emails/class-wc-sc-combined-email-coupon.php:221 +#: includes/emails/class-wc-sc-email-coupon.php:202 +#: includes/emails/class-wc-sc-email-coupon.php:281 +msgid "from" +msgstr "de" + +#: includes/class-wc-sc-admin-welcome.php:424 +msgid "From version 4.11.0, you can add/link coupons to product variations as well. This feature is not available in a version lower than 4.11.0." +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block-frontend.js:1 +#: blocks/src/js/send-coupon-form/block.js:235 +#: blocks/src/js/send-coupon-form/block.js:239 +msgctxt "Frontend" +msgid "Deliver coupon" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block-frontend.js:1 +#: blocks/src/js/send-coupon-form/block.js:262 +#: blocks/src/js/send-coupon-form/block.js:287 +msgctxt "Frontend" +msgid "Enter recipient e-mail address" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block-frontend.js:1 +#: blocks/src/js/send-coupon-form/block.js:207 +msgctxt "Frontend" +msgid "Gift to someone else" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block-frontend.js:1 +#: blocks/src/js/send-coupon-form/block.js:267 +#: blocks/src/js/send-coupon-form/block.js:294 +msgctxt "Frontend" +msgid "Message for receiver" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block-frontend.js:1 +#: blocks/src/js/send-coupon-form/block.js:259 +#: blocks/src/js/send-coupon-form/block.js:284 +msgctxt "Frontend" +msgid "Receiver email address" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block-frontend.js:1 +#: blocks/src/js/send-coupon-form/block.js:195 +msgctxt "Frontend" +msgid "Send coupons to..." +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block-frontend.js:1 +#: blocks/src/js/send-coupon-form/block.js:225 +msgctxt "Frontend" +msgid "Send to different people" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block-frontend.js:1 +#: blocks/src/js/send-coupon-form/block.js:202 +msgctxt "Frontend" +msgid "Send to me" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block-frontend.js:1 +#: blocks/src/js/send-coupon-form/block.js:220 +msgctxt "Frontend" +msgid "Send to one person" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block-frontend.js:1 +#: blocks/src/js/send-coupon-form/block.js:271 +#: blocks/src/js/send-coupon-form/block.js:298 +msgctxt "Frontend" +msgid "Write a message" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block-frontend.js:1 +#: blocks/src/js/send-coupon-form/block.js:197 +msgctxt "Frontend" +msgid "Your order contains coupons. What would you like to do?" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:366 +#: includes/class-wc-sc-background-coupon-importer.php:371 +msgid "generate" +msgstr "générer" + +#: includes/class-wc-sc-admin-pages.php:284 +msgid "Generate coupon code" +msgstr "Générer un code promo" + +#: includes/class-wc-sc-admin-pages.php:1164 +msgid "Generate coupons and" +msgstr "Générer des codes promo et" + +#: includes/class-wc-sc-coupon-fields.php:460 +msgid "Generate exact copy of this coupon with unique coupon code for each purchased product (needs this coupon to be linked with that product)" +msgstr "Générer une copie exacte de ce code promo avec un code promo unique pour chaque produit acheté (ce code promo doit être lié à ce produit)" + +#: includes/class-wc-sc-background-coupon-importer.php:370 +#: includes/class-wc-sc-background-coupon-importer.php:595 +msgid "generated" +msgstr "généré" + +#. translators: %s: Label for store credit +#: includes/class-wc-sc-settings.php:489 +msgid "Generated %s amount" +msgstr "Montant généré du %s" + +#: includes/class-wc-sc-background-coupon-importer.php:365 +msgid "generated & sent" +msgstr "générés et envoyés" + +#: includes/class-wc-sc-privacy.php:390 +msgid "Generated Coupon Data" +msgstr "Données de code promo générées" + +#: includes/class-wc-sc-display-coupons.php:2595 +msgid "Generated coupons" +msgstr "Codes promo générés" + +#. translators: 1. Link to jump to 'Order actions' metabox 2. Text 'Order actions' 3. Text 'arrow' +#: includes/class-wc-sc-display-coupons.php:2107 +msgctxt "Generated coupons metabox - Order edit admin page" +msgid "arrow" +msgstr "" + +#. translators: 1. Link to jump to 'Order actions' metabox 2. Text 'Order actions' 3. Text 'arrow' +#: includes/class-wc-sc-display-coupons.php:2107 +msgctxt "Generated coupons metabox - Order edit admin page" +msgid "Coupons are not generated for this order. You can regenerate it from %1$s. Select an appropriate action from the %2$s dropdown menu and hit the %3$s button next to it." +msgstr "" + +#. translators: 1. Link to jump to 'Order actions' metabox 2. Text 'Order actions' 3. Text 'arrow' +#: includes/class-wc-sc-display-coupons.php:2107 +msgctxt "Generated coupons metabox - Order edit admin page" +msgid "Order actions" +msgstr "" + +#. translators: 1. Label for Order action for regenerating coupons +#: includes/class-wc-sc-display-coupons.php:2120 +msgctxt "Generated coupons metabox - Order edit admin page" +msgid "Select %s to only regenerate coupons. No email will be sent for this." +msgstr "" + +#. translators: 1. Label for Order action for regenerating & resending coupons +#: includes/class-wc-sc-display-coupons.php:2130 +msgctxt "Generated coupons metabox - Order edit admin page" +msgid "Select %s to regenerate as well as resend coupons to the recipients via email." +msgstr "" + +#: includes/class-wc-sc-admin-coupons-dashboard-actions.php:118 +msgid "Get shareable link" +msgstr "Obtenir un lien partageable" + +#: includes/class-wc-sc-admin-welcome.php:389 +msgid "Getting 'Page Not Found Error' when accessing Coupons tab from My Account Page?" +msgstr "Message « Erreur page non trouvée » lors de l’accès à l’onglet « Codes promo » à partir de la page « Mon compte » ?" + +#: includes/class-wc-sc-admin-welcome.php:298 +msgid "Gift a product via coupon" +msgstr "Offrir un produit via un code promo" + +#: includes/emails/class-wc-sc-email-coupon.php:355 +#: includes/emails/class-wc-sc-email-coupon.php:479 +msgid "Gift Card" +msgstr "Carte cadeau" + +#: includes/emails/class-wc-sc-acknowledgement-email.php:336 +#: templates/acknowledgement-email.php:61 +#: templates/plain/acknowledgement-email.php:51 +msgid "Gift card" +msgstr "Carte cadeau" + +#: includes/class-wc-smart-coupons.php:5852 +msgid "Gift Card discount is inclusive of tax" +msgstr "Le montant de la carte cadeau inclut les taxes" + +#: includes/emails/class-wc-sc-acknowledgement-email.php:337 +#: templates/acknowledgement-email.php:62 +#: templates/plain/acknowledgement-email.php:52 +msgid "Gift cards" +msgstr "Cartes cadeau" + +#: includes/class-wc-sc-purchase-credit.php:847 +msgid "Gift to someone else" +msgstr "Les offrir à quelqu’un" + +#: includes/class-wc-sc-settings.php:610 +msgid "Give alternate singular name to Store Credit / Gift Certificate. This label will only rename Store Credit / Gift Certificate used in the Smart Coupons plugin." +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:432 +msgid "Give away a discount or credit on signing up a subscription, give away recurring discount or credits, apply credit during sign up, automatic payment for renewals from credit (Note: When using PayPal Standard Gateway, store credit can be applied only during sign up. Automatic payment for renewals by credit will not work for PayPal Standard Gateway)." +msgstr "Offrez un code promo ou un bon d’achat lors de l’inscription à un abonnement; offrez des codes promo ou des bons d’achat récurrents; appliquez un bon d’achat lors de l’inscription; instaurer un paiement automatique pour les renouvellements de bons d’achat. Note : Lorsque vous utilisez PayPal Standard Gateway, le bon d’achat ne peut être appliqué que lors de l’inscription. Le paiement automatique pour les renouvellements par bon d’achat ne fonctionnera pas pour PayPal Standard Gateway." + +#: includes/class-wc-sc-admin-welcome.php:314 +msgid "Give bigger discounts without hurting your profits. Offer a percentage off coupon upto a particular value. Example - Flat 50% off upto $100." +msgstr "Offrez des remises plus importantes sans nuire à vos bénéfices. Offrez un pourcentage de réduction sur un code promo jusqu’à une certaine valeur. Exemple - Moins 50% o jusqu’à 100 €." + +#: includes/class-wc-sc-admin-welcome.php:306 +msgid "Give discounts to customers for next purchase" +msgstr "Offrir des réductions aux clients pour leur prochain achat" + +#: includes/class-wc-sc-settings.php:617 +msgid "Give plural name for the above singular name." +msgstr "Donnez le nom pluriel pour le nom singulier ci-dessus." + +#: includes/class-wc-sc-admin-welcome.php:179 +msgid "Glad to have you onboard. We hope WooCommerce Smart Coupons adds to your desired success 🏆" +msgstr "Heureux de vous avoir à bord. Nous espérons que WooCommerce Smart Coupons participera à votre succès 🏆" + +#: includes/class-wc-sc-admin-welcome.php:183 +msgid "Go To Coupons" +msgstr "Aller aux Codes promo" + +#: includes/class-wc-sc-admin-welcome.php:390 +msgid "Go to WordPress -> Settings -> Permalinks and click on Save Settings once." +msgstr "Aller à WordPress -> Réglages ->Permaliens et cliquez une fois sur enregistrer les paramètres." + +#: includes/class-wc-sc-settings.php:363 +msgid "Gold" +msgstr "Gold" + +#: includes/class-wc-smart-coupons.php:1603 +msgid "Great News!" +msgstr "Bonnes nouvelles !" + +#. translators: %s: link to submit idea for Smart Coupons on WooCommerce idea board +#: includes/class-wc-sc-admin-notifications.php:330 +msgid "Have a feature request? Submit it %s." +msgstr "Vous avez une demande de fonctionnalité ? Soumettez-la ici %s." + +#. translators: %s: link to submit idea for Smart Coupons on WooCommerce idea board +#. translators: 1. File name 2. File download link +#: includes/class-wc-sc-admin-notifications.php:330 +#: includes/class-wc-sc-admin-welcome.php:361 +#: includes/class-wc-sc-admin-welcome.php:369 +#: includes/class-wc-sc-admin-welcome.php:395 +#: includes/class-wc-sc-background-coupon-importer.php:627 +#: includes/class-wc-sc-print-coupon.php:278 +msgid "here" +msgstr "ici" + +#: includes/class-wc-sc-coupon-fields.php:392 +msgid "HH:MM" +msgstr "HH:MM" + +#: includes/class-wc-sc-coupon-import.php:1036 +msgid "Hi there! Upload a CSV file with coupons details to import them into your shop." +msgstr "Bonjour ! Téléchargez un fichier CSV avec les détails des codes promo pour les importer dans votre boutique." + +#. translators: 1: plugin name 2: page based text 3: Label for store credit 4: Hide notice text +#: includes/class-wc-sc-settings.php:903 +#: includes/class-wc-sc-settings.php:906 +msgid "Hide this notice" +msgstr "Cacher cet avertissement" + +#: includes/class-wc-sc-admin-welcome.php:402 +msgid "How can I resend gift card coupon bought by customers?" +msgstr "Comment puis-je renvoyer la carte cadeau achetée par les clients ?" + +#: includes/class-wc-sc-admin-welcome.php:435 +msgid "How does automatic payment by store credit work with Subscriptions?" +msgstr "Comment fonctionne le paiement automatique par bon d’achat avec les abonnements ?" + +#: includes/class-wc-sc-settings.php:432 +msgid "How many coupons (at max) should be shown on cart, checkout & my account page? If set to 0 (zero) then coupons will not be displayed at all on the website." +msgstr "Combien de codes promo (au maximum) doivent être affichés sur la page « Panier », sur la page « Commande » et sur la page « Mon compte » ? S’il est fixé à 0 (zéro), les codes promo ne seront pas du tout affichés." + +#. translators: Documentation link for 'How to Apply Single or Multiple Coupons on Click of a Link' +#: includes/class-wc-sc-admin-welcome.php:382 +msgid "How to Apply Single or Multiple Coupons on Click of a Link" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:372 +msgid "How to change texts of the emails sent from Smart Coupons?" +msgstr "Comment modifier les textes des e-mails envoyés à partir de Smart Coupons ?" + +#: includes/class-wc-sc-admin-welcome.php:373 +msgid "How to override email template" +msgstr "Comment remplacer le modèle d’e-mail" + +#. translators: Documentation link for 'How to Print Coupons' +#: includes/class-wc-sc-admin-welcome.php:420 +msgid "How to Print Coupons" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:368 +msgid "How to translate texts from Smart Coupons?" +msgstr "Comment faire pour traduire des textes de Smart Coupons ?" + +#: includes/class-wc-sc-admin-welcome.php:280 +msgid "How to use Smart Coupons the best way" +msgstr "Comment utiliser au mieux les codes promo intelligents" + +#. Plugin URI of the plugin +#: woocommerce-smart-coupons.php +#, fuzzy +msgid "https://woocommerce.com/products/smart-coupons/" +msgstr "http://www.woothemes.com/products/smart-coupons/" + +#. Author URI of the plugin +#: woocommerce-smart-coupons.php +msgid "https://www.storeapps.org/" +msgstr "https://www.storeapps.org/" + +#: includes/class-wc-sc-settings.php:1052 +msgid "Hurry. Going fast! On the entire range of products." +msgstr "Dépêchez-vous. Profitez de cette remise sur toute la gamme de produits." + +#: includes/class-wc-sc-admin-welcome.php:447 +msgid "I'm using WPML & WPML provides support for multi-currency, but Smart Coupons only changes currency symbol & the price value remains same. Can Smart Coupons change the currency symbol and the price value associated with it?" +msgstr "J’utilise WPML & WPML prend en charge plusieurs devises, mais Smart Coupons modifie uniquement le symbole monétaire & la valeur prix reste la même. Est-ce que Smart Coupons peut modifier le symbole monétaire et la valeur du prix qui lui sont associés ?" + +#. translators: 1: ID who refunded +#: includes/class-wc-sc-coupon-refund-process.php:671 +msgid "ID: %d" +msgstr "ID : %d" + +#: includes/class-wc-sc-coupon-import.php:945 +msgid "If enabled, existing coupons that match by coupon code will be updated. Coupons that do not exist will be skipped." +msgstr "" + +#: includes/class-wc-sc-privacy.php:116 +msgid "If you are a visitor: We access your billing email address entered during purchase" +msgstr "Si vous êtes un visiteur: nous accèderons à votre adresse e-mail de facturation saisie lors de l’achat" + +#. translators: WooCommerce My Account support link +#: includes/class-wc-sc-admin-welcome.php:476 +msgid "If you are facing any issues, please %s from your WooCommerce account." +msgstr "Si vous êtes confronté à des problèmes, veuillez %s depuis votre compte WooCommerce." + +#: includes/class-wc-sc-privacy.php:115 +msgid "If you are logged in: We access your billing email address saved in your account & billing email address entered during purchase" +msgstr "Si vous êtes connecté(e) : nous accèderons à votre adresse e-mail de facturation enregistrée dans votre compte et votre adresse e-mail de facturation saisie lors de l’achat" + +#. translators: 1. File name 2. File download link +#: includes/class-wc-sc-admin-welcome.php:395 +msgid "If you want to import coupon through file, the file should be like" +msgstr "Si vous voulez importer des codes promo par le biais d’un fichier, le fichier doit être comme ceci" + +#. translators: WooCommerce Subscriptions product link +#: includes/class-wc-sc-admin-welcome.php:275 +msgid "If your store is using %s and your customer has purchased a subscription using a Store Credit. If that store credit has balance left in it, store will automatically use it for renewing that subscription." +msgstr "Si votre magasin utilise %s et que votre client a acheté un abonnement en utilisant un bon d’achat. S’il reste un solde dans ce crédit, le magasin l’utilisera automatiquement pour renouveler cet abonnement." + +#: includes/class-wc-sc-admin-pages.php:205 +#: includes/class-wc-sc-coupon-import.php:955 +msgid "Import" +msgstr "Importer" + +#: includes/class-wc-sc-admin-pages.php:1184 +#: includes/class-wc-sc-background-coupon-importer.php:360 +msgid "import" +msgstr "importer" + +#: includes/class-wc-sc-admin-pages.php:385 +msgid "Import coupons to your store via a csv file." +msgstr "Importez des codes promo à votre magasin via un fichier CSV." + +#: includes/class-wc-sc-admin-welcome.php:294 +msgid "Import and export unique coupons in bulk via CSV. Share coupon codes to deal sites or email them to your customers." +msgstr "Importation et exportation de codes promo uniques en masse via CSV. Partagez les codes promo sur des sites de vente ou envoyez-les par e-mail à vos clients." + +#: includes/class-wc-sc-admin-pages.php:320 +msgid "Import complete - imported" +msgstr "Import complet - importé" + +#: includes/class-wc-sc-admin-pages.php:133 +#: includes/class-wc-sc-admin-pages.php:566 +#: includes/class-wc-sc-admin-pages.php:1587 +msgid "Import Coupons" +msgstr "Importer des codes promo" + +#. translators: 1. Important 2. Upload path +#. translators: 1. Coupon type +#: includes/class-wc-sc-admin-notifications.php:165 +#: includes/class-wc-sc-background-coupon-importer.php:333 +#: includes/class-wc-sc-background-coupon-importer.php:400 +#: includes/class-wc-smart-coupons.php:5409 +msgid "Important" +msgstr "Important" + +#. translators: 1: plugin name 2: page based text 3: Label for store credit 4: Hide notice text +#: includes/class-wc-sc-settings.php:906 +msgid "Important setting" +msgstr "Réglage important" + +#: includes/class-wc-sc-background-coupon-importer.php:359 +msgid "imported" +msgstr "importé" + +#: includes/class-wc-sc-background-coupon-importer.php:402 +msgid "in the background. You will be notified when it is completed." +msgstr "en arrière-plan. Vous serez notifié une fois qu’il sera terminé." + +#: includes/class-wc-sc-coupons-by-taxonomy.php:103 +#: includes/class-wc-sc-coupons-by-taxonomy.php:290 +msgid "Include" +msgstr "Inclure" + +#. translators: %s: Preview link +#: includes/class-wc-sc-settings.php:501 +msgid "Include coupon details on product's page, for products that issue coupons %s" +msgstr "Inclure les détails du code promo sur la page « Produit », pour les produits qui émettent des codes promo %s" + +#. translators: %s: Preview link +#: includes/class-wc-sc-settings.php:519 +msgid "Include coupons received from other people on My Account > Coupons page %s" +msgstr "Inclure les codes promo reçus de la part d’autres personnes sur la page « Mon compte » > onglet « Codes promo » %s" + +#. translators: %s: Label for store credit +#: includes/class-wc-sc-settings.php:491 +msgid "Include tax in the amount of the generated %s" +msgstr "Inclure la taxe dans le montant généré du %s" + +#: includes/class-wc-smart-coupons.php:5850 +msgid "Include tax in the amount of the generated gift card" +msgstr "Inclure la taxe dans le montant généré de la carte cadeau" + +#. translators: Discount amount applied on tax +#: includes/class-wc-smart-coupons.php:2780 +msgid "includes -%s on tax" +msgstr "" + +#. translators: 1. Coupon code 2. Expiry date +#: includes/class-wc-sc-coupon-parser.php:416 +msgid "Incorrect format for expiry date of coupon \"%1$s\". Entered date is %2$s. Expected date format: YYYY-MM-DD" +msgstr "Format incorrect pour la date d’expiration du code promo « %1$s ». La date entrée est « %2$s ». Format de la date prévue: AAAA-MM-DD" + +#: includes/class-wc-smart-coupons.php:5014 +msgid "Individual USe" +msgstr "Usage individuel" + +#: includes/class-wc-sc-shortcode.php:941 +msgid "Insert Shortcode" +msgstr "Insérer un Shortcode" + +#: includes/class-wc-sc-display-coupons.php:1245 +msgid "Invalid / Used Coupons" +msgstr "Codes promo invalides / déjà utilisés" + +#: includes/class-wc-sc-admin-pages.php:790 +#: includes/class-wc-sc-purchase-credit.php:156 +msgid "Invalid amount." +msgstr "Montant invalide." + +#: includes/class-wc-sc-coupon-import.php:857 +msgid "Invalid CSV file. Make sure your CSV file contains all columns, header row, and data in correct format." +msgstr "Fichier CSV non valide. Assurez-vous que votre fichier CSV contient toutes les colonnes, la ligne d’en-tête et les données au format correct." + +#: includes/class-wc-sc-admin-pages.php:770 +msgid "Invalid email address." +msgstr "Adresse e-mail non valide." + +#. translators: 1. Product/s 2. Product names 3. is/are 4. Coupons code +#: includes/class-wc-sc-coupon-actions.php:504 +msgid "is" +msgid_plural "are" +msgstr[0] "est" +msgstr[1] "sont" + +#: includes/class-wc-smart-coupons.php:5409 +msgid "is active but it will only work with WooCommerce 3.0.0+." +msgstr "est actif mais ne fonctionnera qu’avec WooCommerce 3.0.0+." + +#: includes/class-wc-sc-coupon-message.php:436 +msgid "Is Email Coupon Message" +msgstr "Message du code promo pour l’e-mail" + +#: includes/class-wc-sc-admin-welcome.php:423 +msgid "Is it possible to have a coupon for each variation of the variable product?" +msgstr "Est-il possible d’avoir un code promo pour chaque variation d’un produit variable ?" + +#: includes/class-wc-sc-admin-welcome.php:439 +msgid "Is it possible to partially pay for a subscription with store credit and the remainder by another method?" +msgstr "Est-il possible de payer partiellement un abonnement avec un bon d’achat et le reste avec une autre méthode de paiement ?" + +#: includes/class-wc-smart-coupons.php:4653 +msgid "Is Pick Price of Product" +msgstr "Choix du prix du produit" + +#: includes/class-wc-sc-admin-welcome.php:427 +msgid "Is Smart Coupons compatible with WooCommerce Subscriptions?" +msgstr "Smart Coupons est-il compatible avec WooCommerce Subscriptions ?" + +#: includes/class-wc-sc-admin-welcome.php:443 +msgid "Is Smart Coupons WPML compatible?" +msgstr "Smart Coupon est-il compatible avec WPML ?" + +#: includes/class-wc-sc-admin-welcome.php:393 +msgid "Is there any reference file for creating an import file for coupons?" +msgstr "Y a t-il un fichier de référence pour la création d’un fichier d’importation pour les codes promo ?" + +#: includes/class-wc-sc-admin-notifications.php:177 +msgid "it to use" +msgstr "à utiliser" + +#: includes/class-wc-sc-settings.php:361 +msgid "Keppel" +msgstr "Keppel" + +#: includes/class-wc-sc-admin-welcome.php:214 +msgid "Know Smart Coupons" +msgstr "En savoir plus sur Smart Coupons" + +#: includes/class-wc-sc-settings.php:599 +msgid "Labels" +msgstr "Libellés" + +#: includes/class-wc-sc-purchase-credit.php:545 +msgid "Later" +msgstr "Plus tard" + +#: includes/class-wc-sc-admin-pages.php:1184 +msgid "later" +msgstr "plus tard" + +#: includes/class-wc-sc-admin-welcome.php:365 +msgid "latest version of Smart Coupons" +msgstr "la dernière version de Smart Coupons" + +#: includes/class-wc-sc-admin-notifications.php:243 +msgid "leaving a review" +msgstr "laisser un commentaire" + +#: includes/class-wc-sc-display-coupons.php:2218 +#: includes/class-wc-sc-display-coupons.php:2229 +msgid "Less details" +msgstr "Moins de détails" + +#. translators: 1: Affiliate For WooCommerce 2: Smart Manager 3: Smart Offers +#: includes/class-wc-sc-admin-welcome.php:287 +msgid "Let customers purchase gift cards from you or you issue store credit that your users can redeem on the current or next purchase. See how: %1$s or %2$s" +msgstr "Permettez aux clients de vous acheter des cartes-cadeaux ou émettez des bons d’achat que vos utilisateurs peuvent utiliser pour l’achat en cours ou le suivant. Voir comment : %1$s ou %2$s" + +#. translators: %s: link to review WooCommerce Smart Coupons +#: includes/class-wc-sc-admin-notifications.php:304 +msgid "Liked WooCommerce Smart Coupons? Leave us a %s. A huge thank you from WooCommerce & StoreApps in advance!" +msgstr "Aimez-vous WooCommerce Smart Coupons ? Laissez-nous un %s. WooCommerce & StoreApps vous remercient à l’avance !" + +#: includes/class-wc-smart-coupons.php:5023 +msgid "Limit Usage to X Items" +msgstr "Limiter l’utilisation à X articles" + +#: includes/class-wc-smart-coupons.php:1606 +msgid "Limited Time Offer!" +msgstr "Offre à durée limitée !" + +#: includes/class-wc-sc-display-coupons.php:2168 +msgid "List of coupons & their details which you have received from the store. Click on the coupon to see the details." +msgstr "Liste des codes promo que vous avez reçus. Cliquez sur le code promo pour voir les détails." + +#: includes/class-wc-sc-display-coupons.php:978 +msgid "List of coupons which are valid & available for use. Click on the coupon to use it. The coupon discount will be visible only when at least one product is present in the cart." +msgstr "Liste des codes promo valables et disponibles à l’utilisation. Cliquez sur le code promo pour l’utiliser. Le code promo ne sera visible que si au moins un produit est présent dans le panier." + +#: includes/class-wc-sc-display-coupons.php:1260 +msgid "List of coupons which can not be used. The reason can be based on its usage restrictions, usage limits, expiry date." +msgstr "Liste des codes promo qui ne peuvent pas être utilisés. La raison peut être basée sur ses restrictions d’utilisation, ses limites d’utilisation, sa date d’expiration." + +#: includes/class-wc-sc-coupons-by-excluded-email.php:107 +msgid "List of excluded billing emails to check against when an order is placed. Separate email addresses with commas. You can also use an asterisk (*) to match parts of an email. For example \"*@gmail.com\" would match all gmail addresses." +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:233 +msgid "Load the customer's billing information? This will remove any currently entered billing information." +msgstr "Charger les informations de facturation du client ? Ceci supprimera toutes les informations de facturation actuellement saisies." + +#: includes/class-wc-sc-admin-pages.php:234 +msgid "Load the customer's shipping information? This will remove any currently entered shipping information." +msgstr "Charger les informations de livraison du client ? Ceci supprimera toutes les informations de livraison actuellement saisies." + +#: includes/class-wc-sc-coupons-by-location.php:207 +msgid "Locations" +msgstr "Emplacements" + +#: includes/class-wc-sc-coupons-by-location.php:493 +msgid "Locations lookup in" +msgstr "Recherche de lieux dans" + +#: includes/class-wc-sc-admin-welcome.php:369 +msgid "Loco Translate" +msgstr "Loco Translate" + +#: includes/class-wc-sc-settings.php:364 +msgid "Majorelle Blue" +msgstr "Majorelle Blue" + +#: includes/class-wc-sc-admin-coupons-dashboard-actions.php:123 +msgid "Make a duplicate from this coupon" +msgstr "Faire un duplicata de ce code promo" + +#: includes/class-wc-sc-admin-welcome.php:318 +msgid "Make customer's coupon usage, easy & simple" +msgstr "Rendez l’utilisation du code promo par votre client simple et facile" + +#: includes/class-wc-sc-admin-welcome.php:355 +msgid "Make sure use of coupon is enabled in your store. You can find this setting" +msgstr "Assurez-vous que l’utilisation du code promo est activée dans votre magasin. Vous pouvez trouver ce paramètre" + +#: includes/class-wc-sc-admin-welcome.php:365 +msgid "Make sure you are using the " +msgstr "Assurez-vous d’utiliser la " + +#: includes/class-wc-sc-admin-pages.php:1302 +#: includes/class-wc-sc-coupon-categories.php:105 +#: includes/class-wc-sc-coupon-categories.php:165 +#: includes/class-wc-smart-coupons.php:4261 +msgid "Manage coupon categories" +msgstr "Gérer les catégories de codes promo" + +#: includes/class-wc-sc-admin-pages.php:1615 +msgid "Marketing" +msgstr "Marketing" + +#: includes/class-wc-sc-coupon-fields.php:407 +#: includes/class-wc-smart-coupons.php:4657 +msgid "Max discount" +msgstr "Réduction max" + +#: includes/class-wc-sc-coupon-import.php:1075 +msgid "Maximum file size" +msgstr "Taille maximale du fichier" + +#: includes/class-wc-sc-coupons-by-product-quantity.php:135 +msgid "Maximum quantity" +msgstr "Quantité maximale" + +#: includes/class-wc-smart-coupons.php:5013 +msgid "Maximum Spend" +msgstr "Dépenses maximum" + +#: includes/class-wc-sc-settings.php:362 +msgid "McDonald" +msgstr "McDonald" + +#: includes/class-wc-smart-coupons.php:5001 +msgid "Menu Order" +msgstr "Ordre du menu" + +#: includes/class-wc-sc-admin-pages.php:815 +#: includes/class-wc-sc-admin-pages.php:1229 +#: includes/class-wc-sc-display-coupons.php:2464 +#: includes/class-wc-sc-display-coupons.php:2497 +#: includes/class-wc-sc-privacy.php:608 +msgid "Message" +msgstr "Message" + +#: templates/plain/combined-email.php:75 +#: templates/plain/email.php:26 +msgid "Message:" +msgstr "Message :" + +#: includes/class-wc-sc-coupons-by-product-quantity.php:131 +msgid "Minimum quantity" +msgstr "Quantité minimale" + +#: includes/class-wc-smart-coupons.php:5012 +msgid "Minimum Spend" +msgstr "Dépenses minimum" + +#: includes/class-wc-sc-coupon-fields.php:442 +msgid "Months" +msgstr "Mois" + +#: includes/class-wc-sc-display-coupons.php:2220 +#: includes/class-wc-sc-display-coupons.php:2232 +#: includes/class-wc-sc-display-coupons.php:2335 +msgid "More details" +msgstr "Plus de détails" + +#: includes/class-wc-sc-settings.php:667 +msgid "My Account page" +msgstr "Page « Mon compte »" + +#: includes/class-wc-sc-privacy.php:820 +msgid "N/A" +msgstr "N/A" + +#: includes/class-wc-sc-admin-pages.php:222 +msgid "Name" +msgstr "Nom" + +#: includes/class-wc-sc-admin-pages.php:1109 +msgid "Need a lot of coupons? You can easily do that with Smart Coupons." +msgstr "Besoin de beaucoup de codes promo ? Vous pouvez facilement le faire avec des Smart Coupons." + +#: includes/class-wc-sc-display-coupons.php:297 +#: includes/class-wc-sc-display-coupons.php:885 +#: includes/class-wc-sc-display-coupons.php:2442 +#: includes/class-wc-sc-shortcode.php:572 +#: includes/class-wc-smart-coupons.php:4922 +#: includes/emails/class-wc-sc-email-coupon.php:173 +#: templates/combined-email.php:158 +#: templates/email.php:156 +#: templates/plain/combined-email.php:125 +#: templates/plain/email.php:120 +#: templates/print-coupons-default.php:176 +msgid "Never expires" +msgstr "N’expire jamais" + +#: includes/class-wc-sc-admin-notifications.php:240 +#: includes/class-wc-sc-print-coupon.php:275 +msgid "Never show again" +msgstr "Ne plus afficher" + +#: includes/class-wc-sc-coupon-categories.php:97 +msgid "New coupon category name" +msgstr "Nouveau nom de la catégorie de code promo" + +#: includes/class-wc-sc-coupon-import.php:945 +msgid "New feature" +msgstr "" + +#: includes/class-wc-sc-coupon-categories.php:98 +msgid "No coupon categories found" +msgstr "Aucune catégorie de code promo trouvée" + +#: includes/class-wc-sc-shortcode.php:827 +msgid "No coupon code found." +msgstr "Aucun code promo trouvé." + +#: includes/class-wc-sc-admin-coupons-dashboard-actions.php:266 +msgid "No coupon to duplicate has been supplied!" +msgstr "Aucun code promo à dupliquer n’a été fourni !" + +#: includes/class-wc-sc-admin-pages.php:238 +msgid "No customer selected" +msgstr "Aucun client sélectionné" + +#: includes/class-wc-sc-coupons-by-product-quantity.php:136 +#: includes/class-wc-sc-coupons-by-product-quantity.php:158 +#: includes/class-wc-sc-coupons-by-product-quantity.php:196 +#: includes/class-wc-sc-coupons-by-product-quantity.php:226 +#: includes/class-wc-sc-coupons-by-product-quantity.php:238 +msgid "No maximum" +msgstr "Pas de maximum" + +#: includes/class-wc-sc-coupons-by-product-quantity.php:132 +#: includes/class-wc-sc-coupons-by-product-quantity.php:157 +#: includes/class-wc-sc-coupons-by-product-quantity.php:195 +#: includes/class-wc-sc-coupons-by-product-quantity.php:225 +#: includes/class-wc-sc-coupons-by-product-quantity.php:237 +msgid "No minimum" +msgstr "Pas de minimum" + +#: includes/class-wc-sc-coupons-by-payment-method.php:105 +msgid "No payment methods" +msgstr "Pas de mode de paiement" + +#: includes/class-wc-sc-coupons-by-product-attribute.php:182 +#: includes/class-wc-sc-coupons-by-product-attribute.php:201 +msgid "No product attributes" +msgstr "Aucun attribut produit" + +#: includes/class-wc-sc-coupons-by-excluded-email.php:106 +msgid "No restrictions" +msgstr "" + +#: includes/class-wc-sc-shortcode.php:805 +#: includes/class-wc-sc-shortcode.php:846 +#: includes/class-wc-sc-shortcode.php:883 +msgid "No search term specified." +msgstr "Aucun terme de recherche spécifié." + +#: includes/class-wc-sc-coupons-by-shipping-method.php:107 +msgid "No shipping methods" +msgstr "Pas de mode de livraison" + +#: includes/class-wc-sc-coupons-by-user-role.php:117 +#: includes/class-wc-sc-coupons-by-user-role.php:134 +msgid "No user roles" +msgstr "Aucun rôle utilisateur" + +#: includes/class-wc-sc-admin-welcome.php:440 +msgid "No, this is possible only in those cases where subscription amount is more than store credit's balance. If store credit's balance is more than subscription's total then your bank account or credit card will not be charged." +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:377 +msgid "No. Coupon code should not have any spaces in the name, Eg, Coupon code should be “gift-certificate” & not “gift certificate”." +msgstr "Non. Le code promo ne devrait pas avoir d’espace dans le nom, par exemple, le code promo devrait être « carte-cadeau » - pas « certificat de cadeau\"." + +#: includes/class-wc-sc-coupon-refund-process.php:513 +msgid "Nonce verification failed for action \"wc_sc_refund_store_credit\"." +msgstr "" + +#. translators: Excluded product names +#: includes/class-wc-smart-coupons.php:1251 +msgid "Not valid for %s" +msgstr "Non valable pour %s" + +#. translators: 1: The category names excluded +#: includes/class-wc-smart-coupons.php:1265 +msgid "Not valid for category %s" +msgid_plural "Not valid for categories %s" +msgstr[0] "Non valable pour la catégorie %s" +msgstr[1] "Non valable pour les catégories %s" + +#. translators: Formatted maximum amount +#: includes/class-wc-smart-coupons.php:1239 +msgid "Not valid for sale items" +msgstr "Non valable pour les articles en vente" + +#: includes/class-wc-sc-admin-welcome.php:444 +msgid "Not yet, but this is being worked on. You will find this in later versions." +msgstr "Pas encore, mais on y travaille. Vous trouverez ceci dans les versions ultérieures." + +#: includes/class-wc-sc-coupon-import.php:1038 +msgid "Note: If any coupon from the CSV file already exists in the store, it will not update the existing coupon, instead a new coupon will be imported & the previous coupon with the same code will become inactive." +msgstr "Note : Si un code promo du fichier CSV existe déjà dans le magasin, il ne mettra pas à jour le code promo existant, mais un nouveau code promo sera importé et le code promo précédent avec le même code deviendra inactif." + +#: includes/class-wc-sc-admin-notifications.php:456 +msgid "Note: WP CRON has been disabled on your install which may prevent this update from completing." +msgstr "Remarque : WP CRON a été désactivé sur votre installation, ce qui peut empêcher cette mise à jour de se terminer." + +#: includes/class-wc-sc-purchase-credit.php:535 +msgid "Now" +msgstr "Maintenant" + +#: includes/class-wc-sc-settings.php:440 +#: includes/class-wc-smart-coupons.php:5848 +msgid "Number of characters in auto-generated coupon code" +msgstr "Nombre de caractères dans le code promo auto-généré" + +#: includes/class-wc-sc-settings.php:441 +msgid "Number of characters in auto-generated coupon code will be restricted to this number excluding prefix and/or suffix. The default length will be 13. It is recommended to keep this number between 10 to 15 to avoid coupon code duplication." +msgstr "Le nombre de caractères dans le code promo auto-généré sera limité à ce numéro excluant le préfixe et/ou le suffixe. La longueur par défaut sera 13. Il est recommandé de garder ce nombre entre 10 et 15 pour éviter la duplication du code promo." + +#. translators: 1: Path to setting 2: Setting to set email address 3: Setting for number of coupons to generate +#: includes/class-wc-sc-admin-pages.php:1159 +#: includes/class-wc-sc-admin-pages.php:1200 +msgid "Number of coupons to generate" +msgstr "Nombre de codes promo à générer" + +#: includes/class-wc-sc-settings.php:431 +#: includes/class-wc-smart-coupons.php:5847 +msgid "Number of coupons to show" +msgstr "Nombre de codes promo à afficher" + +#: includes/class-wc-sc-settings.php:369 +msgid "Ocean" +msgstr "Océan" + +#. translators: 1. Coupon type 2. Coupon amount +#: includes/class-wc-sc-purchase-credit.php:997 +msgid "of" +msgstr "de" + +#: templates/acknowledgement-email.php:53 +msgid "on" +msgstr "" + +#: includes/class-wc-sc-settings.php:657 +msgid "On Cart/Checkout pages" +msgstr "Sur les pages Panier/Commande" + +#: includes/class-wc-sc-product-columns.php:235 +msgid "Open in a new tab" +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:1076 +msgid "OR" +msgstr "OU" + +#: includes/class-wc-sc-coupon-process.php:1850 +msgctxt "Order edit admin page" +msgid "Coupon details manually sent." +msgstr "" + +#: includes/class-wc-sc-coupon-process.php:1845 +msgctxt "Order edit admin page" +msgid "Coupons manually regenerated & sent." +msgstr "" + +#: includes/class-wc-sc-coupon-process.php:1843 +msgctxt "Order edit admin page" +msgid "Coupons manually regenerated." +msgstr "" + +#: includes/class-wc-sc-coupon-process.php:1816 +msgctxt "Order edit admin page" +msgid "Regenerate & resend coupon emails" +msgstr "" + +#: includes/class-wc-sc-coupon-process.php:1815 +msgctxt "Order edit admin page" +msgid "Regenerate coupons" +msgstr "" + +#: includes/class-wc-sc-coupon-process.php:1813 +msgctxt "Order edit admin page" +msgid "Resend coupon emails" +msgstr "" + +#. translators: %s: singular name for store credit +#: includes/compat/class-wcs-sc-compatibility.php:894 +msgid "Order paid by %s" +msgstr "Commande payée par %s" + +#. translators: %s: singular name for store credit +#: includes/compat/class-wcs-sc-compatibility.php:894 +msgid "Order paid by store credit." +msgstr "Commande payée avec le code promo." + +#: includes/class-wc-sc-admin-pages.php:1633 +msgid "Original amount" +msgstr "" + +#: includes/class-wc-sc-admin-notifications.php:243 +msgid "our support team" +msgstr "notre équipe de support" + +#: includes/class-wc-sc-print-coupon.php:123 +msgctxt "Page slug" +msgid "wc-sc-coupons-terms" +msgstr "wc-sc-coupons-terms" + +#: includes/class-wc-sc-print-coupon.php:124 +msgctxt "Page title" +msgid "Smart Coupons Terms" +msgstr "Termes des Codes promo" + +#: includes/class-wc-sc-coupon-categories.php:92 +msgid "Parent coupon category" +msgstr "Catégorie parente de code promo" + +#: includes/class-wc-sc-coupon-categories.php:93 +msgid "Parent coupon category:" +msgstr "Catégorie de code promo parent :" + +#. translators: 1. The coupon code 2. The text 'payment method/s' 3. List of payment method names 4. Link to the checkout page +#: includes/class-wc-sc-coupons-by-payment-method.php:210 +#: includes/class-wc-sc-coupons-by-payment-method.php:214 +msgid "payment method" +msgid_plural "payment methods" +msgstr[0] "" +msgstr[1] "" + +#: includes/class-wc-sc-coupons-by-payment-method.php:104 +#: includes/class-wc-sc-coupons-by-payment-method.php:233 +msgid "Payment methods" +msgstr "Moyens de paiement" + +#: includes/class-wc-sc-coupons-by-payment-method.php:115 +msgid "Payment methods that must be selected during checkout for this coupon to be valid." +msgstr "Moyens de paiement qui doivent être sélectionnés lors de la commande pour que ce code promo soit valide." + +#: includes/class-wc-sc-purchase-credit.php:890 +#: includes/class-wc-sc-purchase-credit.php:1003 +msgid "Pick a delivery date & time" +msgstr "Choisissez une date et une heure de remise" + +#. translators: 1. The discount text +#: includes/class-wc-smart-coupons.php:1621 +msgid "Pick any item today for %s off." +msgstr "Choisissez n’importe quel élément aujourd’hui pour le %s." + +#: includes/class-wc-sc-admin-notifications.php:243 +msgid "Please consider" +msgstr "Veuillez considérer" + +#: includes/class-wc-sc-admin-pages.php:1028 +msgid "Please enter a valid value for Number of Coupons to Generate" +msgstr "Entrez une valeur valide pour le nombre de codes promo à générer" + +#: includes/class-wc-sc-admin-pages.php:201 +msgid "Please enter in a value less than the regular price." +msgstr "Veuillez saisir une valeur inférieure au tarif normal." + +#: includes/class-wc-sc-admin-pages.php:200 +msgid "Please enter in country code with two capital letters." +msgstr "Veuillez saisir un code pays avec deux lettres majuscules." + +#. translators: Decimal point +#: includes/class-wc-sc-admin-pages.php:197 +msgid "Please enter in decimal (%s) format without thousand separators." +msgstr "Veuillez saisir en format décimal (%s) sans séparateur de milliers." + +#. translators: Decimal point +#: includes/class-wc-sc-admin-pages.php:199 +msgid "Please enter in monetary decimal (%s) format without thousand separators and currency symbols." +msgstr "Veuillez saisir en format monétaire, avec décimal, (%s) sans séparateur de milliers et sans symbole monétaire." + +#: includes/class-wc-smart-coupons.php:4244 +msgid "Please select at least one coupon to print." +msgstr "Veuillez sélectionner au moins un code promo à imprimer." + +#: includes/class-wc-sc-coupons-by-product-quantity.php:210 +#: includes/class-wc-sc-coupons-by-product-quantity.php:255 +msgid "Please select some categories" +msgstr "Veuillez sélectionner des catégories" + +#: includes/class-wc-sc-admin-pages.php:216 +msgid "Please select some items." +msgstr "Veuillez sélectionner quelques articles." + +#: includes/class-wc-sc-coupons-by-product-quantity.php:171 +#: includes/class-wc-sc-coupons-by-product-quantity.php:247 +msgid "Please select some products" +msgstr "Veuillez sélectionner des produits" + +#: includes/class-wc-sc-admin-pages.php:677 +msgid "Please try again later." +msgstr "Veuillez réessayer ultérieurement." + +#: includes/class-wc-smart-coupons.php:5409 +msgid "Please update WooCommerce to the latest version" +msgstr "Veuillez mettre à jour WooCommerce vers la dernière version" + +#: includes/class-wc-sc-admin-welcome.php:369 +msgid "plugin and then following steps listed " +msgstr "plugin, puis des suivre les étapes énumérées " + +#: includes/class-wc-sc-settings.php:618 +msgid "Plural name" +msgstr "Nom pluriel" + +#: includes/class-wc-smart-coupons.php:5002 +msgid "Post Date" +msgstr "Date de l’article" + +#: includes/class-wc-smart-coupons.php:4998 +msgid "Post Excerpt" +msgstr "Extrait d’article" + +#: includes/class-wc-smart-coupons.php:5000 +msgid "Post Parent" +msgstr "Article Parent" + +#: includes/class-wc-smart-coupons.php:4999 +msgid "Post Status" +msgstr "Statut de l’article" + +#: includes/class-wc-sc-coupon-fields.php:481 +msgid "Prefix" +msgstr "Préfixe" + +#: includes/class-wc-sc-settings.php:209 +#: includes/class-wc-sc-shortcode.php:892 +msgid "Preview" +msgstr "Aperçu" + +#: includes/class-wc-sc-admin-pages.php:830 +#: includes/class-wc-sc-admin-pages.php:1244 +msgid "Preview Email" +msgstr "Prévisualiser Email" + +#: includes/class-wc-smart-coupons.php:5866 +msgid "Prices entered with tax" +msgstr "Prix saisis en TTC" + +#: includes/class-wc-smart-coupons.php:4259 +msgid "Print" +msgstr "Imprimer" + +#: includes/class-wc-sc-display-coupons.php:1120 +#: templates/combined-email.php:228 +#: templates/email.php:209 +msgid "Print coupon" +msgid_plural "Print coupons" +msgstr[0] "Imprimer le code promo" +msgstr[1] "Imprimer les codes promo" + +#: includes/class-wc-smart-coupons.php:4259 +msgid "Print selected coupons" +msgstr "Imprimer les codes promo sélectionnés" + +#: includes/class-wc-sc-settings.php:574 +#: includes/class-wc-smart-coupons.php:5855 +msgid "Printing coupons" +msgstr "Impression des codes promo" + +#. translators: 1. Product/s 2. Product names 3. is/are 4. Coupons code +#: includes/class-wc-sc-coupon-actions.php:504 +#: includes/class-wc-sc-coupons-by-product-quantity.php:124 +msgid "Product" +msgid_plural "Products" +msgstr[0] "Produit" +msgstr[1] "%s produits" + +#. translators: 1. Singular/plural label for product(s) 2. Excluded product names +#: includes/class-wc-sc-coupons-by-product-attribute.php:525 +#: includes/class-wc-sc-coupons-by-taxonomy.php:729 +msgid "product" +msgid_plural "products" +msgstr[0] "produit" +msgstr[1] "produits" + +#: includes/class-wc-sc-coupons-by-product-attribute.php:545 +msgid "Product Attributes" +msgstr "Attributs du produit" + +#: includes/class-wc-sc-coupons-by-product-attribute.php:181 +msgid "Product attributes" +msgstr "Attributs du produit" + +#. translators: Non product type coupon labels +#: includes/class-wc-sc-coupons-by-product-attribute.php:193 +msgid "Product attributes that the coupon will be applied to, or that need to be in the cart in order for the %s to be applied." +msgstr "Attributs du produit pour que le code promo soit appliqué, ou qui doivent être dans le panier afin que les %s s’appliquent." + +#. translators: Non product type coupon labels +#: includes/class-wc-sc-coupons-by-product-attribute.php:212 +msgid "Product attributes that the coupon will not be applied to, or that cannot be in the cart in order for the %s to be applied." +msgstr "Attributs de produit auxquels le code promo ne sera pas appliqué, ou qui ne peuvent pas être dans le panier pour que les %s soient appliqués." + +#: includes/class-wc-smart-coupons.php:5018 +msgid "Product categories" +msgstr "Catégories de produits" + +#: includes/class-wc-sc-ajax.php:342 +#: includes/class-wc-sc-ajax.php:347 +#: includes/class-wc-smart-coupons.php:1153 +#: includes/class-wc-smart-coupons.php:1158 +msgid "Product Discount" +msgstr "Remise produit" + +#: includes/class-wc-smart-coupons.php:5016 +msgid "Product IDs" +msgstr "ID Produits" + +#: includes/class-wc-sc-coupons-by-product-quantity.php:115 +#: includes/class-wc-sc-coupons-by-product-quantity.php:663 +msgid "Product quantity based restrictions" +msgstr "Restrictions basées sur la quantité de produits" + +#: includes/class-wc-sc-coupons-by-taxonomy.php:183 +msgid "Product taxonomies that the coupon will be applicable for, or its availability in the cart in order for the \"Fixed cart discount\" to be applied, based on whether the taxonomies are included or excluded." +msgstr "Les taxonomies de produits pour lesquelles le code promo sera applicable, ou sa disponibilité dans le panier pour que la « remise panier fixe » soit appliquée, selon que les taxonomies sont incluses ou exclues." + +#: includes/class-wc-sc-coupons-by-taxonomy.php:142 +msgid "Product taxonomies that the coupon will be applicable for, or its availability in the cart in order for the \"Fixed cart discount\" to be applied, based on whether the taxonomies are included or excluded. All the taxonomies selected here, should be valid, for this coupon to be valid." +msgstr "Les taxonomies de produits pour lesquelles le code promo sera applicable, ou sa disponibilité dans le panier afin que la « remise fixe sur le panier » soit appliquée, selon que les taxonomies sont incluses ou exclues. Toutes les taxonomies sélectionnées ici doivent être valides pour que ce code promo soit valable." + +#: includes/class-wc-sc-coupons-by-product-quantity.php:153 +#: includes/class-wc-sc-coupons-by-product-quantity.php:169 +#: includes/class-wc-sc-coupons-by-product-quantity.php:245 +#: includes/class-wc-sc-coupons-by-product-quantity.php:260 +msgid "Products" +msgstr "Produits" + +#: includes/class-wc-sc-background-coupon-importer.php:405 +msgid "Progress" +msgstr "Progression" + +#: includes/class-wc-sc-settings.php:400 +msgid "Promotion" +msgstr "Promotion" + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-purchase-credit.php:218 +msgid "Purchase %s worth" +msgstr "Achat %s valeur" + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-purchase-credit.php:218 +#: includes/class-wc-sc-settings.php:642 +msgid "Purchase credit worth" +msgstr "Montant de la carte cadeau" + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-admin-pages.php:727 +msgid "Quickly create and email %s to one or more people." +msgstr "Créer rapidement et envoyer par e-mail %s à une ou plusieurs personnes." + +#: includes/class-wc-sc-admin-pages.php:729 +msgid "Quickly create and email Store Credit or Gift Card to one or more people." +msgstr "Créez et envoyer rapidement par e-mail un bon d’achat ou une carte-cadeau à une ou plusieurs personnes." + +#: includes/class-wc-sc-coupon-import.php:1039 +msgid "Ready to import? Choose a .csv file, then click \"Upload file\"." +msgstr "Prêt à importer ? Choisissez un fichier. csv, puis cliquez sur « Télécharger le fichier »." + +#: includes/class-wc-sc-display-coupons.php:2462 +#: includes/class-wc-sc-display-coupons.php:2496 +msgid "Receiver" +msgstr "Destinataire" + +#: includes/compat/class-wcs-sc-compatibility.php:951 +msgid "Recurring subscriptions" +msgstr "Abonnements récurrents" + +#. translators: 1: refund id 2: refund date +#: includes/class-wc-sc-coupon-refund-process.php:678 +msgid "Refund %1$s - %2$s" +msgstr "Remboursement %1$s - %2$s" + +#. translators: 1: refund id 2: refund date 3: username +#: includes/class-wc-sc-coupon-refund-process.php:665 +msgid "Refund %1$s - %2$s by %3$s" +msgstr "Remboursement %1$s - %2$s par %3$s" + +#: includes/class-wc-sc-coupon-refund-process.php:213 +msgid "Refund to Store Credit" +msgstr "Remboursement au crédit d’achat" + +#: includes/class-wc-sc-admin-notifications.php:239 +msgid "Remind me after a month" +msgstr "Rappelez-moi après un mois" + +#: includes/class-wc-sc-admin-pages.php:223 +msgid "Remove" +msgstr "Supprimer" + +#: includes/class-wc-sc-coupons-by-taxonomy.php:219 +msgid "Remove taxonomy restriction" +msgstr "Supprimer la restriction de taxonomie" + +#: includes/class-wc-sc-admin-pages.php:221 +msgid "Remove this attribute?" +msgstr "Supprimer cet attribut ?" + +#: includes/class-wc-sc-admin-pages.php:220 +msgid "Remove this item meta?" +msgstr "Supprimer la méta de cet article ?" + +#: includes/class-wc-sc-privacy.php:324 +msgid "Removed Coupon Personal Data" +msgstr "Données personnelles des codes promo supprimées" + +#: includes/class-wc-sc-privacy.php:734 +msgid "Removed Order Personal Data" +msgstr "Données personnelles des commandes supprimées" + +#: includes/class-wc-sc-privacy.php:443 +msgid "Removed User Personal Data" +msgstr "Données personnelles des utilisateurs supprimés" + +#: includes/class-wc-smart-coupons.php:5858 +#: includes/compat/class-wcs-sc-compatibility.php:961 +msgid "Renewal orders should not generate coupons even when they include a product that issues coupons" +msgstr "Les commandes de renouvellement ne doivent pas générer de code promo même lorsqu’ils comprennent un produit qui émet des codes promo" + +#: includes/class-wc-sc-admin-pages.php:1159 +msgid "Required" +msgstr "Requis" + +#: blocks/class-wc-sc-extend-store-endpoint.php:133 +msgctxt "REST API" +msgid "Coupons scheduled date & time" +msgstr "" + +#: blocks/class-wc-sc-extend-store-endpoint.php:118 +msgctxt "REST API" +msgid "Email address of recipients" +msgstr "" + +#: blocks/class-wc-sc-extend-store-endpoint.php:148 +msgctxt "REST API" +msgid "Message for coupon recipient" +msgstr "" + +#: blocks/class-wc-sc-extend-store-endpoint.php:106 +msgctxt "REST API" +msgid "Whether to send coupons now or schedule for later." +msgstr "" + +#: blocks/class-wc-sc-extend-store-endpoint.php:94 +msgctxt "REST API" +msgid "Whether to send coupons to only one person or multiple people." +msgstr "" + +#: blocks/class-wc-sc-extend-store-endpoint.php:81 +msgctxt "REST API" +msgid "Whether to send coupons to someone else." +msgstr "" + +#: includes/class-wc-sc-privacy.php:816 +msgid "Retain Store Credit/Gift Certificate" +msgstr "Conserver le bon d’achat/carte cadeau" + +#: includes/class-wc-sc-admin-notifications.php:103 +msgid "Review" +msgstr "Avis" + +#: includes/class-wc-sc-coupons-by-user-role.php:145 +msgid "Role of the users for whom this coupon is not valid. Keep empty if you want this coupon to be valid for users with any role." +msgstr "Rôle des utilisateurs pour lesquels ce code promo n’est pas valable. Laissez vide si vous voulez que ce code promo soit valable pour les utilisateurs ayant un rôle quelconque." + +#: includes/class-wc-sc-coupons-by-user-role.php:128 +msgid "Role of the users for whom this coupon is valid. Keep empty if you want this coupon to be valid for users with any role." +msgstr "Rôle des utilisateurs pour lesquels ce code promo est valable. Laissez vide si vous voulez que ce code promo soit valable pour tous les types de rôles." + +#: includes/class-wc-sc-settings.php:365 +msgid "Rose Pink" +msgstr "Rose" + +#: includes/class-wc-smart-coupons.php:5869 +msgid "Rounding" +msgstr "Arrondir" + +#: includes/emails/class-wc-sc-acknowledgement-email.php:116 +msgid "Scheduled email heading" +msgstr "Entête de l’e-mail planifié" + +#: includes/emails/class-wc-sc-acknowledgement-email.php:108 +msgid "Scheduled email subject" +msgstr "Sujet de l’e-mail planifié" + +#: includes/class-wc-sc-settings.php:474 +msgid "Search & select a coupon which you want to display as store notice. The selected coupon's description will be displayed along with the coupon code (if it is set) otherwise, a description will be generated automatically. To disable the feature, keep this field empty." +msgstr "Recherchez et sélectionnez un code promo que vous souhaitez afficher comme avis de magasin. La description du code promo sélectionné sera affichée avec le code du code promo (si celui-ci est défini), sinon une description sera générée automatiquement. Pour désactiver la fonction, laissez ce champ vide." + +#: includes/class-wc-sc-coupon-categories.php:90 +msgid "Search coupon categories" +msgstr "Rechercher des catégories de codes promo" + +#: includes/class-wc-sc-shortcode.php:879 +msgid "Search coupon..." +msgstr "Rechercher un code promo…" + +#: includes/class-wc-sc-product-fields.php:100 +#: includes/class-wc-sc-product-fields.php:161 +msgid "Search for a coupon…" +msgstr "Chercher un code promo…" + +#: includes/class-wc-sc-settings.php:480 +msgid "Search for a coupon..." +msgstr "Recherche un code promo…" + +#: includes/class-wc-sc-coupon-fields.php:967 +#: includes/class-wc-sc-coupon-fields.php:994 +msgid "Search for a product…" +msgstr "Rechercher un produit…" + +#: includes/class-wc-sc-settings.php:211 +msgid "See coupon search limitations" +msgstr "Voir les limitations de la recherche de coupons" + +#: includes/class-wc-sc-admin-welcome.php:294 +#: includes/class-wc-sc-admin-welcome.php:300 +#: includes/class-wc-sc-admin-welcome.php:308 +#: includes/class-wc-sc-admin-welcome.php:403 +msgid "See how" +msgstr "Voyez comment" + +#: includes/class-wc-sc-coupons-by-location.php:282 +msgid "Select Additional Locations" +msgstr "Sélectionnez d’autres emplacements" + +#: includes/class-wc-sc-coupons-by-location.php:219 +msgid "Select location" +msgstr "Sélectionner le lieu" + +#: includes/class-wc-sc-display-coupons.php:722 +#: includes/class-wc-sc-settings.php:630 +#: includes/class-wc-smart-coupons.php:296 +msgid "Select options" +msgstr "Sélectionner les options" + +#: includes/class-wc-sc-settings.php:465 +msgid "Select order status…" +msgstr "Sélectionnez l’état de la commande …" + +#. translators: %s: Label for store credit +#: includes/class-wc-sc-settings.php:584 +msgid "Sell %s at less price?" +msgstr "Vendre %s à moindre prix ?" + +#: includes/class-wc-smart-coupons.php:5856 +msgid "Sell gift cards at less price?" +msgstr "Vendre des cartes cadeaux à moindre prix ?" + +#: includes/class-wc-sc-admin-welcome.php:283 +msgid "Sell or issue store credit / gift cards" +msgstr "Vendre ou émettre des bons d’achat/cartes cadeaux" + +#. translators: 1. Coupon type 2. Coupon amount +#: includes/class-wc-sc-admin-pages.php:824 +#: includes/class-wc-sc-purchase-credit.php:997 +msgid "Send" +msgstr "Envoyer" + +#. translators: %s: singular name for store credit +#. translators: Store Credit label +#: includes/class-wc-sc-admin-pages.php:143 +#: includes/class-wc-sc-admin-pages.php:579 +#: includes/class-wc-sc-admin-pages.php:1591 +msgid "Send %s" +msgstr "Envoyer %s" + +#: includes/emails/class-wc-sc-acknowledgement-email.php:42 +msgid "Send an acknowledgement email to the purchaser. One email per customer." +msgstr "Envoyer un e-mail d’accusé de réception à l’acheter. Un e-mail par client." + +#: includes/class-wc-sc-product-fields.php:127 +#: includes/class-wc-sc-product-fields.php:186 +msgid "Send coupons on renewals?" +msgstr "Envoyer des codes promo sur les renouvellements ?" + +#: includes/class-wc-sc-purchase-credit.php:820 +#: includes/class-wc-sc-settings.php:702 +msgid "Send Coupons to..." +msgstr "Envoyer le(s) codes(s) promo à..." + +#: includes/class-wc-sc-settings.php:727 +msgid "Send only one email instead of multiple emails when multiple coupons are generated for same recipient" +msgstr "Envoyer un seul e-mail au lieu de plusieurs lorsque plusieurs codes promo sont générés pour le même destinataire" + +#: includes/emails/class-wc-sc-combined-email-coupon.php:35 +msgid "Send only one email instead of multiple emails when multiple coupons are generated per recipient." +msgstr "Envoyer un seul e-mail au lieu de plusieurs lorsque plusieurs codes promo sont générés pour le même destinataire." + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-admin-pages.php:143 +#: includes/class-wc-sc-admin-pages.php:579 +msgid "Send Store Credit" +msgstr "Envoyer le bon d’achat" + +#. translators: 1: Path to setting 2: Setting to set email address 3: Setting for number of coupons to generate +#: includes/class-wc-sc-admin-pages.php:762 +#: includes/class-wc-sc-admin-pages.php:1200 +#: includes/class-wc-sc-admin-pages.php:1218 +msgid "Send to" +msgstr "Envoyer à" + +#: includes/class-wc-sc-purchase-credit.php:850 +msgid "Send to different people" +msgstr "L’envoyer à plusieurs personnes" + +#: includes/class-wc-sc-purchase-credit.php:845 +msgid "Send to me" +msgstr "Me les envoyer" + +#: includes/class-wc-sc-purchase-credit.php:849 +msgid "Send to one person" +msgstr "L’envoyer à une personne" + +#: includes/class-wc-sc-display-coupons.php:2461 +#: includes/class-wc-sc-display-coupons.php:2498 +msgid "Sender" +msgstr "Expéditeur" + +#: includes/class-wc-sc-background-coupon-importer.php:590 +msgid "sent" +msgstr "envoyé" + +#: includes/class-wc-sc-admin-welcome.php:312 +msgid "Set a maximum discount limit" +msgstr "Fixer une limite maximale de remise" + +#: includes/class-wc-sc-settings.php:347 +msgid "Set up Smart Coupons the way you like. Use these options to configure/change the way Smart Coupons works." +msgstr "Configurez les codes promo comme vous le souhaitez. Utilisez ces options pour configurer/modifier la façon dont fonctionne l’extension Smart Coupons." + +#. translators: 1: plugin name 2: page based text 3: Label for store credit 4: Hide notice text +#: includes/class-wc-sc-settings.php:903 +#: includes/class-wc-sc-settings.php:906 +msgid "Setting" +msgstr "Paramètre" + +#: includes/class-wc-sc-admin-notifications.php:165 +msgid "Setting \"Enable the use of coupon codes\" is disabled." +msgstr "Le paramètre « activer l’utilisation des codes promo » est désactivé." + +#: includes/class-wc-sc-admin-notifications.php:99 +#: includes/class-wc-sc-admin-welcome.php:197 +msgid "Settings" +msgstr "Paramètres" + +#: includes/class-wc-sc-settings.php:404 +msgid "Shipment" +msgstr "Expédition" + +#: includes/class-wc-sc-coupons-by-location.php:203 +msgid "Shipping" +msgstr "Livraison" + +#: includes/class-wc-sc-coupons-by-location.php:478 +msgid "shipping address" +msgstr "adresse de livraison" + +#: includes/class-wc-sc-coupons-by-location.php:495 +msgid "Shipping Locations" +msgstr "Emplacement de livraison" + +#: includes/class-wc-sc-coupons-by-shipping-method.php:106 +#: includes/class-wc-sc-coupons-by-shipping-method.php:224 +msgid "Shipping methods" +msgstr "Méthodes d’expédition" + +#: includes/class-wc-sc-coupons-by-shipping-method.php:117 +msgid "Shipping methods that must be selected during checkout for this coupon to be valid." +msgstr "Modes de livraison qui doivent être sélectionnées lors du paiement pour que ce code promo soit valide." + +#. translators: %s: Preview link +#: includes/class-wc-sc-settings.php:510 +msgid "Show coupons available to customers on their My Account > Coupons page %s" +msgstr "Afficher les codes promo disponibles pour les clients sur leur page « Mon compte » > onglet « Codes promo » %s" + +#. translators: %s: Preview link +#: includes/class-wc-sc-settings.php:528 +msgid "Show invalid or used coupons in My Account > Coupons %s" +msgstr "Afficher les codes promo non valides ou déjà utilisés sur la page « Mon compte » > onglet « Codes promo » %s" + +#: includes/class-wc-sc-coupon-fields.php:497 +msgid "Show on cart, checkout" +msgstr "Afficher sur les pages « Panier », « Commande »" + +#: includes/class-wc-sc-admin-welcome.php:320 +msgid "Show only valid coupons to your customer (if logged in) on cart, checkout & My Account page. Coupons can be applied with single click. So, no need to remember the coupon code or copy-pasting." +msgstr "Ne montrez à votre client (s’il est connecté) que des codes promo valables sur les pages « Panier », « Paiement » et « Mon compte ». Les codes promo peuvent être appliqués en un seul clic. Il n’est donc pas nécessaire de mémoriser le code promo ou de le copier-coller." + +#: includes/class-wc-sc-admin-welcome.php:369 +msgid "Simplest method is by installing" +msgstr "La méthode la plus simple consiste à installer" + +#: includes/class-wc-sc-settings.php:609 +msgid "Singular name" +msgstr "Nom singulier" + +#: includes/class-wc-sc-background-coupon-importer.php:617 +msgid "Skipped" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:320 +msgid "skipped" +msgstr "ignoré" + +#: includes/class-wc-sc-admin-pages.php:521 +#: includes/class-wc-sc-admin-pages.php:523 +msgid "Smart Coupon" +msgstr "Smart Coupon" + +#: includes/class-wc-sc-admin-welcome.php:364 +msgid "Smart Coupon's fields are broken?" +msgstr "Les champs de Smart Coupons sont défectueux ?" + +#: includes/class-wc-sc-settings.php:94 +#: includes/blocks/sc-gutenberg-block.js:43 +msgid "Smart Coupons" +msgstr "Smart Coupons" + +#: includes/emails/class-wc-sc-acknowledgement-email.php:41 +msgid "Smart Coupons - Acknowledgement email" +msgstr "Smart Coupons - E-mail accusé de réception" + +#: includes/emails/class-wc-sc-email-coupon.php:34 +msgid "Smart Coupons - Auto generated coupon email" +msgstr "Smart Coupons - E-mail de code promo généré automatiquement" + +#: includes/emails/class-wc-sc-combined-email-coupon.php:34 +msgid "Smart Coupons - Combined auto generated coupons email" +msgstr "Smart Coupons - E-mail regroupant plusieurs codes promo générés automatiquement" + +#: includes/class-wc-sc-admin-welcome.php:255 +msgid "Smart Coupons enable coupons to become an automatic/interactive system." +msgstr "Les codes promo intelligents permettent aux codes promo de devenir un système automatique/interactif." + +#: includes/class-wc-sc-print-coupon.php:278 +msgid "Smart Coupons has created a coupon's terms page (used during coupon printing) for you. Please edit it as required from" +msgstr "Smart Coupons a créé pour vous une page de termes de code promo (utilisée lors de l’impression de codes promo). Veuillez la modifier au besoin" + +#: includes/class-wc-sc-admin-welcome.php:254 +msgid "Smart Coupons is a powerful extension, built on top of WooCommerce coupons. It adds a new discount type - Store Credit - and advanced functionality to the default coupons." +msgstr "Smart Coupons est une extension puissante, construite sur les codes promo de WooCommerce. Elle ajoute un nouveau type de réduction - le bon d’achat - et des fonctionnalités avancées aux codes promo par défaut." + +#: includes/class-wc-sc-admin-welcome.php:410 +msgid "Smart Coupons is not sending emails." +msgstr "Smart Coupons n’envoie pas d’e-mails." + +#: includes/class-wc-smart-coupons.php:5883 +msgid "Smart Coupons related settings" +msgstr "Réglages Smart Coupons" + +#: includes/class-wc-sc-admin-welcome.php:411 +msgid "Smart Coupons sends email only after order completion. So make sure that order complete email is enabled and sending. If enabled, then make sure all settings of coupons, products are in place. Also check by switching your theme." +msgstr "Smart Coupons envoie des e-mails seulement après une commande terminée. Assurez-vous donc que l’e-mail de commande terminée est activé et fonctionnel. Si c’est le cas, assurez-vous que tous les paramètres de codes promo et de produits sont en place. Vérifiez également le fonctionnement des e-mails en changeant provisoirement de thème." + +#: includes/class-wc-sc-admin-pages.php:152 +#: includes/class-wc-sc-admin-pages.php:595 +#: includes/class-wc-sc-settings.php:345 +msgid "Smart Coupons Settings" +msgstr "Paramètres des codes promos" + +#: includes/class-wc-sc-admin-notifications.php:266 +msgid "Smart Coupons settings" +msgstr "Réglages Smart Coupons" + +#: includes/class-wc-sc-admin-welcome.php:399 +msgid "Smart Coupons uses hooks of Cart, Checkout & My Account page to display available coupons. If your theme is not using those hooks in cart, checkout & my-account template, coupons will not be displayed." +msgstr "Smart Coupons utilise des hooks de la page Cart, de la page Checkout et My Account pour afficher les codes promo disponibles. Si votre thème n’utilise pas ces hooks dans les modèles de Cart, Checkout & My Account, les codes promo ne s’afficheront pas." + +#: includes/class-wc-sc-admin-notifications.php:243 +msgid "so far?" +msgstr "jusqu’à présent ?" + +#: includes/class-wc-sc-display-coupons.php:606 +#: includes/class-wc-sc-display-coupons.php:615 +#: includes/class-wc-sc-display-coupons.php:624 +msgid "some products" +msgstr "certains produits" + +#: includes/class-wc-smart-coupons.php:6507 +#: includes/class-wc-smart-coupons.php:6561 +#: includes/class-wc-smart-coupons.php:6590 +#: includes/class-wc-smart-coupons.php:6614 +msgid "Some values required for $item_id & $item_key" +msgstr "" + +#: includes/class-wc-smart-coupons.php:6122 +#: includes/class-wc-smart-coupons.php:6237 +#: includes/class-wc-smart-coupons.php:6351 +msgid "Some values required for $post_id & $meta_key" +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:925 +#: includes/class-wc-sc-display-coupons.php:981 +msgid "Sorry, No coupons available for you." +msgstr "Désolé, aucun code promo actuellement disponible." + +#: includes/class-wc-sc-coupon-import.php:702 +#: includes/class-wc-sc-coupon-import.php:758 +#: includes/class-wc-sc-coupon-import.php:770 +msgid "Sorry, there has been an error." +msgstr "Désolé, il y a eu une erreur." + +#: includes/class-wc-sc-coupons-by-product-attribute.php:491 +#: includes/class-wc-sc-coupons-by-taxonomy.php:700 +msgid "Sorry, this coupon is not applicable to selected products." +msgstr "Désolé, ce code promo n’est pas applicable aux produits sélectionnés." + +#. translators: 1. Singular/plural label for product(s) 2. Excluded product names +#: includes/class-wc-sc-coupons-by-product-attribute.php:525 +#: includes/class-wc-sc-coupons-by-taxonomy.php:729 +msgid "Sorry, this coupon is not applicable to the %1$s: %2$s." +msgstr "Désolé, ce code promo n’est pas applicable aux %1$s : %2$s." + +#: includes/class-wc-sc-settings.php:367 +msgid "Spanish Orange" +msgstr "Orange espagnole" + +#: includes/class-wc-sc-settings.php:403 +msgid "Special" +msgstr "Spécial" + +#. translators: Formatted minimum amount +#: includes/class-wc-smart-coupons.php:1231 +msgid "Spend at least %s" +msgstr "Dépensez au moins %s" + +#. translators: Formatted maximum amount +#: includes/class-wc-smart-coupons.php:1235 +msgid "Spend up to %s" +msgstr "Dépensez jusqu’à %s" + +#: includes/class-wc-sc-background-coupon-importer.php:407 +msgid "Stop" +msgstr "Arrêter" + +#. translators: Store Credit label +#: includes/class-wc-sc-admin-pages.php:1426 +#: includes/class-wc-sc-admin-pages.php:1436 +#: includes/class-wc-sc-admin-pages.php:1591 +#: includes/class-wc-sc-ajax.php:332 +#: includes/class-wc-sc-coupon-refund-process.php:666 +#: includes/class-wc-sc-coupon-refund-process.php:679 +#: includes/class-wc-smart-coupons.php:1143 +#: includes/emails/class-wc-sc-email-coupon.php:357 +#: includes/emails/class-wc-sc-email-coupon.php:481 +msgid "Store Credit" +msgstr "Bon d’achat" + +#: includes/class-wc-sc-background-coupon-importer.php:589 +msgid "Store credit" +msgstr "Bon d’achat" + +#: includes/class-wc-sc-settings.php:301 +#: includes/compat/class-wcs-sc-compatibility.php:947 +msgid "store credit" +msgstr "bon d’achat" + +#: includes/class-wc-sc-background-coupon-importer.php:602 +msgid "store credit / gift card" +msgstr "bon d’achat/carte cadeau" + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-order-fields.php:501 +msgid "Store Credit / Gift Card Balance" +msgstr "Solde Bon d’achat / Carte Cadeau" + +#: includes/class-wc-sc-coupon-fields.php:1359 +#: includes/class-wc-sc-settings.php:605 +msgid "Store Credit / Gift Certificate" +msgstr "Bon d’achat / Carte cadeau" + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-admin-pages.php:672 +msgid "Store Credit / Gift Certificate sent successfully." +msgstr "Bon d’achat/carte cadeau envoyé avec succès." + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-display-coupons.php:591 +msgid "Store Credit of " +msgstr "Bon d’achat de " + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-order-fields.php:197 +msgid "Store Credit Used" +msgstr "Bon d’achat utilisé" + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-order-fields.php:254 +msgid "Store Credit Used:" +msgstr "Crédit bon d’achat utilisé :" + +#: includes/class-wc-sc-admin-welcome.php:407 +msgid "Store Credit's default behavior is auto-generate because, when using a store credit, it's balance keeps reducing. Therefore it should be uniquely created for every user automatically." +msgstr "Le comportement par défaut d’un bon d’achat est d’être auto-généré parce que, lorsque vous utilisez un bon d’achat, le solde conserve les réductions. C’est pourquoi il doit être créé automatiquement et de manière unique pour chaque utilisateur." + +#: includes/class-wc-sc-privacy.php:112 +#: includes/class-wc-sc-privacy.php:324 +#: includes/class-wc-sc-privacy.php:443 +#: includes/class-wc-sc-privacy.php:734 +msgid "Store Credit/Gift Certificate" +msgstr "Bon d’achat / Carte cadeau" + +#: includes/class-wc-sc-privacy.php:247 +msgid "Store Credit/Gift Certificate - Coupon Data" +msgstr "Bon d’achat/carte cadeau - Données du code promo" + +#: includes/class-wc-sc-privacy.php:618 +msgid "Store Credit/Gift Certificate - Order Data" +msgstr "Bon d’achat/Carte cadeau - Données de la commande" + +#: includes/class-wc-sc-privacy.php:817 +msgid "Store Credit/Gift Certificate that are stored for customers via coupons. If erased, the customer will not be able to use the coupons." +msgstr "Bons d’achat/cartes cadeau qui sont stockés pour les clients via les codes promo. S’ils sont effacés, le client ne pourra pas utiliser les codes promo." + +#: includes/class-wc-sc-order-fields.php:341 +msgid "Store Credit:" +msgstr "Bon d’achat :" + +#: includes/class-wc-sc-display-coupons.php:1185 +msgid "Store Credits" +msgstr "Bons d’achat" + +#: includes/class-wc-sc-settings.php:302 +#: includes/class-wc-sc-settings.php:896 +msgid "store credits" +msgstr "bons d’achat" + +#: includes/class-wc-sc-background-coupon-importer.php:394 +msgid "Store Credits / Gift Cards" +msgstr "Bons d’achat/Cartes cadeau" + +#: includes/class-wc-sc-background-coupon-importer.php:603 +msgid "store credits / gift cards" +msgstr "bons d’achat/cartes cadeau" + +#. Author of the plugin +#: woocommerce-smart-coupons.php +msgid "StoreApps" +msgstr "StoreApps" + +#: includes/class-wc-smart-coupons.php:5280 +msgid "Style 1" +msgstr "Style 1" + +#: includes/class-wc-smart-coupons.php:5281 +msgid "Style 2" +msgstr "Style 2" + +#: includes/class-wc-smart-coupons.php:5282 +msgid "Style 3" +msgstr "Style 3" + +#: includes/class-wc-smart-coupons.php:5283 +msgid "Style 4" +msgstr "Style 4" + +#: includes/class-wc-smart-coupons.php:5284 +msgid "Style 5" +msgstr "Style 5" + +#: includes/class-wc-smart-coupons.php:5285 +msgid "Style 6" +msgstr "Style 6" + +#: includes/class-wc-sc-settings.php:420 +msgid "Style for coupon in email." +msgstr "Style du code promo dans l’e-mail." + +#: includes/class-wc-sc-settings.php:416 +msgid "Style for email" +msgstr "Style pour l’e-mail" + +#: includes/class-wc-sc-settings.php:391 +msgid "Styles" +msgstr "Styles" + +#: includes/emails/class-wc-sc-email.php:116 +msgid "Subject" +msgstr "Sujet" + +#. translators: WooCommerce My Account support link +#: includes/class-wc-sc-admin-welcome.php:476 +msgid "submit a ticket" +msgstr "soumettre une demande" + +#: includes/class-wc-sc-background-coupon-importer.php:614 +msgid "Successfully" +msgstr "Avec succès" + +#: includes/class-wc-sc-act-deact.php:268 +msgid "Successfully cleared WooCommerce Smart Coupons cache!" +msgstr "Cache WooCommerce Smart Coupons effacé !" + +#: includes/class-wc-sc-coupon-refund-process.php:500 +msgid "Successfully updated store credit refund details." +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:483 +msgid "Suffix" +msgstr "Suffixe" + +#: includes/class-wc-smart-coupons.php:1604 +msgid "Super Savings!" +msgstr "De super économies !" + +#: includes/class-wc-sc-admin-notifications.php:102 +msgid "Support" +msgstr "Support" + +#: includes/class-wc-sc-coupons-by-taxonomy.php:141 +#: includes/class-wc-sc-coupons-by-taxonomy.php:182 +msgid "Taxonomy" +msgstr "Taxonomie" + +#: includes/class-wc-sc-coupons-by-taxonomy.php:871 +msgid "Taxonomy based restrictions" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:177 +msgid "Thank you for installing WooCommerce Smart Coupons" +msgstr "Merci d’avoir installé WooCommerce Smart Coupons" + +#: includes/class-wc-sc-rest-coupons-controller.php:147 +msgid "The coupon code already exists" +msgstr "Ce code promotionnel existe déjà" + +#: includes/class-wc-sc-settings.php:717 +msgid "The coupons will be sent to the recipients via email on the selected date & time" +msgstr "Les codes promo seront envoyés aux destinataires par e-mail à la date et l’heure sélectionnées" + +#: includes/class-wc-sc-coupon-import.php:1037 +msgid "The CSV must adhere to a specific format and include a header row." +msgstr "Le CSV doit respecter un format spécifique et inclure une ligne d’en-tête." + +#: includes/class-wc-sc-admin-notifications.php:417 +msgid "The database update process runs in the background and may take a little while, so please be patient." +msgstr "Le processus de mise à jour de la base de données s’exécute en arrière-plan et peut prendre un peu de temps, alors soyez patient." + +#: includes/class-wc-sc-coupon-import.php:703 +msgid "The file does not exist, please try again." +msgstr "Le fichier n’existe pas, veuillez essayer de nouveau." + +#: includes/class-wc-sc-coupon-fields.php:409 +msgid "The maximum discount this coupon can give on a cart." +msgstr "La réduction maximale que ce code promo peut donner sur un panier." + +#: includes/class-wc-sc-admin-pages.php:807 +msgid "The store credit will expire at 00:00:00 of this date." +msgstr "Ce crédit expirera à 00:00:00 à cette date." + +#: includes/class-wc-sc-settings.php:701 +msgid "The title for coupon receiver details block." +msgstr "Le titre pour le bloc des détails du destinataire du code promo." + +#: includes/class-wc-sc-purchase-credit.php:163 +msgid "The value should not be greater than" +msgstr "La valeur ne doit pas être supérieure à" + +#: includes/class-wc-sc-purchase-credit.php:161 +msgid "The value should not be less than" +msgstr "La valeur ne doit pas être inférieure à" + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-admin-pages.php:676 +msgid "There has been an error in sending %s." +msgstr "Il y a eu une erreur lors de l’envoi de %s." + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-admin-pages.php:676 +msgid "There has been an error in sending Store Credit / Gift Certificate." +msgstr "Il y a eu une erreur dans l’envoi de bon d’achat/carte cadeau." + +#. translators: 1. File name 2. File download link +#: includes/class-wc-sc-admin-welcome.php:395 +msgid "There is one file which is located inside the plugin. You can download the %1$s file from %2$s." +msgstr "" + +#: includes/class-wc-sc-product-fields.php:123 +#: includes/class-wc-sc-product-fields.php:160 +msgid "These coupon/s will be given to customers who buy this product. The coupon code will be automatically sent to their email address on purchase." +msgstr "Ce ou ces codes promo seront accordés aux clients qui achèteront ce produit. Le ou les codes promo seront automatiquement envoyés à leur adresse e-mail après achat." + +#: includes/class-wc-smart-coupons.php:977 +msgid "This coupon has pending emails to be sent. Deleting it will delete those emails also. Are you sure to delete this coupon?" +msgstr "Ce code promo a des e-mails en attente à envoyer. Le supprimer supprimera également ces e-mails. Êtes-vous sûr de vouloir supprimer ce code promo ?" + +#: includes/class-wc-sc-coupons-by-shipping-method.php:200 +#: includes/class-wc-sc-coupons-by-shipping-method.php:205 +msgid "This coupon is not valid for selected shipping method." +msgstr "Ce code promo n’est pas valable pour le mode de livraison sélectionné." + +#: includes/class-wc-sc-coupons-by-excluded-email.php:239 +#: includes/class-wc-sc-coupons-by-excluded-email.php:253 +#: includes/class-wc-sc-coupons-by-user-role.php:220 +#: includes/class-wc-sc-coupons-by-user-role.php:227 +msgid "This coupon is not valid for you." +msgstr "Ce code promo n’est pas valable pour vous." + +#: includes/class-wc-smart-coupons.php:3416 +msgid "This coupon is valid for the first order only." +msgstr "Ce code promo est valable uniquement pour la première commande." + +#: includes/class-wc-sc-admin-welcome.php:415 +msgid "This form is displayed using a hook which is available in My Account template. Make sure your theme's my-account template contains all hooks required for that template. Update your theme if it is not updated." +msgstr "Ce formulaire s’affiche à l’aide d’un hook disponible dans le modèle my-account Assurez-vous que le modèle my-account de votre thème contient tous les hooks requis pour ce modèle. Mettez à jour votre thème s’il n’est pas à jour." + +#: includes/class-wc-sc-settings.php:651 +msgid "This is the heading above coupon details displayed on products that issue coupons." +msgstr "Il s’agit de l’entête au dessus des détails du code promo qui sont affichés sur les produits qui émettent des codes promo." + +#: includes/class-wc-sc-settings.php:661 +msgid "This is the title for the list of available coupons, shown on Cart and Checkout pages." +msgstr "Titre de la liste des codes promo disponibles figurant sur la page « Panier » et la page « Commande »." + +#: includes/class-wc-sc-order-fields.php:199 +msgid "This is the total credit used." +msgstr "Ceci est le total des bons d’achat utilisé." + +#. translators: %s: Label for store credit +#: includes/class-wc-sc-settings.php:629 +msgid "This is what will be shown instead of \"Add to Cart\" for products that sell %s." +msgstr "C’est ce qui sera affiché à la place de \"Ajouter au panier\" pour les produits qui vendent %s." + +#: includes/class-wc-sc-coupon-fields.php:1000 +msgid "This much quantity of each product, selected above, will be added to cart." +msgstr "Cette quantité de chaque produit, sélectionné ci-dessus, sera ajoutée au panier." + +#. translators: %s: $coupon_code coupon code +#: includes/class-wc-sc-url-coupon.php:347 +msgctxt "This notice will be shown on the cart or the checkout page if the coupon is already applied." +msgid "Coupon code \"%s\" already applied! Please add some products to the cart to see the discount." +msgstr "" + +#. translators: %s: $coupon_code coupon code +#: includes/class-wc-sc-url-coupon.php:343 +msgctxt "This notice will be shown on the cart or the checkout page if the coupon will be applied successfully." +msgid "Coupon code \"%s\" applied successfully. Please add some products to the cart to see the discount." +msgstr "" + +#: includes/class-wc-smart-coupons.php:5883 +msgid "This section shows settings that affects Smart Coupons' functionalities." +msgstr "Cette section présente les paramètres relatifs aux fonctionnalités de Smart Coupons." + +#: includes/class-wc-smart-coupons.php:3276 +msgid "This tool will clear the cache created by WooCommerce Smart Coupons." +msgstr "Cet outil effacera le cache créé par WooCommerce Smart coupons." + +#: includes/class-wc-smart-coupons.php:1607 +msgid "This Week Only!" +msgstr "Cette semaine seulement !" + +#: includes/class-wc-smart-coupons.php:1610 +msgid "This will be over soon! Hurry." +msgstr "Ce sera bientôt terminé ! Dépêchez-vous." + +#. translators: %s: list of placeholders +#: includes/emails/class-wc-sc-acknowledgement-email.php:104 +msgid "This will be used when the setting \"WooCommerce > Settings > Smart Coupons > Allow schedule sending of coupons?\" is enabled. Available placeholders: %s." +msgstr "Cela sera utilisé lorsque le paramètre « WooCommerce > Paramètres > Smart Coupons > Autoriser l'envoi programmé de codes promo ?\" est coché. Espaces réservés disponibles : %s." + +#: includes/class-wc-sc-settings.php:401 +msgid "Ticket" +msgstr "Ticket" + +#: includes/class-wc-sc-coupon-fields.php:393 +msgid "Time after which coupon will be expired. This will work in conjunction with Coupon expiry date." +msgstr "Heure à laquelle le code promo expirera. Cela fonctionnera en conjonction avec la date d’expiration du code promo." + +#: includes/class-wc-sc-coupon-fields.php:352 +msgctxt "Timepicker on the admin side" +msgid "Choose Time" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:286 +msgctxt "Timepicker on the admin side" +msgid "Done" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:350 +msgctxt "Timepicker on the admin side" +msgid "HH:mm" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:354 +msgctxt "Timepicker on the admin side" +msgid "Hour" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:358 +msgctxt "Timepicker on the admin side" +msgid "Microsecond" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:357 +msgctxt "Timepicker on the admin side" +msgid "Millisecond" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:355 +msgctxt "Timepicker on the admin side" +msgid "Minute" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:285 +msgctxt "Timepicker on the admin side" +msgid "Now" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:356 +msgctxt "Timepicker on the admin side" +msgid "Second" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:353 +msgctxt "Timepicker on the admin side" +msgid "Time" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:359 +msgctxt "Timepicker on the admin side" +msgid "Time Zone" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:682 +msgctxt "Timepicker on the frontend side" +msgid "Choose Time" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:616 +msgctxt "Timepicker on the frontend side" +msgid "Done" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:680 +msgctxt "Timepicker on the frontend side" +msgid "HH:mm" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:684 +msgctxt "Timepicker on the frontend side" +msgid "Hour" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:688 +msgctxt "Timepicker on the frontend side" +msgid "Microsecond" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:687 +msgctxt "Timepicker on the frontend side" +msgid "Millisecond" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:685 +msgctxt "Timepicker on the frontend side" +msgid "Minute" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:615 +msgctxt "Timepicker on the frontend side" +msgid "Now" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:686 +msgctxt "Timepicker on the frontend side" +msgid "Second" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:683 +msgctxt "Timepicker on the frontend side" +msgid "Time" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:689 +msgctxt "Timepicker on the frontend side" +msgid "Time Zone" +msgstr "" + +#: includes/class-wc-sc-settings.php:697 +msgid "Title" +msgstr "Titre" + +#: includes/class-wc-sc-product-columns.php:102 +msgctxt "Title for coupon column on the products page" +msgid "Linked coupons" +msgstr "" + +#: includes/class-wc-sc-settings.php:671 +msgid "Title of available coupons list on My Account page." +msgstr "Titre de la liste des codes promo disponibles sur la page « Mon compte »." + +#: templates/acknowledgement-email.php:71 +msgid "to" +msgstr "" + +#: templates/combined-email.php:82 +msgid "To redeem your discount click on the following coupon(s):" +msgstr "Pour profiter de votre remise, cliquez sur le(s) code(s) promo suivant(s) :" + +#: templates/plain/combined-email.php:22 +msgid "To redeem your discount use below coupon codes during checkout or copy and paste the below URLs and hit enter in your browser" +msgstr "Pour utiliser votre réduction, utilisez les codes promo ci-dessous lors de votre commande ou copiez-collez les URL ci-dessous et appuyez sur Entrée dans votre navigateur" + +#. translators: %s: Coupon code +#: templates/email.php:85 +msgid "To redeem your discount use coupon code %s during checkout or click on the following coupon:" +msgstr "Pour bénéficier de votre réduction, utilisez le code promo %s lors du paiement ou cliquez sur le code promo suivant :" + +#. translators: %s: Coupon code +#: templates/plain/email.php:23 +msgid "To redeem your discount use coupon code %s during checkout or copy and paste the below URL and hit enter in your browser:" +msgstr "Pour bénéficier de votre remise, utilisez le code promo %s lors du paiement, ou copier/coller l’URL ci-dessous et appuyez sur « Entrer » dans votre navigateur :" + +#: includes/class-wc-sc-admin-welcome.php:259 +msgid "Top Smart Coupons features" +msgstr "Caractéristiques de Smart Coupons" + +#: includes/class-wc-sc-display-coupons.php:1194 +msgid "Total Credit Amount" +msgstr "Montant total du bon" + +#. translators: 1. Discount type 2. Discount Type Label +#: includes/class-wc-sc-ajax.php:132 +#: includes/class-wc-sc-product-fields.php:114 +#: includes/class-wc-sc-product-fields.php:175 +msgid "Type" +msgstr "Type" + +#. translators: 1: plugin name 2: page based text 3: Label for store credit 4: Hide notice text +#: includes/class-wc-sc-settings.php:903 +msgid "Uncheck" +msgstr "Décochez" + +#: includes/class-wc-sc-admin-welcome.php:406 +msgid "Uncheck \"Auto-generate\" option in Store Credit is not saving? Is it always checked?" +msgstr "Décocher l’option « Générer automatiquement » dans le bon d’achat n’est pas sauvegardée ? Est-elle toujours cochée ?" + +#: includes/class-wc-sc-coupon-fields.php:408 +msgid "Unlimited discount" +msgstr "Rabais illimité" + +#: includes/class-wc-sc-coupon-categories.php:95 +msgid "Update coupon category" +msgstr "Mise à jour de la catégorie de code promo" + +#: includes/class-wc-sc-admin-notifications.php:430 +msgid "Update database" +msgstr "Mettre à jour la base de données" + +#: includes/class-wc-sc-coupon-import.php:945 +msgid "Update existing coupons" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:586 +msgid "updated" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:578 +msgid "updated & emailed" +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:1079 +msgid "Upload file" +msgstr "Télécharger le fichier" + +#. translators: %s: Maximum coupon discount amount +#: includes/class-wc-sc-ajax.php:357 +msgid "upto %s" +msgstr "jusqu’à %s" + +#. translators: Documentation link for 'How to Apply Single or Multiple Coupons on Click of a Link' +#: includes/class-wc-sc-admin-welcome.php:382 +msgid "URL of coupon should be like this:" +msgstr "L’URL de code promo doit être comme ceci :" + +#: includes/class-wc-smart-coupons.php:5024 +msgid "Usage Count" +msgstr "Nombre d’utillisation" + +#: includes/class-wc-smart-coupons.php:5021 +msgid "Usage Limit" +msgstr "Limite d’utilisation" + +#: includes/class-wc-smart-coupons.php:5022 +msgid "Usage Limit Per User" +msgstr "Limite d’utilisation par utilisateur" + +#. translators: %s: Label for store credit +#: includes/compat/class-wcs-sc-compatibility.php:953 +msgid "Use %s applied in first subscription order for subsequent renewals until credit reaches zero" +msgstr "Utiliser %s appliqué dans le premier ordre de souscription pour les renouvellements ultérieurs jusqu’à ce que le crédit atteigne zéro" + +#: includes/class-wc-smart-coupons.php:1637 +msgid "Use code" +msgstr "Utiliser un code" + +#. translators: 1. The coupon code +#: includes/class-wc-smart-coupons.php:1654 +msgid "Use code: %s" +msgstr "Utilisez le code : %s" + +#: includes/class-wc-sc-admin-pages.php:773 +#: includes/class-wc-sc-admin-pages.php:1224 +msgid "Use comma \",\" to separate multiple email addresses" +msgstr "Utilisez la virgule \",\" pour séparer plusieurs adresses e-mail" + +#: includes/class-wc-smart-coupons.php:5857 +msgid "Use gift card applied in first subscription order for subsequent renewals until credit reaches zero" +msgstr "Utilisez la carte-cadeau appliquée lors de la première commande d’abonnement pour les renouvellements ultérieurs jusqu’à ce que le crédit atteigne zéro" + +#: includes/class-wc-smart-coupons.php:5025 +msgid "Used By" +msgstr "Utilisé par" + +#: includes/class-wc-sc-print-coupon.php:420 +msgid "Used during coupon printing" +msgstr "Utilisé lors de l’impression des codes promo" + +#: includes/class-wc-sc-admin-pages.php:228 +msgid "Used for variations" +msgstr "Utilisé pour les variations" + +#: includes/class-wc-sc-coupon-columns.php:128 +msgid "Used in orders" +msgstr "Utilisé dans les commandes" + +#: includes/class-wc-sc-coupons-by-user-role.php:243 +msgid "User Role" +msgstr "Rôle de l’utilisateur" + +#: includes/class-wc-sc-coupon-fields.php:437 +msgid "Valid for" +msgstr "Valide pendant" + +#. translators: Product names +#: includes/class-wc-smart-coupons.php:1245 +msgid "Valid for %s" +msgstr "Valable pour %s" + +#. translators: 1: The category names +#: includes/class-wc-smart-coupons.php:1258 +msgid "Valid for category %s" +msgid_plural "Valid for categories %s" +msgstr[0] "Valide pour la catégorie %s" +msgstr[1] "Valide pour les catégories %s" + +#: includes/class-wc-smart-coupons.php:1287 +msgid "Valid on entire range of products. Buy anything in the store." +msgstr "Valable sur toute la gamme de produits. Achetez ce que vous voulez." + +#: includes/class-wc-sc-settings.php:455 +#: includes/class-wc-smart-coupons.php:5849 +msgid "Valid order status for auto-generating coupon" +msgstr "État(s) de commande qui déclencheront la génération automatique de codes promo" + +#: includes/class-wc-sc-coupons-by-product-quantity.php:117 +msgid "Validate quantity of" +msgstr "Valider la quantité de" + +#: includes/class-wc-smart-coupons.php:4649 +msgid "Validity Suffix" +msgstr "Suffixe de validité" + +#: includes/class-wc-sc-admin-pages.php:225 +msgid "Value(s)" +msgstr "Valeur(s)" + +#: includes/class-wc-sc-coupons-by-product-attribute.php:167 +msgid "Value=" +msgstr "Valeur=" + +#. translators: 1: Affiliate For WooCommerce 2: Smart Manager 3: Smart Offers +#: includes/class-wc-sc-admin-welcome.php:287 +msgid "variable but fixed amount" +msgstr "variable, mais montant fixe" + +#: includes/class-wc-sc-admin-notifications.php:458 +msgid "View status" +msgstr "Voir le statut" + +#: includes/class-wc-sc-settings.php:366 +msgid "Vintage" +msgstr "Millésime" + +#: includes/class-wc-sc-admin-pages.php:227 +msgid "Visible on the product page" +msgstr "Visible sur la page « Produit »" + +#: templates/combined-email.php:209 +#: templates/email.php:194 +#: templates/plain/combined-email.php:131 +#: templates/plain/email.php:124 +msgid "Visit store" +msgstr "Visiter la boutique" + +#: includes/class-wc-sc-background-coupon-importer.php:487 +msgid "We are processing coupons in background. Please wait before starting new process." +msgstr "Nous traitons les codes promo en arrière-plan. S’il vous plaît attendez avant de commencer un nouveau processus." + +#: includes/class-wc-sc-privacy.php:124 +msgid "We store these data so that we can process it for you whenever required." +msgstr "Nous stockons ces données afin que nous puissions les traiter pour vous chaque fois que nécessaire." + +#: includes/class-wc-sc-coupon-fields.php:441 +msgid "Weeks" +msgstr "Semaines" + +#: includes/class-wc-sc-admin-welcome.php:88 +msgid "Welcome to Smart Coupons" +msgstr "Bienvenue dans Smart Coupons" + +#: includes/class-wc-sc-admin-welcome.php:252 +msgid "What is Smart Coupons?" +msgstr "Qu’est-ce que Smart Coupons ?" + +#: includes/class-wc-sc-privacy.php:113 +msgid "What we access?" +msgstr "À quelles informations avons-nous accès ?" + +#: includes/class-wc-sc-privacy.php:118 +msgid "What we store & why?" +msgstr "Quelles données enregistrons-nous et pourquoi ?" + +#: includes/class-wc-sc-admin-welcome.php:380 +msgid "What's the URL to a coupon, so it's automatically inserted when visiting?" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:453 +msgid "When checked, generated coupon's value will be same as product's price" +msgstr "Une fois cochée, la valeur du code promo généré sera identique au prix du produit" + +#: includes/class-wc-sc-auto-apply-coupon.php:121 +msgid "When checked, this coupon will be applied automatically, if it is valid. If enabled in more than 5 coupons, only 5 coupons will be applied automatically, rest will be ignored." +msgstr "Si coché, ce code promo sera appliqué automatiquement, s’il est valide. Si cette option est activée dans plus de 5 codes promo, seuls 5 codes promo seront appliqués automatiquement, les autres seront ignorés." + +#: includes/class-wc-sc-coupon-fields.php:423 +msgid "When checked, this coupon will be valid for the user's first order on the store." +msgstr "Si coché, ce code promo sera valable uniquement pour la première commande d’un client." + +#: includes/class-wc-sc-coupon-fields.php:498 +msgid "When checked, this coupon will be visible on cart/checkout page for everyone" +msgstr "Si coché, ce code promo sera visible sur les pages « Panier », « Commande » et « Mon Compte » pour tout le monde" + +#. translators: %s: Explanation of the setting +#: includes/class-wc-sc-settings.php:547 +msgid "When enabled, each coupon will have the option to enable auto-apply for that coupon %s" +msgstr "" + +#. translators: %s: Label for store credit, 1: : Label for store credit, 2: Label for store credit, 3: Label for store credit +#: includes/class-wc-sc-settings.php:586 +msgid "When selling %1$s, if Regular and Sale price is found for the product, then coupon will be created with product's Regular Price but customer will pay product's Sale price. This setting will also make sure if any discount coupon is applied on the %2$s while purchasing, then customer will get %3$s in their picked price" +msgstr "Lors de la vente %1$s, si le prix normal et le prix de vente sont trouvés pour le produit, le code promo sera créé avec le prix normal du produit mais le client paiera le prix de vente du produit. Ce paramètre permettra également de s’assurer que si un code promo est appliqué sur le %2$s lors de l’achat, le client obtiendra %3$s dans son prix choisi" + +#: includes/class-wc-sc-coupon-fields.php:1009 +msgid "When this coupon will be applied, selected products will be added to cart with set discount. If discount is not set, this coupon's discount will be applied to these products." +msgstr "Lorsque ce code promo sera appliqué, les produits sélectionnés seront ajoutés au panier avec remise définie. Si la remise n’est pas définie, la remise de ce code promo sera appliquée à ces produits." + +#: includes/class-wc-sc-admin-welcome.php:354 +msgid "When trying to add coupon/Smart Coupon, I get \"Invalid post type\" message." +msgstr "Lorsque j’essaie d’ajouter un code promo/code promo intelligent, je reçois le message « invalid post type »." + +#. translators: %s: Label for store credit +#: includes/class-wc-sc-settings.php:641 +msgid "When you opt to allow people to buy %s of any amount, this label will be used." +msgstr "Lorsque vous choisissez d’autoriser les gens à acheter des %s de n’importe quel montant, ce libellé sera utilisé." + +#: includes/class-wc-sc-admin-welcome.php:431 +msgid "Which features of Smart Coupons work with Subscriptions?" +msgstr "Quelles fonctionnalités de Smart Coupons fonctionnent avec WooCommerce Subscriptions ?" + +#. translators: %s: Label for store credit +#: includes/class-wc-sc-settings.php:636 +msgid "While purchasing %s" +msgstr "Lors de l’achat de %s" + +#: includes/class-wc-sc-coupon-fields.php:1003 +msgid "with discount of" +msgstr "avec remise de" + +#: includes/class-wc-sc-admin-pages.php:1610 +msgid "WooCommerce" +msgstr "WooCommerce" + +#: includes/class-wc-smart-coupons.php:5876 +msgid "WooCommerce Account Connected" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:385 +msgid "WooCommerce Coupons (CSV)" +msgstr "WooCommerce Coupons (CSV)" + +#. Plugin Name of the plugin +#. translators: 1: plugin name 2: page based text 3: Label for store credit 4: Hide notice text +#: woocommerce-smart-coupons.php +#: includes/class-wc-sc-admin-notifications.php:177 +#: includes/class-wc-sc-admin-notifications.php:243 +#: includes/class-wc-sc-admin-notifications.php:257 +#: includes/class-wc-sc-settings.php:903 +#: includes/class-wc-sc-settings.php:906 +msgid "WooCommerce Smart Coupons" +msgstr "WooCommerce Smart Coupons" + +#: includes/class-wc-smart-coupons.php:3274 +msgid "WooCommerce Smart Coupons Cache" +msgstr "WooCommerce Smart Coupons cache" + +#. translators: WooCommerce Subscriptions product link +#: includes/class-wc-sc-admin-welcome.php:275 +msgid "WooCommerce Subscriptions" +msgstr "WooCommerce Subscriptions" + +#: includes/class-wc-sc-admin-pages.php:779 +msgid "Worth" +msgstr "Valeur" + +#. translators: 1: coupon amount 2: discount for text +#: includes/emails/class-wc-sc-email-coupon.php:414 +msgid "worth %1$s (%2$s) " +msgstr "d’une valeur de %1$s (%2$s) " + +#. translators: 1: coupon amount 2: max discount text 3: discount for text +#: includes/emails/class-wc-sc-email-coupon.php:443 +msgid "worth %1$s%% %2$s (%3$s) " +msgstr "d’une valeur de %1$s%% %2$s (%3$s) " + +#. translators: 1: coupon amount 2: discount for text +#: includes/emails/class-wc-sc-email-coupon.php:425 +msgid "worth %1$s%% (%2$s) " +msgstr "d’une valeur de %1$s%% (%2$s) " + +#. translators: %s coupon amount +#: includes/emails/class-wc-sc-email-coupon.php:398 +msgid "worth %s " +msgstr "d’une valeur de %s " + +#. translators: %s: coupon amount +#: includes/emails/class-wc-sc-email-coupon.php:403 +msgid "worth %s (for entire purchase) " +msgstr "d’une valeur de %s (pour l’ensemble des achats) " + +#: includes/class-wc-sc-purchase-credit.php:894 +#: includes/class-wc-sc-purchase-credit.php:1009 +msgid "Write a message" +msgstr "Écrire un message" + +#: includes/class-wc-sc-coupon-fields.php:443 +msgid "Years" +msgstr "Années" + +#. translators: Documentation link for 'How to Print Coupons' +#: includes/class-wc-sc-admin-welcome.php:420 +msgid "Yes, Smart Coupons does provide a feature for printing coupons. For more details, check this article: %s" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:428 +msgid "Yes, Smart Coupons does work with WooCommerce Subscriptions." +msgstr "Oui, Les coupons intelligents fonctionnent avec les abonnements WooCommerce." + +#: includes/class-wc-sc-coupon-fields.php:150 +msgid "You can also apply multiple coupon codes via a single URL. For example:" +msgstr "Vous pouvez également appliquer plusieurs codes promo via une seule URL. Par exemple :" + +#: includes/class-wc-sc-background-coupon-importer.php:411 +msgid "You can continue with other work. But for bulk generating or importing new coupons, wait for the current process to complete." +msgstr "Vous pouvez poursuivre d’autres travaux. Mais pour générer ou importer en masse de nouveaux codes promo, attendez que le processus en cours soit terminé." + +#: includes/class-wc-sc-admin-welcome.php:373 +msgid "You can do this by overriding the email template." +msgstr "Vous pouvez le faire en supprimant le modèle d’e-mail." + +#: includes/class-wc-sc-admin-welcome.php:308 +msgid "You can give a coupon to your customer after every purchase, which can encourage them to purchase again from you." +msgstr "Vous pouvez donner un code promo à votre client après chaque achat, ce qui peut inciter à acheter à nouveau dans votre boutique." + +#: includes/class-wc-sc-admin-welcome.php:403 +msgid "You can resend them from order admin edit page." +msgstr "Vous pouvez les renvoyer à partir des pages de commandes sous l’administration." + +#: includes/class-wc-sc-admin-pages.php:273 +msgid "You cannot add the same tax rate twice!" +msgstr "Vous ne pouvez pas ajouter deux fois le même taux de TVA !" + +#: includes/class-wc-smart-coupons.php:1609 +msgid "You don't want to miss this..." +msgstr "" + +#: templates/combined-email.php:237 +msgid "You got these coupons " +msgstr "Vous avez reçu ce(s) code(s) promo " + +#. translators: %s: singular name for store credit +#: templates/email.php:219 +#: templates/plain/combined-email.php:137 +#: templates/plain/email.php:130 +msgid "You got this %s" +msgstr "Vous avez obtenu ce %s" + +#. translators: %s: singular name for store credit +#: templates/email.php:219 +#: templates/plain/combined-email.php:137 +#: templates/plain/email.php:130 +msgid "You got this gift card" +msgstr "Vous avez reçu cette carte cadeau" + +#. translators: 1: email heading 2: suffix +#: includes/emails/class-wc-sc-email-coupon.php:460 +msgid "You have received a" +msgstr "Vous avez reçu un" + +#: includes/emails/class-wc-sc-email-coupon.php:73 +msgid "You have received a {coupon_type} {coupon_value}" +msgstr "Vous avez reçu un {coupon_type} de {coupon_value}" + +#: includes/emails/class-wc-sc-combined-email-coupon.php:70 +msgid "You have received coupons." +msgstr "Vous avez reçu des codes promo." + +#. translators: 1. Receiver's count 2. Gift Card/s 3. Receiver name 4. Receiver details +#: templates/acknowledgement-email.php:37 +msgid "You have scheduled to send %1$d %2$s %3$s %4$s" +msgstr "" + +#. translators: 1. Receiver's count 2. Gift Card/s 3. Receiver name 4. Receiver details +#: templates/plain/acknowledgement-email.php:27 +msgid "You have scheduled to send %1$d %2$s to %3$s (%4$s)" +msgstr "" + +#. translators: 1. Receiver's count 2. Singular/Plural label for store credit(s) 3. Receiver name 4. Receiver details +#: templates/acknowledgement-email.php:34 +msgid "You have successfully sent %1$d %2$s %3$s %4$s" +msgstr "" + +#. translators: 1. Receiver's count 2. Singular/Plural label for store credit(s) 3. Receiver name 4. Receiver details +#: templates/plain/acknowledgement-email.php:24 +msgid "You have successfully sent %1$d %2$s to %3$s (%4$s)" +msgstr "Vous avez envoyé avec succès %1$d %2$s à %3$s (%4$s)" + +#: includes/class-wc-sc-settings.php:652 +msgid "You will get following coupon(s) when you buy this item" +msgstr "Vous obtiendrez le(s) code(s) promo suivant(s) si vous achetez cet article" + +#: includes/class-wc-sc-display-coupons.php:540 +msgid "You will get following coupon(s) when you buy this item:" +msgstr "Vous obtiendrez le ou les code(s) promo suivant(s) si vous achetez cet article :" + +#: includes/class-wc-sc-coupons-by-product-quantity.php:559 +#: includes/class-wc-sc-coupons-by-product-quantity.php:561 +#: includes/class-wc-sc-coupons-by-product-quantity.php:563 +msgid "Your cart does not meet the product quantity requirement." +msgstr "Votre panier ne respecte pas la quantité requise." + +#: includes/class-wc-sc-coupons-by-product-quantity.php:523 +msgid "Your cart does not meet the quantity requirement." +msgstr "Votre panier ne respecte pas la quantité requise." + +#. translators: 1. Number of quantity 2. Singular or plural text based on number of quantities +#: includes/class-wc-sc-coupons-by-product-quantity.php:537 +msgid "Your cart should have a maximum of %1$d %2$s in total." +msgstr "Votre panier doit contenir un maximum de %1$d %2$s au total." + +#. translators: 1. Number of quantity 2. Singular or plural text based on number of quantities +#: includes/class-wc-sc-coupons-by-product-quantity.php:541 +msgid "Your cart should have a minimum of %1$d %2$s in total." +msgstr "Votre panier doit contenir au moins %1$d %2$s au total." + +#: includes/class-wc-sc-display-coupons.php:626 +msgid "your entire purchase" +msgstr "la totalité de votre achat" + +#: includes/class-wc-sc-purchase-credit.php:843 +msgid "Your order contains coupons. What would you like to do?" +msgstr "Vous allez offrir des codes promo. Comment voulez vous procéder ?" + +#: includes/class-wc-sc-purchase-credit.php:832 +msgid "Your order contains coupons. You will receive them after completion of this order." +msgstr "Votre commande contient des codes promo. Vous les recevrez une fois la commande finalisée." + +#: includes/class-wc-sc-admin-pages.php:274 +msgid "Your product has variations! Before changing the product type, it is a good idea to delete the variations to avoid errors in the stock reports." +msgstr "Votre produit comporte des variations ! Avant de changer le type de produit, c’est une bonne idée de supprimer les variations pour éviter les erreurs dans les rapports de stock." + +#: includes/emails/class-wc-sc-acknowledgement-email.php:95 +msgid "{coupon_type} has been successfully scheduled" +msgstr "{coupon_type} planifié avec succès" + +#: includes/emails/class-wc-sc-acknowledgement-email.php:77 +msgid "{coupon_type} sent successfully" +msgstr "\"{coupon_type}\" envoyé avec succès" + +#: includes/emails/class-wc-sc-email-coupon.php:64 +msgid "{site_title}: Congratulations! You've received a {coupon_type} from {sender_name}" +msgstr "{site_title} : Félicitations ! Vous avez reçu un(e) {coupon_type} de la part de {sender_name}" + +#: includes/emails/class-wc-sc-combined-email-coupon.php:61 +msgid "{site_title}: Congratulations! You've received coupons from {sender_name}" +msgstr "{site_title} : Félicitations ! Vous avez reçu des codes promo de la part de {from_sender_name}" + +#: includes/emails/class-wc-sc-acknowledgement-email.php:86 +msgid "{site_title}: {coupon_type} has been successfully scheduled" +msgstr "{site_title}: {coupon_type} planifié avec succès" + +#: includes/emails/class-wc-sc-acknowledgement-email.php:68 +msgid "{site_title}: {coupon_type} sent successfully" +msgstr "{site_title}: \"{coupon_type}\" envoyé avec succès" diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons.pot b/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons.pot new file mode 100644 index 00000000..9871f39b --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/languages/woocommerce-smart-coupons.pot @@ -0,0 +1,4548 @@ +# Copyright (C) 2024 StoreApps +# This file is distributed under the GNU General Public License v3.0. +msgid "" +msgstr "" +"Project-Id-Version: WooCommerce Smart Coupons 9.3.0\n" +"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/woocommerce-smart-coupons\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"POT-Creation-Date: 2024-06-14T12:51:58+00:00\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"X-Generator: WP-CLI 2.10.0\n" +"X-Domain: woocommerce-smart-coupons\n" + +#. Plugin Name of the plugin +#. translators: 1: plugin name 2: page based text 3: Label for store credit 4: Hide notice text +#: woocommerce-smart-coupons.php +#: includes/class-wc-sc-admin-notifications.php:177 +#: includes/class-wc-sc-admin-notifications.php:243 +#: includes/class-wc-sc-admin-notifications.php:257 +#: includes/class-wc-sc-settings.php:903 +#: includes/class-wc-sc-settings.php:906 +msgid "WooCommerce Smart Coupons" +msgstr "" + +#. Plugin URI of the plugin +#: woocommerce-smart-coupons.php +msgid "https://woocommerce.com/products/smart-coupons/" +msgstr "" + +#. Description of the plugin +#: woocommerce-smart-coupons.php +msgid "WooCommerce Smart Coupons lets customers buy gift certificates, store credits or coupons easily. They can use purchased credits themselves or gift to someone else." +msgstr "" + +#. Author of the plugin +#: woocommerce-smart-coupons.php +msgid "StoreApps" +msgstr "" + +#. Author URI of the plugin +#: woocommerce-smart-coupons.php +msgid "https://www.storeapps.org/" +msgstr "" + +#: blocks/blocks.php:51 +msgctxt "Block editor" +msgid "WooCommerce Smart Coupons" +msgstr "" + +#: blocks/class-wc-sc-blocks-integration.php:423 +msgctxt "Block editor & frontend" +msgid "Available Coupons (click on a coupon to use it)" +msgstr "" + +#: blocks/class-wc-sc-blocks-integration.php:515 +#: blocks/class-wc-sc-blocks-integration.php:516 +msgctxt "Block editor & frontend" +msgid "Send Coupons to..." +msgstr "" + +#: blocks/class-wc-sc-blocks-integration.php:597 +msgctxt "Block editor & frontend" +msgid "Free Shipping coupon" +msgstr "" + +#: blocks/class-wc-sc-blocks-integration.php:600 +msgctxt "Block editor & frontend" +msgid "coupon" +msgstr "" + +#: blocks/class-wc-sc-blocks-integration.php:604 +msgctxt "Block editor & frontend" +msgid "Send" +msgstr "" + +#: blocks/class-wc-sc-blocks-integration.php:604 +msgctxt "Block editor & frontend" +msgid "of" +msgstr "" + +#: blocks/class-wc-sc-blocks-integration.php:621 +msgctxt "Block editor & frontend" +msgid "Your order contains coupons. What would you like to do?" +msgstr "" + +#: blocks/class-wc-sc-blocks-integration.php:625 +msgctxt "Block editor & frontend" +msgid "Send to me" +msgstr "" + +#: blocks/class-wc-sc-blocks-integration.php:629 +msgctxt "Block editor & frontend" +msgid "Gift to someone else" +msgstr "" + +#: blocks/class-wc-sc-blocks-integration.php:635 +msgctxt "Block editor & frontend" +msgid "Send to one person" +msgstr "" + +#: blocks/class-wc-sc-blocks-integration.php:639 +msgctxt "Block editor & frontend" +msgid "Send to different people" +msgstr "" + +#: blocks/class-wc-sc-blocks-integration.php:645 +msgctxt "Block editor & frontend" +msgid "now" +msgstr "" + +#: blocks/class-wc-sc-blocks-integration.php:649 +msgctxt "Block editor & frontend" +msgid "later" +msgstr "" + +#: blocks/class-wc-sc-blocks-integration.php:653 +msgctxt "Block editor & frontend" +msgid "Deliver coupon" +msgstr "" + +#: blocks/class-wc-sc-blocks-integration.php:654 +msgctxt "Block editor & frontend" +msgid "Enter recipient e-mail address" +msgstr "" + +#: blocks/class-wc-sc-extend-store-endpoint.php:81 +msgctxt "REST API" +msgid "Whether to send coupons to someone else." +msgstr "" + +#: blocks/class-wc-sc-extend-store-endpoint.php:94 +msgctxt "REST API" +msgid "Whether to send coupons to only one person or multiple people." +msgstr "" + +#: blocks/class-wc-sc-extend-store-endpoint.php:106 +msgctxt "REST API" +msgid "Whether to send coupons now or schedule for later." +msgstr "" + +#: blocks/class-wc-sc-extend-store-endpoint.php:118 +msgctxt "REST API" +msgid "Email address of recipients" +msgstr "" + +#: blocks/class-wc-sc-extend-store-endpoint.php:133 +msgctxt "REST API" +msgid "Coupons scheduled date & time" +msgstr "" + +#: blocks/class-wc-sc-extend-store-endpoint.php:148 +msgctxt "REST API" +msgid "Message for coupon recipient" +msgstr "" + +#: includes/class-wc-sc-act-deact.php:268 +msgid "Successfully cleared WooCommerce Smart Coupons cache!" +msgstr "" + +#: includes/class-wc-sc-admin-coupons-dashboard-actions.php:116 +msgid "Copy this coupon code" +msgstr "" + +#: includes/class-wc-sc-admin-coupons-dashboard-actions.php:116 +msgid "Copy" +msgstr "" + +#: includes/class-wc-sc-admin-coupons-dashboard-actions.php:118 +msgid "Copy coupon shareable link and apply via URL" +msgstr "" + +#: includes/class-wc-sc-admin-coupons-dashboard-actions.php:118 +msgid "Get shareable link" +msgstr "" + +#: includes/class-wc-sc-admin-coupons-dashboard-actions.php:123 +msgid "Make a duplicate from this coupon" +msgstr "" + +#: includes/class-wc-sc-admin-coupons-dashboard-actions.php:123 +msgid "Duplicate" +msgstr "" + +#: includes/class-wc-sc-admin-coupons-dashboard-actions.php:199 +msgid "(Copy)" +msgstr "" + +#: includes/class-wc-sc-admin-coupons-dashboard-actions.php:266 +msgid "No coupon to duplicate has been supplied!" +msgstr "" + +#. translators: %d: Post ID +#: includes/class-wc-sc-admin-coupons-dashboard-actions.php:288 +msgid "Coupon creation failed, could not find original coupon: %d" +msgstr "" + +#. translators: %s: coupon id +#: includes/class-wc-sc-admin-coupons-dashboard-actions.php:311 +msgid "Coupon creation failed, could not find original coupon: %s" +msgstr "" + +#: includes/class-wc-sc-admin-notifications.php:99 +#: includes/class-wc-sc-admin-welcome.php:197 +msgid "Settings" +msgstr "" + +#: includes/class-wc-sc-admin-notifications.php:100 +#: includes/class-wc-sc-admin-pages.php:159 +#: includes/class-wc-sc-admin-pages.php:608 +#: includes/class-wc-sc-admin-welcome.php:223 +msgid "FAQ's" +msgstr "" + +#: includes/class-wc-sc-admin-notifications.php:101 +#: includes/class-wc-sc-admin-welcome.php:198 +msgid "Docs" +msgstr "" + +#: includes/class-wc-sc-admin-notifications.php:102 +msgid "Support" +msgstr "" + +#: includes/class-wc-sc-admin-notifications.php:103 +msgid "Review" +msgstr "" + +#. translators: 1. Important 2. Upload path +#. translators: 1. Coupon type +#: includes/class-wc-sc-admin-notifications.php:165 +#: includes/class-wc-sc-background-coupon-importer.php:333 +#: includes/class-wc-sc-background-coupon-importer.php:400 +#: includes/class-wc-smart-coupons.php:5409 +msgid "Important" +msgstr "" + +#: includes/class-wc-sc-admin-notifications.php:165 +msgid "Setting \"Enable the use of coupon codes\" is disabled." +msgstr "" + +#: includes/class-wc-sc-admin-notifications.php:176 +msgid "Enable" +msgstr "" + +#: includes/class-wc-sc-admin-notifications.php:177 +msgid "it to use" +msgstr "" + +#: includes/class-wc-sc-admin-notifications.php:177 +msgid "features." +msgstr "" + +#: includes/class-wc-sc-admin-notifications.php:239 +msgid "Remind me after a month" +msgstr "" + +#: includes/class-wc-sc-admin-notifications.php:240 +#: includes/class-wc-sc-print-coupon.php:275 +msgid "Never show again" +msgstr "" + +#: includes/class-wc-sc-admin-notifications.php:243 +msgid "Awesome, you successfully auto-generated a coupon! Are you having a great experience with" +msgstr "" + +#: includes/class-wc-sc-admin-notifications.php:243 +msgid "so far?" +msgstr "" + +#: includes/class-wc-sc-admin-notifications.php:243 +msgid "Please consider" +msgstr "" + +#: includes/class-wc-sc-admin-notifications.php:243 +msgid "leaving a review" +msgstr "" + +#: includes/class-wc-sc-admin-notifications.php:243 +msgid "! If things aren't going quite as expected, we're happy to help -- please reach out to" +msgstr "" + +#: includes/class-wc-sc-admin-notifications.php:243 +msgid "our support team" +msgstr "" + +#. translators: 1: WooCommerce Smart Coupons 2: Link for the Smart Coupons settings +#: includes/class-wc-sc-admin-notifications.php:256 +msgid "%1$s: You are using a custom coupon style which is planned to be removed from the plugin in upcoming versions. New, improved styles & colors are added in the version 4.9.0. We would request you to choose a color scheme & a style for coupon from the newly added colors & styles. You can do this from %2$s." +msgstr "" + +#: includes/class-wc-sc-admin-notifications.php:266 +msgid "Smart Coupons settings" +msgstr "" + +#. translators: %s: link to review WooCommerce Smart Coupons +#: includes/class-wc-sc-admin-notifications.php:304 +msgid "Liked WooCommerce Smart Coupons? Leave us a %s. A huge thank you from WooCommerce & StoreApps in advance!" +msgstr "" + +#. translators: %s: link to submit idea for Smart Coupons on WooCommerce idea board +#: includes/class-wc-sc-admin-notifications.php:330 +msgid "Have a feature request? Submit it %s." +msgstr "" + +#. translators: %s: link to submit idea for Smart Coupons on WooCommerce idea board +#. translators: 1. File name 2. File download link +#: includes/class-wc-sc-admin-notifications.php:330 +#: includes/class-wc-sc-admin-welcome.php:361 +#: includes/class-wc-sc-admin-welcome.php:369 +#: includes/class-wc-sc-admin-welcome.php:395 +#: includes/class-wc-sc-background-coupon-importer.php:627 +#: includes/class-wc-sc-print-coupon.php:278 +msgid "here" +msgstr "" + +#. translators: %s: Plugin name +#: includes/class-wc-sc-admin-notifications.php:416 +msgid "%s database update required" +msgstr "" + +#: includes/class-wc-sc-admin-notifications.php:417 +msgid "The database update process runs in the background and may take a little while, so please be patient." +msgstr "" + +#: includes/class-wc-sc-admin-notifications.php:430 +msgid "Update database" +msgstr "" + +#. translators: %s: Plugin name +#: includes/class-wc-sc-admin-notifications.php:454 +msgid "%s is updating the database in the background. The database update process may take a little while, so please be patient." +msgstr "" + +#: includes/class-wc-sc-admin-notifications.php:456 +msgid "Note: WP CRON has been disabled on your install which may prevent this update from completing." +msgstr "" + +#: includes/class-wc-sc-admin-notifications.php:458 +msgid "View status" +msgstr "" + +#. translators: %s: Plugin name +#: includes/class-wc-sc-admin-notifications.php:467 +msgid "%s database update completed. Thank you for updating to the latest version!" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:123 +#: includes/class-wc-sc-admin-pages.php:550 +#: includes/class-wc-sc-admin-pages.php:555 +#: includes/class-wc-sc-admin-pages.php:1620 +#: includes/class-wc-sc-background-coupon-importer.php:396 +#: includes/class-wc-sc-display-coupons.php:791 +#: includes/class-wc-sc-display-coupons.php:828 +#: includes/class-wc-sc-display-coupons.php:1940 +#: includes/class-wc-sc-product-fields.php:99 +#: includes/class-wc-sc-product-fields.php:159 +msgid "Coupons" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:124 +#: includes/class-wc-sc-admin-pages.php:556 +#: includes/class-wc-sc-admin-pages.php:1594 +msgid "Bulk Generate" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:133 +#: includes/class-wc-sc-admin-pages.php:566 +#: includes/class-wc-sc-admin-pages.php:1587 +msgid "Import Coupons" +msgstr "" + +#. translators: %s: singular name for store credit +#. translators: Store Credit label +#: includes/class-wc-sc-admin-pages.php:143 +#: includes/class-wc-sc-admin-pages.php:579 +#: includes/class-wc-sc-admin-pages.php:1591 +msgid "Send %s" +msgstr "" + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-admin-pages.php:143 +#: includes/class-wc-sc-admin-pages.php:579 +msgid "Send Store Credit" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:152 +#: includes/class-wc-sc-admin-pages.php:595 +#: includes/class-wc-sc-settings.php:345 +msgid "Smart Coupons Settings" +msgstr "" + +#. translators: Decimal point +#: includes/class-wc-sc-admin-pages.php:197 +msgid "Please enter in decimal (%s) format without thousand separators." +msgstr "" + +#. translators: Decimal point +#: includes/class-wc-sc-admin-pages.php:199 +msgid "Please enter in monetary decimal (%s) format without thousand separators and currency symbols." +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:200 +msgid "Please enter in country code with two capital letters." +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:201 +msgid "Please enter in a value less than the regular price." +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:205 +#: includes/class-wc-sc-coupon-import.php:955 +msgid "Import" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:206 +#: includes/class-wc-smart-coupons.php:4257 +msgid "Export" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:215 +msgid "Are you sure you want to remove the selected items? If you have previously reduced this item's stock, or this order was submitted by a customer, you will need to manually restore the item's stock." +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:216 +msgid "Please select some items." +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:217 +msgid "Are you sure you wish to process this refund? This action cannot be undone." +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:218 +#: includes/class-wc-sc-coupon-refund-process.php:566 +msgid "Are you sure you wish to delete this refund? This action cannot be undone." +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:219 +msgid "Are you sure you wish to delete this tax column? This action cannot be undone." +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:220 +msgid "Remove this item meta?" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:221 +msgid "Remove this attribute?" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:222 +msgid "Name" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:223 +msgid "Remove" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:224 +msgid "Click to toggle" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:225 +msgid "Value(s)" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:226 +msgid "Enter some text, or some attributes by pipe (|) separating values." +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:227 +msgid "Visible on the product page" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:228 +msgid "Used for variations" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:229 +msgid "Enter a name for the new attribute term:" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:230 +msgid "Calculate totals based on order items, discounts, and shipping?" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:231 +msgid "Calculate line taxes? This will calculate taxes based on the customers country. If no billing/shipping is set it will use the store base country." +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:232 +msgid "Copy billing information to shipping information? This will remove any currently entered shipping information." +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:233 +msgid "Load the customer's billing information? This will remove any currently entered billing information." +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:234 +msgid "Load the customer's shipping information? This will remove any currently entered shipping information." +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:235 +msgid "Featured" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:238 +msgid "No customer selected" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:271 +msgid "Could not grant access - the user may already have permission for this file or billing email is not set. Ensure the billing email is set, and the order has been saved." +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:272 +msgid "Are you sure you want to revoke access to this download?" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:273 +msgid "You cannot add the same tax rate twice!" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:274 +msgid "Your product has variations! Before changing the product type, it is a good idea to delete the variations to avoid errors in the stock reports." +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:284 +msgid "Generate coupon code" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:320 +msgid "Import complete - imported" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:320 +msgid "skipped" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:385 +msgid "WooCommerce Coupons (CSV)" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:385 +msgid "Import coupons to your store via a csv file." +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:521 +#: includes/class-wc-sc-admin-pages.php:523 +msgid "Smart Coupon" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:551 +msgid "Add Coupon" +msgstr "" + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-admin-pages.php:672 +msgid "%s sent successfully." +msgstr "" + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-admin-pages.php:672 +msgid "Store Credit / Gift Certificate sent successfully." +msgstr "" + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-admin-pages.php:676 +msgid "There has been an error in sending %s." +msgstr "" + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-admin-pages.php:676 +msgid "There has been an error in sending Store Credit / Gift Certificate." +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:677 +msgid "Please try again later." +msgstr "" + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-admin-pages.php:727 +msgid "Quickly create and email %s to one or more people." +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:729 +msgid "Quickly create and email Store Credit or Gift Card to one or more people." +msgstr "" + +#. translators: 1: Path to setting 2: Setting to set email address 3: Setting for number of coupons to generate +#: includes/class-wc-sc-admin-pages.php:762 +#: includes/class-wc-sc-admin-pages.php:1200 +#: includes/class-wc-sc-admin-pages.php:1218 +msgid "Send to" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:770 +msgid "Invalid email address." +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:773 +#: includes/class-wc-sc-admin-pages.php:1224 +msgid "Use comma \",\" to separate multiple email addresses" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:779 +msgid "Worth" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:784 +#: includes/class-wc-sc-coupon-fields.php:1004 +msgid "0.00" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:790 +#: includes/class-wc-sc-purchase-credit.php:156 +msgid "Invalid amount." +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:800 +msgid "Expiry Date" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:807 +msgid "The store credit will expire at 00:00:00 of this date." +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:815 +#: includes/class-wc-sc-admin-pages.php:1229 +#: includes/class-wc-sc-display-coupons.php:2464 +#: includes/class-wc-sc-display-coupons.php:2497 +#: includes/class-wc-sc-privacy.php:608 +msgid "Message" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:815 +#: includes/class-wc-sc-admin-pages.php:1229 +msgid "(optional)" +msgstr "" + +#. translators: 1. Coupon type 2. Coupon amount +#: includes/class-wc-sc-admin-pages.php:824 +#: includes/class-wc-sc-purchase-credit.php:997 +msgid "Send" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:830 +#: includes/class-wc-sc-admin-pages.php:1244 +msgid "Preview Email" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:1028 +msgid "Please enter a valid value for Number of Coupons to Generate" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:1109 +msgid "Need a lot of coupons? You can easily do that with Smart Coupons." +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:1153 +msgid "Action" +msgstr "" + +#. translators: 1: Path to setting 2: Setting to set email address 3: Setting for number of coupons to generate +#: includes/class-wc-sc-admin-pages.php:1159 +#: includes/class-wc-sc-admin-pages.php:1200 +msgid "Number of coupons to generate" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:1159 +msgid "Required" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:1160 +msgid "10" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:1164 +msgid "Generate coupons and" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:1166 +msgid "Add to store" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:1172 +msgid "Export to CSV" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:1184 +msgid "(Does not add to store, but creates a .csv file, that you can" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:1184 +#: includes/class-wc-sc-background-coupon-importer.php:360 +msgid "import" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:1184 +msgid "later" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:1192 +msgid "Email to recipients" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:1194 +msgid "(Add to store and email generated coupons to recipients)" +msgstr "" + +#. translators: 1: Path to setting 2: Setting to set email address 3: Setting for number of coupons to generate +#: includes/class-wc-sc-admin-pages.php:1200 +msgid "Enter the email addresses of the recipients separated by comma under %1$1s. Make sure to match the count of email addresses in %2$2s to %3$3s" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:1212 +msgid "Email to " +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:1266 +msgid "Coupon Description " +msgstr "" + +#. translators: 1: HTML small tag start 2: HTML small tag end +#: includes/class-wc-sc-admin-pages.php:1268 +msgid "%1$s(This will add the same coupon description in all the bulk generated coupons)%2$s" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:1288 +msgid "Coupon Data" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:1298 +#: includes/class-wc-sc-coupon-categories.php:87 +#: includes/class-wc-sc-coupon-categories.php:225 +msgid "Coupon categories" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:1302 +#: includes/class-wc-sc-coupon-categories.php:105 +#: includes/class-wc-sc-coupon-categories.php:165 +#: includes/class-wc-smart-coupons.php:4261 +msgid "Manage coupon categories" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:1344 +msgid "Apply" +msgstr "" + +#. translators: Store Credit label +#: includes/class-wc-sc-admin-pages.php:1426 +#: includes/class-wc-sc-admin-pages.php:1436 +#: includes/class-wc-sc-admin-pages.php:1591 +#: includes/class-wc-sc-ajax.php:332 +#: includes/class-wc-sc-coupon-refund-process.php:666 +#: includes/class-wc-sc-coupon-refund-process.php:679 +#: includes/class-wc-smart-coupons.php:1143 +#: includes/emails/class-wc-sc-email-coupon.php:357 +#: includes/emails/class-wc-sc-email-coupon.php:481 +msgid "Store Credit" +msgstr "" + +#. translators: 1: Singular name for post type 2: Email +#: includes/class-wc-sc-admin-pages.php:1551 +msgid "[%1$s restricted with email: %2$s]" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:1610 +msgid "WooCommerce" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:1615 +msgid "Marketing" +msgstr "" + +#: includes/class-wc-sc-admin-pages.php:1633 +msgid "Original amount" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:87 +msgid "About Smart Coupons" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:88 +msgid "Welcome to Smart Coupons" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:177 +msgid "Thank you for installing WooCommerce Smart Coupons" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:179 +msgid "Glad to have you onboard. We hope WooCommerce Smart Coupons adds to your desired success 🏆" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:183 +msgid "Go To Coupons" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:214 +msgid "Know Smart Coupons" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:252 +msgid "What is Smart Coupons?" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:254 +msgid "Smart Coupons is a powerful extension, built on top of WooCommerce coupons. It adds a new discount type - Store Credit - and advanced functionality to the default coupons." +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:255 +msgid "Smart Coupons enable coupons to become an automatic/interactive system." +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:259 +msgid "Top Smart Coupons features" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:261 +msgid "Create and gift Store Credit / Gift Cards" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:262 +msgid "Bulk generate coupons" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:263 +msgid "Apply multiple coupons via URL" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:264 +msgid "Advanced restrictions - payment, shipping, location, user roles, product attributes" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:267 +msgid "and a lot more…" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:271 +msgid "Automatic payment for subscription renewals" +msgstr "" + +#. translators: WooCommerce Subscriptions product link +#: includes/class-wc-sc-admin-welcome.php:275 +msgid "If your store is using %s and your customer has purchased a subscription using a Store Credit. If that store credit has balance left in it, store will automatically use it for renewing that subscription." +msgstr "" + +#. translators: WooCommerce Subscriptions product link +#: includes/class-wc-sc-admin-welcome.php:275 +msgid "WooCommerce Subscriptions" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:280 +msgid "How to use Smart Coupons the best way" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:283 +msgid "Sell or issue store credit / gift cards" +msgstr "" + +#. translators: 1: Affiliate For WooCommerce 2: Smart Manager 3: Smart Offers +#: includes/class-wc-sc-admin-welcome.php:287 +msgid "Let customers purchase gift cards from you or you issue store credit that your users can redeem on the current or next purchase. See how: %1$s or %2$s" +msgstr "" + +#. translators: 1: Affiliate For WooCommerce 2: Smart Manager 3: Smart Offers +#: includes/class-wc-sc-admin-welcome.php:287 +msgid "any amount" +msgstr "" + +#. translators: 1: Affiliate For WooCommerce 2: Smart Manager 3: Smart Offers +#: includes/class-wc-sc-admin-welcome.php:287 +msgid "variable but fixed amount" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:292 +msgid "Bulk create unique coupons & email them" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:294 +msgid "Import and export unique coupons in bulk via CSV. Share coupon codes to deal sites or email them to your customers." +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:294 +#: includes/class-wc-sc-admin-welcome.php:300 +#: includes/class-wc-sc-admin-welcome.php:308 +#: includes/class-wc-sc-admin-welcome.php:403 +msgid "See how" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:298 +msgid "Gift a product via coupon" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:300 +msgid "Attach a gift of any value (free or paid product) to a particular coupon. Here, instead of a discount, a product is redeemed for the coupon code." +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:306 +msgid "Give discounts to customers for next purchase" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:308 +msgid "You can give a coupon to your customer after every purchase, which can encourage them to purchase again from you." +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:312 +msgid "Set a maximum discount limit" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:314 +msgid "Give bigger discounts without hurting your profits. Offer a percentage off coupon upto a particular value. Example - Flat 50% off upto $100." +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:318 +msgid "Make customer's coupon usage, easy & simple" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:320 +msgid "Show only valid coupons to your customer (if logged in) on cart, checkout & My Account page. Coupons can be applied with single click. So, no need to remember the coupon code or copy-pasting." +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:349 +msgid "FAQ / Common Problems" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:354 +msgid "When trying to add coupon/Smart Coupon, I get \"Invalid post type\" message." +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:355 +msgid "Make sure use of coupon is enabled in your store. You can find this setting" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:364 +msgid "Smart Coupon's fields are broken?" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:365 +msgid "Make sure you are using the " +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:365 +msgid "latest version of Smart Coupons" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:365 +msgid ". If still the issue persist, temporarily de-activate all plugins except WooCommerce & Smart Coupons. Re-check the issue, if the issue still persists, contact us (from the link at the end of this page). If the issue goes away, re-activate other plugins one-by-one & re-checking the fields, to find out which plugin is conflicting." +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:368 +msgid "How to translate texts from Smart Coupons?" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:369 +msgid "Simplest method is by installing" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:369 +msgid "Loco Translate" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:369 +msgid "plugin and then following steps listed " +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:372 +msgid "How to change texts of the emails sent from Smart Coupons?" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:373 +msgid "You can do this by overriding the email template." +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:373 +msgid "How to override email template" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:376 +msgid "Can coupon code have any spaces in the name? / My Store Credit/Gift Certificate is not working (not generating new coupon code)." +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:377 +msgid "No. Coupon code should not have any spaces in the name, Eg, Coupon code should be “gift-certificate” & not “gift certificate”." +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:380 +msgid "What's the URL to a coupon, so it's automatically inserted when visiting?" +msgstr "" + +#. translators: Documentation link for 'How to Apply Single or Multiple Coupons on Click of a Link' +#: includes/class-wc-sc-admin-welcome.php:382 +msgid "URL of coupon should be like this:" +msgstr "" + +#. translators: Documentation link for 'How to Apply Single or Multiple Coupons on Click of a Link' +#: includes/class-wc-sc-admin-welcome.php:382 +msgid ". Replace www.mysite.com with your own site URL and replace discount5 with the your coupon code." +msgstr "" + +#. translators: Documentation link for 'How to Apply Single or Multiple Coupons on Click of a Link' +#: includes/class-wc-sc-admin-welcome.php:382 +msgid "For more details you can refer to this article: %s" +msgstr "" + +#. translators: Documentation link for 'How to Apply Single or Multiple Coupons on Click of a Link' +#: includes/class-wc-sc-admin-welcome.php:382 +msgid "How to Apply Single or Multiple Coupons on Click of a Link" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:385 +msgid "Do not want to tie store credit to be used by only one customer? / Can a customer send a gift certificate to themselves to pass on to someone else?" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:386 +msgid "Edit the main coupon which is entered in \"Coupons\" field of the product edit page, then go to \"Usage Restrictions\" > \"Disable Email Restriction\" and disable this setting and save the coupon." +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:389 +msgid "Getting 'Page Not Found Error' when accessing Coupons tab from My Account Page?" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:390 +msgid "Go to WordPress -> Settings -> Permalinks and click on Save Settings once." +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:393 +msgid "Is there any reference file for creating an import file for coupons?" +msgstr "" + +#. translators: 1. File name 2. File download link +#: includes/class-wc-sc-admin-welcome.php:395 +msgid "There is one file which is located inside the plugin. You can download the %1$s file from %2$s." +msgstr "" + +#. translators: 1. File name 2. File download link +#: includes/class-wc-sc-admin-welcome.php:395 +msgid "If you want to import coupon through file, the file should be like" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:398 +msgid "Available coupons are not visible on Cart, Checkout & My Account page?" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:399 +msgid "Smart Coupons uses hooks of Cart, Checkout & My Account page to display available coupons. If your theme is not using those hooks in cart, checkout & my-account template, coupons will not be displayed." +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:402 +msgid "How can I resend gift card coupon bought by customers?" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:403 +msgid "You can resend them from order admin edit page." +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:406 +msgid "Uncheck \"Auto-generate\" option in Store Credit is not saving? Is it always checked?" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:407 +msgid "Store Credit's default behavior is auto-generate because, when using a store credit, it's balance keeps reducing. Therefore it should be uniquely created for every user automatically." +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:410 +msgid "Smart Coupons is not sending emails." +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:411 +msgid "Smart Coupons sends email only after order completion. So make sure that order complete email is enabled and sending. If enabled, then make sure all settings of coupons, products are in place. Also check by switching your theme." +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:414 +msgid "\"Store Credit Receiver detail\" form not appearing on checkout page?" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:415 +msgid "This form is displayed using a hook which is available in My Account template. Make sure your theme's my-account template contains all hooks required for that template. Update your theme if it is not updated." +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:418 +msgid "Does Smart Coupons allow printing of coupon as Gift Card?" +msgstr "" + +#. translators: Documentation link for 'How to Print Coupons' +#: includes/class-wc-sc-admin-welcome.php:420 +msgid "Yes, Smart Coupons does provide a feature for printing coupons. For more details, check this article: %s" +msgstr "" + +#. translators: Documentation link for 'How to Print Coupons' +#: includes/class-wc-sc-admin-welcome.php:420 +msgid "How to Print Coupons" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:423 +msgid "Is it possible to have a coupon for each variation of the variable product?" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:424 +msgid "From version 4.11.0, you can add/link coupons to product variations as well. This feature is not available in a version lower than 4.11.0." +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:427 +msgid "Is Smart Coupons compatible with WooCommerce Subscriptions?" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:428 +msgid "Yes, Smart Coupons does work with WooCommerce Subscriptions." +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:431 +msgid "Which features of Smart Coupons work with Subscriptions?" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:432 +msgid "Give away a discount or credit on signing up a subscription, give away recurring discount or credits, apply credit during sign up, automatic payment for renewals from credit (Note: When using PayPal Standard Gateway, store credit can be applied only during sign up. Automatic payment for renewals by credit will not work for PayPal Standard Gateway)." +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:435 +msgid "How does automatic payment by store credit work with Subscriptions?" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:436 +msgid "Customers can apply store credit on a subscription during purchase of subscription. If the same store credit has sufficient balance, it'll keep applying it to renewals till the remainder in store credit is higher than renewal price. Customers will be able to apply store credit only during signup. They will not get an option to apply store credit in renewals. But if the store credit will not have sufficient balance to pay for the renewals, then the order will go into pending mode. Now when the customer will go to pay for this renewal order, they'll get an option to apply store credit again. To activate the subscription again, the customer will have to pay for the renewals. When the customer is paying for the renewals from their account, then in that process they can use the same store credit which didn't have the sufficient balance, again & pay for the remaining amount." +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:439 +msgid "Is it possible to partially pay for a subscription with store credit and the remainder by another method?" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:440 +msgid "No, this is possible only in those cases where subscription amount is more than store credit's balance. If store credit's balance is more than subscription's total then your bank account or credit card will not be charged." +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:443 +msgid "Is Smart Coupons WPML compatible?" +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:444 +msgid "Not yet, but this is being worked on. You will find this in later versions." +msgstr "" + +#: includes/class-wc-sc-admin-welcome.php:447 +msgid "I'm using WPML & WPML provides support for multi-currency, but Smart Coupons only changes currency symbol & the price value remains same. Can Smart Coupons change the currency symbol and the price value associated with it?" +msgstr "" + +#. translators: Link for the plugin 'Aelia Currency Switcher for WooCommerce' +#: includes/class-wc-sc-admin-welcome.php:449 +msgid "Currently, Smart Coupons is compatible with %s. But it is not compatible with any other multi-currency plugin or with WPML." +msgstr "" + +#. translators: Link for the plugin 'Aelia Currency Switcher for WooCommerce' +#: includes/class-wc-sc-admin-welcome.php:449 +msgid "Aelia Currency Switcher for WooCommerce" +msgstr "" + +#. translators: WooCommerce My Account support link +#: includes/class-wc-sc-admin-welcome.php:476 +msgid "If you are facing any issues, please %s from your WooCommerce account." +msgstr "" + +#. translators: WooCommerce My Account support link +#: includes/class-wc-sc-admin-welcome.php:476 +msgid "submit a ticket" +msgstr "" + +#. translators: 1. Discount type 2. Discount Type Label +#: includes/class-wc-sc-ajax.php:132 +#: includes/class-wc-sc-product-fields.php:114 +#: includes/class-wc-sc-product-fields.php:175 +msgid "Type" +msgstr "" + +#. translators: 1. The coupon code, 2. The discount type +#: includes/class-wc-sc-ajax.php:252 +#: includes/class-wc-sc-settings.php:332 +msgid "%1$s (Type: %2$s)" +msgstr "" + +#: includes/class-wc-sc-ajax.php:337 +#: includes/class-wc-sc-ajax.php:352 +#: includes/class-wc-smart-coupons.php:1148 +#: includes/class-wc-smart-coupons.php:1163 +msgid "Cart Discount" +msgstr "" + +#: includes/class-wc-sc-ajax.php:342 +#: includes/class-wc-sc-ajax.php:347 +#: includes/class-wc-smart-coupons.php:1153 +#: includes/class-wc-smart-coupons.php:1158 +msgid "Product Discount" +msgstr "" + +#: includes/class-wc-sc-ajax.php:352 +#: includes/class-wc-sc-settings.php:1051 +#: includes/class-wc-smart-coupons.php:1163 +msgid "Discount" +msgstr "" + +#. translators: %s: Maximum coupon discount amount +#: includes/class-wc-sc-ajax.php:357 +msgid "upto %s" +msgstr "" + +#: includes/class-wc-sc-auto-apply-coupon.php:120 +#: includes/class-wc-sc-auto-apply-coupon.php:186 +msgid "Auto apply?" +msgstr "" + +#: includes/class-wc-sc-auto-apply-coupon.php:121 +msgid "When checked, this coupon will be applied automatically, if it is valid. If enabled in more than 5 coupons, only 5 coupons will be applied automatically, rest will be ignored." +msgstr "" + +#. translators: 1. Important 2. Upload path +#: includes/class-wc-sc-background-coupon-importer.php:333 +msgid "%1$s: To allow bulk generation of coupons, please make sure %2$s directory is writable." +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:338 +msgid "Bulk generation is disabled since uploads directory is not writable. Please ensure uploads directory is writable before starting bulk generate process." +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:359 +msgid "imported" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:365 +msgid "generated & sent" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:366 +#: includes/class-wc-sc-background-coupon-importer.php:371 +msgid "generate" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:370 +#: includes/class-wc-sc-background-coupon-importer.php:595 +msgid "generated" +msgstr "" + +#. translators: 1. Error title 2. The bulk process +#: includes/class-wc-sc-background-coupon-importer.php:385 +msgid "%1$s: The coupon bulk %2$s process stopped. Please review the coupons list to check the status." +msgstr "" + +#. translators: 1. Error title 2. The bulk process +#: includes/class-wc-sc-background-coupon-importer.php:385 +msgid "Error" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:394 +msgid "Store Credits / Gift Cards" +msgstr "" + +#. translators: 1. Coupon type +#: includes/class-wc-sc-background-coupon-importer.php:400 +msgid "%s are being" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:402 +msgid "in the background. You will be notified when it is completed." +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:405 +msgid "Progress" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:406 +msgid "--:--:--" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:407 +msgid "Stop" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:411 +msgid "You can continue with other work. But for bulk generating or importing new coupons, wait for the current process to complete." +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:487 +msgid "We are processing coupons in background. Please wait before starting new process." +msgstr "" + +#. translators: 1. The bulk process +#: includes/class-wc-sc-background-coupon-importer.php:551 +msgid "Are you sure you want to stop the coupon bulk %s process? Click OK to stop." +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:577 +#: includes/class-wc-sc-background-coupon-importer.php:585 +msgid "Coupon import" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:578 +msgid "updated & emailed" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:578 +#: includes/class-wc-sc-background-coupon-importer.php:582 +msgid "added & emailed" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:581 +#: includes/class-wc-sc-background-coupon-importer.php:594 +msgid "Coupon bulk generation" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:586 +msgid "updated" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:586 +#: includes/class-wc-sc-background-coupon-importer.php:595 +msgid "added" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:589 +msgid "Store credit" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:590 +msgid "sent" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:602 +msgid "store credit / gift card" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:603 +msgid "store credits / gift cards" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:605 +#: includes/class-wc-sc-purchase-credit.php:991 +#: includes/emails/class-wc-sc-email-coupon.php:488 +msgid "coupon" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:606 +msgid "coupons" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:614 +msgid "Successfully" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:617 +msgid "Skipped" +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:627 +msgid "CSV file has been generated. You can download it from " +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:743 +#: includes/class-wc-sc-background-coupon-importer.php:760 +msgid "Failed to create export file." +msgstr "" + +#: includes/class-wc-sc-background-coupon-importer.php:1257 +msgid "Every 5 Seconds" +msgstr "" + +#. translators: 1. Product title +#: includes/class-wc-sc-coupon-actions.php:421 +msgid "%s has been added to your cart!" +msgstr "" + +#. translators: 1. Product/s 2. Product names 3. is/are 4. Coupons code +#: includes/class-wc-sc-coupon-actions.php:504 +msgid "%1$s %2$s %3$s removed because coupon %4$s is removed." +msgstr "" + +#. translators: 1. Product/s 2. Product names 3. is/are 4. Coupons code +#: includes/class-wc-sc-coupon-actions.php:504 +#: includes/class-wc-sc-coupons-by-product-quantity.php:124 +msgid "Product" +msgid_plural "Products" +msgstr[0] "" +msgstr[1] "" + +#. translators: 1. Product/s 2. Product names 3. is/are 4. Coupons code +#: includes/class-wc-sc-coupon-actions.php:504 +msgid "is" +msgid_plural "are" +msgstr[0] "" +msgstr[1] "" + +#: includes/class-wc-sc-coupon-actions.php:580 +msgid "Add product details" +msgstr "" + +#: includes/class-wc-sc-coupon-categories.php:88 +msgid "Category" +msgstr "" + +#: includes/class-wc-sc-coupon-categories.php:89 +msgctxt "Admin menu name" +msgid "Categories" +msgstr "" + +#: includes/class-wc-sc-coupon-categories.php:90 +msgid "Search coupon categories" +msgstr "" + +#: includes/class-wc-sc-coupon-categories.php:91 +msgid "All coupon categories" +msgstr "" + +#: includes/class-wc-sc-coupon-categories.php:92 +msgid "Parent coupon category" +msgstr "" + +#: includes/class-wc-sc-coupon-categories.php:93 +msgid "Parent coupon category:" +msgstr "" + +#: includes/class-wc-sc-coupon-categories.php:94 +msgid "Edit coupon category" +msgstr "" + +#: includes/class-wc-sc-coupon-categories.php:95 +msgid "Update coupon category" +msgstr "" + +#: includes/class-wc-sc-coupon-categories.php:96 +msgid "Add new coupon category" +msgstr "" + +#: includes/class-wc-sc-coupon-categories.php:97 +msgid "New coupon category name" +msgstr "" + +#: includes/class-wc-sc-coupon-categories.php:98 +msgid "No coupon categories found" +msgstr "" + +#: includes/class-wc-sc-coupon-columns.php:128 +msgid "Used in orders" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:101 +msgid "Coupon shareable link" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:139 +msgid "Copy the following link and share it to apply this coupon via URL." +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:146 +#: includes/class-wc-sc-coupon-fields.php:1434 +msgid "Click to copy" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:150 +msgid "You can also apply multiple coupon codes via a single URL. For example:" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:285 +msgctxt "Timepicker on the admin side" +msgid "Now" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:286 +msgctxt "Timepicker on the admin side" +msgid "Done" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:350 +msgctxt "Timepicker on the admin side" +msgid "HH:mm" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:352 +msgctxt "Timepicker on the admin side" +msgid "Choose Time" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:353 +msgctxt "Timepicker on the admin side" +msgid "Time" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:354 +msgctxt "Timepicker on the admin side" +msgid "Hour" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:355 +msgctxt "Timepicker on the admin side" +msgid "Minute" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:356 +msgctxt "Timepicker on the admin side" +msgid "Second" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:357 +msgctxt "Timepicker on the admin side" +msgid "Millisecond" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:358 +msgctxt "Timepicker on the admin side" +msgid "Microsecond" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:359 +msgctxt "Timepicker on the admin side" +msgid "Time Zone" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:391 +#: includes/class-wc-smart-coupons.php:4661 +msgid "Coupon expiry time" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:392 +msgid "HH:MM" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:393 +msgid "Time after which coupon will be expired. This will work in conjunction with Coupon expiry date." +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:407 +#: includes/class-wc-smart-coupons.php:4657 +msgid "Max discount" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:408 +msgid "Unlimited discount" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:409 +msgid "The maximum discount this coupon can give on a cart." +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:422 +#: includes/class-wc-smart-coupons.php:4656 +#: includes/class-wc-smart-coupons.php:5026 +msgid "For new user only?" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:423 +msgid "When checked, this coupon will be valid for the user's first order on the store." +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:437 +msgid "Valid for" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:440 +msgid "Days" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:441 +msgid "Weeks" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:442 +msgid "Months" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:443 +msgid "Years" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:445 +msgid "(Used only for auto-generated coupons)" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:452 +msgid "Coupon value same as product's price?" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:453 +msgid "When checked, generated coupon's value will be same as product's price" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:459 +msgid "Auto generate new coupons with each item" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:460 +msgid "Generate exact copy of this coupon with unique coupon code for each purchased product (needs this coupon to be linked with that product)" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:480 +msgid "Coupon code format" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:481 +msgid "Prefix" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:483 +msgid "Suffix" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:484 +msgid "(We recommend up to three letters for prefix/suffix)" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:497 +msgid "Show on cart, checkout" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:497 +msgid "and my account?" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:498 +msgid "When checked, this coupon will be visible on cart/checkout page for everyone" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:536 +msgid "Disable email restriction?" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:537 +msgid "Do not restrict auto-generated coupons to buyer/receiver email, anyone with coupon code can use it" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:934 +msgid "Actions" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:962 +msgid "After applying the coupon do these also" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:964 +msgid "Add products to cart" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:967 +#: includes/class-wc-sc-coupon-fields.php:994 +msgid "Search for a product…" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:998 +msgid "each with quantity" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:999 +msgid "1" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:1000 +msgid "This much quantity of each product, selected above, will be added to cart." +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:1003 +msgid "with discount of" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:1006 +msgid "%" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:1009 +msgid "When this coupon will be applied, selected products will be added to cart with set discount. If discount is not set, this coupon's discount will be applied to these products." +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:1044 +#: includes/class-wc-smart-coupons.php:5139 +msgctxt "enhanced select" +msgid "One result is available, press enter to select it." +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:1045 +#: includes/class-wc-smart-coupons.php:5140 +msgctxt "enhanced select" +msgid "%qty% results are available, use up and down arrow keys to navigate." +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:1046 +#: includes/class-wc-smart-coupons.php:5141 +msgctxt "enhanced select" +msgid "No matches found" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:1047 +#: includes/class-wc-sc-coupon-fields.php:1055 +#: includes/class-wc-smart-coupons.php:5150 +msgctxt "enhanced select" +msgid "Searching…" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:1048 +#: includes/class-wc-smart-coupons.php:5143 +msgctxt "enhanced select" +msgid "Please enter 1 or more characters" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:1049 +#: includes/class-wc-smart-coupons.php:5144 +msgctxt "enhanced select" +msgid "Please enter %qty% or more characters" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:1050 +#: includes/class-wc-smart-coupons.php:5145 +msgctxt "enhanced select" +msgid "Please delete 1 character" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:1051 +#: includes/class-wc-smart-coupons.php:5146 +msgctxt "enhanced select" +msgid "Please delete %qty% characters" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:1052 +#: includes/class-wc-smart-coupons.php:5147 +msgctxt "enhanced select" +msgid "You can only select 1 item" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:1053 +#: includes/class-wc-smart-coupons.php:5148 +msgctxt "enhanced select" +msgid "You can only select %qty% items" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:1054 +#: includes/class-wc-smart-coupons.php:5149 +msgctxt "enhanced select" +msgid "Loading more results…" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:1312 +msgid "Could not locate WooCommerce" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:1359 +#: includes/class-wc-sc-settings.php:605 +msgid "Store Credit / Gift Certificate" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:1432 +#: includes/class-wc-sc-coupon-fields.php:1447 +msgid "Copied!" +msgstr "" + +#: includes/class-wc-sc-coupon-fields.php:1439 +#: includes/class-wc-sc-coupon-fields.php:1449 +msgid "Copy coupon code" +msgstr "" + +#. translators: 1. Receiver email 2. Coupon code +#: includes/class-wc-sc-coupon-import.php:669 +msgid "Failed to schedule email to \"%1$s\" for coupon \"%2$s\"." +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:702 +#: includes/class-wc-sc-coupon-import.php:758 +#: includes/class-wc-sc-coupon-import.php:770 +msgid "Sorry, there has been an error." +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:703 +msgid "The file does not exist, please try again." +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:857 +msgid "Coupon Import Error" +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:857 +msgid "Invalid CSV file. Make sure your CSV file contains all columns, header row, and data in correct format." +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:857 +msgid "Download a sample.csv to confirm" +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:936 +msgid "All set, Begin import?" +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:940 +msgid "File uploaded OK" +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:941 +msgid "File format seems OK" +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:945 +msgid "Update existing coupons" +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:945 +msgid "New feature" +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:945 +msgid "If enabled, existing coupons that match by coupon code will be updated. Coupons that do not exist will be skipped." +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:951 +msgid "Email coupon to recipients" +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:951 +msgid "Enable this to send coupon to recipient's email addresses, provided in imported file." +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:1020 +msgid "Chosen" +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:1036 +msgid "Hi there! Upload a CSV file with coupons details to import them into your shop." +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:1037 +msgid "The CSV must adhere to a specific format and include a header row." +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:1037 +msgid "Click here to download a sample" +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:1037 +msgid "and create your CSV based on that." +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:1038 +msgid "Note: If any coupon from the CSV file already exists in the store, it will not update the existing coupon, instead a new coupon will be imported & the previous coupon with the same code will become inactive." +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:1039 +msgid "Ready to import? Choose a .csv file, then click \"Upload file\"." +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:1061 +msgid "Before you can upload your import file, you will need to fix the following error:" +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:1070 +msgid "Choose a CSV file" +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:1075 +msgid "Maximum file size" +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:1076 +msgid "OR" +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:1077 +msgid "Already uploaded CSV to the server?" +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:1077 +msgid "Enter location on the server" +msgstr "" + +#: includes/class-wc-sc-coupon-import.php:1079 +msgid "Upload file" +msgstr "" + +#: includes/class-wc-sc-coupon-message.php:125 +msgid "Display message" +msgstr "" + +#: includes/class-wc-sc-coupon-message.php:133 +msgid "Email message?" +msgstr "" + +#: includes/class-wc-sc-coupon-message.php:134 +msgid "Check this box to include above message in order confirmation email" +msgstr "" + +#: includes/class-wc-sc-coupon-message.php:418 +#: includes/class-wc-sc-coupon-message.php:435 +msgid "Coupon Message" +msgstr "" + +#: includes/class-wc-sc-coupon-message.php:436 +msgid "Is Email Coupon Message" +msgstr "" + +#. translators: 1. Coupon code 2. Expiry date +#: includes/class-wc-sc-coupon-parser.php:416 +msgid "Incorrect format for expiry date of coupon \"%1$s\". Entered date is %2$s. Expected date format: YYYY-MM-DD" +msgstr "" + +#: includes/class-wc-sc-coupon-process.php:322 +msgid "Email address" +msgstr "" + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-coupon-process.php:352 +msgid "Error: %s Receiver’s E-mail address is invalid." +msgstr "" + +#: includes/class-wc-sc-coupon-process.php:354 +msgid "Error: Gift Card Receiver’s E-mail address is invalid." +msgstr "" + +#. translators: 1. amount of store credit 2. store credit label 3. coupon code +#: includes/class-wc-sc-coupon-process.php:776 +msgid "%1$s worth of %2$s restored to coupon %3$s." +msgstr "" + +#. translators: 1. amount of store credit 2. coupon code +#: includes/class-wc-sc-coupon-process.php:779 +msgid "%1$s worth of Store Credit restored to coupon %2$s." +msgstr "" + +#. translators: Order notes +#: includes/class-wc-sc-coupon-process.php:787 +msgid "%s Because PayPal doesn't accept discount on shipping & tax." +msgstr "" + +#. translators: 1. Receiver email 2. Coupon code 3. Order id +#: includes/class-wc-sc-coupon-process.php:1081 +#: includes/class-wc-smart-coupons.php:873 +msgid "Failed to schedule email to \"%1$s\" for coupon \"%2$s\" received from order #%3$s." +msgstr "" + +#: includes/class-wc-sc-coupon-process.php:1813 +msgctxt "Order edit admin page" +msgid "Resend coupon emails" +msgstr "" + +#: includes/class-wc-sc-coupon-process.php:1815 +msgctxt "Order edit admin page" +msgid "Regenerate coupons" +msgstr "" + +#: includes/class-wc-sc-coupon-process.php:1816 +msgctxt "Order edit admin page" +msgid "Regenerate & resend coupon emails" +msgstr "" + +#: includes/class-wc-sc-coupon-process.php:1843 +msgctxt "Order edit admin page" +msgid "Coupons manually regenerated." +msgstr "" + +#: includes/class-wc-sc-coupon-process.php:1845 +msgctxt "Order edit admin page" +msgid "Coupons manually regenerated & sent." +msgstr "" + +#: includes/class-wc-sc-coupon-process.php:1850 +msgctxt "Order edit admin page" +msgid "Coupon details manually sent." +msgstr "" + +#: includes/class-wc-sc-coupon-refund-process.php:213 +msgid "Refund to Store Credit" +msgstr "" + +#: includes/class-wc-sc-coupon-refund-process.php:225 +msgid "Auto-fill refund amount" +msgstr "" + +#: includes/class-wc-sc-coupon-refund-process.php:500 +msgid "Successfully updated store credit refund details." +msgstr "" + +#: includes/class-wc-sc-coupon-refund-process.php:502 +msgid "Failed to update store credit refund details." +msgstr "" + +#: includes/class-wc-sc-coupon-refund-process.php:513 +msgid "Nonce verification failed for action \"wc_sc_refund_store_credit\"." +msgstr "" + +#. translators: 1: refund id 2: refund date 3: username +#: includes/class-wc-sc-coupon-refund-process.php:665 +msgid "Refund %1$s - %2$s by %3$s" +msgstr "" + +#. translators: 1: ID who refunded +#: includes/class-wc-sc-coupon-refund-process.php:671 +msgid "ID: %d" +msgstr "" + +#. translators: 1: refund id 2: refund date +#: includes/class-wc-sc-coupon-refund-process.php:678 +msgid "Refund %1$s - %2$s" +msgstr "" + +#: includes/class-wc-sc-coupons-by-excluded-email.php:105 +#: includes/class-wc-sc-coupons-by-excluded-email.php:341 +#: includes/class-wc-sc-coupons-by-excluded-email.php:469 +msgid "Excluded emails" +msgstr "" + +#: includes/class-wc-sc-coupons-by-excluded-email.php:106 +msgid "No restrictions" +msgstr "" + +#: includes/class-wc-sc-coupons-by-excluded-email.php:107 +msgid "List of excluded billing emails to check against when an order is placed. Separate email addresses with commas. You can also use an asterisk (*) to match parts of an email. For example \"*@gmail.com\" would match all gmail addresses." +msgstr "" + +#: includes/class-wc-sc-coupons-by-excluded-email.php:239 +#: includes/class-wc-sc-coupons-by-excluded-email.php:253 +#: includes/class-wc-sc-coupons-by-user-role.php:220 +#: includes/class-wc-sc-coupons-by-user-role.php:227 +msgid "This coupon is not valid for you." +msgstr "" + +#: includes/class-wc-sc-coupons-by-excluded-email.php:468 +msgid "Allowed emails" +msgstr "" + +#: includes/class-wc-sc-coupons-by-location.php:196 +msgid "Address to look in" +msgstr "" + +#: includes/class-wc-sc-coupons-by-location.php:199 +msgid "Billing" +msgstr "" + +#: includes/class-wc-sc-coupons-by-location.php:203 +msgid "Shipping" +msgstr "" + +#: includes/class-wc-sc-coupons-by-location.php:207 +msgid "Locations" +msgstr "" + +#: includes/class-wc-sc-coupons-by-location.php:219 +msgid "Select location" +msgstr "" + +#: includes/class-wc-sc-coupons-by-location.php:282 +msgid "Select Additional Locations" +msgstr "" + +#: includes/class-wc-sc-coupons-by-location.php:306 +msgid "Entered location not found. On pressing \"Enter\" button, a new custom location will be saved as: " +msgstr "" + +#: includes/class-wc-sc-coupons-by-location.php:478 +msgid "Coupon is not valid for the" +msgstr "" + +#: includes/class-wc-sc-coupons-by-location.php:478 +msgid "billing address" +msgstr "" + +#: includes/class-wc-sc-coupons-by-location.php:478 +msgid "shipping address" +msgstr "" + +#: includes/class-wc-sc-coupons-by-location.php:493 +msgid "Locations lookup in" +msgstr "" + +#: includes/class-wc-sc-coupons-by-location.php:494 +msgid "Billing Locations" +msgstr "" + +#: includes/class-wc-sc-coupons-by-location.php:495 +msgid "Shipping Locations" +msgstr "" + +#: includes/class-wc-sc-coupons-by-payment-method.php:104 +#: includes/class-wc-sc-coupons-by-payment-method.php:233 +msgid "Payment methods" +msgstr "" + +#: includes/class-wc-sc-coupons-by-payment-method.php:105 +msgid "No payment methods" +msgstr "" + +#: includes/class-wc-sc-coupons-by-payment-method.php:115 +msgid "Payment methods that must be selected during checkout for this coupon to be valid." +msgstr "" + +#. translators: 1. The coupon code 2. The text 'payment method/s' 3. List of payment method names 4. Link to the checkout page +#: includes/class-wc-sc-coupons-by-payment-method.php:210 +msgid "Coupon code %1$s has been removed. It is valid only for %2$s: %3$s. You can change the payment method from the %4$s page." +msgstr "" + +#. translators: 1. The coupon code 2. The text 'payment method/s' 3. List of payment method names 4. Link to the checkout page +#: includes/class-wc-sc-coupons-by-payment-method.php:210 +#: includes/class-wc-sc-coupons-by-payment-method.php:214 +msgid "payment method" +msgid_plural "payment methods" +msgstr[0] "" +msgstr[1] "" + +#. translators: 1. The coupon code 2. The text 'payment method/s' 3. List of payment method names 4. Link to the checkout page +#: includes/class-wc-sc-coupons-by-payment-method.php:210 +#: includes/class-wc-sc-coupons-by-payment-method.php:214 +msgid "Checkout" +msgstr "" + +#. translators: 1. The coupon code 2. The text 'payment method/s' 3. List of payment method names 4. Link to the checkout page +#: includes/class-wc-sc-coupons-by-payment-method.php:214 +msgid "Coupon code %1$s is valid only for %2$s: %3$s. You can change payment method from the %4$s page." +msgstr "" + +#: includes/class-wc-sc-coupons-by-payment-method.php:411 +msgid "An error occurred:" +msgstr "" + +#: includes/class-wc-sc-coupons-by-product-attribute.php:167 +msgid "Attribute=" +msgstr "" + +#: includes/class-wc-sc-coupons-by-product-attribute.php:167 +msgid "Value=" +msgstr "" + +#: includes/class-wc-sc-coupons-by-product-attribute.php:181 +msgid "Product attributes" +msgstr "" + +#: includes/class-wc-sc-coupons-by-product-attribute.php:182 +#: includes/class-wc-sc-coupons-by-product-attribute.php:201 +msgid "No product attributes" +msgstr "" + +#. translators: Non product type coupon labels +#: includes/class-wc-sc-coupons-by-product-attribute.php:193 +msgid "Product attributes that the coupon will be applied to, or that need to be in the cart in order for the %s to be applied." +msgstr "" + +#: includes/class-wc-sc-coupons-by-product-attribute.php:200 +msgid "Exclude attributes" +msgstr "" + +#. translators: Non product type coupon labels +#: includes/class-wc-sc-coupons-by-product-attribute.php:212 +msgid "Product attributes that the coupon will not be applied to, or that cannot be in the cart in order for the %s to be applied." +msgstr "" + +#: includes/class-wc-sc-coupons-by-product-attribute.php:491 +#: includes/class-wc-sc-coupons-by-taxonomy.php:700 +msgid "Sorry, this coupon is not applicable to selected products." +msgstr "" + +#. translators: 1. Singular/plural label for product(s) 2. Excluded product names +#: includes/class-wc-sc-coupons-by-product-attribute.php:525 +#: includes/class-wc-sc-coupons-by-taxonomy.php:729 +msgid "Sorry, this coupon is not applicable to the %1$s: %2$s." +msgstr "" + +#. translators: 1. Singular/plural label for product(s) 2. Excluded product names +#: includes/class-wc-sc-coupons-by-product-attribute.php:525 +#: includes/class-wc-sc-coupons-by-taxonomy.php:729 +msgid "product" +msgid_plural "products" +msgstr[0] "" +msgstr[1] "" + +#: includes/class-wc-sc-coupons-by-product-attribute.php:545 +msgid "Product Attributes" +msgstr "" + +#: includes/class-wc-sc-coupons-by-product-attribute.php:546 +msgid "Exclude Attributes" +msgstr "" + +#: includes/class-wc-sc-coupons-by-product-quantity.php:115 +#: includes/class-wc-sc-coupons-by-product-quantity.php:663 +msgid "Product quantity based restrictions" +msgstr "" + +#: includes/class-wc-sc-coupons-by-product-quantity.php:117 +msgid "Validate quantity of" +msgstr "" + +#: includes/class-wc-sc-coupons-by-product-quantity.php:120 +msgid "Cart" +msgstr "" + +#: includes/class-wc-sc-coupons-by-product-quantity.php:127 +msgid "Choose whether to validate the quantity, cart-wise or product-wise" +msgstr "" + +#: includes/class-wc-sc-coupons-by-product-quantity.php:131 +msgid "Minimum quantity" +msgstr "" + +#: includes/class-wc-sc-coupons-by-product-quantity.php:132 +#: includes/class-wc-sc-coupons-by-product-quantity.php:157 +#: includes/class-wc-sc-coupons-by-product-quantity.php:195 +#: includes/class-wc-sc-coupons-by-product-quantity.php:225 +#: includes/class-wc-sc-coupons-by-product-quantity.php:237 +msgid "No minimum" +msgstr "" + +#: includes/class-wc-sc-coupons-by-product-quantity.php:135 +msgid "Maximum quantity" +msgstr "" + +#: includes/class-wc-sc-coupons-by-product-quantity.php:136 +#: includes/class-wc-sc-coupons-by-product-quantity.php:158 +#: includes/class-wc-sc-coupons-by-product-quantity.php:196 +#: includes/class-wc-sc-coupons-by-product-quantity.php:226 +#: includes/class-wc-sc-coupons-by-product-quantity.php:238 +msgid "No maximum" +msgstr "" + +#: includes/class-wc-sc-coupons-by-product-quantity.php:153 +#: includes/class-wc-sc-coupons-by-product-quantity.php:169 +#: includes/class-wc-sc-coupons-by-product-quantity.php:245 +#: includes/class-wc-sc-coupons-by-product-quantity.php:260 +msgid "Products" +msgstr "" + +#: includes/class-wc-sc-coupons-by-product-quantity.php:171 +#: includes/class-wc-sc-coupons-by-product-quantity.php:247 +msgid "Please select some products" +msgstr "" + +#: includes/class-wc-sc-coupons-by-product-quantity.php:191 +#: includes/class-wc-sc-coupons-by-product-quantity.php:208 +#: includes/class-wc-sc-coupons-by-product-quantity.php:253 +#: includes/class-wc-sc-coupons-by-product-quantity.php:263 +msgid "Categories" +msgstr "" + +#: includes/class-wc-sc-coupons-by-product-quantity.php:210 +#: includes/class-wc-sc-coupons-by-product-quantity.php:255 +msgid "Please select some categories" +msgstr "" + +#: includes/class-wc-sc-coupons-by-product-quantity.php:523 +msgid "Your cart does not meet the quantity requirement." +msgstr "" + +#. translators: 1. Number of quantity 2. Singular or plural text based on number of quantities +#: includes/class-wc-sc-coupons-by-product-quantity.php:537 +msgid "Your cart should have a maximum of %1$d %2$s in total." +msgstr "" + +#. translators: 1. Number of quantity 2. Singular or plural text based on number of quantities +#: includes/class-wc-sc-coupons-by-product-quantity.php:541 +msgid "Your cart should have a minimum of %1$d %2$s in total." +msgstr "" + +#: includes/class-wc-sc-coupons-by-product-quantity.php:559 +#: includes/class-wc-sc-coupons-by-product-quantity.php:561 +#: includes/class-wc-sc-coupons-by-product-quantity.php:563 +msgid "Your cart does not meet the product quantity requirement." +msgstr "" + +#: includes/class-wc-sc-coupons-by-shipping-method.php:106 +#: includes/class-wc-sc-coupons-by-shipping-method.php:224 +msgid "Shipping methods" +msgstr "" + +#: includes/class-wc-sc-coupons-by-shipping-method.php:107 +msgid "No shipping methods" +msgstr "" + +#: includes/class-wc-sc-coupons-by-shipping-method.php:117 +msgid "Shipping methods that must be selected during checkout for this coupon to be valid." +msgstr "" + +#: includes/class-wc-sc-coupons-by-shipping-method.php:200 +#: includes/class-wc-sc-coupons-by-shipping-method.php:205 +msgid "This coupon is not valid for selected shipping method." +msgstr "" + +#: includes/class-wc-sc-coupons-by-taxonomy.php:103 +#: includes/class-wc-sc-coupons-by-taxonomy.php:290 +msgid "Include" +msgstr "" + +#: includes/class-wc-sc-coupons-by-taxonomy.php:104 +#: includes/class-wc-sc-coupons-by-taxonomy.php:291 +msgid "Exclude" +msgstr "" + +#: includes/class-wc-sc-coupons-by-taxonomy.php:141 +#: includes/class-wc-sc-coupons-by-taxonomy.php:182 +msgid "Taxonomy" +msgstr "" + +#: includes/class-wc-sc-coupons-by-taxonomy.php:142 +msgid "Product taxonomies that the coupon will be applicable for, or its availability in the cart in order for the \"Fixed cart discount\" to be applied, based on whether the taxonomies are included or excluded. All the taxonomies selected here, should be valid, for this coupon to be valid." +msgstr "" + +#: includes/class-wc-sc-coupons-by-taxonomy.php:146 +#: includes/class-wc-sc-coupons-by-taxonomy.php:219 +msgid "Add taxonomy restriction" +msgstr "" + +#: includes/class-wc-sc-coupons-by-taxonomy.php:183 +msgid "Product taxonomies that the coupon will be applicable for, or its availability in the cart in order for the \"Fixed cart discount\" to be applied, based on whether the taxonomies are included or excluded." +msgstr "" + +#: includes/class-wc-sc-coupons-by-taxonomy.php:219 +msgid "Remove taxonomy restriction" +msgstr "" + +#: includes/class-wc-sc-coupons-by-taxonomy.php:871 +msgid "Taxonomy based restrictions" +msgstr "" + +#: includes/class-wc-sc-coupons-by-user-role.php:116 +msgid "Allowed user roles" +msgstr "" + +#: includes/class-wc-sc-coupons-by-user-role.php:117 +#: includes/class-wc-sc-coupons-by-user-role.php:134 +msgid "No user roles" +msgstr "" + +#: includes/class-wc-sc-coupons-by-user-role.php:128 +msgid "Role of the users for whom this coupon is valid. Keep empty if you want this coupon to be valid for users with any role." +msgstr "" + +#: includes/class-wc-sc-coupons-by-user-role.php:133 +msgid "Exclude user roles" +msgstr "" + +#: includes/class-wc-sc-coupons-by-user-role.php:145 +msgid "Role of the users for whom this coupon is not valid. Keep empty if you want this coupon to be valid for users with any role." +msgstr "" + +#: includes/class-wc-sc-coupons-by-user-role.php:243 +msgid "User Role" +msgstr "" + +#: includes/class-wc-sc-coupons-by-user-role.php:244 +msgid "Exclude User Role" +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:278 +#: includes/class-wc-sc-display-coupons.php:869 +#: includes/class-wc-sc-display-coupons.php:2410 +#: includes/class-wc-sc-shortcode.php:540 +#: includes/class-wc-smart-coupons.php:4893 +#: templates/combined-email.php:125 +#: templates/email.php:123 +#: templates/print-coupons-default.php:142 +msgid " & " +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:280 +#: includes/class-wc-sc-display-coupons.php:871 +#: includes/class-wc-sc-display-coupons.php:2412 +#: includes/class-wc-sc-shortcode.php:542 +#: includes/class-wc-smart-coupons.php:4895 +#: templates/combined-email.php:127 +#: templates/email.php:125 +#: templates/plain/combined-email.php:93 +#: templates/plain/email.php:88 +#: templates/print-coupons-default.php:144 +msgid "Free Shipping" +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:297 +#: includes/class-wc-sc-display-coupons.php:885 +#: includes/class-wc-sc-display-coupons.php:2442 +#: includes/class-wc-sc-shortcode.php:572 +#: includes/class-wc-smart-coupons.php:4922 +#: includes/emails/class-wc-sc-email-coupon.php:173 +#: templates/combined-email.php:158 +#: templates/email.php:156 +#: templates/plain/combined-email.php:125 +#: templates/plain/email.php:120 +#: templates/print-coupons-default.php:176 +msgid "Never expires" +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:342 +#: includes/class-wc-sc-display-coupons.php:735 +#: includes/class-wc-sc-settings.php:662 +msgid "Available Coupons (click on a coupon to use it)" +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:540 +msgid "You will get following coupon(s) when you buy this item:" +msgstr "" + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-display-coupons.php:591 +msgid "%s of " +msgstr "" + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-display-coupons.php:591 +msgid "Store Credit of " +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:601 +msgid " discount on your entire purchase" +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:606 +#: includes/class-wc-sc-display-coupons.php:615 +#: includes/class-wc-sc-display-coupons.php:624 +msgid "some products" +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:608 +#: includes/class-wc-sc-display-coupons.php:617 +msgid "all products" +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:610 +#: includes/class-wc-sc-display-coupons.php:619 +msgid " discount on " +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:626 +msgid "your entire purchase" +msgstr "" + +#. translators: %s: Maximum coupon discount amount +#: includes/class-wc-sc-display-coupons.php:632 +#: includes/class-wc-smart-coupons.php:1168 +#: includes/emails/class-wc-sc-email-coupon.php:439 +msgid " upto %s" +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:634 +msgid " discount" +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:634 +msgid " on " +msgstr "" + +#. translators: 1. Discount type 2. Discount amount +#. translators: 1: coupon type 2: coupon amount +#: includes/class-wc-sc-display-coupons.php:641 +#: includes/emails/class-wc-sc-email-coupon.php:452 +msgid "%1$s coupon of %2$s" +msgstr "" + +#. translators: Add more detail to coupon description +#: includes/class-wc-sc-display-coupons.php:649 +msgid "%s Free Shipping" +msgstr "" + +#. translators: Add more detail to coupon description +#: includes/class-wc-sc-display-coupons.php:649 +msgid " &" +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:722 +#: includes/class-wc-sc-settings.php:630 +#: includes/class-wc-smart-coupons.php:296 +msgid "Select options" +msgstr "" + +#. translators: %s: plural name for store credit +#. translators: %s: Label for store credit +#: includes/class-wc-sc-display-coupons.php:749 +#: includes/class-wc-sc-display-coupons.php:940 +#: includes/class-wc-sc-settings.php:673 +msgid "Available Coupons & %s" +msgstr "" + +#. translators: %s: plural name for store credit +#: includes/class-wc-sc-display-coupons.php:749 +#: includes/class-wc-sc-display-coupons.php:940 +msgid "Available Coupons & Store Credits" +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:925 +#: includes/class-wc-sc-display-coupons.php:981 +msgid "Sorry, No coupons available for you." +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:978 +msgid "List of coupons which are valid & available for use. Click on the coupon to use it. The coupon discount will be visible only when at least one product is present in the cart." +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:1120 +#: templates/combined-email.php:228 +#: templates/email.php:209 +msgid "Print coupon" +msgid_plural "Print coupons" +msgstr[0] "" +msgstr[1] "" + +#: includes/class-wc-sc-display-coupons.php:1185 +msgid "Store Credits" +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:1194 +msgid "Total Credit Amount" +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:1213 +msgid "Discount Coupons" +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:1245 +msgid "Invalid / Used Coupons" +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:1260 +msgid "List of coupons which can not be used. The reason can be based on its usage restrictions, usage limits, expiry date." +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:1941 +msgid "Endpoint for the My Account → Coupons page" +msgstr "" + +#. translators: 1. Link to jump to 'Order actions' metabox 2. Text 'Order actions' 3. Text 'arrow' +#: includes/class-wc-sc-display-coupons.php:2107 +msgctxt "Generated coupons metabox - Order edit admin page" +msgid "Coupons are not generated for this order. You can regenerate it from %1$s. Select an appropriate action from the %2$s dropdown menu and hit the %3$s button next to it." +msgstr "" + +#. translators: 1. Link to jump to 'Order actions' metabox 2. Text 'Order actions' 3. Text 'arrow' +#: includes/class-wc-sc-display-coupons.php:2107 +msgctxt "Generated coupons metabox - Order edit admin page" +msgid "Order actions" +msgstr "" + +#. translators: 1. Link to jump to 'Order actions' metabox 2. Text 'Order actions' 3. Text 'arrow' +#: includes/class-wc-sc-display-coupons.php:2107 +msgctxt "Generated coupons metabox - Order edit admin page" +msgid "arrow" +msgstr "" + +#. translators: 1. Label for Order action for regenerating coupons +#: includes/class-wc-sc-display-coupons.php:2120 +msgctxt "Generated coupons metabox - Order edit admin page" +msgid "Select %s to only regenerate coupons. No email will be sent for this." +msgstr "" + +#. translators: 1. Label for Order action for regenerating & resending coupons +#: includes/class-wc-sc-display-coupons.php:2130 +msgctxt "Generated coupons metabox - Order edit admin page" +msgid "Select %s to regenerate as well as resend coupons to the recipients via email." +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:2167 +msgid "Coupon Received" +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:2168 +msgid "List of coupons & their details which you have received from the store. Click on the coupon to see the details." +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:2218 +#: includes/class-wc-sc-display-coupons.php:2229 +msgid "Less details" +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:2220 +#: includes/class-wc-sc-display-coupons.php:2232 +#: includes/class-wc-sc-display-coupons.php:2335 +msgid "More details" +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:2461 +#: includes/class-wc-sc-display-coupons.php:2498 +msgid "Sender" +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:2462 +#: includes/class-wc-sc-display-coupons.php:2496 +msgid "Receiver" +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:2494 +msgid "Code" +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:2495 +msgid "Amount" +msgstr "" + +#: includes/class-wc-sc-display-coupons.php:2595 +msgid "Generated coupons" +msgstr "" + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-order-fields.php:197 +msgid "%s Used" +msgstr "" + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-order-fields.php:197 +msgid "Store Credit Used" +msgstr "" + +#: includes/class-wc-sc-order-fields.php:199 +msgid "This is the total credit used." +msgstr "" + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-order-fields.php:254 +msgid "%s Used:" +msgstr "" + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-order-fields.php:254 +msgid "Store Credit Used:" +msgstr "" + +#: includes/class-wc-sc-order-fields.php:280 +#: templates/plain/combined-email.php:83 +#: templates/plain/email.php:78 +msgid "Discount:" +msgstr "" + +#: includes/class-wc-sc-order-fields.php:341 +msgid "Store Credit:" +msgstr "" + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-order-fields.php:501 +msgid "%s Balance " +msgstr "" + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-order-fields.php:501 +msgid "Store Credit / Gift Card Balance" +msgstr "" + +#: includes/class-wc-sc-print-coupon.php:123 +msgctxt "Page slug" +msgid "wc-sc-coupons-terms" +msgstr "" + +#: includes/class-wc-sc-print-coupon.php:124 +msgctxt "Page title" +msgid "Smart Coupons Terms" +msgstr "" + +#: includes/class-wc-sc-print-coupon.php:278 +msgid "Smart Coupons has created a coupon's terms page (used during coupon printing) for you. Please edit it as required from" +msgstr "" + +#: includes/class-wc-sc-print-coupon.php:420 +msgid "Used during coupon printing" +msgstr "" + +#. translators: Plugin's name +#: includes/class-wc-sc-privacy.php:51 +msgid "%s - Coupon Personal Data Exporter" +msgstr "" + +#. translators: Plugin's name +#: includes/class-wc-sc-privacy.php:53 +msgid "%s - Coupon Personal Data Eraser" +msgstr "" + +#. translators: Plugin's name +#: includes/class-wc-sc-privacy.php:56 +msgid "%s - Order Personal Data Exporter" +msgstr "" + +#. translators: Plugin's name +#: includes/class-wc-sc-privacy.php:58 +msgid "%s - Order Personal Data Eraser" +msgstr "" + +#. translators: Plugin's name +#: includes/class-wc-sc-privacy.php:61 +msgid "%s - User Personal Data Exporter" +msgstr "" + +#. translators: Plugin's name +#: includes/class-wc-sc-privacy.php:63 +msgid "%s - User Personal Data Eraser" +msgstr "" + +#: includes/class-wc-sc-privacy.php:112 +#: includes/class-wc-sc-privacy.php:324 +#: includes/class-wc-sc-privacy.php:443 +#: includes/class-wc-sc-privacy.php:734 +msgid "Store Credit/Gift Certificate" +msgstr "" + +#: includes/class-wc-sc-privacy.php:113 +msgid "What we access?" +msgstr "" + +#: includes/class-wc-sc-privacy.php:115 +msgid "If you are logged in: We access your billing email address saved in your account & billing email address entered during purchase" +msgstr "" + +#: includes/class-wc-sc-privacy.php:116 +msgid "If you are a visitor: We access your billing email address entered during purchase" +msgstr "" + +#: includes/class-wc-sc-privacy.php:118 +msgid "What we store & why?" +msgstr "" + +#: includes/class-wc-sc-privacy.php:120 +msgid "Coupon code generated for you" +msgstr "" + +#: includes/class-wc-sc-privacy.php:121 +msgid "Coupon code passed via URL" +msgstr "" + +#: includes/class-wc-sc-privacy.php:122 +msgid "Coupon amount, email & message entered for gift card receiver" +msgstr "" + +#: includes/class-wc-sc-privacy.php:124 +msgid "We store these data so that we can process it for you whenever required." +msgstr "" + +#: includes/class-wc-sc-privacy.php:247 +msgid "Store Credit/Gift Certificate - Coupon Data" +msgstr "" + +#: includes/class-wc-sc-privacy.php:324 +msgid "Removed Coupon Personal Data" +msgstr "" + +#: includes/class-wc-sc-privacy.php:384 +#: includes/emails/class-wc-sc-acknowledgement-email.php:342 +#: templates/acknowledgement-email.php:66 +#: templates/coupon-design/basic.php:39 +#: templates/coupon-design/clipper.php:38 +#: templates/coupon-design/cutout.php:55 +#: templates/coupon-design/deal.php:29 +#: templates/coupon-design/deliver.php:34 +#: templates/coupon-design/shipment.php:33 +#: templates/coupon-design/special.php:58 +#: templates/coupon-design/ticket.php:40 +#: templates/plain/acknowledgement-email.php:56 +msgid "Coupon" +msgid_plural "Coupons" +msgstr[0] "" +msgstr[1] "" + +#: includes/class-wc-sc-privacy.php:390 +msgid "Generated Coupon Data" +msgstr "" + +#: includes/class-wc-sc-privacy.php:401 +msgid "Coupon passed in URL" +msgstr "" + +#: includes/class-wc-sc-privacy.php:443 +msgid "Removed User Personal Data" +msgstr "" + +#: includes/class-wc-sc-privacy.php:599 +#: includes/class-wc-smart-coupons.php:4997 +msgid "Coupon Code" +msgstr "" + +#: includes/class-wc-sc-privacy.php:602 +#: includes/class-wc-smart-coupons.php:5009 +msgid "Coupon Amount" +msgstr "" + +#: includes/class-wc-sc-privacy.php:605 +msgid "Coupon For" +msgstr "" + +#: includes/class-wc-sc-privacy.php:618 +msgid "Store Credit/Gift Certificate - Order Data" +msgstr "" + +#: includes/class-wc-sc-privacy.php:734 +msgid "Removed Order Personal Data" +msgstr "" + +#: includes/class-wc-sc-privacy.php:816 +msgid "Retain Store Credit/Gift Certificate" +msgstr "" + +#: includes/class-wc-sc-privacy.php:817 +msgid "Store Credit/Gift Certificate that are stored for customers via coupons. If erased, the customer will not be able to use the coupons." +msgstr "" + +#: includes/class-wc-sc-privacy.php:820 +msgid "N/A" +msgstr "" + +#: includes/class-wc-sc-product-columns.php:102 +msgctxt "Title for coupon column on the products page" +msgid "Linked coupons" +msgstr "" + +#: includes/class-wc-sc-product-columns.php:235 +msgid "Open in a new tab" +msgstr "" + +#: includes/class-wc-sc-product-fields.php:100 +#: includes/class-wc-sc-product-fields.php:161 +msgid "Search for a coupon…" +msgstr "" + +#. translators: 1. Discount type 2. Discount Type Label +#: includes/class-wc-sc-product-fields.php:114 +#: includes/class-wc-sc-product-fields.php:175 +msgid " ( %1$s: %2$s )" +msgstr "" + +#: includes/class-wc-sc-product-fields.php:123 +#: includes/class-wc-sc-product-fields.php:160 +msgid "These coupon/s will be given to customers who buy this product. The coupon code will be automatically sent to their email address on purchase." +msgstr "" + +#: includes/class-wc-sc-product-fields.php:127 +#: includes/class-wc-sc-product-fields.php:186 +msgid "Send coupons on renewals?" +msgstr "" + +#: includes/class-wc-sc-product-fields.php:129 +#: includes/class-wc-sc-product-fields.php:185 +msgid "Check this box to send above coupons on each renewal order." +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:158 +msgid "Enter a numeric value." +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:161 +msgid "The value should not be less than" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:163 +msgid "The value should not be greater than" +msgstr "" + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-purchase-credit.php:218 +msgid "Purchase %s worth" +msgstr "" + +#. translators: %s: singular name for store credit +#: includes/class-wc-sc-purchase-credit.php:218 +#: includes/class-wc-sc-settings.php:642 +msgid "Purchase credit worth" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:535 +msgid "Now" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:545 +msgid "Later" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:615 +msgctxt "Timepicker on the frontend side" +msgid "Now" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:616 +msgctxt "Timepicker on the frontend side" +msgid "Done" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:680 +msgctxt "Timepicker on the frontend side" +msgid "HH:mm" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:682 +msgctxt "Timepicker on the frontend side" +msgid "Choose Time" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:683 +msgctxt "Timepicker on the frontend side" +msgid "Time" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:684 +msgctxt "Timepicker on the frontend side" +msgid "Hour" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:685 +msgctxt "Timepicker on the frontend side" +msgid "Minute" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:686 +msgctxt "Timepicker on the frontend side" +msgid "Second" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:687 +msgctxt "Timepicker on the frontend side" +msgid "Millisecond" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:688 +msgctxt "Timepicker on the frontend side" +msgid "Microsecond" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:689 +msgctxt "Timepicker on the frontend side" +msgid "Time Zone" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:820 +#: includes/class-wc-sc-settings.php:702 +msgid "Send Coupons to..." +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:832 +msgid "Your order contains coupons. You will receive them after completion of this order." +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:843 +msgid "Your order contains coupons. What would you like to do?" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:845 +msgid "Send to me" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:847 +msgid "Gift to someone else" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:849 +msgid "Send to one person" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:850 +msgid "Send to different people" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:854 +msgid "Deliver coupon" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:887 +#: includes/class-wc-sc-purchase-credit.php:998 +msgid "Enter recipient e-mail address" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:890 +#: includes/class-wc-sc-purchase-credit.php:1003 +msgid "Pick a delivery date & time" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:894 +#: includes/class-wc-sc-purchase-credit.php:1009 +msgid "Write a message" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:988 +msgid "Free Shipping coupon" +msgstr "" + +#. translators: 1. Coupon type 2. Coupon amount +#: includes/class-wc-sc-purchase-credit.php:997 +msgid "of" +msgstr "" + +#: includes/class-wc-sc-purchase-credit.php:1324 +#: includes/compat/class-wc-sc-kco-compatibility.php:123 +msgid "Failed to update coupon receiver details in session." +msgstr "" + +#. translators: %s: field name +#: includes/class-wc-sc-purchase-credit.php:1427 +msgid "Coupon delivery date and time is a required field." +msgstr "" + +#: includes/class-wc-sc-rest-coupons-controller.php:147 +msgid "The coupon code already exists" +msgstr "" + +#: includes/class-wc-sc-settings.php:94 +#: includes/blocks/sc-gutenberg-block.js:43 +msgid "Smart Coupons" +msgstr "" + +#: includes/class-wc-sc-settings.php:209 +#: includes/class-wc-sc-shortcode.php:892 +msgid "Preview" +msgstr "" + +#: includes/class-wc-sc-settings.php:211 +msgid "See coupon search limitations" +msgstr "" + +#: includes/class-wc-sc-settings.php:301 +#: includes/compat/class-wcs-sc-compatibility.php:947 +msgid "store credit" +msgstr "" + +#: includes/class-wc-sc-settings.php:302 +#: includes/class-wc-sc-settings.php:896 +msgid "store credits" +msgstr "" + +#: includes/class-wc-sc-settings.php:347 +msgid "Set up Smart Coupons the way you like. Use these options to configure/change the way Smart Coupons works." +msgstr "" + +#: includes/class-wc-sc-settings.php:351 +msgid "Colors" +msgstr "" + +#: includes/class-wc-sc-settings.php:355 +msgid "Choose a color scheme for coupons." +msgstr "" + +#: includes/class-wc-sc-settings.php:359 +msgid "Amaranth red" +msgstr "" + +#: includes/class-wc-sc-settings.php:360 +msgid "Carolina Blue" +msgstr "" + +#: includes/class-wc-sc-settings.php:361 +msgid "Keppel" +msgstr "" + +#: includes/class-wc-sc-settings.php:362 +msgid "McDonald" +msgstr "" + +#: includes/class-wc-sc-settings.php:363 +msgid "Gold" +msgstr "" + +#: includes/class-wc-sc-settings.php:364 +msgid "Majorelle Blue" +msgstr "" + +#: includes/class-wc-sc-settings.php:365 +msgid "Rose Pink" +msgstr "" + +#: includes/class-wc-sc-settings.php:366 +msgid "Vintage" +msgstr "" + +#: includes/class-wc-sc-settings.php:367 +msgid "Spanish Orange" +msgstr "" + +#: includes/class-wc-sc-settings.php:368 +msgid "Chocolate" +msgstr "" + +#: includes/class-wc-sc-settings.php:369 +msgid "Ocean" +msgstr "" + +#: includes/class-wc-sc-settings.php:376 +msgid "Customize colors" +msgstr "" + +#: includes/class-wc-sc-settings.php:380 +msgid "Customize color scheme for coupons." +msgstr "" + +#: includes/class-wc-sc-settings.php:384 +msgid "Custom colors" +msgstr "" + +#: includes/class-wc-sc-settings.php:391 +msgid "Styles" +msgstr "" + +#: includes/class-wc-sc-settings.php:395 +msgid "Choose a style for coupon on the website." +msgstr "" + +#: includes/class-wc-sc-settings.php:399 +msgid "Flat" +msgstr "" + +#: includes/class-wc-sc-settings.php:400 +msgid "Promotion" +msgstr "" + +#: includes/class-wc-sc-settings.php:401 +msgid "Ticket" +msgstr "" + +#: includes/class-wc-sc-settings.php:402 +msgid "Festive" +msgstr "" + +#: includes/class-wc-sc-settings.php:403 +msgid "Special" +msgstr "" + +#: includes/class-wc-sc-settings.php:404 +msgid "Shipment" +msgstr "" + +#: includes/class-wc-sc-settings.php:405 +msgid "Cutout" +msgstr "" + +#: includes/class-wc-sc-settings.php:406 +msgid "Deliver" +msgstr "" + +#: includes/class-wc-sc-settings.php:407 +msgid "Clipper" +msgstr "" + +#: includes/class-wc-sc-settings.php:408 +msgid "Basic" +msgstr "" + +#: includes/class-wc-sc-settings.php:409 +msgid "Deal" +msgstr "" + +#: includes/class-wc-sc-settings.php:416 +msgid "Style for email" +msgstr "" + +#: includes/class-wc-sc-settings.php:420 +msgid "Style for coupon in email." +msgstr "" + +#: includes/class-wc-sc-settings.php:424 +msgid "Email coupon" +msgstr "" + +#: includes/class-wc-sc-settings.php:431 +#: includes/class-wc-smart-coupons.php:5847 +msgid "Number of coupons to show" +msgstr "" + +#: includes/class-wc-sc-settings.php:432 +msgid "How many coupons (at max) should be shown on cart, checkout & my account page? If set to 0 (zero) then coupons will not be displayed at all on the website." +msgstr "" + +#: includes/class-wc-sc-settings.php:440 +#: includes/class-wc-smart-coupons.php:5848 +msgid "Number of characters in auto-generated coupon code" +msgstr "" + +#: includes/class-wc-sc-settings.php:441 +msgid "Number of characters in auto-generated coupon code will be restricted to this number excluding prefix and/or suffix. The default length will be 13. It is recommended to keep this number between 10 to 15 to avoid coupon code duplication." +msgstr "" + +#: includes/class-wc-sc-settings.php:455 +#: includes/class-wc-smart-coupons.php:5849 +msgid "Valid order status for auto-generating coupon" +msgstr "" + +#: includes/class-wc-sc-settings.php:456 +msgid "Choose order status which will trigger the auto-generation of coupon, if the order contains product which will generate the coupon." +msgstr "" + +#: includes/class-wc-sc-settings.php:465 +msgid "Select order status…" +msgstr "" + +#: includes/class-wc-sc-settings.php:470 +msgid "Enable store notice for the coupon" +msgstr "" + +#: includes/class-wc-sc-settings.php:474 +msgid "Search & select a coupon which you want to display as store notice. The selected coupon's description will be displayed along with the coupon code (if it is set) otherwise, a description will be generated automatically. To disable the feature, keep this field empty." +msgstr "" + +#: includes/class-wc-sc-settings.php:480 +msgid "Search for a coupon..." +msgstr "" + +#. translators: %s: Label for store credit +#: includes/class-wc-sc-settings.php:489 +msgid "Generated %s amount" +msgstr "" + +#. translators: %s: Label for store credit +#: includes/class-wc-sc-settings.php:491 +msgid "Include tax in the amount of the generated %s" +msgstr "" + +#: includes/class-wc-sc-settings.php:499 +msgid "Displaying coupons" +msgstr "" + +#. translators: %s: Preview link +#: includes/class-wc-sc-settings.php:501 +msgid "Include coupon details on product's page, for products that issue coupons %s" +msgstr "" + +#. translators: %s: Preview link +#: includes/class-wc-sc-settings.php:501 +#: includes/class-wc-sc-settings.php:510 +#: includes/class-wc-sc-settings.php:519 +#: includes/class-wc-sc-settings.php:528 +#: includes/class-wc-sc-settings.php:537 +#: includes/class-wc-sc-settings.php:625 +#: includes/class-wc-sc-settings.php:637 +#: includes/class-wc-sc-settings.php:648 +#: includes/class-wc-sc-settings.php:658 +#: includes/class-wc-sc-settings.php:668 +#: includes/class-wc-sc-settings.php:689 +#: includes/class-wc-sc-settings.php:698 +#: includes/class-wc-sc-settings.php:708 +#: includes/class-wc-sc-settings.php:717 +msgid "[Preview]" +msgstr "" + +#. translators: %s: Preview link +#: includes/class-wc-sc-settings.php:510 +msgid "Show coupons available to customers on their My Account > Coupons page %s" +msgstr "" + +#. translators: %s: Preview link +#: includes/class-wc-sc-settings.php:519 +msgid "Include coupons received from other people on My Account > Coupons page %s" +msgstr "" + +#. translators: %s: Preview link +#: includes/class-wc-sc-settings.php:528 +msgid "Show invalid or used coupons in My Account > Coupons %s" +msgstr "" + +#. translators: %s: Preview link +#: includes/class-wc-sc-settings.php:537 +msgid "Display coupon description along with coupon code (on site as well as in emails) %s" +msgstr "" + +#: includes/class-wc-sc-settings.php:545 +msgid "Auto apply coupons" +msgstr "" + +#. translators: %s: Explanation of the setting +#: includes/class-wc-sc-settings.php:547 +msgid "When enabled, each coupon will have the option to enable auto-apply for that coupon %s" +msgstr "" + +#. translators: %s: Explanation of the setting +#: includes/class-wc-sc-settings.php:547 +msgid "Disabling this, no coupons will be auto-applied - even if any coupon has \"Auto apply?\" enabled." +msgstr "" + +#: includes/class-wc-sc-settings.php:555 +#: includes/class-wc-smart-coupons.php:5853 +msgid "Automatic deletion" +msgstr "" + +#. translators: %s: Note for admin +#: includes/class-wc-sc-settings.php:557 +msgid "Delete the %1$s when entire credit amount is used up %2$s" +msgstr "" + +#. translators: %s: Note for admin +#: includes/class-wc-sc-settings.php:557 +msgid "(Note: It's recommended to keep it Disabled)" +msgstr "" + +#: includes/class-wc-sc-settings.php:565 +#: includes/class-wc-smart-coupons.php:5854 +msgid "Coupon emails" +msgstr "" + +#: includes/class-wc-sc-settings.php:566 +msgid "Email auto generated coupons to recipients" +msgstr "" + +#: includes/class-wc-sc-settings.php:574 +#: includes/class-wc-smart-coupons.php:5855 +msgid "Printing coupons" +msgstr "" + +#: includes/class-wc-sc-settings.php:575 +msgid "Enable feature to allow printing of coupons" +msgstr "" + +#. translators: %s: Label for store credit, 1: : Label for store credit, 2: Label for store credit, 3: Label for store credit +#: includes/class-wc-sc-settings.php:575 +#: includes/class-wc-sc-settings.php:586 +#: includes/class-wc-sc-settings.php:606 +msgid "[Read More]" +msgstr "" + +#. translators: %s: Label for store credit +#: includes/class-wc-sc-settings.php:584 +msgid "Sell %s at less price?" +msgstr "" + +#. translators: %s: Label for store credit, 1: : Label for store credit, 2: Label for store credit, 3: Label for store credit +#: includes/class-wc-sc-settings.php:586 +msgid "Allow selling %s at discounted price" +msgstr "" + +#. translators: %s: Label for store credit, 1: : Label for store credit, 2: Label for store credit, 3: Label for store credit +#: includes/class-wc-sc-settings.php:586 +msgid "When selling %1$s, if Regular and Sale price is found for the product, then coupon will be created with product's Regular Price but customer will pay product's Sale price. This setting will also make sure if any discount coupon is applied on the %2$s while purchasing, then customer will get %3$s in their picked price" +msgstr "" + +#: includes/class-wc-sc-settings.php:599 +msgid "Labels" +msgstr "" + +#: includes/class-wc-sc-settings.php:601 +msgid "Call it something else! Use these to quickly change text labels through your store. Use translations for complete control." +msgstr "" + +#: includes/class-wc-sc-settings.php:609 +msgid "Singular name" +msgstr "" + +#: includes/class-wc-sc-settings.php:610 +msgid "Give alternate singular name to Store Credit / Gift Certificate. This label will only rename Store Credit / Gift Certificate used in the Smart Coupons plugin." +msgstr "" + +#: includes/class-wc-sc-settings.php:617 +msgid "Give plural name for the above singular name." +msgstr "" + +#: includes/class-wc-sc-settings.php:618 +msgid "Plural name" +msgstr "" + +#. translators: %s: Label for store credit +#: includes/class-wc-sc-settings.php:624 +msgid "%s product CTA" +msgstr "" + +#. translators: %s: Label for store credit +#: includes/class-wc-sc-settings.php:629 +msgid "This is what will be shown instead of \"Add to Cart\" for products that sell %s." +msgstr "" + +#. translators: %s: Label for store credit +#: includes/class-wc-sc-settings.php:636 +msgid "While purchasing %s" +msgstr "" + +#. translators: %s: Label for store credit +#: includes/class-wc-sc-settings.php:641 +msgid "When you opt to allow people to buy %s of any amount, this label will be used." +msgstr "" + +#: includes/class-wc-sc-settings.php:647 +msgid "\"Coupons with Product\" description" +msgstr "" + +#: includes/class-wc-sc-settings.php:651 +msgid "This is the heading above coupon details displayed on products that issue coupons." +msgstr "" + +#: includes/class-wc-sc-settings.php:652 +msgid "You will get following coupon(s) when you buy this item" +msgstr "" + +#: includes/class-wc-sc-settings.php:657 +msgid "On Cart/Checkout pages" +msgstr "" + +#: includes/class-wc-sc-settings.php:661 +msgid "This is the title for the list of available coupons, shown on Cart and Checkout pages." +msgstr "" + +#: includes/class-wc-sc-settings.php:667 +msgid "My Account page" +msgstr "" + +#: includes/class-wc-sc-settings.php:671 +msgid "Title of available coupons list on My Account page." +msgstr "" + +#: includes/class-wc-sc-settings.php:682 +msgid "Coupon Receiver Details during Checkout" +msgstr "" + +#: includes/class-wc-sc-settings.php:684 +msgid "Buyers can send purchased coupons to anyone – right while they're checking out." +msgstr "" + +#: includes/class-wc-sc-settings.php:688 +#: includes/class-wc-smart-coupons.php:5859 +msgid "Allow sending of coupons to others" +msgstr "" + +#: includes/class-wc-sc-settings.php:689 +msgid "Allow the buyer to send coupons to someone else." +msgstr "" + +#: includes/class-wc-sc-settings.php:697 +msgid "Title" +msgstr "" + +#: includes/class-wc-sc-settings.php:701 +msgid "The title for coupon receiver details block." +msgstr "" + +#: includes/class-wc-sc-settings.php:707 +msgid "Description" +msgstr "" + +#: includes/class-wc-sc-settings.php:711 +msgid "Additional text below the title." +msgstr "" + +#: includes/class-wc-sc-settings.php:716 +#: includes/class-wc-smart-coupons.php:5860 +msgid "Allow schedule sending of coupons?" +msgstr "" + +#: includes/class-wc-sc-settings.php:717 +msgid "Enable this to allow buyers to select date & time for delivering the coupon." +msgstr "" + +#: includes/class-wc-sc-settings.php:717 +msgid "The coupons will be sent to the recipients via email on the selected date & time" +msgstr "" + +#: includes/class-wc-sc-settings.php:726 +#: includes/class-wc-smart-coupons.php:5861 +msgid "Combine emails" +msgstr "" + +#: includes/class-wc-sc-settings.php:727 +msgid "Send only one email instead of multiple emails when multiple coupons are generated for same recipient" +msgstr "" + +#: includes/class-wc-sc-settings.php:741 +msgid "Apply before tax" +msgstr "" + +#: includes/class-wc-sc-settings.php:742 +#: includes/class-wc-smart-coupons.php:5851 +msgid "Deduct credit/gift before doing tax calculations" +msgstr "" + +#. translators: %s: Label for store credit +#: includes/class-wc-sc-settings.php:756 +msgid "%s include tax?" +msgstr "" + +#. translators: %s: Label for store credit +#: includes/class-wc-sc-settings.php:758 +msgid "%s discount is inclusive of tax" +msgstr "" + +#. translators: 1: plugin name 2: page based text 3: Label for store credit 4: Hide notice text +#: includes/class-wc-sc-settings.php:903 +#: includes/class-wc-sc-settings.php:906 +msgid "%1$s: %2$s to avoid issues related to missing data for %3$s. %4$s" +msgstr "" + +#. translators: 1: plugin name 2: page based text 3: Label for store credit 4: Hide notice text +#: includes/class-wc-sc-settings.php:903 +msgid "Uncheck" +msgstr "" + +#. translators: 1: plugin name 2: page based text 3: Label for store credit 4: Hide notice text +#: includes/class-wc-sc-settings.php:903 +msgid "Delete Gift / Credit, when credit is used up" +msgstr "" + +#. translators: 1: plugin name 2: page based text 3: Label for store credit 4: Hide notice text +#: includes/class-wc-sc-settings.php:903 +#: includes/class-wc-sc-settings.php:906 +msgid "Setting" +msgstr "" + +#. translators: 1: plugin name 2: page based text 3: Label for store credit 4: Hide notice text +#: includes/class-wc-sc-settings.php:903 +#: includes/class-wc-sc-settings.php:906 +msgid "Hide this notice" +msgstr "" + +#. translators: 1: plugin name 2: page based text 3: Label for store credit 4: Hide notice text +#: includes/class-wc-sc-settings.php:906 +msgid "Important setting" +msgstr "" + +#: includes/class-wc-sc-settings.php:1052 +msgid "Hurry. Going fast! On the entire range of products." +msgstr "" + +#: includes/class-wc-sc-shortcode.php:607 +#: templates/combined-email.php:195 +#: templates/email.php:182 +msgid "Click to visit store. This coupon will be applied automatically." +msgstr "" + +#: includes/class-wc-sc-shortcode.php:805 +#: includes/class-wc-sc-shortcode.php:846 +#: includes/class-wc-sc-shortcode.php:883 +msgid "No search term specified." +msgstr "" + +#: includes/class-wc-sc-shortcode.php:809 +msgid "Enter more than one character to search." +msgstr "" + +#: includes/class-wc-sc-shortcode.php:825 +msgid "Click to select coupon code." +msgstr "" + +#: includes/class-wc-sc-shortcode.php:827 +msgid "No coupon code found." +msgstr "" + +#: includes/class-wc-sc-shortcode.php:879 +msgid "Coupon code" +msgstr "" + +#: includes/class-wc-sc-shortcode.php:879 +msgid "Search coupon..." +msgstr "" + +#: includes/class-wc-sc-shortcode.php:941 +msgid "Insert Shortcode" +msgstr "" + +#: includes/class-wc-sc-shortcode.php:944 +msgid "Cancel" +msgstr "" + +#. translators: %s: $coupon_code coupon code +#: includes/class-wc-sc-url-coupon.php:343 +msgctxt "This notice will be shown on the cart or the checkout page if the coupon will be applied successfully." +msgid "Coupon code \"%s\" applied successfully. Please add some products to the cart to see the discount." +msgstr "" + +#. translators: %s: $coupon_code coupon code +#: includes/class-wc-sc-url-coupon.php:347 +msgctxt "This notice will be shown on the cart or the checkout page if the coupon is already applied." +msgid "Coupon code \"%s\" already applied! Please add some products to the cart to see the discount." +msgstr "" + +#: includes/class-wc-smart-coupons.php:71 +msgid "Cheatin’ huh?" +msgstr "" + +#: includes/class-wc-smart-coupons.php:977 +msgid "This coupon has pending emails to be sent. Deleting it will delete those emails also. Are you sure to delete this coupon?" +msgstr "" + +#: includes/class-wc-smart-coupons.php:986 +msgid "An error has occurred. Please try again later." +msgstr "" + +#. translators: Formatted minimum amount +#: includes/class-wc-smart-coupons.php:1231 +msgid "Spend at least %s" +msgstr "" + +#. translators: Formatted maximum amount +#: includes/class-wc-smart-coupons.php:1235 +msgid "Spend up to %s" +msgstr "" + +#. translators: Formatted maximum amount +#: includes/class-wc-smart-coupons.php:1239 +msgid "Not valid for sale items" +msgstr "" + +#. translators: Product names +#: includes/class-wc-smart-coupons.php:1245 +msgid "Valid for %s" +msgstr "" + +#. translators: Excluded product names +#: includes/class-wc-smart-coupons.php:1251 +msgid "Not valid for %s" +msgstr "" + +#. translators: 1: The category names +#: includes/class-wc-smart-coupons.php:1258 +msgid "Valid for category %s" +msgid_plural "Valid for categories %s" +msgstr[0] "" +msgstr[1] "" + +#. translators: 1: The category names excluded +#: includes/class-wc-smart-coupons.php:1265 +msgid "Not valid for category %s" +msgid_plural "Not valid for categories %s" +msgstr[0] "" +msgstr[1] "" + +#. translators: 1: The expiry date +#: includes/class-wc-smart-coupons.php:1278 +msgid "Expiry: %s" +msgstr "" + +#: includes/class-wc-smart-coupons.php:1287 +msgid "Valid on entire range of products. Buy anything in the store." +msgstr "" + +#: includes/class-wc-smart-coupons.php:1603 +msgid "Great News!" +msgstr "" + +#: includes/class-wc-smart-coupons.php:1604 +msgid "Super Savings!" +msgstr "" + +#: includes/class-wc-smart-coupons.php:1605 +msgid "Ending Soon!" +msgstr "" + +#: includes/class-wc-smart-coupons.php:1606 +msgid "Limited Time Offer!" +msgstr "" + +#: includes/class-wc-smart-coupons.php:1607 +msgid "This Week Only!" +msgstr "" + +#: includes/class-wc-smart-coupons.php:1608 +msgid "Attention!" +msgstr "" + +#: includes/class-wc-smart-coupons.php:1609 +msgid "You don't want to miss this..." +msgstr "" + +#: includes/class-wc-smart-coupons.php:1610 +msgid "This will be over soon! Hurry." +msgstr "" + +#: includes/class-wc-smart-coupons.php:1611 +msgid "Act before the offer expires." +msgstr "" + +#: includes/class-wc-smart-coupons.php:1612 +msgid "Don't Miss Out." +msgstr "" + +#. translators: 1. The discount text +#: includes/class-wc-smart-coupons.php:1617 +msgid "%s discount on anything you want." +msgstr "" + +#. translators: 1. The discount text +#: includes/class-wc-smart-coupons.php:1619 +msgid "%s discount on entire store." +msgstr "" + +#. translators: 1. The discount text +#: includes/class-wc-smart-coupons.php:1621 +msgid "Pick any item today for %s off." +msgstr "" + +#. translators: 1. The discount text +#: includes/class-wc-smart-coupons.php:1623 +msgid "Buy as much as you want. Flat %s off everything." +msgstr "" + +#. translators: 1. The discount text +#: includes/class-wc-smart-coupons.php:1625 +msgid "Flat %s discount on everything today." +msgstr "" + +#: includes/class-wc-smart-coupons.php:1637 +msgid "Use code" +msgstr "" + +#. translators: 1. The coupon code +#: includes/class-wc-smart-coupons.php:1654 +msgid "Use code: %s" +msgstr "" + +#. translators: Discount amount applied on tax +#: includes/class-wc-smart-coupons.php:2777 +msgid "excludes -%s on tax" +msgstr "" + +#. translators: Discount amount applied on tax +#: includes/class-wc-smart-coupons.php:2780 +msgid "includes -%s on tax" +msgstr "" + +#: includes/class-wc-smart-coupons.php:3274 +msgid "WooCommerce Smart Coupons Cache" +msgstr "" + +#: includes/class-wc-smart-coupons.php:3275 +msgid "Clear Smart Coupons Cache" +msgstr "" + +#: includes/class-wc-smart-coupons.php:3276 +msgid "This tool will clear the cache created by WooCommerce Smart Coupons." +msgstr "" + +#. translators: The coupon code +#: includes/class-wc-smart-coupons.php:3319 +msgid "Coupon %s is valid for a new user only, hence removed." +msgstr "" + +#. translators: The coupon code +#: includes/class-wc-smart-coupons.php:3378 +msgid "Coupon removed. There is no credit remaining in %s." +msgstr "" + +#: includes/class-wc-smart-coupons.php:3416 +msgid "This coupon is valid for the first order only." +msgstr "" + +#: includes/class-wc-smart-coupons.php:4224 +msgid "Filter by category" +msgstr "" + +#: includes/class-wc-smart-coupons.php:4244 +msgid "Please select at least one coupon to print." +msgstr "" + +#: includes/class-wc-smart-coupons.php:4259 +msgid "Print selected coupons" +msgstr "" + +#: includes/class-wc-smart-coupons.php:4259 +msgid "Print" +msgstr "" + +#: includes/class-wc-smart-coupons.php:4648 +msgid "Coupon Validity" +msgstr "" + +#: includes/class-wc-smart-coupons.php:4649 +msgid "Validity Suffix" +msgstr "" + +#: includes/class-wc-smart-coupons.php:4650 +msgid "Auto Generate Coupon" +msgstr "" + +#: includes/class-wc-smart-coupons.php:4651 +msgid "Coupon Title Prefix" +msgstr "" + +#: includes/class-wc-smart-coupons.php:4652 +msgid "Coupon Title Suffix" +msgstr "" + +#: includes/class-wc-smart-coupons.php:4653 +msgid "Is Pick Price of Product" +msgstr "" + +#: includes/class-wc-smart-coupons.php:4654 +msgid "Disable Email Restriction" +msgstr "" + +#: includes/class-wc-smart-coupons.php:4655 +msgid "Coupon Is Visible Storewide" +msgstr "" + +#: includes/class-wc-smart-coupons.php:4998 +msgid "Post Excerpt" +msgstr "" + +#: includes/class-wc-smart-coupons.php:4999 +msgid "Post Status" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5000 +msgid "Post Parent" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5001 +msgid "Menu Order" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5002 +msgid "Post Date" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5008 +msgid "Discount Type" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5010 +msgid "Free shipping" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5011 +msgid "Expiry date" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5012 +msgid "Minimum Spend" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5013 +msgid "Maximum Spend" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5014 +msgid "Individual USe" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5015 +msgid "Exclude Sale Items" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5016 +msgid "Product IDs" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5017 +msgid "Exclude product IDs" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5018 +msgid "Product categories" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5019 +msgid "Exclude Product categories" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5020 +msgid "Customer Email" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5021 +msgid "Usage Limit" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5022 +msgid "Usage Limit Per User" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5023 +msgid "Limit Usage to X Items" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5024 +msgid "Usage Count" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5025 +msgid "Used By" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5031 +msgid "Coupon Category" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5142 +msgctxt "enhanced select" +msgid "Loading failed" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5280 +msgid "Style 1" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5281 +msgid "Style 2" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5282 +msgid "Style 3" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5283 +msgid "Style 4" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5284 +msgid "Style 5" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5285 +msgid "Style 6" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5286 +msgid "Custom Style" +msgstr "" + +#. translators: File path +#: includes/class-wc-smart-coupons.php:5317 +#: includes/class-wc-smart-coupons.php:5325 +msgid "File not found %s" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5409 +msgid "is active but it will only work with WooCommerce 3.0.0+." +msgstr "" + +#: includes/class-wc-smart-coupons.php:5409 +msgid "Please update WooCommerce to the latest version" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5850 +msgid "Include tax in the amount of the generated gift card" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5852 +msgid "Gift Card discount is inclusive of tax" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5856 +msgid "Sell gift cards at less price?" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5857 +msgid "Use gift card applied in first subscription order for subsequent renewals until credit reaches zero" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5858 +#: includes/compat/class-wcs-sc-compatibility.php:961 +msgid "Renewal orders should not generate coupons even when they include a product that issues coupons" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5862 +msgid "Auto generated coupon email" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5863 +msgid "Combined auto generated coupons email" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5864 +msgid "Acknowledgement email" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5865 +msgid "Enable taxes" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5866 +msgid "Prices entered with tax" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5867 +msgid "Display prices in the shop" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5868 +msgid "Display prices during cart and checkout" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5869 +msgid "Rounding" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5870 +msgid "Display tax totals" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5871 +msgid "Enable the use of coupon codes" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5872 +msgid "Calculate coupon discounts sequentially" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5873 +msgid "Account endpoints > Coupons" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5874 +msgid "Block-enabled Cart" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5875 +msgid "Block-enabled Checkout" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5876 +msgid "WooCommerce Account Connected" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5883 +msgid "Smart Coupons related settings" +msgstr "" + +#: includes/class-wc-smart-coupons.php:5883 +msgid "This section shows settings that affects Smart Coupons' functionalities." +msgstr "" + +#: includes/class-wc-smart-coupons.php:6022 +msgid "$coupon is not an object of WC_Coupon" +msgstr "" + +#: includes/class-wc-smart-coupons.php:6024 +msgid "$coupon is: " +msgstr "" + +#: includes/class-wc-smart-coupons.php:6122 +#: includes/class-wc-smart-coupons.php:6237 +#: includes/class-wc-smart-coupons.php:6351 +msgid "Some values required for $post_id & $meta_key" +msgstr "" + +#: includes/class-wc-smart-coupons.php:6124 +#: includes/class-wc-smart-coupons.php:6239 +#: includes/class-wc-smart-coupons.php:6353 +msgid "$post_id is: " +msgstr "" + +#: includes/class-wc-smart-coupons.php:6125 +#: includes/class-wc-smart-coupons.php:6240 +#: includes/class-wc-smart-coupons.php:6354 +msgid "$meta_key is: " +msgstr "" + +#: includes/class-wc-smart-coupons.php:6395 +#: includes/class-wc-smart-coupons.php:6450 +msgid "$key is required" +msgstr "" + +#: includes/class-wc-smart-coupons.php:6397 +#: includes/class-wc-smart-coupons.php:6452 +msgid "$key is: " +msgstr "" + +#: includes/class-wc-smart-coupons.php:6507 +#: includes/class-wc-smart-coupons.php:6561 +#: includes/class-wc-smart-coupons.php:6590 +#: includes/class-wc-smart-coupons.php:6614 +msgid "Some values required for $item_id & $item_key" +msgstr "" + +#: includes/class-wc-smart-coupons.php:6509 +#: includes/class-wc-smart-coupons.php:6563 +#: includes/class-wc-smart-coupons.php:6592 +#: includes/class-wc-smart-coupons.php:6616 +#: includes/class-wc-smart-coupons.php:6770 +msgid "$item_id is: " +msgstr "" + +#: includes/class-wc-smart-coupons.php:6510 +#: includes/class-wc-smart-coupons.php:6564 +#: includes/class-wc-smart-coupons.php:6593 +#: includes/class-wc-smart-coupons.php:6617 +msgid "$item_key is: " +msgstr "" + +#: includes/class-wc-smart-coupons.php:6642 +#: includes/class-wc-smart-coupons.php:6690 +msgid "$item is not an object of WC_Order_Item" +msgstr "" + +#: includes/class-wc-smart-coupons.php:6644 +#: includes/class-wc-smart-coupons.php:6692 +msgid "$item is: " +msgstr "" + +#: includes/class-wc-smart-coupons.php:6768 +msgid "$item_id is required" +msgstr "" + +#. translators: Email address of users +#: includes/class-wc-smart-coupons.php:7070 +msgid "Find coupons restricted to %s" +msgstr "" + +#: includes/class-wc-smart-coupons.php:7377 +msgid "Added by coupon" +msgstr "" + +#. translators: %s: singular name for store credit +#: includes/compat/class-wcs-sc-compatibility.php:894 +msgid "Order paid by %s" +msgstr "" + +#. translators: %s: singular name for store credit +#: includes/compat/class-wcs-sc-compatibility.php:894 +msgid "Order paid by store credit." +msgstr "" + +#: includes/compat/class-wcs-sc-compatibility.php:951 +msgid "Recurring subscriptions" +msgstr "" + +#. translators: %s: Label for store credit +#: includes/compat/class-wcs-sc-compatibility.php:953 +msgid "Use %s applied in first subscription order for subsequent renewals until credit reaches zero" +msgstr "" + +#: includes/compat/class-wcs-sc-compatibility.php:1072 +msgid "Active for x payments" +msgstr "" + +#: includes/emails/class-wc-sc-acknowledgement-email.php:41 +msgid "Smart Coupons - Acknowledgement email" +msgstr "" + +#: includes/emails/class-wc-sc-acknowledgement-email.php:42 +msgid "Send an acknowledgement email to the purchaser. One email per customer." +msgstr "" + +#: includes/emails/class-wc-sc-acknowledgement-email.php:68 +msgid "{site_title}: {coupon_type} sent successfully" +msgstr "" + +#: includes/emails/class-wc-sc-acknowledgement-email.php:77 +msgid "{coupon_type} sent successfully" +msgstr "" + +#: includes/emails/class-wc-sc-acknowledgement-email.php:86 +msgid "{site_title}: {coupon_type} has been successfully scheduled" +msgstr "" + +#: includes/emails/class-wc-sc-acknowledgement-email.php:95 +msgid "{coupon_type} has been successfully scheduled" +msgstr "" + +#. translators: %s: list of placeholders +#: includes/emails/class-wc-sc-acknowledgement-email.php:104 +msgid "This will be used when the setting \"WooCommerce > Settings > Smart Coupons > Allow schedule sending of coupons?\" is enabled. Available placeholders: %s." +msgstr "" + +#: includes/emails/class-wc-sc-acknowledgement-email.php:108 +msgid "Scheduled email subject" +msgstr "" + +#: includes/emails/class-wc-sc-acknowledgement-email.php:116 +msgid "Scheduled email heading" +msgstr "" + +#: includes/emails/class-wc-sc-acknowledgement-email.php:336 +#: templates/acknowledgement-email.php:61 +#: templates/plain/acknowledgement-email.php:51 +msgid "Gift card" +msgstr "" + +#: includes/emails/class-wc-sc-acknowledgement-email.php:337 +#: templates/acknowledgement-email.php:62 +#: templates/plain/acknowledgement-email.php:52 +msgid "Gift cards" +msgstr "" + +#: includes/emails/class-wc-sc-combined-email-coupon.php:34 +msgid "Smart Coupons - Combined auto generated coupons email" +msgstr "" + +#: includes/emails/class-wc-sc-combined-email-coupon.php:35 +msgid "Send only one email instead of multiple emails when multiple coupons are generated per recipient." +msgstr "" + +#: includes/emails/class-wc-sc-combined-email-coupon.php:61 +msgid "{site_title}: Congratulations! You've received coupons from {sender_name}" +msgstr "" + +#: includes/emails/class-wc-sc-combined-email-coupon.php:70 +msgid "You have received coupons." +msgstr "" + +#: includes/emails/class-wc-sc-combined-email-coupon.php:144 +#: includes/emails/class-wc-sc-combined-email-coupon.php:221 +#: includes/emails/class-wc-sc-email-coupon.php:202 +#: includes/emails/class-wc-sc-email-coupon.php:281 +msgid "from" +msgstr "" + +#: includes/emails/class-wc-sc-email-coupon.php:34 +msgid "Smart Coupons - Auto generated coupon email" +msgstr "" + +#: includes/emails/class-wc-sc-email-coupon.php:35 +msgid "Email auto generated coupon to recipients. One email per coupon." +msgstr "" + +#: includes/emails/class-wc-sc-email-coupon.php:64 +msgid "{site_title}: Congratulations! You've received a {coupon_type} from {sender_name}" +msgstr "" + +#: includes/emails/class-wc-sc-email-coupon.php:73 +msgid "You have received a {coupon_type} {coupon_value}" +msgstr "" + +#: includes/emails/class-wc-sc-email-coupon.php:355 +#: includes/emails/class-wc-sc-email-coupon.php:479 +msgid "Gift Card" +msgstr "" + +#. translators: %s coupon amount +#: includes/emails/class-wc-sc-email-coupon.php:398 +msgid "worth %s " +msgstr "" + +#. translators: %s: coupon amount +#: includes/emails/class-wc-sc-email-coupon.php:403 +msgid "worth %s (for entire purchase) " +msgstr "" + +#: includes/emails/class-wc-sc-email-coupon.php:408 +#: includes/emails/class-wc-sc-email-coupon.php:419 +#: includes/emails/class-wc-sc-email-coupon.php:430 +msgid "for some products" +msgstr "" + +#: includes/emails/class-wc-sc-email-coupon.php:410 +#: includes/emails/class-wc-sc-email-coupon.php:421 +msgid "for all products" +msgstr "" + +#. translators: 1: coupon amount 2: discount for text +#: includes/emails/class-wc-sc-email-coupon.php:414 +msgid "worth %1$s (%2$s) " +msgstr "" + +#. translators: 1: coupon amount 2: discount for text +#: includes/emails/class-wc-sc-email-coupon.php:425 +msgid "worth %1$s%% (%2$s) " +msgstr "" + +#: includes/emails/class-wc-sc-email-coupon.php:432 +msgid "for entire purchase" +msgstr "" + +#. translators: 1: coupon amount 2: max discount text 3: discount for text +#: includes/emails/class-wc-sc-email-coupon.php:443 +msgid "worth %1$s%% %2$s (%3$s) " +msgstr "" + +#. translators: 1: email heading 2: suffix +#: includes/emails/class-wc-sc-email-coupon.php:460 +msgid "%1$s Free Shipping%2$s" +msgstr "" + +#. translators: 1: email heading 2: suffix +#: includes/emails/class-wc-sc-email-coupon.php:460 +msgid "&" +msgstr "" + +#. translators: 1: email heading 2: suffix +#: includes/emails/class-wc-sc-email-coupon.php:460 +msgid "You have received a" +msgstr "" + +#. translators: 1: email heading 2: suffix +#: includes/emails/class-wc-sc-email-coupon.php:460 +msgid " coupon" +msgstr "" + +#. translators: %s: list of placeholders +#: includes/emails/class-wc-sc-email.php:97 +msgid "Available placeholders: %s" +msgstr "" + +#: includes/emails/class-wc-sc-email.php:101 +msgid "Enable/Disable" +msgstr "" + +#: includes/emails/class-wc-sc-email.php:103 +msgid "Enable this email notification" +msgstr "" + +#: includes/emails/class-wc-sc-email.php:107 +msgid "Email type" +msgstr "" + +#: includes/emails/class-wc-sc-email.php:109 +msgid "Choose which format of email to send." +msgstr "" + +#: includes/emails/class-wc-sc-email.php:116 +msgid "Subject" +msgstr "" + +#: includes/emails/class-wc-sc-email.php:124 +msgid "Email heading" +msgstr "" + +#. translators: 1. Receiver's count 2. Singular/Plural label for store credit(s) 3. Receiver name 4. Receiver details +#: templates/acknowledgement-email.php:34 +msgid "You have successfully sent %1$d %2$s %3$s %4$s" +msgstr "" + +#. translators: 1. Receiver's count 2. Gift Card/s 3. Receiver name 4. Receiver details +#: templates/acknowledgement-email.php:37 +msgid "You have scheduled to send %1$d %2$s %3$s %4$s" +msgstr "" + +#: templates/acknowledgement-email.php:53 +msgid "on" +msgstr "" + +#: templates/acknowledgement-email.php:71 +msgid "to" +msgstr "" + +#: templates/combined-email.php:82 +msgid "To redeem your discount click on the following coupon(s):" +msgstr "" + +#: templates/combined-email.php:209 +#: templates/email.php:194 +#: templates/plain/combined-email.php:131 +#: templates/plain/email.php:124 +msgid "Visit store" +msgstr "" + +#: templates/combined-email.php:237 +msgid "You got these coupons " +msgstr "" + +#. translators: %s: Coupon code +#: templates/email.php:85 +msgid "To redeem your discount use coupon code %s during checkout or click on the following coupon:" +msgstr "" + +#. translators: %s: singular name for store credit +#: templates/email.php:219 +#: templates/plain/combined-email.php:137 +#: templates/plain/email.php:130 +msgid "You got this %s" +msgstr "" + +#. translators: %s: singular name for store credit +#: templates/email.php:219 +#: templates/plain/combined-email.php:137 +#: templates/plain/email.php:130 +msgid "You got this gift card" +msgstr "" + +#. translators: 1. Receiver's count 2. Singular/Plural label for store credit(s) 3. Receiver name 4. Receiver details +#: templates/plain/acknowledgement-email.php:24 +msgid "You have successfully sent %1$d %2$s to %3$s (%4$s)" +msgstr "" + +#. translators: 1. Receiver's count 2. Gift Card/s 3. Receiver name 4. Receiver details +#: templates/plain/acknowledgement-email.php:27 +msgid "You have scheduled to send %1$d %2$s to %3$s (%4$s)" +msgstr "" + +#: templates/plain/combined-email.php:22 +msgid "To redeem your discount use below coupon codes during checkout or copy and paste the below URLs and hit enter in your browser" +msgstr "" + +#: templates/plain/combined-email.php:75 +#: templates/plain/email.php:26 +msgid "Message:" +msgstr "" + +#: templates/plain/combined-email.php:88 +#: templates/plain/email.php:83 +msgid " & " +msgstr "" + +#: templates/plain/combined-email.php:97 +#: templates/plain/email.php:92 +msgid "Coupon Code:" +msgstr "" + +#: templates/plain/combined-email.php:103 +#: templates/plain/email.php:98 +msgid "Description:" +msgstr "" + +#: templates/plain/combined-email.php:108 +#: templates/plain/email.php:103 +msgid "Expires on:" +msgstr "" + +#. translators: %s: Coupon code +#: templates/plain/email.php:23 +msgid "To redeem your discount use coupon code %s during checkout or copy and paste the below URL and hit enter in your browser:" +msgstr "" + +#. translators: 1$-2$: opening and closing tags, 3$-4$: link tags, takes to woocommerce plugin on wp.org, 5$-6$: opening and closing link tags, leads to plugins.php in admin. +#: woocommerce-smart-coupons.php:61 +msgid "%1$sWooCommerce Smart Coupons is inactive.%2$s The %3$sWooCommerce plugin%4$s must be active for the Smart Coupons to work. Please %5$sinstall & activate WooCommerce »%6$s" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-available-coupons-block.js:7 +#: blocks/src/js/available-coupons/edit.js:19 +msgctxt "Block editor" +msgid "Available Coupons (click on a coupon to use it)" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block-frontend.js:1 +#: blocks/src/js/send-coupon-form/block.js:195 +msgctxt "Frontend" +msgid "Send coupons to..." +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block-frontend.js:1 +#: blocks/src/js/send-coupon-form/block.js:197 +msgctxt "Frontend" +msgid "Your order contains coupons. What would you like to do?" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block-frontend.js:1 +#: blocks/src/js/send-coupon-form/block.js:202 +msgctxt "Frontend" +msgid "Send to me" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block-frontend.js:1 +#: blocks/src/js/send-coupon-form/block.js:207 +msgctxt "Frontend" +msgid "Gift to someone else" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block-frontend.js:1 +#: blocks/src/js/send-coupon-form/block.js:220 +msgctxt "Frontend" +msgid "Send to one person" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block-frontend.js:1 +#: blocks/src/js/send-coupon-form/block.js:225 +msgctxt "Frontend" +msgid "Send to different people" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block-frontend.js:1 +#: blocks/src/js/send-coupon-form/block.js:235 +#: blocks/src/js/send-coupon-form/block.js:239 +msgctxt "Frontend" +msgid "Deliver coupon" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block-frontend.js:1 +#: blocks/src/js/send-coupon-form/block.js:259 +#: blocks/src/js/send-coupon-form/block.js:284 +msgctxt "Frontend" +msgid "Receiver email address" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block-frontend.js:1 +#: blocks/src/js/send-coupon-form/block.js:262 +#: blocks/src/js/send-coupon-form/block.js:287 +msgctxt "Frontend" +msgid "Enter recipient e-mail address" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block-frontend.js:1 +#: blocks/src/js/send-coupon-form/block.js:267 +#: blocks/src/js/send-coupon-form/block.js:294 +msgctxt "Frontend" +msgid "Message for receiver" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block-frontend.js:1 +#: blocks/src/js/send-coupon-form/block.js:271 +#: blocks/src/js/send-coupon-form/block.js:298 +msgctxt "Frontend" +msgid "Write a message" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block.js:1 +#: blocks/src/js/send-coupon-form/edit.js:30 +msgctxt "Block editor" +msgid "Send coupons to..." +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block.js:1 +#: blocks/src/js/send-coupon-form/edit.js:31 +msgctxt "Block editor" +msgid "Your order contains coupons. What would you like to do?" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block.js:1 +#: blocks/src/js/send-coupon-form/edit.js:35 +msgctxt "Block editor" +msgid "Send to me" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block.js:1 +#: blocks/src/js/send-coupon-form/edit.js:39 +msgctxt "Block editor" +msgid "Gift to someone else" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block.js:1 +#: blocks/src/js/send-coupon-form/edit.js:49 +msgctxt "Block editor" +msgid "Send to one person" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block.js:1 +#: blocks/src/js/send-coupon-form/edit.js:53 +msgctxt "Block editor" +msgid "Send to different people" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block.js:1 +#: blocks/src/js/send-coupon-form/edit.js:59 +#: blocks/src/js/send-coupon-form/edit.js:63 +msgctxt "Block editor" +msgid "Deliver coupon" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block.js:1 +#: blocks/src/js/send-coupon-form/edit.js:67 +msgctxt "Block editor" +msgid "now" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block.js:1 +#: blocks/src/js/send-coupon-form/edit.js:71 +msgctxt "Block editor" +msgid "later" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block.js:1 +#: blocks/src/js/send-coupon-form/edit.js:80 +msgctxt "Block editor" +msgid "Receiver email address" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block.js:1 +#: blocks/src/js/send-coupon-form/edit.js:84 +msgctxt "Block editor" +msgid "Enter recipient e-mail address" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block.js:1 +#: blocks/src/js/send-coupon-form/edit.js:88 +msgctxt "Block editor" +msgid "Message for receiver" +msgstr "" + +#: blocks/build/woocommerce-smart-coupons-send-coupon-form-block.js:1 +#: blocks/src/js/send-coupon-form/edit.js:92 +msgctxt "Block editor" +msgid "Write a message" +msgstr "" + +#: blocks/build/js/available-coupons/block.json +#: blocks/src/js/available-coupons/block.json +msgctxt "block title" +msgid "Available coupons" +msgstr "" + +#: blocks/build/js/available-coupons/block.json +#: blocks/src/js/available-coupons/block.json +msgctxt "block description" +msgid "Displays available coupons." +msgstr "" + +#: blocks/build/js/send-coupon-form/block.json +#: blocks/src/js/send-coupon-form/block.json +msgctxt "block title" +msgid "Send coupon form" +msgstr "" + +#: blocks/build/js/send-coupon-form/block.json +#: blocks/src/js/send-coupon-form/block.json +msgctxt "block description" +msgid "Displays Send coupon form." +msgstr "" diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/readme.txt b/wp/wp-content/plugins/woocommerce-smart-coupons/readme.txt new file mode 100644 index 00000000..a8972258 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/readme.txt @@ -0,0 +1,66 @@ +=== WooCommerce Smart Coupons === +Contributors: storeapps, niravmehta, ratnakar.dubey, Tarun.Parswani, Mansi Shah, Chandan Kumar, ramendas, manish.kumar +Donate link: https://www.storeapps.org/ +Tags: woocommerce, coupon, credit, store credit, gift, certificate, voucher, discount, gift certificate, gift voucher, customer, self service +Requires at least: 4.4 +Tested up to: 6.5.4 +Stable tag: 9.3.0 + +Powerful, "all in one" solution for gift certificates, store credits, discount coupons and vouchers. Allows customers to buy credits for themselves or gift them to others. Unique "Apply Coupon with One Click" technology during checkout, tight integration with WooCommerce and automatic maintenance. + +== Description == + +WooCommerce Smart Coupons is the most powerful, all in one solution for gift certificates, store credits, discount coupons and vouchers. + +Here's what you can do with this plugin: + +* Create coupons of a new type - "Store Credit / Gift Certificate". Credit balance will be managed automatically. +* Link any coupon with a product - new or existing. Customers automatically get that coupon when they purchase the product. +* Gift Certificates - create a new product, call it a Gift Certificate / Voucher (or anything else that suits your business). Add details and pricing and associate a "Store Credit / Gift Certificate" coupon with it. Customer will get an option to enter email address of the person to send the coupon to during checkout. They can also add a custom message along. +* Works great with Chained Products plugin - allowing you to create product combos that include other products and gift vouchers for future purchase - increasing the overall value of the offer. +* Buy Gift Certificate / Store Credit of any denomination +* Send Gift Certificate / Store Credit to multiple people +* Automatic coupon generation with prefix / suffix support +* Import coupons in bulk +* Admin can send a store credit / gift certificate to anyone +* Link as many coupons as you want with a product +* Link coupons with any product type - standard, digital, variable etc. +* Automatic Balance Maintenance - As a customer keeps using a credit coupon, balance will keep reducing automatically. +* Automatic Deletion on Zero Balance - When the balance reaches zero, the credit / certificate will be deleted automatically. No need to spend time on this. +* Unique coupon code generation for all credits / gift certificates. +* Tight security - coupons can be associated with customers and credits can be used only by their beneficiaries. +* Unique "Apply Coupon with One Click" technology - logged in customers will see available coupons on the cart / checkout pages and can apply a coupon with single click. No longer digging into mailboxes and time / attention waste during the critical checkout process. +* Offer Credits at a Discount - Link a coupon with any product and set the product's price lower than coupon's value. Offering a discounted gift certificate. We've seen huge increase in sales this way. You get money in advance, and customer keeps coming back to the store to buy more. **In our tests we actually discovered 84% customers bought more than the gift certificate value itself.** +* Carries forward benefits of WooCommerce coupon system: limiting coupons to specific products, validity period, usage times, expiry date etc. +* Can search for coupons issued to a customer by their email address +* Notifies customers about remaining store credit balance in order email +* Can even duplicate an existing coupon +* Same convenient and familiar coupon management interface - no need to learn a new interface to manage Smart Coupons + +== Installation == + +1. Ensure you have latest version of [WooCommerce](https://wordpress.org/plugins/woocommerce/) plugin installed +2. Unzip and upload the folder 'woocommerce-smart-coupons' to your `/wp-content/plugins/` directory +3. Activate 'WooCommerce Smart Coupons' through the 'Plugins' menu in WordPress + +== Usage == + +CREATING A COUPON +1. Go to Coupons settings in WooCommerce +2. Add new coupons as usual - if you want to create credit based coupon - Store Credit or Gift Certificate, use "Store Credit / Gift Certificate" in type +3. Add other coupon details as usual +4. Save the coupon! + +LINKING A COUPON WITH A PRODUCT +1. Add a new product (or edit an existing one). +2. Look for "Coupons" under "General" tab +3. Start typing name of a coupon you want to give to your customer with this product +4. Select the exact coupon from the suggestions displayed +5. Add as many coupons as you want like this +6. Set up price and other details for the main product as you like +7. Click 'Update' or 'Publish' to save the changes + +IMPORTING COUPONS IN BULK +Refer to the "sample.csv" file in the plugin root directory. Create your import file in the same structure and import it via Coupons administration in WooCommerce. + +Go to "WooCommerce -> Settings -> Smart Coupons" from WordPress sidebar menu for additional settings for this plugin. diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/sample.csv b/wp/wp-content/plugins/woocommerce-smart-coupons/sample.csv new file mode 100644 index 00000000..0542d5c6 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/sample.csv @@ -0,0 +1,9 @@ +post_title,post_excerpt,post_status,post_parent,menu_order,post_date,discount_type,coupon_amount,free_shipping,expiry_date,minimum_amount,maximum_amount,individual_use,exclude_sale_items,product_ids,exclude_product_ids,product_categories,exclude_product_categories,customer_email,usage_limit,usage_limit_per_user,limit_usage_to_x_items,usage_count,_used_by,sc_restrict_to_new_user,wc_sc_add_product_details,sa_cbl_locations_lookup_in,sa_cbl_billing_locations,sa_cbl_shipping_locations,wc_coupon_message,wc_email_message,sc_coupon_validity,validity_suffix,auto_generate_coupon,coupon_title_prefix,coupon_title_suffix,is_pick_price_of_product,wc_sc_auto_apply_coupon,sc_disable_email_restriction,sc_is_visible_storewide,wc_sc_max_discount,wc_sc_expiry_time,wc_sc_payment_method_ids,wc_sc_shipping_method_ids,wc_sc_user_role_ids,wc_sc_exclude_user_role_ids,wc_sc_product_attribute_ids,wc_sc_exclude_product_attribute_ids,_wcs_number_payments,sc_coupon_category +sczdmjd,,publish,0,0,2023-02-23 12:34:56,Percentage discount,30,yes,,10,1000,yes,yes,,,,,,2,1,,0,,no,,billing,united states (us),,,no,,days,no,,,no,,no,no,50,,PayPal|Credit Card (Stripe),Flat rate|Local pickup,Administrator|Subscriber,,24|26,28,, +sc44noo,,publish,0,0,2023-02-24 12:34:56,Fixed cart discount,25,no,,10,,no,yes,,,,,,,1,,0,,no,"115, 1, 100, percent|114, 1, 100, percent",billing,,,Congratulations on getting free products!!!,yes,,days,no,,,no,yes,no,no,,,Direct bank transfer|Check payments,,,Customer,,,, +scuy08i,,publish,0,0,2023-02-25 12:34:56,Fixed product discount,5,yes,2020/01/20,,100,yes,no,,,,,,2,1,,0,,no,,shipping,,united kingdom (uk),,no,,days,no,,,no,,no,no,,86340,,,Administrator|Editor|Author,,,,, +scyjrlj,,publish,0,0,2023-02-26 12:34:56,Sign Up Fee Discount,1,no,2019/12/20,1,,no,yes,,,,,,,,,0,,,,,,,,,,,,,,,,,,,,,Flat rate|Free shipping|Local pickup,,,,26,, +scrzyzh,,publish,0,0,2023-02-27 12:34:56,Sign Up Fee % Discount,10,yes,,,200,yes,no,,,,,,2,1,,0,,,,,,,,,,,,,,,,,,,,,,,Administrator|Editor|Author,26,,, +schapfo,,publish,0,0,2023-02-28 12:34:56,Recurring Product Discount,0.5,yes,2020/02/20,10,100,yes,yes,,,,,,,,,0,,,,,,,,,,,,,,,,,,,,,,Customer,,,,, +scl5052,,publish,0,0,2023-03-01 12:34:56,Recurring Product % Discount,5,no,2020/01/01,10,,no,yes,,,,,,,1,,0,,,,,,,,,,,,,,,,,,,,,Flat rate|Local pickup,Author,,,,, +sce9z9k,,publish,0,0,2023-03-02 12:34:56,Store Credit / Gift Certificate,20,no,,,500,yes,no,,,,,,2,,,0,,,,,,,,,,,,,,,,,,,,Cash on delivery|Credit Card (Stripe),,,,,,, diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/templates/acknowledgement-email.php b/wp/wp-content/plugins/woocommerce-smart-coupons/templates/acknowledgement-email.php new file mode 100644 index 00000000..9c9d71ea --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/templates/acknowledgement-email.php @@ -0,0 +1,81 @@ + $email_heading ) ); + } else { + woocommerce_get_template( 'emails/email-header.php', array( 'email_heading' => $email_heading ) ); + } +} + +$receivers_email = array_unique( $receivers_detail ); + +if ( empty( $email_scheduled_details ) ) { + /* translators: 1. Receiver's count 2. Singular/Plural label for store credit(s) 3. Receiver name 4. Receiver details */ + $message = __( 'You have successfully sent %1$d %2$s %3$s %4$s', 'woocommerce-smart-coupons' ); +} else { + /* translators: 1. Receiver's count 2. Gift Card/s 3. Receiver name 4. Receiver details */ + $message = __( 'You have scheduled to send %1$d %2$s %3$s %4$s', 'woocommerce-smart-coupons' ); + $receivers_email = array_map( + function( $email ) use ( $email_scheduled_details ) { + // Filter for time format of acknowledgement email. + $time_format = apply_filters( 'wc_sc_acknowledgement_email_time_format', get_option( 'date_format', 'Y-m-d' ) . ' ' . get_option( 'time_format', 'H:i' ) ); + // Check if the scheduled timestamps are available. + if ( isset( $email_scheduled_details[ $email ] ) && is_array( $email_scheduled_details[ $email ] ) ) { + $scheduled_times = array_map( + function( $time ) use ( $time_format ) { + // Convert to date format. + $time = get_date_from_gmt( gmdate( 'c', $time ), $time_format ); + return date_i18n( $time_format, strtotime( $time ) ); + }, + $email_scheduled_details[ $email ] + ); + // Concat scheduled times to comma separated times. + return $email . ' ' . __( 'on', 'woocommerce-smart-coupons' ) . ' ' . implode( ', ', $scheduled_times ); + } + return $email; + }, + $receivers_email + ); +} + +$singular = ( ! empty( $store_credit_label['singular'] ) ) ? ucwords( $store_credit_label['singular'] ) : __( 'Gift card', 'woocommerce-smart-coupons' ); +$plural = ( ! empty( $store_credit_label['plural'] ) ) ? ucwords( $store_credit_label['plural'] ) : __( 'Gift cards', 'woocommerce-smart-coupons' ); +$coupon_type = ( $receiver_count > 1 ) ? $plural : $singular; + +if ( 'yes' === $contains_core_coupons ) { + $coupon_type = _n( 'Coupon', 'Coupons', $receiver_count, 'woocommerce-smart-coupons' ); +} + +$is_receiver_name = ! empty( $gift_certificate_receiver_name ); + +echo esc_html( sprintf( $message, $receiver_count, strtolower( $coupon_type ), ( ( ! empty( $gift_certificate_receiver_name ) || ! empty( $receivers_email ) ) ? __( 'to', 'woocommerce-smart-coupons' ) . ' ' . $gift_certificate_receiver_name : '' ), ( true === $is_receiver_name ? '(' : '' ) . implode( ', ', $receivers_email ) . ( true === $is_receiver_name ? ')' : '' ) ) ); + +if ( has_action( 'woocommerce_email_footer' ) ) { + do_action( 'woocommerce_email_footer', $email_obj ); +} else { + if ( function_exists( 'wc_get_template' ) ) { + wc_get_template( 'emails/email-footer.php' ); + } else { + woocommerce_get_template( 'emails/email-footer.php' ); + } +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/templates/call-for-credit-form.php b/wp/wp-content/plugins/woocommerce-smart-coupons/templates/call-for-credit-form.php new file mode 100644 index 00000000..ec3a3e07 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/templates/call-for-credit-form.php @@ -0,0 +1,37 @@ + +

            +
            +
            +
            + +
            +
            + +
            +
            +
            +

            +
            +

            diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/templates/combined-email.php b/wp/wp-content/plugins/woocommerce-smart-coupons/templates/combined-email.php new file mode 100644 index 00000000..3aaf8f18 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/templates/combined-email.php @@ -0,0 +1,253 @@ + $email_heading ) ); + } else { + woocommerce_get_template( 'emails/email-header.php', array( 'email_heading' => $email_heading ) ); + } +} +?> + + + + + + + +

            + +

            + +
            '; + $order = ( ! empty( $order_id ) ) ? wc_get_order( $order_id ) : null; // phpcs:ignore + foreach ( $receiver_details as $receiver_data ) { + + $coupon_code = $receiver_data['code']; + $sender_message = isset( $receiver_data['message'] ) ? $receiver_data['message'] : ''; + $coupon = new WC_Coupon( $coupon_code ); + + if ( $woocommerce_smart_coupon->is_wc_gte_30() ) { + if ( ! is_object( $coupon ) || ! is_callable( array( $coupon, 'get_id' ) ) ) { + continue; + } + $coupon_id = $coupon->get_id(); + if ( empty( $coupon_id ) ) { + continue; + } + $is_free_shipping = ( $coupon->get_free_shipping() ) ? 'yes' : 'no'; + $expiry_date = $coupon->get_date_expires(); + $coupon_code = $coupon->get_code(); + } else { + $coupon_id = ( ! empty( $coupon->id ) ) ? $coupon->id : 0; + $is_free_shipping = ( ! empty( $coupon->free_shipping ) ) ? $coupon->free_shipping : ''; + $expiry_date = ( ! empty( $coupon->expiry_date ) ) ? $coupon->expiry_date : ''; + $coupon_code = ( ! empty( $coupon->code ) ) ? $coupon->code : ''; + } + + $coupon_amount = $woocommerce_smart_coupon->get_amount( $coupon, true, $order ); + + $coupon_post = get_post( $coupon_id ); + + $coupon_data = $woocommerce_smart_coupon->get_coupon_meta_data( $coupon ); + + $coupon_type = ( ! empty( $coupon_data['coupon_type'] ) ) ? $coupon_data['coupon_type'] : ''; + + if ( 'yes' === $is_free_shipping ) { + if ( ! empty( $coupon_type ) ) { + $coupon_type .= __( ' & ', 'woocommerce-smart-coupons' ); + } + $coupon_type .= __( 'Free Shipping', 'woocommerce-smart-coupons' ); + } + + if ( ! empty( $expiry_date ) ) { + if ( $woocommerce_smart_coupon->is_wc_gte_30() && $expiry_date instanceof WC_DateTime ) { + $expiry_date = ( is_callable( array( $expiry_date, 'getTimestamp' ) ) ) ? $expiry_date->getTimestamp() : null; + } elseif ( ! is_int( $expiry_date ) ) { + $expiry_date = strtotime( $expiry_date ); + } + if ( ! empty( $expiry_date ) && is_int( $expiry_date ) ) { + $expiry_time = (int) $woocommerce_smart_coupon->get_post_meta( $coupon_id, 'wc_sc_expiry_time', true ); + if ( ! empty( $expiry_time ) ) { + $expiry_date += $expiry_time; // Adding expiry time to expiry date. + } + } + } + + $coupon_description = ''; + if ( ! empty( $coupon_post->post_excerpt ) && 'yes' === $show_coupon_description ) { + $coupon_description = $coupon_post->post_excerpt; + } + + $is_percent = $woocommerce_smart_coupon->is_percent_coupon( array( 'coupon_object' => $coupon ) ); + + $args = array( + 'coupon_object' => $coupon, + 'coupon_amount' => $coupon_amount, + 'amount_symbol' => ( true === $is_percent ) ? '%' : get_woocommerce_currency_symbol(), + 'discount_type' => wp_strip_all_tags( $coupon_type ), + 'coupon_description' => ( ! empty( $coupon_description ) ) ? $coupon_description : wp_strip_all_tags( $woocommerce_smart_coupon->generate_coupon_description( array( 'coupon_object' => $coupon ) ) ), + 'coupon_code' => $coupon_code, + 'coupon_expiry' => ( ! empty( $expiry_date ) ) ? $woocommerce_smart_coupon->get_expiration_format( $expiry_date ) : __( 'Never expires', 'woocommerce-smart-coupons' ), + 'thumbnail_src' => $woocommerce_smart_coupon->get_coupon_design_thumbnail_src( + array( + 'design' => $design, + 'coupon_object' => $coupon, + ) + ), + 'classes' => '', + 'template_id' => $design, + 'is_percent' => $is_percent, + ); + + $coupon_target = ''; + $wc_url_coupons_active_urls = get_option( 'wc_url_coupons_active_urls' ); // From plugin WooCommerce URL coupons. + if ( ! empty( $wc_url_coupons_active_urls ) ) { + $coupon_target = ( ! empty( $wc_url_coupons_active_urls[ $coupon_id ]['url'] ) ) ? $wc_url_coupons_active_urls[ $coupon_id ]['url'] : ''; + } + if ( ! empty( $coupon_target ) ) { + $coupon_target = home_url( '/' . $coupon_target ); + } else { + $coupon_target = home_url( '/?sc-page=shop&coupon-code=' . $coupon_code ); + } + + $coupon_target = apply_filters( 'sc_coupon_url_in_email', $coupon_target, $coupon ); + ?> +
            + +
            + +
            + +
            + + + +
            +
            +
            '; +} + +$site_url = ! empty( $url ) ? $url : home_url(); +?> +
            + + $woocommerce_smart_coupon ) ); + $coupons_to_print = ( ! empty( $receiver_details ) ) ? wp_list_pluck( $receiver_details, 'code' ) : array(); + if ( true === $is_print && ! empty( $coupons_to_print ) ) { + $print_coupon_url = add_query_arg( + array( + 'print-coupons' => 'yes', + 'source' => 'wc-smart-coupons', + 'coupon-codes' => implode( + ',', + $coupons_to_print + ), + ), + home_url() + ); + ?> + | + + +
            + + +

            + +

            + + +
            + + +
            +
            +
            + + + + + +
            +
            +
            + + +
            + +
            +
            +
            +
            +
            +
            +
            +
            +
            diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/clipper.php b/wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/clipper.php new file mode 100644 index 00000000..077f03c7 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/clipper.php @@ -0,0 +1,47 @@ + +
            +
            +
            + + + + + + + +
            +
            +
            + + +
            + +
            +
            + +
            +
            +
            +
            +
            diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/custom-design.php b/wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/custom-design.php new file mode 100644 index 00000000..35e64517 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/custom-design.php @@ -0,0 +1,61 @@ + +
            + +
            '; + + $discount_title = ''; + + if ( ! empty( $coupon_amount ) ) { + $discount_title = ( true === $is_percent ) ? $coupon_amount . '%' : wc_price( $coupon_amount ); + } + + if ( ! empty( $discount_type ) ) { + $discount_title .= ' ' . $discount_type; + } + + $discount_title = apply_filters( 'wc_smart_coupons_display_discount_title', $discount_title, $coupon_object ); + + if ( $discount_title ) { + + // Not escaping because 3rd party developer can have HTML code in discount title. + echo $discount_title; // phpcs:ignore + + } + + echo '
            '; + + echo '
            ' . esc_html( $coupon_code ) . '
            '; + + $show_coupon_description = get_option( 'smart_coupons_show_coupon_description', 'no' ); + if ( ! empty( $coupon_description ) && 'yes' === $show_coupon_description ) { + echo '
            ' . esc_html( $coupon_description ) . '
            '; + } + + if ( ! empty( $coupon_expiry ) ) { + echo '
            ' . esc_html( $coupon_expiry ) . '
            '; + } + + echo '
            '; + ?> +
            diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/cutout.php b/wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/cutout.php new file mode 100644 index 00000000..f556ca8e --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/cutout.php @@ -0,0 +1,67 @@ + +
            + + + + + +
            +
            +
            +
            + + + + + +
            +
            + + + + +
            +
            +
            +
            +
            + + +
            + +
            +
            +
            +
            + + +
            + +
            +
            +
            +
            diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/deal.php b/wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/deal.php new file mode 100644 index 00000000..35b002ff --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/deal.php @@ -0,0 +1,44 @@ + +
            +
            +
            + +
            +
            +
            + + +
            + +
            +
            + +
            +
            +
            +
            + +
            +
            +
            +
            +
            diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/deliver.php b/wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/deliver.php new file mode 100644 index 00000000..fee055b8 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/deliver.php @@ -0,0 +1,44 @@ + +
            +
            +
            +
            + +
            + +
            +
            +
            + + +
            + +
            +
            +
            + +
            +
            +
            +
            +
            +
            diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/email-coupon.php b/wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/email-coupon.php new file mode 100644 index 00000000..b7a7241f --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/email-coupon.php @@ -0,0 +1,67 @@ + +
            + get_coupon_content_classes() ) . '"> +
            '; + + $discount_title = ''; + + if ( ! empty( $coupon_amount ) ) { + $discount_title = ( true === $is_percent ) ? $coupon_amount . '%' : wc_price( $coupon_amount ); + } + + if ( ! empty( $discount_type ) ) { + $discount_title .= ' ' . $discount_type; + } + + $discount_title = apply_filters( 'wc_smart_coupons_display_discount_title', $discount_title, $coupon_object ); + + if ( $discount_title ) { + + // Not escaping because 3rd party developer can have HTML code in discount title. + echo $discount_title; // phpcs:ignore + + } + + echo '
            '; + + echo '
            ' . esc_html( $coupon_code ) . '
            '; + + $show_coupon_description = get_option( 'smart_coupons_show_coupon_description', 'no' ); + if ( ! empty( $coupon_description ) && 'yes' === $show_coupon_description ) { + echo '
            ' . esc_html( $coupon_description ) . '
            '; + } + + if ( ! empty( $coupon_expiry ) ) { + echo '
            ' . esc_html( $coupon_expiry ) . '
            '; + } + + echo '
            '; + ?> +
            diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/festive.php b/wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/festive.php new file mode 100644 index 00000000..d60d7b87 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/festive.php @@ -0,0 +1,88 @@ + +
            +
            + + + + + + + +
            + + +
            + +
            +
            +
            +
            +
            + get_emoji() ); ?> + +
            +
            +
            +
            +
            +
            + +
            +
            +
            +
            +
            +
            +
            +
            +
            diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/flat.php b/wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/flat.php new file mode 100644 index 00000000..e1354a7a --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/flat.php @@ -0,0 +1,64 @@ + +
            +
            +
            +
            +
            + get_emoji() ); ?> + +
            +
            +
            +
            + +
            +
            +
            +
            + + + + + +
            +
            + + + + +
            +
            +
            +
            diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/promotion.php b/wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/promotion.php new file mode 100644 index 00000000..d5c26ce7 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/promotion.php @@ -0,0 +1,76 @@ + +
            +
            + + + + + + + + +
            +
            + + + + + +
            +
            + + + + +
            +
            + +
            +
            +
            +
            + get_emoji() ); ?> + +
            +
            +
            +
            + +
            +
            +
            +
            diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/shipment.php b/wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/shipment.php new file mode 100644 index 00000000..5b6b8e69 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/shipment.php @@ -0,0 +1,66 @@ + +
            +
            +
            +
            +
            +
            +
            + + +
            + +
            +
            +
            + + +
            +
            + +
            + +
            +
            + + + + + +
            +
            + + + + +
            +
            +
            +
            diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/special.php b/wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/special.php new file mode 100644 index 00000000..14dc647a --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/special.php @@ -0,0 +1,67 @@ + +
            +
            +
            +
            + +
            + +
            + + + + + + + + + +
            +
            +
            + + +
            + +
            +
            +
            + +
            +
            +
            +
            +
            diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/ticket.php b/wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/ticket.php new file mode 100644 index 00000000..14fff43f --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/templates/coupon-design/ticket.php @@ -0,0 +1,53 @@ + +
            + + + + + + + + + +
            +
            +
            +
            +
            +
            +
            +
            + get_emoji() ); ?> + +
            +
            +
            +
            +
            diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/templates/email.php b/wp/wp-content/plugins/woocommerce-smart-coupons/templates/email.php new file mode 100644 index 00000000..6f6e21de --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/templates/email.php @@ -0,0 +1,235 @@ + $email_heading ) ); + } else { + woocommerce_get_template( 'emails/email-header.php', array( 'email_heading' => $email_heading ) ); + } +} +?> + + + + + + + + + +

            +' . esc_html( $coupon_code ) . '' ); +?> +

            + +is_wc_gte_30() ) { + if ( ! is_object( $coupon ) || ! is_callable( array( $coupon, 'get_id' ) ) ) { + return; + } + $coupon_id = $coupon->get_id(); + if ( empty( $coupon_id ) ) { + return; + } + $is_free_shipping = ( $coupon->get_free_shipping() ) ? 'yes' : 'no'; + $expiry_date = $coupon->get_date_expires(); + $coupon_code = $coupon->get_code(); +} else { + $coupon_id = ( ! empty( $coupon->id ) ) ? $coupon->id : 0; + $is_free_shipping = ( ! empty( $coupon->free_shipping ) ) ? $coupon->free_shipping : ''; + $expiry_date = ( ! empty( $coupon->expiry_date ) ) ? $coupon->expiry_date : ''; + $coupon_code = ( ! empty( $coupon->code ) ) ? $coupon->code : ''; +} + +$coupon_amount = $woocommerce_smart_coupon->get_amount( $coupon, true, $order ); + +$coupon_post = get_post( $coupon_id ); + +$coupon_data = $woocommerce_smart_coupon->get_coupon_meta_data( $coupon ); + +$coupon_type = ( ! empty( $coupon_data['coupon_type'] ) ) ? $coupon_data['coupon_type'] : ''; + +if ( 'yes' === $is_free_shipping ) { + if ( ! empty( $coupon_type ) ) { + $coupon_type .= __( ' & ', 'woocommerce-smart-coupons' ); + } + $coupon_type .= __( 'Free Shipping', 'woocommerce-smart-coupons' ); +} + +if ( ! empty( $expiry_date ) ) { + if ( $woocommerce_smart_coupon->is_wc_gte_30() && $expiry_date instanceof WC_DateTime ) { + $expiry_date = ( is_callable( array( $expiry_date, 'getTimestamp' ) ) ) ? $expiry_date->getTimestamp() : null; + } elseif ( ! is_int( $expiry_date ) ) { + $expiry_date = strtotime( $expiry_date ); + } + if ( ! empty( $expiry_date ) && is_int( $expiry_date ) ) { + $expiry_time = (int) $woocommerce_smart_coupon->get_post_meta( $coupon_id, 'wc_sc_expiry_time', true ); + if ( ! empty( $expiry_time ) ) { + $expiry_date += $expiry_time; // Adding expiry time to expiry date. + } + } +} + +$coupon_description = ''; +if ( ! empty( $coupon_post->post_excerpt ) && 'yes' === $show_coupon_description ) { + $coupon_description = $coupon_post->post_excerpt; +} + +$is_percent = $woocommerce_smart_coupon->is_percent_coupon( array( 'coupon_object' => $coupon ) ); + +$args = array( + 'coupon_object' => $coupon, + 'coupon_amount' => $coupon_amount, + 'amount_symbol' => ( true === $is_percent ) ? '%' : get_woocommerce_currency_symbol(), + 'discount_type' => wp_strip_all_tags( $coupon_type ), + 'coupon_description' => ( ! empty( $coupon_description ) ) ? $coupon_description : wp_strip_all_tags( $woocommerce_smart_coupon->generate_coupon_description( array( 'coupon_object' => $coupon ) ) ), + 'coupon_code' => $coupon_code, + 'coupon_expiry' => ( ! empty( $expiry_date ) ) ? $woocommerce_smart_coupon->get_expiration_format( $expiry_date ) : __( 'Never expires', 'woocommerce-smart-coupons' ), + 'thumbnail_src' => $woocommerce_smart_coupon->get_coupon_design_thumbnail_src( + array( + 'design' => $design, + 'coupon_object' => $coupon, + ) + ), + 'classes' => '', + 'template_id' => $design, + 'is_percent' => $is_percent, +); + + $coupon_target = ''; + $wc_url_coupons_active_urls = get_option( 'wc_url_coupons_active_urls' ); // From plugin WooCommerce URL coupons. +if ( ! empty( $wc_url_coupons_active_urls ) ) { + $coupon_target = ( ! empty( $wc_url_coupons_active_urls[ $coupon_id ]['url'] ) ) ? $wc_url_coupons_active_urls[ $coupon_id ]['url'] : ''; +} +if ( ! empty( $coupon_target ) ) { + $coupon_target = home_url( '/' . $coupon_target ); +} else { + $coupon_target = home_url( '/?sc-page=shop&coupon-code=' . $coupon_code ); +} + + $coupon_target = apply_filters( 'sc_coupon_url_in_email', $coupon_target, $coupon ); +?> + + + + +
            + + $woocommerce_smart_coupon ) ); + if ( true === $is_print ) { + $print_coupon_url = add_query_arg( + array( + 'print-coupons' => 'yes', + 'source' => 'wc-smart-coupons', + 'coupon-codes' => $coupon_code, + ), + home_url() + ); + ?> + | + + +
            + + +

            + +

            + + +
            + + 1 ) ? $plural : $singular; + +if ( 'yes' === $contains_core_coupons ) { + $coupon_type = _n( 'Coupon', 'Coupons', $receiver_count, 'woocommerce-smart-coupons' ); +} + +echo esc_html( sprintf( $message, $receiver_count, strtolower( $coupon_type ), $gift_certificate_receiver_name, implode( ', ', $receivers_email ) ) ); + +echo "\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/templates/plain/combined-email.php b/wp/wp-content/plugins/woocommerce-smart-coupons/templates/plain/combined-email.php new file mode 100644 index 00000000..17a7f304 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/templates/plain/combined-email.php @@ -0,0 +1,139 @@ + + + + +is_wc_gte_30() ) { + if ( ! is_object( $coupon ) || ! is_callable( array( $coupon, 'get_id' ) ) ) { + return; + } + $coupon_id = $coupon->get_id(); + if ( empty( $coupon_id ) ) { + return; + } + $is_free_shipping = ( $coupon->get_free_shipping() ) ? 'yes' : 'no'; + $expiry_date = $coupon->get_date_expires(); + $coupon_code = $coupon->get_code(); + } else { + $coupon_id = ( ! empty( $coupon->id ) ) ? $coupon->id : 0; + $is_free_shipping = ( ! empty( $coupon->free_shipping ) ) ? $coupon->free_shipping : ''; + $expiry_date = ( ! empty( $coupon->expiry_date ) ) ? $coupon->expiry_date : ''; + $coupon_code = ( ! empty( $coupon->code ) ) ? $coupon->code : ''; + } + + $coupon_amount = $woocommerce_smart_coupon->get_amount( $coupon, true, $order ); + + $coupon_post = get_post( $coupon_id ); + + $coupon_data = $woocommerce_smart_coupon->get_coupon_meta_data( $coupon ); + + $coupon_target = ''; + $wc_url_coupons_active_urls = get_option( 'wc_url_coupons_active_urls' ); // From plugin WooCommerce URL coupons. + if ( ! empty( $wc_url_coupons_active_urls ) ) { + $coupon_target = ( ! empty( $wc_url_coupons_active_urls[ $coupon_id ]['url'] ) ) ? $wc_url_coupons_active_urls[ $coupon_id ]['url'] : ''; + } + if ( ! empty( $coupon_target ) ) { + $coupon_target = home_url( '/' . $coupon_target ); + } else { + $coupon_target = home_url( '/?sc-page=shop&coupon-code=' . $coupon_code ); + } + + $coupon_target = apply_filters( 'sc_coupon_url_in_email', $coupon_target, $coupon ); + + if ( ! empty( $sender_message ) ) { + echo "\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; + echo esc_html__( 'Message:', 'woocommerce-smart-coupons' ); + echo esc_html( $sender_message ); + } + + echo "\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; + echo esc_url( $coupon_target ); + echo "\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; + + echo esc_html__( 'Discount:', 'woocommerce-smart-coupons' ); + if ( ! empty( $coupon_data['coupon_amount'] ) && 0 !== $coupon_amount ) { + echo $coupon_data['coupon_amount']; // phpcs:ignore + echo ' ' . $coupon_data['coupon_type']; // phpcs:ignore + if ( 'yes' === $is_free_shipping ) { + echo esc_html__( ' & ', 'woocommerce-smart-coupons' ); + } + } + + if ( 'yes' === $is_free_shipping ) { + echo esc_html__( 'Free Shipping', 'woocommerce-smart-coupons' ); + } + + echo "\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; + echo esc_html__( 'Coupon Code:', 'woocommerce-smart-coupons' ); + echo esc_html( $coupon_code ); + echo "\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; + + $show_coupon_description = get_option( 'smart_coupons_show_coupon_description', 'no' ); + if ( ! empty( $coupon_post->post_excerpt ) && 'yes' === $show_coupon_description ) { + echo esc_html__( 'Description:', 'woocommerce-smart-coupons' ); + echo $coupon_post->post_excerpt; // phpcs:ignore + echo "\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; + } + + echo esc_html__( 'Expires on:', 'woocommerce-smart-coupons' ); + if ( ! empty( $expiry_date ) ) { + if ( $woocommerce_smart_coupon->is_wc_gte_30() && $expiry_date instanceof WC_DateTime ) { + $expiry_date = ( is_callable( array( $expiry_date, 'getTimestamp' ) ) ) ? $expiry_date->getTimestamp() : null; + } elseif ( ! is_int( $expiry_date ) ) { + $expiry_date = strtotime( $expiry_date ); + } + + if ( ! empty( $expiry_date ) && is_int( $expiry_date ) ) { + $expiry_time = (int) $woocommerce_smart_coupon->get_post_meta( $coupon_id, 'wc_sc_expiry_time', true ); + if ( ! empty( $expiry_time ) ) { + $expiry_date += $expiry_time; // Adding expiry time to expiry date. + } + } + $expiry_date = $woocommerce_smart_coupon->get_expiration_format( $expiry_date ); + echo esc_html( $expiry_date ); + } else { + echo esc_html__( 'Never expires', 'woocommerce-smart-coupons' ); + } + echo "\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; +} + +echo "\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; +echo esc_html__( 'Visit store', 'woocommerce-smart-coupons' ); +echo "\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; +$site_url = ! empty( $url ) ? $url : home_url(); +echo esc_url( $site_url ); +if ( ! empty( $from ) ) { + /* translators: %s: singular name for store credit */ + echo ( ! empty( $store_credit_label['singular'] ) ? sprintf( esc_html__( 'You got this %s', 'woocommerce-smart-coupons' ), esc_html( strtolower( $store_credit_label['singular'] ) ) ) : esc_html__( 'You got this gift card', 'woocommerce-smart-coupons' ) ) . ' ' . esc_html( $from ) . esc_html( $sender ); + echo "\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/templates/plain/email.php b/wp/wp-content/plugins/woocommerce-smart-coupons/templates/plain/email.php new file mode 100644 index 00000000..ac09b662 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/templates/plain/email.php @@ -0,0 +1,132 @@ + + + + +is_wc_gte_30() ) { + if ( ! is_object( $coupon ) || ! is_callable( array( $coupon, 'get_id' ) ) ) { + return; + } + $coupon_id = $coupon->get_id(); + if ( empty( $coupon_id ) ) { + return; + } + $is_free_shipping = ( $coupon->get_free_shipping() ) ? 'yes' : 'no'; + $expiry_date = $coupon->get_date_expires(); + $coupon_code = $coupon->get_code(); +} else { + $coupon_id = ( ! empty( $coupon->id ) ) ? $coupon->id : 0; + $is_free_shipping = ( ! empty( $coupon->free_shipping ) ) ? $coupon->free_shipping : ''; + $expiry_date = ( ! empty( $coupon->expiry_date ) ) ? $coupon->expiry_date : ''; + $coupon_code = ( ! empty( $coupon->code ) ) ? $coupon->code : ''; +} + +$coupon_amount = $woocommerce_smart_coupon->get_amount( $coupon, true, $order ); + +$coupon_post = get_post( $coupon_id ); + +$coupon_data = $woocommerce_smart_coupon->get_coupon_meta_data( $coupon ); + +$coupon_target = ''; +$wc_url_coupons_active_urls = get_option( 'wc_url_coupons_active_urls' ); // From plugin WooCommerce URL coupons. +if ( ! empty( $wc_url_coupons_active_urls ) ) { + $coupon_target = ( ! empty( $wc_url_coupons_active_urls[ $coupon_id ]['url'] ) ) ? $wc_url_coupons_active_urls[ $coupon_id ]['url'] : ''; +} +if ( ! empty( $coupon_target ) ) { + $coupon_target = home_url( '/' . $coupon_target ); +} else { + $coupon_target = home_url( '/?sc-page=shop&coupon-code=' . $coupon_code ); +} + +$coupon_target = apply_filters( 'sc_coupon_url_in_email', $coupon_target, $coupon ); + +echo "\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; +echo esc_url( $coupon_target ); +echo "\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; + +echo esc_html__( 'Discount:', 'woocommerce-smart-coupons' ); +if ( ! empty( $coupon_data['coupon_amount'] ) && 0 !== $coupon_amount ) { + echo $coupon_data['coupon_amount']; // phpcs:ignore + echo ' ' . $coupon_data['coupon_type']; // phpcs:ignore + if ( 'yes' === $is_free_shipping ) { + echo esc_html__( ' & ', 'woocommerce-smart-coupons' ); + } +} + +if ( 'yes' === $is_free_shipping ) { + echo esc_html__( 'Free Shipping', 'woocommerce-smart-coupons' ); +} + +echo "\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; +echo esc_html__( 'Coupon Code:', 'woocommerce-smart-coupons' ); +echo esc_html( $coupon_code ); +echo "\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; + +$show_coupon_description = get_option( 'smart_coupons_show_coupon_description', 'no' ); +if ( ! empty( $coupon_post->post_excerpt ) && 'yes' === $show_coupon_description ) { + echo esc_html__( 'Description:', 'woocommerce-smart-coupons' ); + echo $coupon_post->post_excerpt; // phpcs:ignore + echo "\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; +} + +echo esc_html__( 'Expires on:', 'woocommerce-smart-coupons' ); +if ( ! empty( $expiry_date ) ) { + if ( $woocommerce_smart_coupon->is_wc_gte_30() && $expiry_date instanceof WC_DateTime ) { + $expiry_date = ( is_callable( array( $expiry_date, 'getTimestamp' ) ) ) ? $expiry_date->getTimestamp() : null; + } elseif ( ! is_int( $expiry_date ) ) { + $expiry_date = strtotime( $expiry_date ); + } + + if ( ! empty( $expiry_date ) && is_int( $expiry_date ) ) { + $expiry_time = (int) $woocommerce_smart_coupon->get_post_meta( $coupon_id, 'wc_sc_expiry_time', true ); + if ( ! empty( $expiry_time ) ) { + $expiry_date += $expiry_time; // Adding expiry time to expiry date. + } + } + $expiry_date = $woocommerce_smart_coupon->get_expiration_format( $expiry_date ); + echo esc_html( $expiry_date ); +} else { + echo esc_html__( 'Never expires', 'woocommerce-smart-coupons' ); +} + +echo "\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; +echo esc_html__( 'Visit store', 'woocommerce-smart-coupons' ); +echo "\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; +$site_url = ! empty( $url ) ? $url : home_url(); +echo esc_url( $site_url ); +if ( ! empty( $from ) ) { + /* translators: %s: singular name for store credit */ + echo ( ! empty( $store_credit_label['singular'] ) ? sprintf( esc_html__( 'You got this %s', 'woocommerce-smart-coupons' ), esc_html( strtolower( $store_credit_label['singular'] ) ) ) : esc_html__( 'You got this gift card', 'woocommerce-smart-coupons' ) ) . ' ' . esc_html( $from ) . esc_html( $sender ); + echo "\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; +} diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/templates/print-coupons-default.php b/wp/wp-content/plugins/woocommerce-smart-coupons/templates/print-coupons-default.php new file mode 100644 index 00000000..b9ff0a13 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/templates/print-coupons-default.php @@ -0,0 +1,213 @@ + + +> + + + + <?php echo $bloginfo; // phpcs:ignore ?> + + + + + + + + + > +
            +
            + is_wc_gte_30() ) { + if ( ! is_object( $coupon ) || ! is_callable( array( $coupon, 'get_id' ) ) ) { + continue; + } + $coupon_id = $coupon->get_id(); + if ( empty( $coupon_id ) ) { + continue; + } + $is_free_shipping = ( $coupon->get_free_shipping() ) ? 'yes' : 'no'; + $discount_type = $coupon->get_discount_type(); + $expiry_date = $coupon->get_date_expires(); + $coupon_code = $coupon->get_code(); + } else { + $coupon_id = ( ! empty( $coupon->id ) ) ? $coupon->id : 0; + $is_free_shipping = ( ! empty( $coupon->free_shipping ) ) ? $coupon->free_shipping : ''; + $discount_type = ( ! empty( $coupon->discount_type ) ) ? $coupon->discount_type : ''; + $expiry_date = ( ! empty( $coupon->expiry_date ) ) ? $coupon->expiry_date : ''; + $coupon_code = ( ! empty( $coupon->code ) ) ? $coupon->code : ''; + } + + $coupon_amount = $woocommerce_smart_coupon->get_amount( $coupon, true ); + + if ( empty( $coupon_id ) || empty( $discount_type ) ) { + continue; + } + + $coupon_post = get_post( $coupon_id ); + + $coupon_meta = $woocommerce_smart_coupon->get_coupon_meta_data( $coupon ); + + $coupon_type = ( ! empty( $coupon_meta['coupon_type'] ) ) ? $coupon_meta['coupon_type'] : ''; + + if ( 'yes' === $is_free_shipping ) { + if ( ! empty( $coupon_type ) ) { + $coupon_type .= __( ' & ', 'woocommerce-smart-coupons' ); + } + $coupon_type .= __( 'Free Shipping', 'woocommerce-smart-coupons' ); + } + + if ( ! empty( $expiry_date ) ) { + if ( $woocommerce_smart_coupon->is_wc_gte_30() && $expiry_date instanceof WC_DateTime ) { + $expiry_date = ( is_callable( array( $expiry_date, 'getTimestamp' ) ) ) ? $expiry_date->getTimestamp() : null; + } elseif ( ! is_int( $expiry_date ) ) { + $expiry_date = strtotime( $expiry_date ); + } + if ( ! empty( $expiry_date ) && is_int( $expiry_date ) ) { + $expiry_time = (int) $woocommerce_smart_coupon->get_post_meta( $coupon_id, 'wc_sc_expiry_time', true ); + if ( ! empty( $expiry_time ) ) { + $expiry_date += $expiry_time; // Adding expiry time to expiry date. + } + } + } + + $coupon_description = ''; + + if ( ! empty( $coupon_post->post_excerpt ) && 'yes' === $show_coupon_description ) { + $coupon_description = $coupon_post->post_excerpt; + } + + $is_percent = $woocommerce_smart_coupon->is_percent_coupon( array( 'coupon_object' => $coupon ) ); + + $args = array( + 'coupon_object' => $coupon, + 'coupon_amount' => $coupon_amount, + 'amount_symbol' => ( true === $is_percent ) ? '%' : get_woocommerce_currency_symbol(), + 'discount_type' => wp_strip_all_tags( $coupon_type ), + 'coupon_description' => ( ! empty( $coupon_description ) ) ? $coupon_description : wp_strip_all_tags( $woocommerce_smart_coupon->generate_coupon_description( array( 'coupon_object' => $coupon ) ) ), + 'coupon_code' => $coupon_code, + 'coupon_expiry' => ( ! empty( $expiry_date ) ) ? $woocommerce_smart_coupon->get_expiration_format( $expiry_date ) : __( 'Never expires', 'woocommerce-smart-coupons' ), + 'thumbnail_src' => $woocommerce_smart_coupon->get_coupon_design_thumbnail_src( + array( + 'design' => $design, + 'coupon_object' => $coupon, + ) + ), + 'classes' => '', + 'template_id' => $design, + 'is_percent' => $is_percent, + ); + + wc_get_template( 'coupon-design/' . $design . '.php', $args, '', plugin_dir_path( WC_SC_PLUGIN_FILE ) . 'templates/' ); + + } + ?> +
            +
            + +
            + +
            + +
            +
            + + + diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/woocommerce-smart-coupons.php b/wp/wp-content/plugins/woocommerce-smart-coupons/woocommerce-smart-coupons.php new file mode 100644 index 00000000..9df0ee48 --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/woocommerce-smart-coupons.php @@ -0,0 +1,95 @@ +WooCommerce Smart Coupons
            lets customers buy gift certificates, store credits or coupons easily. They can use purchased credits themselves or gift to someone else. + * Version: 9.3.0 + * Author: StoreApps + * Author URI: https://www.storeapps.org/ + * Developer: StoreApps + * Developer URI: https://www.storeapps.org/ + * Requires at least: 4.4 + * Tested up to: 6.5.4 + * WC requires at least: 3.0.0 + * WC tested up to: 8.9.3 + * Requires Plugins: woocommerce + * Text Domain: woocommerce-smart-coupons + * Domain Path: /languages/ + * Woo: 18729:05c45f2aa466106a466de4402fff9dde + * Copyright (c) 2014-2024 WooCommerce, StoreApps All rights reserved. + * License: GNU General Public License v3.0 + * License URI: http://www.gnu.org/licenses/gpl-3.0.html + * + * @package woocommerce-smart-coupons + */ + +/** + * Include class having function to execute during activation & deactivation of plugin + */ +require_once 'includes/class-wc-sc-act-deact.php'; + +/** + * On activation + */ +register_activation_hook( __FILE__, array( 'WC_SC_Act_Deact', 'smart_coupon_activate' ) ); + +/** + * On deactivation + */ +register_deactivation_hook( __FILE__, array( 'WC_SC_Act_Deact', 'smart_coupon_deactivate' ) ); + + +/** + * WooCommerce fallback notice. + * + * @since 1.0.0 + */ +function smart_coupons_woocommerce_missing_wc_notice() { + $install_url = wp_nonce_url( + add_query_arg( + array( + 'action' => 'install-plugin', + 'plugin' => 'woocommerce', + ), + admin_url( 'update.php' ) + ), + 'install-plugin_woocommerce' + ); + + $admin_notice_content = sprintf( + // translators: 1$-2$: opening and closing tags, 3$-4$: link tags, takes to woocommerce plugin on wp.org, 5$-6$: opening and closing link tags, leads to plugins.php in admin. + esc_html__( '%1$sWooCommerce Smart Coupons is inactive.%2$s The %3$sWooCommerce plugin%4$s must be active for the Smart Coupons to work. Please %5$sinstall & activate WooCommerce »%6$s', 'woocommerce-smart-coupons' ), + '', + '', + '', + '', + '', + '' + ); + + echo '
            '; + echo '

            ' . wp_kses_post( $admin_notice_content ) . '

            '; + echo '
            '; +} + +if ( ! defined( 'WC_SC_PLUGIN_FILE' ) ) { + define( 'WC_SC_PLUGIN_FILE', __FILE__ ); +} +if ( ! defined( 'WC_SC_PLUGIN_DIRNAME' ) ) { + define( 'WC_SC_PLUGIN_DIRNAME', dirname( plugin_basename( __FILE__ ) ) ); +} + +add_action( + 'plugins_loaded', + function() { + if ( ! class_exists( 'WooCommerce' ) ) { + add_action( 'admin_notices', 'smart_coupons_woocommerce_missing_wc_notice' ); + return; + } + + include_once 'includes/class-wc-smart-coupons.php'; + $GLOBALS['woocommerce_smart_coupon'] = WC_Smart_Coupons::get_instance(); + + include_once 'blocks/blocks.php'; + } +);// End woocommerce active check. diff --git a/wp/wp-content/plugins/woocommerce-smart-coupons/wpml-config.xml b/wp/wp-content/plugins/woocommerce-smart-coupons/wpml-config.xml new file mode 100644 index 00000000..d56316ef --- /dev/null +++ b/wp/wp-content/plugins/woocommerce-smart-coupons/wpml-config.xml @@ -0,0 +1,15 @@ + + + auto_generate_coupon + coupon_title_prefix + coupon_title_suffix + sc_coupon_validity + validity_suffix + sc_is_visible_storewide + sc_disable_email_restriction + is_pick_price_of_product + _coupon_title + send_coupons_on_renewals + generated_from_order_id + + \ No newline at end of file