The Astro logo on a dark background with a purple gradient arc.

How to Make Checkout Fields Required in WooCommerce

A question that often occurs when I provide support for WooCommerce is how to make some fields on the checkout form required.

So, in case anyone is looking for an easy solution on how to modify the checkout form to make some fields required, you’re in luck.

Implementation on Classic Checkout

First, it would be wise to use a tool like Code Snippets1 to modularly implement this code on your website.

Once it’s installed, you can activate the following code snippet, which serves as an example to make the “Company Name” fields in both the Shipping Details and Billing Details sections required, rather than optional.

/**
 * Require Billing and Shipping Company Name
 */

// Hook in
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );

// Our hooked in function - $fields is passed via the filter!
function custom_override_checkout_fields( $fields ) {
	
	// Modify the "Shipping — Company Name" field.
	// Uncomment any other fields you want to modify.
     $fields['shipping']['shipping_company'] = array(
		// 'label'       => __( 'Phone', 'woocommerce' ),
        // 'placeholder' => _x( 'Phone', 'placeholder', 'woocommerce' ),
        // 'required'    => false,
        // 'class'       => array( 'form-row-wide' ),
        // 'clear'       => true
        'required'    => true,
     );
	
	// Modify the "Billing — Company Name" field.
	// Uncomment any other fields you want to modify.
	 $fields['billing']['billing_company'] = array(
        'required'    => true,
     );

     return $fields;
}

If you’re looking for a list of fields you can modify, check out the developer documentation. Its important to note that this code doesn’t work with checkout using the Checkout blocks. With the Checkout Block experience, you should be able to directly toggle the fields to be “Required” or not by.

Here’s a screenshot for reference:

Checkout Block Field "Required" Toggles

Footnotes

  1. Code Snippets

Sources

profile picture

"Let's learn about the implications of adding alt text to icons."

# accessibility

# php

# tutorial

# wordpress

# woocommerce