woo-discount-rules
Last commit date
assets
8 years ago
helper
8 years ago
includes
8 years ago
vendor
8 years ago
view
8 years ago
loader.php
8 years ago
readme.txt
8 years ago
woo-discount-rules.php
8 years ago
loader.php
162 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 | |
| 36 | /** |
| 37 | * To run the plugin |
| 38 | * */ |
| 39 | public static function init() { |
| 40 | if ( self::$instance == null ) { |
| 41 | self::$instance = new FlycartWooDiscountRules(); |
| 42 | } |
| 43 | return self::$instance; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * FlycartWooDiscountRules constructor |
| 48 | * */ |
| 49 | public function __construct() { |
| 50 | $this->includeFiles(); |
| 51 | $this->runUpdater(); |
| 52 | $this->discountBase = new FlycartWooDiscountBase(); |
| 53 | $this->pricingRules = new FlycartWooDiscountRulesPricingRules(); |
| 54 | if (is_admin()) { |
| 55 | $this->loadAdminScripts(); |
| 56 | } else { |
| 57 | $this->loadSiteScripts(); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * To include Files |
| 63 | * */ |
| 64 | protected function includeFiles(){ |
| 65 | include_once('helper/woo-function.php'); |
| 66 | include_once('includes/pricing-rules.php'); |
| 67 | include_once('helper/general-helper.php'); |
| 68 | include_once('includes/cart-rules.php'); |
| 69 | include_once('includes/discount-base.php'); |
| 70 | include_once('helper/purchase.php'); |
| 71 | require_once __DIR__ . '/vendor/autoload.php'; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Run Plugin updater |
| 76 | * */ |
| 77 | protected function runUpdater(){ |
| 78 | try{ |
| 79 | require plugin_dir_path( __FILE__ ).'/vendor/yahnis-elsts/plugin-update-checker/plugin-update-checker.php'; |
| 80 | |
| 81 | $purchase_helper = new FlycartWooDiscountRulesPurchase(); |
| 82 | $purchase_helper->init(); |
| 83 | $update_url = $purchase_helper->getUpdateURL(); |
| 84 | |
| 85 | $myUpdateChecker = Puc_v4_Factory::buildUpdateChecker( |
| 86 | $update_url, |
| 87 | plugin_dir_path( __FILE__ ).'woo-discount-rules.php', |
| 88 | 'woo-discount-rules' |
| 89 | ); |
| 90 | add_action( 'after_plugin_row', array($purchase_helper, 'woodisc_after_plugin_row'),10,3 ); |
| 91 | |
| 92 | add_action('wp_ajax_forceValidateLicenseKey', array($purchase_helper, 'forceValidateLicenseKey')); |
| 93 | |
| 94 | add_action( 'admin_notices', array($purchase_helper, 'errorNoticeInAdminPages')); |
| 95 | } catch (Exception $e){} |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Load Admin scripts |
| 100 | * */ |
| 101 | protected function loadAdminScripts(){ |
| 102 | // Init in Admin Menu |
| 103 | add_action('admin_menu', array($this->discountBase, 'adminMenu')); |
| 104 | add_action('wp_ajax_savePriceRule', array($this->discountBase, 'savePriceRule')); |
| 105 | add_action('wp_ajax_saveCartRule', array($this->discountBase, 'saveCartRule')); |
| 106 | add_action('wp_ajax_saveConfig', array($this->discountBase, 'saveConfig')); |
| 107 | |
| 108 | add_action('wp_ajax_UpdateStatus', array($this->discountBase, 'updateStatus')); |
| 109 | add_action('wp_ajax_RemoveRule', array($this->discountBase, 'removeRule')); |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Load Admin scripts |
| 114 | * */ |
| 115 | protected function loadSiteScripts(){ |
| 116 | $postData = \FlycartInput\FInput::getInstance(); |
| 117 | // Handling Tight update with wooCommerce Changes. |
| 118 | $empty_add_to_cart = $postData->get('add-to-cart'); |
| 119 | $empty_apply_coupon = $postData->get('apply_coupon'); |
| 120 | $empty_update_cart = $postData->get('update_cart'); |
| 121 | $empty_proceed = $postData->get('proceed'); |
| 122 | if ((!empty($empty_add_to_cart) && is_numeric($postData->get('add-to-cart'))) || $postData->get('action', false) == 'woocommerce_add_to_cart') { |
| 123 | |
| 124 | } else if (!empty($empty_apply_coupon) || !empty($empty_update_cart) || !empty($empty_proceed)) { |
| 125 | add_action('woocommerce_after_cart_item_quantity_update', array($this->discountBase, 'handleDiscount'), 100); |
| 126 | } else { |
| 127 | add_action('woocommerce_cart_loaded_from_session', array($this->discountBase, 'handleDiscount'), 100); |
| 128 | } |
| 129 | |
| 130 | // Manually Update Line Item Name. |
| 131 | add_filter('woocommerce_cart_item_name', array($this->discountBase, 'modifyName')); |
| 132 | |
| 133 | // Remove Filter to make the previous one as last filter. |
| 134 | remove_filter('woocommerce_cart_item_name', 'filter_woocommerce_cart_item_name', 10, 3); |
| 135 | |
| 136 | // Alter the Display Price HTML. |
| 137 | add_filter('woocommerce_cart_item_price', array($this->pricingRules, 'replaceVisiblePricesCart'), 100, 3); |
| 138 | |
| 139 | //replace visible price in product page |
| 140 | add_filter('woocommerce_get_price_html', array($this->pricingRules, 'replaceVisiblePrices'), 100, 3); |
| 141 | //replace visible price in product page for variant |
| 142 | add_filter('woocommerce_available_variation', array($this->pricingRules, 'replaceVisiblePricesForVariant'), 100, 3); |
| 143 | |
| 144 | |
| 145 | // Older Version support this hook. |
| 146 | add_filter('woocommerce_cart_item_price_html', array($this->pricingRules, 'replaceVisiblePricesCart'), 100, 3); |
| 147 | |
| 148 | // Pricing Table of Individual Product. |
| 149 | add_filter('woocommerce_before_add_to_cart_form', array($this->pricingRules, 'priceTable')); |
| 150 | |
| 151 | // Updating Log After Creating Order |
| 152 | add_action('woocommerce_thankyou', array($this->discountBase, 'storeLog')); |
| 153 | |
| 154 | add_action( 'woocommerce_after_checkout_form', array($this->discountBase, 'addScriptInCheckoutPage')); |
| 155 | } |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * init Woo Discount Rules |
| 161 | */ |
| 162 | FlycartWooDiscountRules::init(); |