WooCommerce : Show Only One Error Message on Checkout Field Error.

Their are approximately 7 to 10 default field which are required on WooCommerce checkout field.
In case these all have error then their are so much error in top, you can see in screenshot below. so for removing or we can say replacing all error with only one msg , you can view in screenshot 2.

null

Example :


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

null

Enjoy

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top