Manu
Manu

Reputation: 21

Change woocommerce 'coupon does not exist! error message

I would like to change the default woocommerce error message that I get when client enters a coupon that does not exist Coupon “%s” does not exist!. Is it possible to do this directly in the function.php file of my child theme? If so it would be greatly appreciated to get some suggestions as to the code to use and where. I have tried to add the below code to the funtion.php file, but it didn't work.

add_filter( 'woocommerce_coupon_error','coupon_error_message_change', 10, 3 );

public function coupon_error_message_change( $err, $err_code, $parm )
{
    switch ( $err_code ) {
        case 105:
            /* translators: %s: coupon code */
            $err = sprintf( __( 'Coupon "%s" does not test!', 'woocommerce' ), $parm->get_code() );
            break;
    }
    return $err;
}

Upvotes: 0

Views: 2643

Answers (1)

Talita Mota
Talita Mota

Reputation: 93

add_filter( 'woocommerce_coupon_error','coupon_error_message_change',10,3 );

function coupon_error_message_change($err, $err_code, $WC_Coupon) {
    switch ( $err_code ) {
        case $WC_Coupon::E_WC_COUPON_NOT_EXIST:
            $err = 'your message';
    }
    return $err;
}

Upvotes: 2

Related Questions