1 year ago

#366986

test-img

Jacob Bayless

How do I change the Woocommerce checkout page error messages?

I run an e-commerce site and need to change my checkout error messages.

Recently I have had a customer say that they made a mistake entering their credit card's expiration date, but they were confused because the error message displayed by woocommerce says "Your card's security code is incorrect." This led them to double and triple check the security code instead of the expiration date which was the real problem.

Getting the "Your card's security code is incorrect." error message even though the expiration date is the field that is incorrect.

I would like to find a solution that allows me to change that error message to say, "Your card's security code or expiration date is incorrect."

I would also be okay with a solution that allows me to input a single generic error message such as, "Some information is incorrect or missing." that would be used for all payment info errors.

Somebody please help me.

I have tried implementing the following solutions from other forums into my functions.php file with no luck:

Attempt 1:

function ShowOneError( $fields, $errors ){

  // if their is any validation errors

  if( !empty( $errors->get_error_codes() ) ) {

  // remove all of Error msg

  foreach( $errors->get_error_codes() as $code ) {

    $errors->remove( $code );

    }

  // our custom Error msg

$errors->add('validation','There is an error in filed data.');

}

}

add_action('woocommerce_after_checkout_validation','ShowOneError',999,2);

Attempt 2:

// alter the subscriptions error
function my_woocommerce_add_error( $error ) {
    if( 'The generic error message' == $error ) {
        $error = 'The shiny brand new error message';
    }
    return $error;
}
add_filter( 'woocommerce_add_error', 'my_woocommerce_add_error' );

Attempt 3:

add_action( 'woocommerce_after_checkout_validation', 'quadlayers', 9999, 2);
function quadlayers( $fields, $errors ){
// in case any validation errors
if( !empty( $errors->get_error_codes() ) ) {

// omit all existing error messages
foreach( $errors->get_error_codes() as $code ) {
$errors->remove( $code );
}
// display custom single error message
$errors->add( 'validation', 'Your Custom Message Goes Here!!!' );
}
}

php

wordpress

woocommerce

hook-woocommerce

checkout

0 Answers

Your Answer

Accepted video resources