Home > OS >  Is there a filter for Checkout Error Message
Is there a filter for Checkout Error Message

Time:04-06

I would like to edit the text on the checkout page. There are some issues with the items in your cart. Please go back to the cart page and resolve these issues before checking out.

I've been searching for ways to edit it without editing the source file. Is there a filter to edit the text on checkout page?

tried this

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

CodePudding user response:

add_filter('gettext_woocommerce', 'modify_cart_error_message', 10, 3);

function modify_cart_error_message($translation, $text, $domain) {
    if ('There are some issues with the items in your cart. Please go back to the cart page and resolve these issues before checking out.' === $translation) {
        $translation = 'Your Custom Message Goes Here!!!';
    }
    return $translation;
}

The cart error message mentioned is coming from /woocommerce/templates/checkout/cart-errors.php file. Either you can override the template in themes or use the above code snippet in the active theme functions.php file

  • Related