Not everyday scenario, but sometimes you would like to have a custom message when the coupon is applied to your woocommerce shop.
Straight to the code.
add_filter( 'woocommerce_coupon_message', 'change_coupon_message', 3, 10 );
function change_coupon_message( $msg, $msg_code, $coupon_obj ) {
$coupon_code = $coupon_obj->get_code();
$coupon_desc = $coupon_obj->get_description();
if ( $msg_code === 200 ) {
return $coupon_desc;
}
return $msg;
}
Here, we are applying a filter hook, to change the woocommerce default “Coupon applied successfully” message.
We are hooking up a custom function that checks if the $msg_code is 200 i.e. it applied successfully.
But we will like our custom message. In this case I have get the description from the coupon settings which also makes it dynamic. Every coupon can have its own custom message.
And finally, we return $msg that is to be displayed.