PluginProbe ʕ •ᴥ•ʔ
Discount Rules for WooCommerce / 1.7.12
Discount Rules for WooCommerce v1.7.12
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
527 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 include_once(dirname(__FILE__).'/includes/compatibility.php');
87 require_once __DIR__ . '/vendor/autoload.php';
88 }
89
90 /**
91 * Run Plugin updater
92 * */
93 protected function runUpdater(){
94 try{
95 require plugin_dir_path( __FILE__ ).'/vendor/yahnis-elsts/plugin-update-checker/plugin-update-checker.php';
96
97 $purchase_helper = new FlycartWooDiscountRulesPurchase();
98 $purchase_helper->init();
99 $update_url = $purchase_helper->getUpdateURL();
100 if(!$purchase_helper->isPro()){
101 $dlid = $this->discountBase->getConfigData('license_key', null);
102 if(empty($dlid)) return false;
103 }
104 $myUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
105 $update_url,
106 plugin_dir_path( __FILE__ ).'woo-discount-rules.php',
107 'woo-discount-rules'
108 );
109 add_action( 'after_plugin_row', array($purchase_helper, 'woodisc_after_plugin_row'),10,3 );
110
111 add_action('wp_ajax_forceValidateLicenseKey', array($purchase_helper, 'forceValidateLicenseKey'));
112
113 add_action( 'admin_notices', array($purchase_helper, 'errorNoticeInAdminPages'));
114 } catch (Exception $e){}
115 }
116
117 /**
118 * Load Admin scripts
119 * */
120 protected function loadAdminScripts(){
121 // Init in Admin Menu
122 add_action('admin_menu', array($this->discountBase, 'adminMenu'));
123 add_action('wp_ajax_savePriceRule', array($this->discountBase, 'savePriceRule'));
124 add_action('wp_ajax_saveCartRule', array($this->discountBase, 'saveCartRule'));
125 add_action('wp_ajax_saveConfig', array($this->discountBase, 'saveConfig'));
126 add_action('wp_ajax_resetWDRCache', array($this->discountBase, 'resetWDRCache'));
127 add_action('wp_ajax_loadProductSelectBox', array($this->discountBase, 'loadProductSelectBox'));
128 add_action('wp_ajax_loadCoupons', array($this->discountBase, 'loadCoupons'));
129
130 add_action('wp_ajax_UpdateStatus', array($this->discountBase, 'updateStatus'));
131 add_action('wp_ajax_RemoveRule', array($this->discountBase, 'removeRule'));
132 add_action('wp_ajax_doBulkAction', array($this->discountBase, 'doBulkAction'));
133 add_action('wp_ajax_createDuplicateRule', array($this->discountBase, 'createDuplicateRule'));
134 add_action('admin_enqueue_scripts', array($this->discountBase, 'woo_discount_adminPageScript'), 100 );
135 $display_you_saved_text = $this->discountBase->getConfigData('display_you_saved_text', 'no');
136 if(in_array($display_you_saved_text, array('on_each_line_item', 'both_line_item_and_after_total'))){
137 add_action( 'woocommerce_after_order_itemmeta', array( $this->pricingRules, 'addAdditionalContentInAfterOrderItemMeta'), 1000, 3);
138 }
139 if(in_array($display_you_saved_text, array('after_total', 'both_line_item_and_after_total'))){
140 add_action( 'woocommerce_admin_order_totals_after_total', array( $this->pricingRules, 'displayTotalSavingsThroughDiscountInOrder'), 10);
141 }
142 }
143
144 /**
145 * Apply discount rules
146 * */
147 public function applyDiscountRules(){
148 $this->discountBase->handlePriceDiscount();
149 $removeTheEvent = apply_filters('woo_discount_rules_remove_event_woocommerce_before_calculate_totals', false);
150 if(!$removeTheEvent){
151 remove_action('woocommerce_before_calculate_totals', array($this, 'applyDiscountRules'), 1000);
152 }
153 }
154
155 /**
156 * Apply discount rules
157 * */
158 public function applyCartDiscountRules(){
159 remove_action('woocommerce_cart_loaded_from_session', array($this, 'applyCartDiscountRules'), 97);
160 $this->discountBase->handleCartDiscount();
161 }
162
163 /**
164 * Script on product page for loading variant strikeout
165 * */
166 public function script_on_product_page(){
167 $runVariationStrikeoutAjax = apply_filters('woo_discount_rules_run_variation_strikeout_through_ajax', true);
168 $script = '<script>';
169 $script .= 'if(flycart_woo_discount_rules_strikeout_script_executed == undefined){';
170 $script .= 'jQuery( document ).ready( function() {';
171 $do_product_page_strikeout = $this->discountBase->getConfigData('show_price_discount_on_product_page', 'show');
172 $enable_variable_product_cache = $this->discountBase->getConfigData('enable_variable_product_cache', 0);
173 if($do_product_page_strikeout == 'show' && $runVariationStrikeoutAjax) {
174 $script .= 'jQuery( ".single_variation_wrap" ).on( "show_variation", function ( event, variation, purchasable ) {';
175 $script .= ' var container = jQuery(".single_variation .woocommerce-variation-price");';
176 $script .= ' var current_object = jQuery(this);
177 current_object.trigger("woo_discount_rules_before_variant_strikeout");/*container.hide("slow");*/';
178 $script .= ' jQuery.ajax({
179 url: woo_discount_rules.ajax_url,
180 dataType: "json",
181 type: "POST",
182 data: {action: "loadWooDiscountedPriceForVariant", id: variation.variation_id, price_html: variation.price_html},
183 beforeSend: function() {
184 },
185 complete: function() {
186 },
187 success: function (response) {
188 if(response.status == 1){
189 jQuery(".single_variation .woocommerce-variation-price").html(response.price_html);
190 }
191 current_object.trigger("woo_discount_rules_after_variant_strikeout");
192 /*container.show("slow");*/
193 }
194 });';
195 $script .= ' });';
196 }
197 if($enable_variable_product_cache){
198 $script .= ' var woo_discount_rules_session_storage_id = "woo_discount_rules_session_storage_id_";
199 var woo_discount_rules_session_storage_time_id = "woo_discount_rules_session_storage_time_id_";
200 const WOO_DISCOUNT_RULES = {
201 checkSessionStorageExists: function (id) {
202 var name = woo_discount_rules_session_storage_id+id;
203 if (sessionStorage.getItem(name) === null) {
204 return false;
205 }
206 return true;
207 },
208 setSessionStorage: function (id, value) {
209 var name = woo_discount_rules_session_storage_id+id;
210 sessionStorage.setItem(name, value);
211 },
212 getSessionStorage: function (id) {
213 var name = woo_discount_rules_session_storage_id+id;
214 return sessionStorage.getItem(name);
215 },
216 setSessionStorageTime: function (id, value) {
217 var name = woo_discount_rules_session_storage_time_id+id;
218 sessionStorage.setItem(name, value);
219 },
220 getSessionStorageTime: function (id) {
221 var name = woo_discount_rules_session_storage_time_id+id;
222 return sessionStorage.getItem(name);
223 }
224 }
225 ';
226 }
227
228 $script .= ' if(jQuery(".woo_discount_rules_variant_table").length > 0){
229 var p_id = jQuery( ".woo_discount_rules_variant_table" ).attr("data-id");';
230 if($enable_variable_product_cache) {
231 $script .= ' var already_exists = WOO_DISCOUNT_RULES.checkSessionStorageExists(p_id);';
232 $script .= ' var last_storage_time = WOO_DISCOUNT_RULES.getSessionStorageTime(p_id);';
233 } else {
234 $script .= ' var already_exists = 0;';
235 $script .= ' var last_storage_time = "";';
236 }
237 $script .= ' setTimeout(function(){
238 jQuery.ajax({
239 url: woo_discount_rules.ajax_url,
240 type: "POST",
241 data: {action: "loadWooDiscountedDiscountTable", id: p_id, loaded: already_exists, time: last_storage_time},
242 beforeSend: function() {
243 },
244 complete: function() {
245 },
246 success: function (response) {
247 responseData = jQuery.parseJSON(response);
248 if(responseData.cookie == "1" && already_exists){';
249 if($enable_variable_product_cache) {
250 $script .= ' jQuery(".woo_discount_rules_variant_table").html(WOO_DISCOUNT_RULES.getSessionStorage(p_id));';
251 }
252 $script .= ' } else {
253 jQuery(".woo_discount_rules_variant_table").html(responseData.html);';
254 if($enable_variable_product_cache) {
255 $script .= ' WOO_DISCOUNT_RULES.setSessionStorage(p_id, responseData.html);
256 WOO_DISCOUNT_RULES.setSessionStorageTime(p_id, responseData.time);';
257 }
258 $script .= ' }
259 }
260 });
261 }, 1);';
262 $script .= ' }';
263 $script .= '});';
264 $script .= 'var flycart_woo_discount_rules_strikeout_script_executed = 1; }';
265 $script .= '</script>';
266
267 echo $script;
268 }
269
270 /**
271 * Load common scripts
272 * */
273 protected function loadCommonScripts(){
274 add_filter( 'woocommerce_email_styles', array($this, 'add_additional_woocommerce_email_styles'), 100);
275 $display_you_saved_text = $this->discountBase->getConfigData('display_you_saved_text', 'no');
276 if(in_array($display_you_saved_text, array('on_each_line_item', 'both_line_item_and_after_total'))){
277 add_filter( 'woocommerce_order_formatted_line_subtotal', array( $this->pricingRules, 'addAdditionalContentInOrderItemSubTotal'), 1000, 3);
278 }
279 if(in_array($display_you_saved_text, array('after_total', 'both_line_item_and_after_total'))){
280 add_action( 'woocommerce_email_after_order_table', array( $this->pricingRules, 'displayTotalSavingsThroughDiscountInOrder'), 10);
281 }
282 add_action( 'woo_discount_rules_get_total_savings_through_discount_in_cart', array( $this->pricingRules, 'displayTotalSavingsThroughDiscountInCart'), 10);
283 add_action( 'woo_discount_rules_get_total_savings_through_discount_from_order', array( $this->pricingRules, 'displayTotalSavingsThroughDiscountInOrder'), 10);
284 }
285
286 /**
287 * Add additional css in emails
288 * */
289 public function add_additional_woocommerce_email_styles($css){
290 return $css.'.wdr_you_saved_con {
291 color: green;
292 }';
293 }
294
295 /**
296 * Load Admin scripts
297 * */
298 protected function loadSiteScripts(){
299 $woocommerce_version = '2.0.0';
300 $pluginDetails = get_plugin_data(WP_PLUGIN_DIR.'/woocommerce/woocommerce.php');
301 if(isset($pluginDetails['Version'])){
302 $woocommerce_version = $pluginDetails['Version'];
303 }
304
305 add_action('woocommerce_after_cart_item_quantity_update', array($this->discountBase, 'handleDiscount'), 100);
306 if(version_compare($woocommerce_version, '3.0', '>=')){
307 add_action('woocommerce_before_calculate_totals', array($this, 'applyDiscountRules'), 1000);
308 add_action('woocommerce_cart_loaded_from_session', array($this, 'applyCartDiscountRules'), 97);
309 add_action( 'woocommerce_after_cart_item_quantity_update', array($this->pricingRules, 'handleBOGODiscountOnUpdateQuantity'), 10, 4 );
310 } else {
311 add_action( 'woocommerce_after_cart_item_quantity_update', array($this->pricingRules, 'handleBOGODiscountOnUpdateQuantity'), 10, 3 );
312 add_action('woocommerce_cart_loaded_from_session', array($this->discountBase, 'handleDiscount'), 100);
313 }
314
315 add_action('woocommerce_after_calculate_totals', array($this->discountBase, 'removeThirdPartyCoupon'), 20);
316
317 add_action('woocommerce_add_to_cart', array($this->pricingRules, 'handleBOGODiscount'), 10, 6);
318
319 $add_free_product_on_coupon_applied = $this->discountBase->getConfigData('add_free_product_on_coupon_applied', 0);
320 if($add_free_product_on_coupon_applied){
321 add_action('woocommerce_applied_coupon', array($this->pricingRules, 'handleBOGODiscountAfterApplyCoupon'), 10, 1);
322 }
323
324 add_action( 'woocommerce_checkout_create_order_line_item', array( $this->pricingRules, 'onCreateWoocommerceOrderLineItem'), 10, 4);
325 $display_you_saved_text = $this->discountBase->getConfigData('display_you_saved_text', 'no');
326 if(in_array($display_you_saved_text, array('on_each_line_item', 'both_line_item_and_after_total'))){
327 add_filter( 'woocommerce_cart_item_subtotal', array( $this->pricingRules, 'addAdditionalContentInCartItemSubTotal'), 1000, 3);
328 }
329 if(in_array($display_you_saved_text, array('after_total', 'both_line_item_and_after_total'))){
330 add_action( 'woocommerce_cart_totals_after_order_total', array( $this->pricingRules, 'displayTotalSavingsThroughDiscountInCart'), 10);
331 add_action( 'woocommerce_review_order_after_order_total', array( $this->pricingRules, 'displayTotalSavingsThroughDiscountInCart'), 10);
332 add_action( 'woocommerce_order_details_after_order_table', array( $this->pricingRules, 'displayTotalSavingsThroughDiscountInOrder'), 10);
333 }
334
335 // Manually Update Line Item Name.
336 add_filter('woocommerce_cart_item_name', array($this->discountBase, 'modifyName'));
337
338 // Remove Filter to make the previous one as last filter.
339 remove_filter('woocommerce_cart_item_name', 'filter_woocommerce_cart_item_name', 10, 3);
340
341 // Alter the Display Price HTML.
342 add_filter('woocommerce_cart_item_price', array($this->pricingRules, 'replaceVisiblePricesCart'), 1000, 3);
343
344 //replace visible price in product page
345 add_filter('woocommerce_get_price_html', array($this->pricingRules, 'replaceVisiblePricesOptimized'), 100, 3);
346 add_filter('woocommerce_get_price_html', array($this->pricingRules, 'replaceVisiblePricesForSalePriceAdjustment'), 99, 3);
347
348 //replace visible price in product page for variant
349 add_filter('woocommerce_available_variation', array($this->pricingRules, 'replaceVisiblePricesForVariant'), 100, 3);
350
351 // Older Version support this hook.
352 add_filter('woocommerce_cart_item_price_html', array($this->pricingRules, 'replaceVisiblePricesCart'), 1000, 3);
353
354 //For changing the sale tag text
355 add_filter( 'woocommerce_sale_flash', array($this->pricingRules, 'replaceSaleTagText'), 100, 3);
356
357 // Pricing Table of Individual Product.
358 $discount_table_placement = $this->discountBase->getConfigData('discount_table_placement', 'before_cart_form');
359 if($discount_table_placement == 'before_cart_form'){
360 add_filter('woocommerce_before_add_to_cart_form', array($this->pricingRules, 'priceTable'));
361 add_filter('woocommerce_before_add_to_cart_form', array($this, 'script_on_product_page'));
362 } else {
363 add_filter('woocommerce_after_add_to_cart_form', array($this->pricingRules, 'priceTable'));
364 add_filter('woocommerce_after_add_to_cart_form', array($this, 'script_on_product_page'));
365 }
366
367 // Updating Log After Creating Order
368 add_action('woocommerce_thankyou', array($this->discountBase, 'storeLog'));
369
370 add_action( 'woocommerce_after_checkout_form', array($this->discountBase, 'addScriptInCheckoutPage'));
371
372 //To enable on-sale tag
373 add_filter('woocommerce_product_is_on_sale', array($this->pricingRules, 'displayProductIsOnSaleTagOptimized'), 10, 2);
374
375 $force_refresh_cart_widget = $this->discountBase->getConfigData('force_refresh_cart_widget', 0);
376 if($force_refresh_cart_widget){
377 if (isset($_REQUEST['wc-ajax']) && ($_REQUEST['wc-ajax'] == 'add_to_cart' || $_REQUEST['wc-ajax'] == 'remove_from_cart')) {
378 add_action('woocommerce_before_mini_cart', array($this, 'applyRulesBeforeMiniCart'), 10);
379 }
380 }
381
382 add_action('wp_ajax_loadWooDiscountedPriceForVariant', array($this->pricingRules, 'getWooDiscountedPriceForVariant'));
383 add_action('wp_ajax_nopriv_loadWooDiscountedPriceForVariant', array($this->pricingRules, 'getWooDiscountedPriceForVariant'));
384 add_action('wp_ajax_loadWooDiscountedDiscountTable', array($this->pricingRules, 'getWooDiscountedPriceTableForVariant'));
385 add_action('wp_ajax_nopriv_loadWooDiscountedDiscountTable', array($this->pricingRules, 'getWooDiscountedPriceTableForVariant'));
386 add_action( 'wp_enqueue_scripts', array($this, 'includeScriptAndStyles') );
387
388 add_action('woocommerce_before_checkout_form', array($this, 'displayAppliedDiscountMessagesForPriceRules'));
389 add_action('woocommerce_before_checkout_form', array($this, 'displayAppliedDiscountMessagesForCartRules'));
390 add_action('woocommerce_before_cart', array($this, 'displayAppliedDiscountMessagesForPriceRules'));
391 add_action('woocommerce_before_cart', array($this, 'displayAppliedDiscountMessagesForCartRules'));
392
393 add_filter('woo_discount_rule_products_to_exclude', array($this, 'woo_discount_get_variations'));
394 add_filter('woo_discount_rule_products_to_include', array($this, 'woo_discount_get_variations'));
395 }
396
397 /**
398 * Include the variant product as well while choose parent product
399 *
400 * @param array $excluded_products
401 * @return array
402 * */
403 public function woo_discount_get_variations($excluded_products = array()) {
404 $include_variants_on_select_parent_product = $this->discountBase->getConfigData('include_variants_on_select_parent_product', 0);
405 if($include_variants_on_select_parent_product){
406 static $sets;
407 if (!is_array($sets)) {
408 $sets = array();
409 }
410
411 if(count($excluded_products) < 1) return $excluded_products;
412 $string = json_encode($excluded_products);
413
414 if (!isset($sets[$string])) {
415 $all_excluded_products = $excluded_products;
416 foreach ($excluded_products as $exclude_id) {
417 $product = wc_get_product($exclude_id);
418 if (is_object($product) && method_exists($product, 'get_type') && $product->get_type() == 'variable') {
419 $children_ids = $product->get_children();
420 $all_excluded_products = array_merge($all_excluded_products, $children_ids);
421 }
422 }
423 $sets[$string] = $all_excluded_products;
424 }
425
426 return $sets[$string];
427 } else {
428 return $excluded_products;
429 }
430 }
431
432 /**
433 * To include the styles
434 * */
435 public function includeScriptAndStyles(){
436 wp_register_style('woo_discount_rules_front_end', WOO_DISCOUNT_URI . '/assets/css/woo_discount_rules.css', array(), WOO_DISCOUNT_VERSION);
437 wp_enqueue_style('woo_discount_rules_front_end');
438 // Enqueued script with localized data.
439 wp_register_script( 'woo_discount_rules_site', WOO_DISCOUNT_URI . '/assets/js/woo_discount_rules.js', array('jquery'), WOO_DISCOUNT_VERSION, true );
440 wp_localize_script('woo_discount_rules_site', 'woo_discount_rules', array(
441 'home_url' => get_home_url(),
442 'admin_url' => admin_url(),
443 'ajax_url' => admin_url('admin-ajax.php')
444 ));
445 wp_enqueue_script( 'woo_discount_rules_site');
446 }
447
448 /**
449 * To load the dynamic data in mini-cart/cart widget while add to cart and remove from cart through widget
450 * */
451 public function applyRulesBeforeMiniCart(){
452 WC()->cart->get_cart_from_session();
453 $this->discountBase->handlePriceDiscount();
454 WC()->cart->calculate_totals();
455 }
456
457 /**
458 * To display applied discount messages for cart rules
459 * */
460 public function displayAppliedDiscountMessagesForCartRules(){
461 $message_on_apply_cart_discount = $this->discountBase->getConfigData('message_on_apply_cart_discount', 'no');
462 if($message_on_apply_cart_discount == "yes"){
463 if(!empty($this->cart_rules)){
464 if(!empty($this->cart_rules->matched_discounts)){
465 $matched_discounts = $this->cart_rules->matched_discounts;
466 if(!empty($matched_discounts['name'])){
467 foreach ($matched_discounts['name'] as $key => $matched_discount_name){
468 $rule_sets = $this->cart_rules->rule_sets;
469 $rule_title = $matched_discount_name;
470 $rule_description = '';
471 if(isset($rule_sets[$key])){
472 if(!empty($rule_sets[$key]['descr'])) $rule_description = $rule_sets[$key]['descr'];
473 }
474 $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.');
475 $message_on_apply_cart_discount_text = __($message_on_apply_cart_discount_text, 'woo-discount-rules');
476 $message_on_apply_cart_discount_text = str_replace('{{title}}', $rule_title, $message_on_apply_cart_discount_text);
477 $message_on_apply_cart_discount_text = str_replace('{{description}}', $rule_description, $message_on_apply_cart_discount_text);
478 wc_print_notice( apply_filters('woo_discount_rules_message_on_apply_cart_rules', $message_on_apply_cart_discount_text, $rule_sets), 'success' );
479 }
480 }
481 }
482 }
483 }
484 }
485
486 /**
487 * To display applied discount messages for cart rules
488 * */
489 public function displayAppliedDiscountMessagesForPriceRules(){
490 $message_on_apply_price_discount = $this->discountBase->getConfigData('message_on_apply_price_discount', 'no');
491 if($message_on_apply_price_discount == "yes"){
492 $applied_discount_rules = FlycartWooDiscountRulesPricingRules::$applied_discount_rules;
493 if(!empty($applied_discount_rules)){
494 foreach ($applied_discount_rules as $key => $matched_discount_rules){
495 $rule_title = $matched_discount_rules['name'];
496 $rule_description = $matched_discount_rules['descr'];
497 $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.');
498 $message_on_apply_cart_discount_text = __($message_on_apply_cart_discount_text, 'woo-discount-rules');
499 $message_on_apply_cart_discount_text = str_replace('{{title}}', $rule_title, $message_on_apply_cart_discount_text);
500 $message_on_apply_cart_discount_text = str_replace('{{description}}', $rule_description, $message_on_apply_cart_discount_text);
501 wc_print_notice( apply_filters('woo_discount_rules_message_on_apply_price_rules', $message_on_apply_cart_discount_text, $matched_discount_rules), 'success' );
502 }
503 }
504 }
505 }
506 }
507 }
508
509 add_filter('woocommerce_screen_ids', function($screen_ids){
510 $screen_ids[] = 'woocommerce_page_woo_discount_rules';
511 return $screen_ids;
512 });
513
514 /**
515 * init Woo Discount Rules
516 */
517 if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
518 global $flycart_woo_discount_rules;
519 $flycart_woo_discount_rules = FlycartWooDiscountRules::init();
520 $purchase_helper = new FlycartWooDiscountRulesPurchase();
521 if($purchase_helper->isPro()){
522 include_once(dirname(__FILE__).'/includes/advanced/free_shipping_method.php');
523 include_once(dirname(__FILE__).'/includes/advanced/pricing-productdependent.php');
524 include_once(dirname(__FILE__).'/includes/advanced/cart-totals.php');
525 include_once(dirname(__FILE__).'/includes/advanced/advanced-helper.php');
526 }
527 }