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, the Jaipur-based IT company he has led since 2009. An AI & IT Solutions Consultant with 16+ years of experience, he works with startups and enterprises to turn ideas into market-ready SaaS platforms, mobile apps and AI-driven solutions. His team has delivered 700+ projects across SaaS, mobile and web apps, automation and AI. He previously served as Chief Technology Officer for a US company.

Latest Posts

RAG chatbot architecture and guardrails banner with archive shelving representing a company knowledge base

RAG Chatbot Architecture and Guardrails: A Production Guide

A chatbot can quote a policy accurately and still give an unacceptable answer: the policy might be withdrawn, or belong…

Shafeeq Khan
November 20, 2026
Food delivery app development cost in the UAE 2026 banner with a delivery rider and scooter

Food Delivery App Development Cost in the UAE (2026)

A food delivery order in the UAE only works if four things line up: the right kitchen accepts it, the…

Shafeeq Khan
November 20, 2026
Colour photograph illustrating the Eoxys blog post 'Hire an AI Governance Engineer: Skills, Laws and When to Hire', used as the featured image for hire ai governance engineer.

Hire an AI Governance Engineer: Skills, Laws and When to Hire

Two years ago most companies building with AI had no one whose job was to ask “what happens when this…

Shafeeq Khan
November 20, 2026
,

Leave a Reply

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