WooCommerce checkout validation: how to validate fields
To validate WooCommerce checkout fields, start with what WooCommerce already checks, then add the checks it lacks. WooCommerce confirms required fields are filled and that an email looks like an email. Real address verification, country-aware phone numbers, email domain checks, and your own rules need a plugin or code. Run them inline, as the customer types, with short messages, and stop before the rules cause abandoned orders.
Good validation catches a wrong shipping address before it costs you a reshipment, and it stops failed orders caused by mistyped details. Here’s how to set it up, in the order most stores need it.
What WooCommerce validates by default
Out of the box, WooCommerce checks that required fields are filled in, that the email address is formatted like one, and that the state matches the country. It also checks postcode format for many countries. It doesn’t confirm that a street address exists, it gives little real-time feedback, and it has no settings screen for your own rules. VAT numbers, custom ID formats, and phone numbers by country all need extra work.
CheckoutWC checks fields as customers fill them in and shows a message under any field that needs fixing, so mistakes are caught before the customer clicks to pay. Its built-in checks cover:
- required fields;
- email format, plus a check that the email domain can receive mail (it catches typos such as “gmail.con”);
- postcodes for the selected country, with US ZIP+4 codes accepted with or without the hyphen;
- names that are email addresses;
- phone numbers, when the international phone field is on and the phone is required.
The full list of messages is in the custom error messages documentation.
Validate addresses and pair them with autocomplete
Format checks tell you an address looks right; they don’t tell you it exists. Address verification and autocomplete cover that gap.
- Address verification. CheckoutWC checks the shipping address (or the billing address on orders that don’t ship) with Smarty, and offers a corrected address when it finds a close match. The customer chooses Use Recommended or Use Your Address. It needs your own Smarty account, and you turn it on under CheckoutWC » Pages, on the Checkout tab.
- Address autocomplete. Customers pick their address from suggestions as they type, using Google or Fetchify with your own API key. Smarty still checks the final address, whether it was typed or picked.
- Postcode lookup. With no setup, CheckoutWC fills in the state, and the city when the postcode belongs to one place, from the postcode alone.
Validate phone numbers and email addresses
For phone numbers, turn on the international phone field. It adds a country picker and checks the number for that country when the phone is required. That beats a pattern that only counts digits, which rejects valid numbers from other countries.
For email, the domain check does most of the work. Occasionally it rejects a real address, such as one on a brand new domain or an unusual company mail server. A developer can allow specific domains without turning the check off; the snippet is in the documentation.
Change error messages and add your own rules
CheckoutWC uses the Parsley validation library, so developers can change a field’s message with the data-parsley-error-message attribute. Add this in a code snippets plugin or CheckoutWC’s PHP Snippets box (CheckoutWC » Advanced, Scripts tab):
add_filter( 'woocommerce_checkout_fields', function ( $fields ) {
$fields['billing']['billing_first_name']['custom_attributes']['data-parsley-error-message'] = 'Please tell us your first name.';
$fields['billing']['billing_email']['custom_attributes']['data-parsley-error-message'] = 'Please check your email address.';
return $fields;
}, 100001 );
Use the same pattern for other fields: the group (billing, shipping or order) and the field’s key, such as shipping_city.
You can also add a rule of your own. This one rejects a street address with no number:
add_filter( 'woocommerce_default_address_fields', function ( $fields ) {
$fields['address_1']['custom_attributes']['data-parsley-pattern'] = '/^(?=.*\d).+$/';
$fields['address_1']['custom_attributes']['data-parsley-error-message'] = 'Please include your house number in the street address.';
return $fields;
}, 100001 );
These checks run in the visitor’s browser, so they improve the form but can’t stop a request that skips the page. If you ship to countries where the house number is entered separately, turn on Enable Separate House Number and Street Name Address Fields instead; the number then gets its own required field. Google and Fetchify address autocomplete can’t be used while the separate fields are on. Other rules, such as a custom validator, a different trigger for when a field is checked, or translated messages, are covered in the custom validation documentation.
Don’t over-validate
Every extra rule is another place a customer can get stuck. You may be over-validating if:
- you require more fields than you use to fulfill the order;
- you ask for information that feels intrusive;
- error messages are long or technical;
- strict rules, such as password formats, make people stop before they can pay;
- fields depend on each other, so fixing one breaks another.
The cost shows up in cart abandonment and conversion rate. Ask for essentials only, write short messages, validate inline, and offer guest checkout. Removing a field you don’t need is the cheapest fix, and removing billing address fields takes a few clicks.
Beka Rice, Product Architect at Kestrel, puts it this way: “Every additional field or validation rule is a potential exit point for your customer.”
Get validation that works from the start
CheckoutWC checks fields inline out of the box, and you can add address verification, country-aware phone validation, and your own rules on top. See the features or pricing.
The simplicity of Shopify with the power of WooCommerce. Replace your WooCommerce checkout page with CheckoutWC to boost sales and reduce cart abandonment.