Change 'Zip' field label to 'Postal Code' - Code Parrots

Knowledge Base

Change ‘Zip’ field label to ‘Postal Code’

Article Last Updated: March 4, 2021

International need the ability to swap out the ‘Zip’ label for another label (‘Postal Code’ for example).

To alter the field label You can use one of the built in filters to change any of the form field labels. We’ve built in a ton of hooks and filters for users to take advantage of, to allow for customization beyond what can be done in the admin dashboard. The filter you’ll want to use to alter the label text is:

yikes-mailchimp-address-$field_type-label

Where $field_type is the form field type. Since the field is nested inside of the address field, $field_type can be any of the following:

  • addr1
  • addr2
  • city
  • state – US/CA Only
  • zip – US/UK Only
  • country

Since we’ll be altering the label for the ‘Zip’ field, you can substitute ‘zip’ for $field type in the filter, like so: yikes-mailchimp-address-zip-label.

Example:

/**
*    Change the 'Zip' field label to 'Postal Code' (beneficial for UK residents)
*    @reference: https://github.com/yikesinc/yikes-inc-easy-mailchimp-extender/issues/453
*/
function yikes_mailchimp_change_zip_label_to_postcode( $field_label ) {
    $field_label = 'Postal Code';
    return $field_label;
}
add_filter( 'yikes-mailchimp-address-zip-label', 'yikes_mailchimp_change_zip_label_to_postcode' );

If you are an international user, specifically from the UK, you’ll also want to change the regex pattern used to validate the zip code entered by the user. By default, the regex pattern used validates US zip codes only (\d{5,5}(-\d{4,4})?).

We’ve included an additional filter to allow for our users to alter, or remove, the regex pattern used to validate the zip code. Obviously, if you’re outside of the United States – you don’t only want to accept US formatted zip codes.

If you’ll be accepting zip codes from all over the world, your best bet is to input a custom regex pattern for the zip (postal code) fields. The following snippet will do just that, and allow any value to pass through the validation check:

/**
*    Completley remove the regex pattern for validating zip codes
*    @reference: https://github.com/yikesinc/yikes-inc-easy-mailchimp-extender/issues/453
*/
function yikes_mailchimp_remove_zip_regex_pattern( $regex_pattern ) {    
    $regex_pattern = '[\s\S]*';
    return $regex_pattern;
}
add_filter( 'yikes-mailchimp-zip-pattern', 'yikes_mailchimp_remove_zip_regex_pattern' );