Support » Plugin: WooCommerce » How to make postcode field required

  • Resolved lamayas


    Hi there,

    I need to set the billing postcode as required because my store only delivers locally and the shipping is free except for a few areas outside the city.

    I make the validation through the postcode but I have not found a way to make it a required field. So if a user has a free shipping covered postcode (most cases) but does not fill it out, they will be charged for it.

    I looked for solutions online and checked your guide to customizing the checkout fields but I’m not an expert on php. Tried this but didn’t work:

    add_filter( 'woocommerce_billing_fields', 'check_shipping_postcode', 10, 1 );
    function check_shipping_postcode( $address_fields ) {
    	$address_fields['billing_postcode']['required'] = true;
    	return $address_fields;

    Is it possible? What can I do? Thanks for your help!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support kellymetal a11n


    Hi there,

    The Postal/Zip code being required/optional depends on the country being selected. In order to make it required for all countries, you could use a snippet like this:

    // Make Postal Code Required for all Countries
    add_filter('woocommerce_get_country_locale', function($locales){
        foreach ($locales as $key => $value) {
            $locales[$key]['postcode']['required'] = true;
        return $locales;

    That code should be added to your child theme’s functions.php file or via a plugin that allows custom functions to be added, such as the Code Snippets plugin. Please don’t add custom code directly to your parent theme’s functions.php file as this will be wiped entirely when you update.

    I hope that helps!

    Thread Starter lamayas


    The country is set by default since I only deliver locally but nothing I tried worked.

    The snippet works! Thanks for your help.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to make postcode field required’ is closed to new replies.