3

I want to show postcode/zip field even for the countries that do not use postcodes/zip on WooCommerce checkout page.

WooCommerce hides postcode/zip field by default for countries that don't use them.

I have used following filter in theme functions.php but it doesn't work.

add_filter( 'woocommerce_default_address_fields' , 'custom_override_default_address_fields' );

function custom_override_default_address_fields( $address_fields ) {
     $address_fields['postcode']['hidden'] = false; 
     return $address_fields;
}

How can I override this behavior?

7uc1f3r
  • 28,449
  • 17
  • 32
  • 50
aliencity
  • 83
  • 2
  • 12

1 Answers1

2

You can use the woocommerce_get_country_locale filter hook, to unhide this by default for all countries.

So you get:

function filter_woocommerce_get_country_locale( $country_locale ) { 
    // Loop through
    foreach( $country_locale as $key => $locale ) {
        // Isset
        if ( isset ( $locale['postcode']['hidden'] ) ) {
            // When true
            if ( $locale['postcode']['hidden'] == true ) {
                // Set to false
                $country_locale[$key]['postcode']['hidden'] = false;
            }
        }
    }

    return $country_locale;
}
add_filter( 'woocommerce_get_country_locale', 'filter_woocommerce_get_country_locale', 10, 1 );
7uc1f3r
  • 28,449
  • 17
  • 32
  • 50