Create Custom Menu in WordPress Dashboard
Complete tutorial on create custom menu in wordpress dashboard. Discover practical examples, implementation tips, and expert advice for WordPress and WooCo
Read More โSimplify WooCommerce checkout error display using woocommerce_after_checkout_validation action hook with priority 999. Check if errors exist with get_error_codes method, loop through all error codes removing each with remove method, add single consolidated error message with descriptive text like "There is an error in form data", conditionally handle specific error types including required-field for missing required inputs, terms for unchecked terms checkbox, and payment for payment method errors, selectively remove only certain error types preserving others, reduce visual clutter on checkout page showing 10+ field errors, improve user experience with cleaner error presentation, and maintain validation functionality while providing simplified feedback messaging.
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.
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);
Please note, that above code removes all types of errors, not only “This Field Is Required” etc. We can remove them conditionally . For this first we need to type of error. Types of errors:
So for removing Only "required-field" error:
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 ) {
if( $code == 'required-field') {
$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);
Search our archives or reach out to our team for solutions and expert advice.