WooCommerce: Show Required Field Errors Inline on Checkout Page.

Code

How To Show Required Field Errors Inline on Checkout Required Fields.

On WooCommerce checkout page all error are shown on top of form as we can see this in image.

Before:
null

Before Adding inline error to required field first we need to get all the fields that are required and have labels.
After getting required field we need to add error message for it .

Now the question is how can we add error message to it?

We will do this in two steps:
1. Add Span Tag With Error Message, and set display none by default.
2. Show This Error When Form Is Submitted.

1. Add Span Tag With Error Message, and set display none by default.

We will use ‘woocommerce_form_field’ hook for it. Using this hook we can add a span containing error, before the closing label tag.

By default, this is set as display:none, which will be displayed via CSS later.

function  CheckoutFieldsInlineError( $field, $key, $args, $value ) {
  if ( strpos( $field, '</label>') !== false && $args['required'] ) {
    $error = '<span class="error" style="display:none">';
    $error .= sprintf( __('%s is a required field.','woocommerce' ), $args['label'] );
    $error .= '</span>';
    $field = substr_replace( $field, $error, strpos( $field,'</label>'),0);
  }
return $field;
}
add_filter('woocommerce_form_field','CheckoutFieldsInlineError',99,4);

2. Show This Error When Form Is Submitted.

When form is submitted, the field which has an error ,WooCommerce will add “woocommerce-invalid-required-field” class to the parent “p” tag of input field. so we can use this as parent class and add css “display: block !important;” to show error msg.

<style>
.woocommerce-checkout p.woocommerce-invalid-required-field span.error {
   color: red;
   display: block !important;
   font-weight: bold;
}
<style>
After:
null

Enjoy

Related reading:

Shiv Kumawat

Executive Director & CEO

Shiv Kumawat is the CEO of Eoxys IT Solution LLP, a Jaipur-based IT and GenAI development company he has led since 2009. Eoxys has delivered 700+ projects, building custom AI agents, chatbots, mobile apps and web platforms for businesses worldwide. Shiv writes about practical AI app development and what it takes to ship software that works.

Latest Posts

Isometric illustration of a business hiring a remote AI development team in India, with a laptop showing an AI chip linked across a globe to developer workstations

Hire AI Developers in India: Models, Vetting and Red Flags

If you plan to hire AI developers in India, the hard part is not finding people. It is telling a…

Shiv Kumawat
October 11, 2026
DPDP compliance for AI apps: isometric shield protecting a phone and cloud server, with consent toggle, padlock and data cubes on a navy background

DPDP Compliance for AI Apps: What to Fix Before May 2027

If your app or AI chatbot handles personal data of people in India, DPDP compliance for AI apps is now…

Shiv Kumawat
October 10, 2026
GPT-6.1 Sol vs Claude Sonnet 5.5: isometric illustration of two AI model cubes connected by a data stream on a navy background

GPT-6.1 Sol vs Claude Sonnet 5.5: Which Model for Your App?

GPT-6.1 Sol vs Claude Sonnet 5.5 is the mid-tier choice most founders are making right now. Both models launched in…

Shiv Kumawat
October 9, 2026
,

Leave a Reply

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