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' );
}
}