_version = $version; $this->_token = AWDP_TOKEN; $this->discount = $discount; add_action('init', array($this, 'register_awdp_discounts')); if ( $this->awdp_check_woocommerce_active() ) { // Apply Fee // add_filter('woocommerce_cart_calculate_fees', array( $this, 'cart_apply_discount'), 10, 1 ); // Cart Item Price add_filter('woocommerce_cart_item_price', array($this, 'cart_price_view'), 1000, 3); add_filter('woocommerce_cart_item_price_html', array($this, 'cart_price_view'), 1000, 3); // Price add_filter('woocommerce_product_get_price', array($this, 'get_product_price'), 99, 2 ); add_filter('woocommerce_product_get_regular_price', array($this, 'get_product_price'), 99, 2 ); // Change Discount Price HTML View add_filter('woocommerce_get_price_html', array($this, 'get_product_price_html'), 100, 2 ); // Variations add_filter('woocommerce_product_variation_get_regular_price', array($this, 'get_product_price'), 100, 2 ); add_filter('woocommerce_product_variation_get_price', array($this, 'get_product_price'), 100, 2 ); // Pricing table if( false === get_option('awdp_table_position') ){ $tablePosition = get_option('tableposition'); } else { $tablePosition = get_option('awdp_table_position'); } if ( 'before_product' == $tablePosition ) { add_filter( 'woocommerce_before_single_product', array($this, 'show_pricing_table'), 98, 3 ); } else if ( 'before_product_summary' == $tablePosition ) { add_filter( 'woocommerce_before_single_product_summary', array($this, 'show_pricing_table'), 98, 3 ); } else if ( 'in_product_summary' == $tablePosition ) { add_filter( 'woocommerce_single_product_summary', array($this, 'show_pricing_table'), 98, 3 ); } else if ( 'before_form' == $tablePosition ) { add_filter( 'woocommerce_before_add_to_cart_form', array($this, 'show_pricing_table'), 98, 3 ); } else if ( 'before_variations_form' == $tablePosition ) { add_filter( 'woocommerce_before_variations_form', array($this, 'show_pricing_table'), 98, 3 ); } else if ( 'before_button' == $tablePosition ) { add_filter( 'woocommerce_before_add_to_cart_button', array($this, 'show_pricing_table'), 98, 3 ); } else if ( 'after_button' == $tablePosition ) { add_filter( 'woocommerce_after_add_to_cart_button', array($this, 'show_pricing_table'), 98, 3 ); } else if ( 'after_variations_form' == $tablePosition ) { add_filter( 'woocommerce_after_variations_form', array($this, 'show_pricing_table'), 98, 3 ); } else if ( 'after_form' == $tablePosition ) { add_filter( 'woocommerce_after_add_to_cart_form', array($this, 'show_pricing_table'), 98, 3 ); } else if ( 'meta_start' == $tablePosition ) { add_filter( 'woocommerce_product_meta_start', array($this, 'show_pricing_table'), 98, 3 ); } else if ( 'meta_end' == $tablePosition ) { add_filter( 'woocommerce_product_meta_end', array($this, 'show_pricing_table'), 98, 3 ); } else if ( 'after_product_summary' == $tablePosition ) { add_filter( 'woocommerce_after_single_product_summary', array($this, 'show_pricing_table'), 98, 3 ); } else if ( 'after_product' == $tablePosition ) { add_filter( 'woocommerce_after_single_product', array($this, 'show_pricing_table'), 98, 3 ); } else { add_filter( 'woocommerce_before_add_to_cart_button', array($this, 'show_pricing_table'), 98, 3 ); } // Apply Cart Rules add_action( 'woocommerce_before_calculate_totals', array( $this, 'apply_cart_discounts' ), 98, 2 ); add_filter( 'woocommerce_get_shop_coupon_data', array( $this, 'addVirtualCoupon'), 10, 2 ); add_action( 'woocommerce_after_calculate_totals', array( $this, 'applyFakeCoupons') ); add_filter( 'woocommerce_cart_totals_coupon_label', array( $this, 'couponLabel'), 10, 2 ); add_filter( 'woocommerce_coupon_message', array($this, 'coupon_message'), 10, 3 ); add_filter( 'woocommerce_coupon_error', array($this, 'coupon_message'), 10, 3 ); // Adding Frontend Styles add_action('wp_footer', array($this, 'awdp_styles'), 25); // Cart add_action( 'woocommerce_cart_item_subtotal', array( $this, 'wdpCartLoop' ), 99, 3 ); // Coupon Not Enabled Warning add_action('admin_notices', array($this, 'wdpAdminNotice')); // Hide Coupon Box $hideCouponBox = get_option('awdp_hide_coupon_box') ? get_option('awdp_hide_coupon_box') : false; if ( $hideCouponBox ) { add_filter( 'woocommerce_coupons_enabled', array( $this, 'wdpHideCouponField' ) ); } } } /** * Hide Coupon Box * @since 3.7.0 */ public function wdpHideCouponField ( $enabled ) { if ( is_checkout() || is_cart() ) { $enabled = false; } return $enabled; } /** * Handling Virtual Coupon * @param $cart_obj object */ public function addVirtualCoupon($response, $curr_coupon_code) { return $this->discount->addVirtualCoupon($response, $curr_coupon_code); } public function applyFakeCoupons() { return $this->discount->applyFakeCoupons(); } public function couponLabel($label, $coupon) { return $this->discount->couponLabel($label, $coupon); } public function coupon_message($msg, $msg_code, $coupon=null) { $awdappliedCode = $coupon->get_code(); $awdpluginLabel = get_option('awdp_fee_label') ? get_option('awdp_fee_label') : 'Discount'; if ( $awdappliedCode == $awdpluginLabel || mb_strtolower($awdappliedCode, 'UTF-8') == mb_strtolower($awdpluginLabel, 'UTF-8')) { return ''; } return $msg; } /** * Show quantity discount on cart items * @param $cart_obj object **/ public function wdpCartLoop ( $wc, $cart_content, $cart_item_key ) { return $this->discount->wdpCartLoop( $wc, $cart_content, $cart_item_key ); } /** * Admin Notices **/ public function wdpAdminNotice () { if ( 'yes' !== get_option( 'woocommerce_enable_coupons' ) ) { ?>
uses virtual coupons for applying discounts. For proper working of our plugin, please enable coupons (WooCommerce -> Settings -> Enable coupons).