(REQUEST) Advanced Coupons

lezral

New member
Banned User
Jul 3, 2020
25
4
3
EG
as alternative way you can use this free plugin

also you may use my snippet to show custom message
PHP:
add_action( 'woocommerce_before_cart', 'custom_coupon_messages' );
add_action( 'woocommerce_before_checkout_form', 'custom_coupon_messages' );
function custom_coupon_messages() {
    global $woocommerce;
    //Set coupon codes.
    $coupon_code = 'Your-Coupon-here';
    //Set coupon objects.
    $coupon_test = new WC_Coupon( 'Your-Coupon-here' );
    //Get the cart subtotal. Should return as a Double.
    $cart_subtotal = WC()->cart->subtotal;
    //If coupon test is passed add coupon.
    if ( $coupon_test->is_valid() && $woocommerce->cart->has_discount( $coupon_code ) ) {
        //Filter the coupon success message to display a custom message.
        add_filter( 'woocommerce_coupon_message', 'filter_woocommerce_coupon_message', 10, 3 );
        function filter_woocommerce_coupon_message( $msg, $msg_code, $instance ) {
            //Set a custom coupon message.
            $msg_code = 'case self::WC_COUPON_SUCCESS';
            $msg = __( 'Your message here!', 'your-theme-text-domain' );
            return $msg;
            return $msg_code;
            //Or return nothing (no message will be displayed - comment out the above/uncomment below).
            // return '';
        };
        //Print the above notice to screen.
        wc_print_notices();
    }
    elseif ( $cart_subtotal > 499 ) {
        //Print a notice (the blue boxed one)
        wc_print_notice( 'Spend $500 to qualify for the BIGLY YUGE discount!!!', 'notice' );
    }
}
 

Attachments

  • woocommerce-coupon-schedule.zip
    12.7 KB · Views: 19

About us

  • Our community has been around for many years and pride ourselves on offering unbiased, critical discussion among people of all different backgrounds. We are working every day to make sure our community is one of the best.

Quick Navigation

User Menu