Can’t change a label in woocommerce with the normal filter

You have to use the woocommerce_default_address_fields hook:

add_filter( 'woocommerce_default_address_fields' , 'wpse_120741_wc_def_state_label' );
function wpse_120741_wc_def_state_label( $address_fields ) {
     $address_fields['state']['label'] = 'County';
     return $address_fields;
}

This (and more) is described at the woocommerce docs: Customizing checkout fields using actions and filters, so read your stuff next time thoroughly… 😉


Edit:
Above code isn’t working for all cases, because on country selection the state field of the checkout form gets updated via javascript. To make it work it’s necessary to add the desired name for those cases as translation, using the woocommerce_get_country_locale hook like this:

add_filter('woocommerce_get_country_locale', 'wpse_120741_wc_change_state_label_locale');
function wpse_120741_wc_change_state_label_locale($locale){
    // uncomment /** like this /**/ to show the locales
    /**
    echo '<pre>';
    print_r($locale);
    echo '</pre>';
    /**/
    $locale['GB']['state']['label'] = __('test', 'woocommerce');
    $locale['US']['state']['label'] = __('anything', 'woocommerce');
    return $locale;
}

The hook is located at the class-wc-countries.php in the get_country_locale() function.

Leave a Comment