Avishay28 Avishay28 - 2 years ago 247
PHP Question

Can't change "Postcode / ZIP" field label in woocommerce

I have a site in hebrew based on woocommerce. The translation is work great, however, the field "Postcode / ZIP" is refuse to be trasnlate:

enter image description here

I've tried to change it using this code:

add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {

$fields['billing']['billing_postcode']['label'] = 'test';

return $fields;

But something weird happen: when I reload the page I can see the change take effect, but after a second it change back to "Postcode / ZIP".
Another weird thing: the above script work for the other fields, something is wrong with that specific field.

Anyone know what's going on?


Answer Source

The following code solve this out:

function my_text_strings( $translated_text, $text, $domain ) {
    switch ( $translated_text ) {
        case 'Postcode / ZIP' :
            $translated_text = __( 'test, 'woocommerce' );
    return $translated_text;
add_filter( 'gettext', 'my_text_strings', 20, 3 );
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download