'Rename the state placeholder when UK/GB is selected as the billing country on checkout (WooCommerce)

When UK is selected as the billing country during checkout the billing_state field has the placeholder 'State / County'.

Is there a way to rename this state placeholder specifically when UK is selected as country? (When US, Germany or other EU countries are selected the state field has a select-dropdown-menu... UK is the only country I found where there is no dropdown but a manual field... and this is messing up my css)

In my case I want to leave the placeholder for the state field blank when UK is selected as a country.

I can rename the placeholder for the state field with this code but how do I do this for one specific country?

add_filter( 'woocommerce_checkout_fields' , 'custom_rename_wc_checkout_fields' );

function custom_rename_wc_checkout_fields( $fields ) {
  $fields['billing']['billing_state']['placeholder'] = '';
  return $fields;
}

Help is very much appreciated.



Solution 1:[1]

add_action('wp_footer', 'change_state_field_placeholder');

function change_state_field_placeholder() {
    // Only on checkout page
    if (is_checkout() && !is_wc_endpoint_url()):
        ?>
        <script type="text/javascript">
        jQuery(function($){
            $(document.body).on('change', 'select[name=billing_country]', function(){
                if( 'GB' == $(this).val()){
                    $('#billing_state').attr("placeholder", "");
                }
            });
        });
        </script>
    <?php

    endif;
}
        

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mujuonly