WooCommerce required checkout fields: classic, block, and CheckoutWC
Table of Contents
- Find out which WooCommerce checkout you use
- Set required fields on the classic checkout
- Use a checkout field editor plugin
- Use a code snippet
- Fix "billing state is a required field"
- Make a field required on the block checkout
- Make fields required with CheckoutWC
- Add your own required fields
- Manage your WooCommerce checkout fields
To make a WooCommerce checkout field required, the method depends on your checkout. On the classic (shortcode) checkout, set ['required'] = true on the field in the woocommerce_billing_fields filter. On the block checkout, WooCommerce only exposes settings for a few core fields, such as phone, company, and address line 2, and you add anything else through its additional checkout fields API. With CheckoutWC, you set the field to Required in the settings, with no code, and it works on both.
Find out which WooCommerce checkout you use
WooCommerce has two checkout systems, and a snippet written for one often does nothing on the other, with no error message. Open your Checkout page in WordPress:
- If it contains a
[woocommerce_checkout]shortcode, you use the classic checkout. - If you see draggable blocks in the block editor, you use the block checkout.
Set required fields on the classic checkout
The classic checkout accepts nearly any change, as long as your payment gateway doesn’t need the data you remove. There are two routes: a plugin or a snippet.
Use a checkout field editor plugin
A checkout field editor plugin gives you a screen to set a field to required, optional, or hidden, reorder fields, and change labels. The trade-off is one more plugin to keep updated, and some editors lag behind WooCommerce releases, so check the plugin lists WooCommerce’s current version as supported.
Use a code snippet
If you’re comfortable with PHP, a snippet is lighter than a plugin. This makes the billing phone field required:
add_filter( 'woocommerce_billing_fields', 'make_phone_required' );
function make_phone_required( $fields ) {
$fields['billing_phone']['required'] = true;
return $fields;
}
Billing and shipping fields use separate filters (woocommerce_billing_fields and woocommerce_shipping_fields), and woocommerce_checkout_fields covers both. Add the snippet to your child theme’s functions.php or a code snippets plugin; Kestrel’s guide to adding custom code to WooCommerce safely explains how. Setting ['required'] = false makes a field optional the same way.
Fix “billing state is a required field”
This error appears when WooCommerce still requires a state or county for the customer’s country but the field is empty or hidden. It usually follows a snippet or plugin that removed the state field while leaving the country field in place. You have two options:
- Keep the state field. Remove your snippet or turn the field back on, so customers in countries with states can pick one.
- Make it optional. Set
['state']['required'] = falsein thewoocommerce_default_address_fieldsfilter, then test an order from a country that uses states.
On CheckoutWC, the safer route is the Enabled Billing Address Fields list: clearing a field removes it and skips its validation, and the settings screen warns you before you remove country or state, which can cause gateway issues.
If you remove address fields, remove country and state together or neither; WooCommerce’s country and state handling produces errors when only one is present. Also test a real payment afterward, because some gateways and tax rates read the billing address.
Make a field required on the block checkout
The block checkout is built differently, so most classic snippets don’t apply. WooCommerce lets you show or hide the phone, company, and address line 2 fields and set each to optional or required. In the block editor, select the Checkout block and open Address Fields in the sidebar. Everything else needs either a plugin built for blocks or code.
For code, WooCommerce provides an additional checkout fields API. It adds new fields, and required works for them:
add_action( 'woocommerce_init', function() {
woocommerce_register_additional_checkout_field(
array(
'id' => 'namespace/phone-required',
'label' => 'Phone Number',
'location' => 'contact',
'type' => 'text',
'required' => true,
'attributes' => array( 'autocomplete' => 'tel' ),
)
);
} );
This registers a new field; it doesn’t change an existing core field. For validation, hook woocommerce_validate_additional_field and add a WP_Error:
add_action( 'woocommerce_validate_additional_field', function ( WP_Error $errors, $field_key, $field_value ) {
if ( 'namespace/phone-required' === $field_key && strlen( $field_value ) < 10 ) {
$errors->add( 'invalid_phone', 'Please enter a valid phone number' );
}
}, 10, 3 );
WooCommerce documents the API in its additional checkout fields guide. Changing core fields beyond the built-in settings means JavaScript filters, which is a different skill set from PHP.
Make fields required with CheckoutWC
CheckoutWC replaces the checkout page with its own, so these settings work on a page that uses either the classic shortcode or the checkout block:
- Phone, company, and address line 2: set each to Required. Phone is under CheckoutWC » Pages, Checkout tab, Field Options; company and address line 2 are in the Addresses section of the Checkout Editor. These are WooCommerce’s own Hidden / Optional / Required settings, so the change applies in WooCommerce too. When the phone field is required, the international phone field also checks each number is valid for the customer’s country (see phone fields).
- Billing fields you don’t want: clear them under Enabled Billing Address Fields (CheckoutWC » Pages, Checkout tab, Address Options). Cleared fields aren’t shown or validated. See billing address options.
- New fields: in the Checkout Editor, open Slots, add a field with + New custom field (text, text area, dropdown, radio, or checkbox) and turn on Required. A field with display conditions is only required when it shows.
CheckoutWC 11.4.0 added custom fields; the release announcement shows how they look. For validation beyond required, see validating WooCommerce checkout fields.
Add your own required fields
You can also add fields WooCommerce doesn’t ask for, such as a PO number, a gift message or a delivery note, and make them required. CheckoutWC’s custom checkout fields work without code:
- Go to CheckoutWC » Checkout Editor and expand Slots.
- Expand the slot where the field should appear, such as After Billing Address or Before Terms & Conditions, and click +.
- Under Custom Fields, click + New custom field, choose the type (text, text area, dropdown, radio buttons or checkbox), add a label, and turn on Required.
- Click Add custom field, then Save Changes.
Customers then can’t place the order until they fill in the field, or select the checkbox. The answer is saved on the order. Two details worth knowing:
- Required only when it shows. Add display conditions to show a field only in some situations, such as when the cart contains a certain product or for one shipping country. A field hidden by its rules isn’t required.
- Express checkout. Apple Pay and similar buttons can let a customer pay before filling in a required field. To prevent that, turn off Ignore Required Custom Fields in the Express Checkout section of the Checkout Editor, so the buttons are hidden while a required custom field is showing.
The custom checkout fields guide covers every setting, including charging a fee for an option.
Manage your WooCommerce checkout fields
Every required field is one more place a shopper can stall. Baymard Institute’s cart abandonment research lists a long or complicated checkout among the reasons shoppers leave, so ask only for what you’ll use when you set up your WooCommerce checkout fields, such as a phone number for the courier. If you’re also trimming fields, our guide to removing WooCommerce checkout fields covers the other direction.
If you’d rather set required, optional, and custom fields from a settings screen than maintain snippets, CheckoutWC does that on both checkouts. It’s one plan with every feature, from $249 a year for one site. See the plans.
The simplicity of Shopify with the power of WooCommerce. Replace your WooCommerce checkout page with CheckoutWC to boost sales and reduce cart abandonment.