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