I had a request from a client today to change the Postcode field in the WooCommerce checkout page to a required field and to rename it to ‘Eircode’. After some trial and error, the following two snippets worked a treat. Just add the code to whatever code snippets plugin you use. My favourite is WP Codebox but any will work.
1. Make the Postcode field required
We do this by adding the following code snippet to the site:
// Make Postcode Required for all Countries
add_filter('woocommerce_get_country_locale', function($locales){
foreach ($locales as $key => $value) {
$locales[$key]['postcode']['required'] = true;
}
return $locales;
});
2. Rename the Postal Code field to ‘Eircode’
Add the following snippet to the site:
add_filter( 'woocommerce_checkout_fields', 'ifd_rename_woo_checkout_fields' );
function ifd_rename_woo_checkout_fields( $fields ) {
$fields['billing']['billing_postcode']['placeholder'] = '';
$fields['billing']['billing_postcode']['label'] = 'Eircode';
return $fields;
}
I hope you find this useful but let me know if you have any trouble implementing it.
8 comments
Himanshu Rohira
I really appreciate your help, @Amanda Lucas, this code was incredibly helpful. Love to you from INDIA.
Amanda Lucas
Glad this has helped you.
Jesssica
Have tried adding the code into code snippets but whereabouts do I put it is it in the head or the body?
Amanda Lucas
Hi Jessica,
I would add it to the body. I use WPCodebox so I have much more control on where its loaded.
Lucy Atkinson
Can anyone tell me which file this needs to be added to please?
Amanda Lucas
Hi Lucy,
You add these as code snippets. There are many plugins available but I recommend this one from the WordPress repository – Code Snippets .
Hope that helps.
Pasquale Mellone
Just to let you know, I found this very helpful. I used the snippet of code on two websites for a client of mine. Thanks for sharing!
Amanda Lucas
Hi Pasquale,
Thank you so much for letting me know, really glad it helped you out.
All the best,
Amanda