_version = $version; $this->_token = AWDP_TOKEN; $this->discount = $discount; // $couponStatus = get_option('awdp_apply_coupon_discount') ? get_option('awdp_apply_coupon_discount') : false; $couponStatus = false; add_action('init', array($this, 'register_awdp_discounts')); // Deactivation hook add_action( 'deactivate_' . plugin_basename(dirname(AWDP_FILE)), array( $this, 'awdp_plugin_deactivate') ); if ( $this->awdp_check_woocommerce_active() ) { add_action ( 'woocommerce_before_calculate_totals', array($this, 'wdpCalculateDiscount'), 1000, 1 ); add_filter( 'woocommerce_get_cart_item_from_session', array( $this, 'restore_cart_item_from_session' ), 20, 3 ); // Change Discount Price HTML View add_filter( 'woocommerce_get_price_html', array($this, 'get_product_price_html'), 100, 2 ); // Cart Item Price add_filter( 'woocommerce_cart_item_price', array($this, 'cart_price_view'), 1000, 2 ); add_filter( 'woocommerce_cart_item_price_html', array($this, 'cart_price_view'), 1000, 2 ); // Cart add_action( 'woocommerce_cart_item_subtotal', array( $this, 'wdpCartLoop' ), 8, 3 ); // Coupon Management /* * Coupon status check added from version 4.0.0 * Compatibility Fix */ // if ( !$couponStatus ) { add_action( 'admin_notices', array ( $this, 'wdpAdminNotice' ) ); add_filter( 'woocommerce_get_shop_coupon_data', array( $this, 'addVirtualCoupon'), 99, 2 ); add_action( 'woocommerce_after_calculate_totals', array( $this, 'applyFakeCoupons') ); add_filter( 'woocommerce_cart_totals_coupon_label', array( $this, 'couponLabel'), 99, 2 ); add_filter( 'woocommerce_coupon_message', array($this, 'coupon_message'), 15, 3 ); add_filter( 'woocommerce_coupon_error', array($this, 'coupon_message'), 15, 3 ); // } // Clear Show discount applied message on cart page add_action( 'woocommerce_checkout_update_order_meta', array($this, 'wdpfirstOrderMsg')); add_action( 'woocommerce_after_calculate_totals', array( $this, 'show_cart_discount_notice_rest' ), 1000, 1 ); add_filter( 'the_content', array( $this, 'show_cart_discount_notice_via_content' ) ); add_filter( 'the_content', array( $this, 'append_saved_text_to_content' ), 100 ); // 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'), 100 ); } else if ( 'before_product_summary' == $tablePosition ) { add_filter( 'woocommerce_before_single_product_summary', array($this, 'show_pricing_table'), 100 ); } else if ( 'in_product_summary' == $tablePosition ) { add_filter( 'woocommerce_single_product_summary', array($this, 'show_pricing_table'), 100 ); } else if ( 'before_form' == $tablePosition ) { add_filter( 'woocommerce_before_add_to_cart_form', array($this, 'show_pricing_table'), 100 ); } else if ( 'before_variations_form' == $tablePosition ) { add_filter( 'woocommerce_before_variations_form', array($this, 'show_pricing_table'), 100 ); } else if ( 'before_button' == $tablePosition ) { add_filter( 'woocommerce_before_add_to_cart_button', array($this, 'show_pricing_table'), 100 ); } else if ( 'after_button' == $tablePosition ) { add_filter( 'woocommerce_after_add_to_cart_button', array($this, 'show_pricing_table'), 100 ); } else if ( 'after_variations_form' == $tablePosition ) { add_filter( 'woocommerce_after_variations_form', array($this, 'show_pricing_table'), 100 ); } else if ( 'after_form' == $tablePosition ) { add_filter( 'woocommerce_after_add_to_cart_form', array($this, 'show_pricing_table'), 100 ); } else if ( 'meta_start' == $tablePosition ) { add_filter( 'woocommerce_product_meta_start', array($this, 'show_pricing_table'), 100 ); } else if ( 'meta_end' == $tablePosition ) { add_filter( 'woocommerce_product_meta_end', array($this, 'show_pricing_table'), 100 ); } else if ( 'after_product_summary' == $tablePosition ) { add_filter( 'woocommerce_after_single_product_summary', array($this, 'show_pricing_table'), 100 ); } else if ( 'after_product' == $tablePosition ) { add_filter( 'woocommerce_after_single_product', array($this, 'show_pricing_table'), 100 ); } else { add_filter( 'woocommerce_before_add_to_cart_button', array($this, 'show_pricing_table'), 100 ); } // Offer Description $offer_desc_config = get_option('awdp_disc_desc_config') ? get_option('awdp_disc_desc_config') : []; $offerMsgPos = array_key_exists ( 'dismessage_position', $offer_desc_config ) ? $offer_desc_config['dismessage_position'] : ''; $offerMsgEnable = array_key_exists ( 'enable_dismessage', $offer_desc_config ) ? $offer_desc_config['enable_dismessage'] : ''; if ( $offerMsgEnable ) { if ( 'before_product' == $offerMsgPos ) { add_filter( 'woocommerce_before_single_product', array($this, 'show_offer_message'), 99 ); } else if ( 'before_product_summary' == $offerMsgPos ) { add_filter( 'woocommerce_before_single_product_summary', array($this, 'show_offer_message'), 99 ); } else if ( 'in_product_summary' == $offerMsgPos ) { add_filter( 'woocommerce_single_product_summary', array($this, 'show_offer_message'), 99 ); } else if ( 'before_form' == $offerMsgPos ) { add_filter( 'woocommerce_before_add_to_cart_form', array($this, 'show_offer_message'), 99 ); } else if ( 'before_button' == $offerMsgPos ) { add_filter( 'woocommerce_before_add_to_cart_button', array($this, 'show_offer_message'), 99 ); } else if ( 'after_button' == $offerMsgPos ) { add_filter( 'woocommerce_after_add_to_cart_button', array($this, 'show_offer_message'), 99 ); } else if ( 'after_form' == $offerMsgPos ) { add_filter( 'woocommerce_after_add_to_cart_form', array($this, 'show_offer_message'), 99 ); } else if ( 'meta_start' == $offerMsgPos ) { add_filter( 'woocommerce_product_meta_start', array($this, 'show_offer_message'), 99 ); } else if ( 'meta_end' == $offerMsgPos ) { add_filter( 'woocommerce_product_meta_end', array($this, 'show_offer_message'), 99 ); } else if ( 'after_product_summary' == $offerMsgPos ) { add_filter( 'woocommerce_after_single_product_summary', array($this, 'show_offer_message'), 99 ); } else if ( 'after_product' == $offerMsgPos ) { add_filter( 'woocommerce_after_single_product', array($this, 'show_offer_message'), 99 ); } else { add_filter( 'woocommerce_before_add_to_cart_button', array($this, 'show_offer_message'), 99 ); } } // Adding Frontend Styles add_action( 'wp_footer', array($this, 'awdp_styles'), 10 ); // WCPA Price add_filter( 'wcpa_product_price', array($this, 'wdpWCPAPrice'), 10, 2 ); // Mini Cart add_action( 'woocommerce_widget_shopping_cart_total', array( $this, 'wdpMiniCart'), 15 ); // Admin Order Page Customization add_action( 'woocommerce_admin_order_item_headers', array( $this, 'wdpAdminOrderHeader'), 10, 1 ); add_action( 'woocommerce_admin_order_item_values', array( $this, 'wdpAdminOrderContent'), 10, 3 ); // add_action( 'admin_footer', array( $this, 'wdpCustomJS') ); /* * Order Meta @@ Ver 5.0.4 * The 'woocommerce_add_order_item_meta' hook has been changed to 'woocommerce_new_order_item' @@ ver 3.0.0 */ // add_action( 'woocommerce_add_order_item_meta', array( $this, 'wdpOrderMeta'), 10, 3 ); add_action( 'woocommerce_new_order_item', array( $this, 'wdpOrderMeta'), 10, 3 ); add_action( 'woocommerce_after_order_itemmeta', array( $this, 'wdpDisplayOrderMeta'), 10, 3 ); add_filter( 'woocommerce_hidden_order_itemmeta', array( $this, 'hide_awdp_order_item_meta' ), 10, 1 ); add_filter( 'woocommerce_order_item_get_formatted_meta_data', array( $this, 'filter_awdp_formatted_order_item_meta' ), 10, 2 ); // Enqueue Scripts add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 10 ); // Dynamic Pricing Table add_action( 'wp_ajax_wdpAjax', array( $this, 'wdpDynamicPricingTable') ); add_action( 'wp_ajax_nopriv_wdpAjax', array( $this, 'wdpDynamicPricingTable') ); // WCPA Discount For Frontend Quantity Change add_action( 'wp_ajax_wdpDynamicDiscount', array( $this, 'wdpDynamicDiscount') ); add_action( 'wp_ajax_nopriv_wdpDynamicDiscount', array( $this, 'wdpDynamicDiscount') ); // Adding WCPA Filed Value For Quantity Discount add_action( 'wp_ajax_wcpaQunantity_Discount', array( $this, 'wcpaQunantity_Discount') ); add_action( 'wp_ajax_nopriv_wcpaQunantity_Discount', array( $this, 'wcpaQunantity_Discount') ); // Cart Message add_action( 'woocommerce_after_cart_table', array( $this, 'wdpCartMessage') ); // WCPA 5.0.0 add_filter ( 'wcpa_discount_rule', array( $this, 'wcpaDiscount' ), 10, 2); } } /** * Cart Message */ public function wdpCartMessage() { $this->cart_message_rendered = true; echo $this->discount->wdpCartMessage(); } /** * Append You've Saved Text on block-based cart pages */ public function append_saved_text_to_content( $content ) { if ( !is_admin() && is_cart() && !$this->cart_message_rendered ) { ob_start(); $this->discount->wdpCartMessage(); $saved_text = ob_get_clean(); if ( $saved_text ) { $content .= $saved_text; } } return $content; } /** * Mini Cart */ public function wdpMiniCart() { echo $this->discount->wdpMiniCart(); } /** * Admin Order */ public function wdpAdminOrderHeader($order) { echo $this->discount->wdpAdminOrderHeader($order); } public function wdpAdminOrderContent($_product, $item, $item_id = null) { echo $this->discount->wdpAdminOrderContent($_product, $item, $item_id = null); } public function wdpCustomJS() { echo $this->discount->wdpCustomJS(); } /** * Clear Show discount applied message on cart page */ public function wdpfirstOrderMsg(){ WC()->session->set( 'AWDP_CART_NOTICE', null ); } /** * Helper to detect classic cart page or WooCommerce Blocks Store API cart request. */ private function is_cart_context() { if ( is_cart() ) { return true; } if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) { if ( isset( $_SERVER['REQUEST_URI'] ) ) { $uri = $_SERVER['REQUEST_URI']; if ( strpos( $uri, '/wc/store' ) !== false && strpos( $uri, '/checkout' ) === false ) { return true; } } } return false; } /** * Show discount notice via REST API (for WooCommerce Blocks Cart) */ public function show_cart_discount_notice_rest($cart) { if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) { $is_cart = $this->is_cart_context(); if ( $is_cart && get_option( 'awdp_message_status' ) == 1 ) { if ( !empty( $this->discount->discounts ) ) { $message_once = ( get_option( 'awdp_message_once' ) !== false ) ? get_option( 'awdp_message_once' ) : 1; $label = get_option('awdp_fee_label') ? get_option('awdp_fee_label') : 'Discount'; $notice = get_option('awdp_discount_message') ? str_replace('[label]', $label, get_option('awdp_discount_message')) : (('discount' == mb_strtolower($label, 'UTF-8')) ? $label . __(" has been applied!", "aco-woo-dynamic-pricing") : __("Discount '", "aco-woo-dynamic-pricing") . $label . __("' has been applied!", "aco-woo-dynamic-pricing")); if ( $message_once == 1 ) { if ( !WC()->session->get( 'AWDP_CART_NOTICE' ) ) { if ( false === wc_has_notice( $notice, 'notice' ) ) { wc_add_notice( $notice, 'notice' ); } WC()->session->set( 'AWDP_CART_NOTICE', true ); } } else { if ( false === wc_has_notice( $notice, 'notice' ) ) { wc_add_notice( $notice, 'notice' ); } } } else { WC()->session->set( 'AWDP_CART_NOTICE', null ); } } } } /** * Show discount notice via direct HTML output prepended to the page content (for Classic, Elementor, and Blocks Cart) */ public function show_cart_discount_notice_via_content( $content ) { if ( !is_admin() && is_cart() && get_option( 'awdp_message_status' ) == 1 ) { if ( !empty( $this->discount->discounts ) ) { $message_once = ( get_option( 'awdp_message_once' ) !== false ) ? get_option( 'awdp_message_once' ) : 1; $label = get_option('awdp_fee_label') ? get_option('awdp_fee_label') : 'Discount'; $notice = get_option('awdp_discount_message') ? str_replace('[label]', $label, get_option('awdp_discount_message')) : (('discount' == mb_strtolower($label, 'UTF-8')) ? $label . __(" has been applied!", "aco-woo-dynamic-pricing") : __("Discount '", "aco-woo-dynamic-pricing") . $label . __("' has been applied!", "aco-woo-dynamic-pricing")); $show_notice = false; if ( $message_once == 1 ) { if ( !WC()->session->get( 'AWDP_CART_NOTICE' ) ) { $show_notice = true; } } else { $show_notice = true; } static $notice_prepended = false; // Prevent multiple prepends in same request if ( $show_notice && !$notice_prepended ) { // Standard WooCommerce notice HTML structure $notice_html = '
uses virtual coupons for applying discounts. For proper working of our plugin, please enable coupons (WooCommerce -> Settings -> Enable coupons).
If you are facing any loading issues with , please make sure the permalink settings is not set to plain (Settings -> Permalinks).