0

So, as the title says, I'm trying to translate the output text of WooCommcerce on the "Cart" and "Checkout" pages, it currently says "select a state" where I want "select a province".

I was not able to accomplish this with filters & hooks, as it's something they have overlooked. I was hoping somebody here can help me figure out how to translate the text so it displays as I want. I don't mind if this is using a plugin, native wordpress functionality or whatever, as long as I get it done.

The site in question can be found here.

Thanks in advance, hopefully you guys and gals can give me a hand with this :)

Cheers,

1 Answer 1

1

You can filter gettext:

add_filter( 'gettext', function( $translation, $text, $domain ) 
{
    if ( 'woocommerce' === $domain and 'Select a state…' === $text )
        return 'Select a province…';

    return $translation;
}, 10, 3 );

Note the 3 as last parameter. This ensures you get all three variables passed, so you can replace exactly the text you are looking for.

5
  • Thank you so much for the reply. I appreciate it tons, I've had so much trouble getting help with this However, I added it to my functions.php (child theme), and it broke the site.... any idea why ? Commented Aug 29, 2013 at 22:29
  • Your PHP version is probably completely out of date. PHP 5.3 has reached its end of life already. Your are using PHP 5.2 which lacks some important security fixes. You should update to at least PHP 5.4.
    – fuxia
    Commented Aug 29, 2013 at 22:32
  • Now this might sound kind of stupid, but how do I upgrade my PHP ? Commented Aug 29, 2013 at 22:44
  • That’s usually a setting in your web host back-end.
    – fuxia
    Commented Aug 29, 2013 at 22:47
  • 2
    MY NINJA!!!!! Thank you so much. This was exactly what I needed. You're my hero tonight, dude. I updated the version to 5.4 and it works perfectly. I searched high & wide for this, and never found an answer so concise or effective. I spent literally 2 full days of work looking for this fix. Commented Aug 29, 2013 at 22:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.