How To Change The Postcode To Eircode and Make it Required in WooCommerce

Amanda Lucas
on
January 11, 2021

A very useful snippet that changes the Postcode label to Eircode and makes it a required field.

Postcode required and renamed

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.

  • Have tried adding the code into code snippets but whereabouts do I put it is it in the head or the body?

  • Lucy Atkinson

    Can anyone tell me which file this needs to be added to please?

    • A
      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!

    • A
      Amanda Lucas

      Hi Pasquale,

      Thank you so much for letting me know, really glad it helped you out.

      All the best,
      Amanda

Leave your comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Amanda Lucas

Amanda Lucas

Amanda Lucas runs a web design agency in Ireland called Itchy Fingers Design. She enjoys creating websites that help support business goals and growth and sharing her knowledge.