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