PluginProbe ʕ •ᴥ•ʔ
Discount Rules for WooCommerce / 1.7.7
Discount Rules for WooCommerce v1.7.7
1.4.39 1.4.4 1.4.40 1.4.41 1.4.42 1.4.43 1.4.44 1.4.45 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.10 1.5.11 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.10 1.6.11 1.6.12 1.6.14 1.6.15 1.6.16 1.6.17 1.6.18 1.6.19 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.10 1.7.11 1.7.12 1.7.13 1.7.14 1.7.15 1.7.16 1.7.17 1.7.18 1.7.19 1.7.2 1.7.20 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 1.8.0 1.8.1 1.8.2 1.9.0 1.9.1 1.9.10 1.9.11 1.9.12 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.2 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.3.0 2.3.1 2.3.10 2.3.11 2.3.12 2.3.13 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 2.4.0 2.4.1 2.4.2 2.4.4 2.4.5 2.5.0 2.5.2 2.5.3 2.5.4 2.6.0 2.6.1 2.6.10 2.6.11 2.6.12 2.6.13 2.6.14 2.6.15 2.6.2 2.6.3 2.6.4 2.6.5 2.6.6 2.6.7 2.6.8 2.6.9 trunk 1.1 1.2 1.3 1.4 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 1.4.14 1.4.15 1.4.16 1.4.17 1.4.18 1.4.19 1.4.2 1.4.20 1.4.21 1.4.22 1.4.23 1.4.24 1.4.25 1.4.26 1.4.27 1.4.28 1.4.29 1.4.3 1.4.30 1.4.31 1.4.32 1.4.33 1.4.34 1.4.35 1.4.36 1.4.37 1.4.38
woo-discount-rules / loader.php
woo-discount-rules Last commit date
assets 7 years ago helper 7 years ago i18n 7 years ago includes 7 years ago vendor 7 years ago view 7 years ago loader.php 7 years ago readme.txt 7 years ago woo-discount-rules.php 7 years ago
loader.php
523 lines
1 <?php
2 if (!defined('ABSPATH')) exit; // Exit if accessed directly
3
4 /**
5 * Plugin Directory.
6 */
7 define('WOO_DISCOUNT_DIR', untrailingslashit(plugin_dir_path(__FILE__)));
8
9 /**
10 * Plugin Directory URI.
11 */
12 define('WOO_DISCOUNT_URI', untrailingslashit(plugin_dir_url(__FILE__)));
13
14 /**
15 * Plugin Base Name.
16 */
17 define('WOO_DISCOUNT_PLUGIN_BASENAME', plugin_basename(__FILE__));
18
19 if(!function_exists('get_plugin_data')){
20 require_once ABSPATH . 'wp-admin/includes/plugin.php';
21 }
22
23 /**
24 * Version of Woo Discount Rules.
25 */
26 $pluginDetails = get_plugin_data(plugin_dir_path(__FILE__).'woo-discount-rules.php');
27 define('WOO_DISCOUNT_VERSION', $pluginDetails['Version']);
28
29 if(!class_exists('FlycartWooDiscountRules')){
30 class FlycartWooDiscountRules{
31
32 private static $instance;
33 public $discountBase;
34 public $pricingRules;
35 public $config;
36
37 /**
38 * To run the plugin
39 * */
40 public static function init() {
41 if ( self::$instance == null ) {
42 self::$instance = new FlycartWooDiscountRules();
43 }
44 return self::$instance;
45 }
46
47 /**
48 * FlycartWooDiscountRules constructor
49 * */
50 public function __construct() {
51 $this->hasWPML();
52 $this->includeFiles();
53 $this->discountBase = new FlycartWooDiscountBase();
54 $this->runUpdater();
55 $this->pricingRules = new FlycartWooDiscountRulesPricingRules();
56 if (is_admin()) {
57 $this->loadAdminScripts();
58 }
59 if(FlycartWooDiscountRulesGeneralHelper::doIHaveToRun()){
60 $this->loadSiteScripts();
61 }
62 $this->loadCommonScripts();
63 }
64
65 /**
66 * To check for WPML
67 * */
68 protected function hasWPML(){
69 if ( is_plugin_active( 'sitepress-multilingual-cms/sitepress.php' ) ) {
70 define('WOO_DISCOUNT_AVAILABLE_WPML', true);
71 } else {
72 define('WOO_DISCOUNT_AVAILABLE_WPML', false);
73 }
74 }
75
76 /**
77 * To include Files
78 * */
79 protected function includeFiles(){
80 include_once(dirname(__FILE__).'/helper/woo-function.php');
81 include_once(dirname(__FILE__).'/includes/pricing-rules.php');
82 include_once(dirname(__FILE__).'/helper/general-helper.php');
83 include_once(dirname(__FILE__).'/includes/cart-rules.php');
84 include_once(dirname(__FILE__).'/includes/discount-base.php');
85 include_once(dirname(__FILE__).'/helper/purchase.php');
86 require_once __DIR__ . '/vendor/autoload.php';
87 }
88
89 /**
90 * Run Plugin updater
91 * */
92 protected function runUpdater(){
93 try{
94 require plugin_dir_path( __FILE__ ).'/vendor/yahnis-elsts/plugin-update-checker/plugin-update-checker.php';
95
96 $purchase_helper = new FlycartWooDiscountRulesPurchase();
97 $purchase_helper->init();
98 $update_url = $purchase_helper->getUpdateURL();
99 if(!$purchase_helper->isPro()){
100 $dlid = $this->discountBase->getConfigData('license_key', null);
101 if(empty($dlid)) return false;
102 }
103 $myUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
104 $update_url,
105 plugin_dir_path( __FILE__ ).'woo-discount-rules.php',
106 'woo-discount-rules'
107 );
108 add_action( 'after_plugin_row', array($purchase_helper, 'woodisc_after_plugin_row'),10,3 );
109
110 add_action('wp_ajax_forceValidateLicenseKey', array($purchase_helper, 'forceValidateLicenseKey'));
111
112 add_action( 'admin_notices', array($purchase_helper, 'errorNoticeInAdminPages'));
113 } catch (Exception $e){}
114 }
115
116 /**
117 * Load Admin scripts
118 * */
119 protected function loadAdminScripts(){
120 // Init in Admin Menu
121 add_action('admin_menu', array($this->discountBase, 'adminMenu'));
122 add_action('wp_ajax_savePriceRule', array($this->discountBase, 'savePriceRule'));
123 add_action('wp_ajax_saveCartRule', array($this->discountBase, 'saveCartRule'));
124 add_action('wp_ajax_saveConfig', array($this->discountBase, 'saveConfig'));
125 add_action('wp_ajax_resetWDRCache', array($this->discountBase, 'resetWDRCache'));
126 add_action('wp_ajax_loadProductSelectBox', array($this->discountBase, 'loadProductSelectBox'));
127 add_action('wp_ajax_loadCoupons', array($this->discountBase, 'loadCoupons'));
128
129 add_action('wp_ajax_UpdateStatus', array($this->discountBase, 'updateStatus'));
130 add_action('wp_ajax_RemoveRule', array($this->discountBase, 'removeRule'));
131 add_action('wp_ajax_doBulkAction', array($this->discountBase, 'doBulkAction'));
132 add_action('wp_ajax_createDuplicateRule', array($this->discountBase, 'createDuplicateRule'));
133 add_action('admin_enqueue_scripts', array($this->discountBase, 'woo_discount_adminPageScript'), 100 );
134 $display_you_saved_text = $this->discountBase->getConfigData('display_you_saved_text', 'no');
135 if(in_array($display_you_saved_text, array('on_each_line_item', 'both_line_item_and_after_total'))){
136 add_action( 'woocommerce_after_order_itemmeta', array( $this->pricingRules, 'addAdditionalContentInAfterOrderItemMeta'), 1000, 3);
137 }
138 if(in_array($display_you_saved_text, array('after_total', 'both_line_item_and_after_total'))){
139 add_action( 'woocommerce_admin_order_totals_after_total', array( $this->pricingRules, 'displayTotalSavingsThroughDiscountInOrder'), 10);
140 }
141 }
142
143 /**
144 * Apply discount rules
145 * */
146 public function applyDiscountRules(){
147 $this->discountBase->handlePriceDiscount();
148 $removeTheEvent = apply_filters('woo_discount_rules_remove_event_woocommerce_before_calculate_totals', false);
149 if(!$removeTheEvent){
150 remove_action('woocommerce_before_calculate_totals', array($this, 'applyDiscountRules'), 1000);
151 }
152 }
153
154 /**
155 * Apply discount rules
156 * */
157 public function applyCartDiscountRules(){
158 remove_action('woocommerce_cart_loaded_from_session', array($this, 'applyCartDiscountRules'), 97);
159 $this->discountBase->handleCartDiscount();
160 }
161
162 /**
163 * Script on product page for loading variant strikeout
164 * */
165 public function script_on_product_page(){
166 $runVariationStrikeoutAjax = apply_filters('woo_discount_rules_run_variation_strikeout_through_ajax', true);
167 $script = '<script>';
168 $script .= 'jQuery( document ).ready( function() {';
169 $do_product_page_strikeout = $this->discountBase->getConfigData('show_price_discount_on_product_page', 'show');
170 $enable_variable_product_cache = $this->discountBase->getConfigData('enable_variable_product_cache', 0);
171 if($do_product_page_strikeout == 'show' && $runVariationStrikeoutAjax) {
172 $script .= 'jQuery( ".single_variation_wrap" ).on( "show_variation", function ( event, variation, purchasable ) {';
173 $script .= ' var container = jQuery(".single_variation .woocommerce-variation-price");';
174 $script .= ' var current_object = jQuery(this);
175 current_object.trigger("woo_discount_rules_before_variant_strikeout");/*container.hide("slow");*/';
176 $script .= ' jQuery.ajax({
177 url: woo_discount_rules.ajax_url,
178 dataType: "json",
179 type: "POST",
180 data: {action: "loadWooDiscountedPriceForVariant", id: variation.variation_id, price_html: variation.price_html},
181 beforeSend: function() {
182 },
183 complete: function() {
184 },
185 success: function (response) {
186 if(response.status == 1){
187 jQuery(".single_variation .woocommerce-variation-price").html(response.price_html);
188 }
189 current_object.trigger("woo_discount_rules_after_variant_strikeout");
190 /*container.show("slow");*/
191 }
192 });';
193 $script .= ' });';
194 }
195 if($enable_variable_product_cache){
196 $script .= ' var woo_discount_rules_session_storage_id = "woo_discount_rules_session_storage_id_";
197 var woo_discount_rules_session_storage_time_id = "woo_discount_rules_session_storage_time_id_";
198 const WOO_DISCOUNT_RULES = {
199 checkSessionStorageExists: function (id) {
200 var name = woo_discount_rules_session_storage_id+id;
201 if (sessionStorage.getItem(name) === null) {
202 return false;
203 }
204 return true;
205 },
206 setSessionStorage: function (id, value) {
207 var name = woo_discount_rules_session_storage_id+id;
208 sessionStorage.setItem(name, value);
209 },
210 getSessionStorage: function (id) {
211 var name = woo_discount_rules_session_storage_id+id;
212 return sessionStorage.getItem(name);
213 },
214 setSessionStorageTime: function (id, value) {
215 var name = woo_discount_rules_session_storage_time_id+id;
216 sessionStorage.setItem(name, value);
217 },
218 getSessionStorageTime: function (id) {
219 var name = woo_discount_rules_session_storage_time_id+id;
220 return sessionStorage.getItem(name);
221 }
222 }
223 ';
224 }
225
226 $script .= ' if(jQuery(".woo_discount_rules_variant_table").length > 0){
227 var p_id = jQuery( ".woo_discount_rules_variant_table" ).attr("data-id");';
228 if($enable_variable_product_cache) {
229 $script .= ' var already_exists = WOO_DISCOUNT_RULES.checkSessionStorageExists(p_id);';
230 $script .= ' var last_storage_time = WOO_DISCOUNT_RULES.getSessionStorageTime(p_id);';
231 } else {
232 $script .= ' var already_exists = 0;';
233 $script .= ' var last_storage_time = "";';
234 }
235 $script .= ' setTimeout(function(){
236 jQuery.ajax({
237 url: woo_discount_rules.ajax_url,
238 type: "POST",
239 data: {action: "loadWooDiscountedDiscountTable", id: p_id, loaded: already_exists, time: last_storage_time},
240 beforeSend: function() {
241 },
242 complete: function() {
243 },
244 success: function (response) {
245 responseData = jQuery.parseJSON(response);
246 if(responseData.cookie == "1" && already_exists){';
247 if($enable_variable_product_cache) {
248 $script .= ' jQuery(".woo_discount_rules_variant_table").html(WOO_DISCOUNT_RULES.getSessionStorage(p_id));';
249 }
250 $script .= ' } else {
251 jQuery(".woo_discount_rules_variant_table").html(responseData.html);';
252 if($enable_variable_product_cache) {
253 $script .= ' WOO_DISCOUNT_RULES.setSessionStorage(p_id, responseData.html);
254 WOO_DISCOUNT_RULES.setSessionStorageTime(p_id, responseData.time);';
255 }
256 $script .= ' }
257 }
258 });
259 }, 1);';
260 $script .= ' }';
261 $script .= '});';
262 $script .= '</script>';
263
264 echo $script;
265 }
266
267 /**
268 * Load common scripts
269 * */
270 protected function loadCommonScripts(){
271 add_filter( 'woocommerce_email_styles', array($this, 'add_additional_woocommerce_email_styles'), 100);
272 $display_you_saved_text = $this->discountBase->getConfigData('display_you_saved_text', 'no');
273 if(in_array($display_you_saved_text, array('on_each_line_item', 'both_line_item_and_after_total'))){
274 add_filter( 'woocommerce_order_formatted_line_subtotal', array( $this->pricingRules, 'addAdditionalContentInOrderItemSubTotal'), 1000, 3);
275 }
276 if(in_array($display_you_saved_text, array('after_total', 'both_line_item_and_after_total'))){
277 add_action( 'woocommerce_email_after_order_table', array( $this->pricingRules, 'displayTotalSavingsThroughDiscountInOrder'), 10);
278 }
279 add_action( 'woo_discount_rules_get_total_savings_through_discount_in_cart', array( $this->pricingRules, 'displayTotalSavingsThroughDiscountInCart'), 10);
280 add_action( 'woo_discount_rules_get_total_savings_through_discount_from_order', array( $this->pricingRules, 'displayTotalSavingsThroughDiscountInOrder'), 10);
281 }
282
283 /**
284 * Add additional css in emails
285 * */
286 public function add_additional_woocommerce_email_styles($css){
287 return $css.'.wdr_you_saved_con {
288 color: green;
289 }';
290 }
291
292 /**
293 * Load Admin scripts
294 * */
295 protected function loadSiteScripts(){
296 $woocommerce_version = '2.0.0';
297 $pluginDetails = get_plugin_data(WP_PLUGIN_DIR.'/woocommerce/woocommerce.php');
298 if(isset($pluginDetails['Version'])){
299 $woocommerce_version = $pluginDetails['Version'];
300 }
301
302 add_action('woocommerce_after_cart_item_quantity_update', array($this->discountBase, 'handleDiscount'), 100);
303 if(version_compare($woocommerce_version, '3.0', '>=')){
304 add_action('woocommerce_before_calculate_totals', array($this, 'applyDiscountRules'), 1000);
305 add_action('woocommerce_cart_loaded_from_session', array($this, 'applyCartDiscountRules'), 97);
306 add_action( 'woocommerce_after_cart_item_quantity_update', array($this->pricingRules, 'handleBOGODiscountOnUpdateQuantity'), 10, 4 );
307 } else {
308 add_action( 'woocommerce_after_cart_item_quantity_update', array($this->pricingRules, 'handleBOGODiscountOnUpdateQuantity'), 10, 3 );
309 add_action('woocommerce_cart_loaded_from_session', array($this->discountBase, 'handleDiscount'), 100);
310 }
311
312 add_action('woocommerce_add_to_cart', array($this->pricingRules, 'handleBOGODiscount'), 10, 6);
313
314 $add_free_product_on_coupon_applied = $this->discountBase->getConfigData('add_free_product_on_coupon_applied', 0);
315 if($add_free_product_on_coupon_applied){
316 add_action('woocommerce_applied_coupon', array($this->pricingRules, 'handleBOGODiscountAfterApplyCoupon'), 10, 1);
317 }
318
319 add_action( 'woocommerce_checkout_create_order_line_item', array( $this->pricingRules, 'onCreateWoocommerceOrderLineItem'), 10, 4);
320 $display_you_saved_text = $this->discountBase->getConfigData('display_you_saved_text', 'no');
321 if(in_array($display_you_saved_text, array('on_each_line_item', 'both_line_item_and_after_total'))){
322 add_filter( 'woocommerce_cart_item_subtotal', array( $this->pricingRules, 'addAdditionalContentInCartItemSubTotal'), 1000, 3);
323 }
324 if(in_array($display_you_saved_text, array('after_total', 'both_line_item_and_after_total'))){
325 add_action( 'woocommerce_cart_totals_after_order_total', array( $this->pricingRules, 'displayTotalSavingsThroughDiscountInCart'), 10);
326 add_action( 'woocommerce_review_order_after_order_total', array( $this->pricingRules, 'displayTotalSavingsThroughDiscountInCart'), 10);
327 add_action( 'woocommerce_order_details_after_order_table', array( $this->pricingRules, 'displayTotalSavingsThroughDiscountInOrder'), 10);
328 }
329
330 // Manually Update Line Item Name.
331 add_filter('woocommerce_cart_item_name', array($this->discountBase, 'modifyName'));
332
333 // Remove Filter to make the previous one as last filter.
334 remove_filter('woocommerce_cart_item_name', 'filter_woocommerce_cart_item_name', 10, 3);
335
336 // Alter the Display Price HTML.
337 add_filter('woocommerce_cart_item_price', array($this->pricingRules, 'replaceVisiblePricesCart'), 1000, 3);
338
339 //replace visible price in product page
340 add_filter('woocommerce_get_price_html', array($this->pricingRules, 'replaceVisiblePricesOptimized'), 100, 3);
341 add_filter('woocommerce_get_price_html', array($this->pricingRules, 'replaceVisiblePricesForSalePriceAdjustment'), 99, 3);
342
343 //replace visible price in product page for variant
344 add_filter('woocommerce_available_variation', array($this->pricingRules, 'replaceVisiblePricesForVariant'), 100, 3);
345
346 // Older Version support this hook.
347 add_filter('woocommerce_cart_item_price_html', array($this->pricingRules, 'replaceVisiblePricesCart'), 1000, 3);
348
349 //For changing the sale tag text
350 add_filter( 'woocommerce_sale_flash', array($this->pricingRules, 'replaceSaleTagText'), 100, 3);
351
352 // Pricing Table of Individual Product.
353 $discount_table_placement = $this->discountBase->getConfigData('discount_table_placement', 'before_cart_form');
354 if($discount_table_placement == 'before_cart_form'){
355 add_filter('woocommerce_before_add_to_cart_form', array($this->pricingRules, 'priceTable'));
356 add_filter('woocommerce_before_add_to_cart_form', array($this, 'script_on_product_page'));
357 } else {
358 add_filter('woocommerce_after_add_to_cart_form', array($this->pricingRules, 'priceTable'));
359 add_filter('woocommerce_after_add_to_cart_form', array($this, 'script_on_product_page'));
360 }
361
362 // Updating Log After Creating Order
363 add_action('woocommerce_thankyou', array($this->discountBase, 'storeLog'));
364
365 add_action( 'woocommerce_after_checkout_form', array($this->discountBase, 'addScriptInCheckoutPage'));
366
367 //To enable on-sale tag
368 add_filter('woocommerce_product_is_on_sale', array($this->pricingRules, 'displayProductIsOnSaleTagOptimized'), 10, 2);
369
370 $force_refresh_cart_widget = $this->discountBase->getConfigData('force_refresh_cart_widget', 0);
371 if($force_refresh_cart_widget){
372 if (isset($_REQUEST['wc-ajax']) && ($_REQUEST['wc-ajax'] == 'add_to_cart' || $_REQUEST['wc-ajax'] == 'remove_from_cart')) {
373 add_action('woocommerce_before_mini_cart', array($this, 'applyRulesBeforeMiniCart'), 10);
374 }
375 }
376
377 add_action('wp_ajax_loadWooDiscountedPriceForVariant', array($this->pricingRules, 'getWooDiscountedPriceForVariant'));
378 add_action('wp_ajax_nopriv_loadWooDiscountedPriceForVariant', array($this->pricingRules, 'getWooDiscountedPriceForVariant'));
379 add_action('wp_ajax_loadWooDiscountedDiscountTable', array($this->pricingRules, 'getWooDiscountedPriceTableForVariant'));
380 add_action('wp_ajax_nopriv_loadWooDiscountedDiscountTable', array($this->pricingRules, 'getWooDiscountedPriceTableForVariant'));
381 add_action( 'wp_enqueue_scripts', array($this, 'includeScriptAndStyles') );
382
383 add_action('woocommerce_before_checkout_form', array($this, 'displayAppliedDiscountMessagesForPriceRules'));
384 add_action('woocommerce_before_checkout_form', array($this, 'displayAppliedDiscountMessagesForCartRules'));
385 add_action('woocommerce_before_cart', array($this, 'displayAppliedDiscountMessagesForPriceRules'));
386 add_action('woocommerce_before_cart', array($this, 'displayAppliedDiscountMessagesForCartRules'));
387
388
389 add_filter('woo_discount_rule_products_to_exclude', array($this, 'woo_discount_get_variations'));
390 add_filter('woo_discount_rule_products_to_include', array($this, 'woo_discount_get_variations'));
391 }
392
393 /**
394 * Include the variant product as well while choose parent product
395 *
396 * @param array $excluded_products
397 * @return array
398 * */
399 public function woo_discount_get_variations($excluded_products = array()) {
400 $include_variants_on_select_parent_product = $this->discountBase->getConfigData('include_variants_on_select_parent_product', 0);
401 if($include_variants_on_select_parent_product){
402 static $sets;
403 if (!is_array($sets)) {
404 $sets = array();
405 }
406
407 if(count($excluded_products) < 1) return $excluded_products;
408 $string = json_encode($excluded_products);
409
410 if (!isset($sets[$string])) {
411 $all_excluded_products = $excluded_products;
412 foreach ($excluded_products as $exclude_id) {
413 $product = wc_get_product($exclude_id);
414 if (is_object($product) && method_exists($product, 'get_type') && $product->get_type() == 'variable') {
415 $children_ids = $product->get_children();
416 $all_excluded_products = array_merge($all_excluded_products, $children_ids);
417 }
418 }
419 $sets[$string] = $all_excluded_products;
420 }
421
422 return $sets[$string];
423 } else {
424 return $excluded_products;
425 }
426 }
427
428 /**
429 * To include the styles
430 * */
431 public function includeScriptAndStyles(){
432 wp_register_style('woo_discount_rules_front_end', WOO_DISCOUNT_URI . '/assets/css/woo_discount_rules.css', array(), WOO_DISCOUNT_VERSION);
433 wp_enqueue_style('woo_discount_rules_front_end');
434 // Enqueued script with localized data.
435 wp_register_script( 'woo_discount_rules_site', WOO_DISCOUNT_URI . '/assets/js/woo_discount_rules.js', array('jquery'), WOO_DISCOUNT_VERSION, true );
436 wp_localize_script('woo_discount_rules_site', 'woo_discount_rules', array(
437 'home_url' => get_home_url(),
438 'admin_url' => admin_url(),
439 'ajax_url' => admin_url('admin-ajax.php')
440 ));
441 wp_enqueue_script( 'woo_discount_rules_site');
442 }
443
444 /**
445 * To load the dynamic data in mini-cart/cart widget while add to cart and remove from cart through widget
446 * */
447 public function applyRulesBeforeMiniCart(){
448 WC()->cart->get_cart_from_session();
449 $this->discountBase->handlePriceDiscount();
450 WC()->cart->calculate_totals();
451 }
452
453 /**
454 * To display applied discount messages for cart rules
455 * */
456 public function displayAppliedDiscountMessagesForCartRules(){
457 $message_on_apply_cart_discount = $this->discountBase->getConfigData('message_on_apply_cart_discount', 'no');
458 if($message_on_apply_cart_discount == "yes"){
459 if(!empty($this->cart_rules)){
460 if(!empty($this->cart_rules->matched_discounts)){
461 $matched_discounts = $this->cart_rules->matched_discounts;
462 if(!empty($matched_discounts['name'])){
463 foreach ($matched_discounts['name'] as $key => $matched_discount_name){
464 $rule_sets = $this->cart_rules->rule_sets;
465 $rule_title = $matched_discount_name;
466 $rule_description = '';
467 if(isset($rule_sets[$key])){
468 if(!empty($rule_sets[$key]['descr'])) $rule_description = $rule_sets[$key]['descr'];
469 }
470 $message_on_apply_cart_discount_text = $this->discountBase->getConfigData('message_on_apply_cart_discount_text', 'Discount <strong>"{{title}}"</strong> has been applied to your cart.');
471 $message_on_apply_cart_discount_text = __($message_on_apply_cart_discount_text, 'woo-discount-rules');
472 $message_on_apply_cart_discount_text = str_replace('{{title}}', $rule_title, $message_on_apply_cart_discount_text);
473 $message_on_apply_cart_discount_text = str_replace('{{description}}', $rule_description, $message_on_apply_cart_discount_text);
474 wc_print_notice( apply_filters('woo_discount_rules_message_on_apply_cart_rules', $message_on_apply_cart_discount_text, $rule_sets), 'success' );
475 }
476 }
477 }
478 }
479 }
480 }
481
482 /**
483 * To display applied discount messages for cart rules
484 * */
485 public function displayAppliedDiscountMessagesForPriceRules(){
486 $message_on_apply_price_discount = $this->discountBase->getConfigData('message_on_apply_price_discount', 'no');
487 if($message_on_apply_price_discount == "yes"){
488 $applied_discount_rules = FlycartWooDiscountRulesPricingRules::$applied_discount_rules;
489 if(!empty($applied_discount_rules)){
490 foreach ($applied_discount_rules as $key => $matched_discount_rules){
491 $rule_title = $matched_discount_rules['name'];
492 $rule_description = $matched_discount_rules['descr'];
493 $message_on_apply_cart_discount_text = $this->discountBase->getConfigData('message_on_apply_price_discount_text', 'Discount <strong>"{{title}}"</strong> has been applied to your cart.');
494 $message_on_apply_cart_discount_text = __($message_on_apply_cart_discount_text, 'woo-discount-rules');
495 $message_on_apply_cart_discount_text = str_replace('{{title}}', $rule_title, $message_on_apply_cart_discount_text);
496 $message_on_apply_cart_discount_text = str_replace('{{description}}', $rule_description, $message_on_apply_cart_discount_text);
497 wc_print_notice( apply_filters('woo_discount_rules_message_on_apply_price_rules', $message_on_apply_cart_discount_text, $matched_discount_rules), 'success' );
498 }
499 }
500 }
501 }
502 }
503 }
504
505 add_filter('woocommerce_screen_ids', function($screen_ids){
506 $screen_ids[] = 'woocommerce_page_woo_discount_rules';
507 return $screen_ids;
508 });
509
510 /**
511 * init Woo Discount Rules
512 */
513 if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
514 global $flycart_woo_discount_rules;
515 $flycart_woo_discount_rules = FlycartWooDiscountRules::init();
516 $purchase_helper = new FlycartWooDiscountRulesPurchase();
517 if($purchase_helper->isPro()){
518 include_once(dirname(__FILE__).'/includes/advanced/free_shipping_method.php');
519 include_once(dirname(__FILE__).'/includes/advanced/pricing-productdependent.php');
520 include_once(dirname(__FILE__).'/includes/advanced/cart-totals.php');
521 include_once(dirname(__FILE__).'/includes/advanced/advanced-helper.php');
522 }
523 }