WooCommerce: How to Translate / Rename any String

There are times you don’t want to translate the whole installation of WordPress or one of its plugins (such as WooCommerce) just for renaming one short string. There are times you need to rename a label or a little thing and don’t feel like installing a bloated translation plugin. Thankfully, here’s a little PHP snippet that will work for you instantly.

Translate a single string in WooCommerce/WordPress

WooCommerce / WordPress PHP Snippet: How to Translate a String of Text

 * @snippet       Translate a String in WooCommerce
 * @how-to        Watch tutorial @ https://businessbloomer.com/?p=19055
 * @sourcecode    https://businessbloomer.com/?p=162
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 3.5.4
 * @donate $9     https://businessbloomer.com/bloomer-armada/

add_filter( 'gettext', 'bbloomer_translate_woocommerce_strings', 999, 3 );

function bbloomer_translate_woocommerce_strings( $translated, $text, $domain ) {

$translated = str_ireplace( 'Sale!', 'ON OFFER', $translated );

$translated = str_ireplace( 'Product Description', 'Product Specifications', $translated );

// ETC.

return $translated;

Where to add this code?

You can place PHP snippets at the bottom of your child theme functions.php file (before "?>" if you have it). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such delicate files - if you need more guidance, please take a look at my free WooCommerce Customization video tutorial.

Does this snippet still work?

Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7.

If you think this code saved you time & money, please join other Business Bloomer supporters and avail of 365 days of WooCommerce benefits. Thank you in advance :)

Need Help with WooCommerce?

Check out these free videos, tutorials and tips!

  • how-to-edit-woocommerce-with-php-snippets
  • woocommerce-hooks-add_action-list-visual
  • woocommerce-customize-single-product-page-PHP
  • woocommerce-customize-shop-page-PHP
  • woocommerce-advanced-customization
  • how-to-edit-woocommerce-cart
  • woocommerce-customize-checkout-page-PHP
  • woocommerce-email-customization
  • woocommerce-conditional-logic

Rodolfo Melogli

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as a WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza.

99 thoughts on “WooCommerce: How to Translate / Rename any String

  1. Thanks man, I was breaking head here with the plugin WooCommerce Subscription, which changes the button at the checkout.

    1. You’re welcome!

  2. Wonderful, simple and useful, it’s for the site and for the emails. One of the most useful codes I’ve ever seen, from my heart, thank you! Success always! Brazil and Italy love you!

    1. Thanks!

  3. Great Snippet! Works easily!

    Is there any way to translate strings only at specific urls?

    1. Hi Chris, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  4. Thanks Rodolfo,

    great snipet and so easy to use πŸ™‚

    1. Thanks!

  5. Finally, a snippet that worked. THANK YOU!

    1. Awesome!

  6. Thank you so so much!!! WooCommerce’s Spanish translation is pretty decent, but a couple of sentences are left in English and it was driving me crazy. I had looked up everything and finally your snippet solved it. THANK YOU!

    1. Excellent πŸ™‚

  7. Hey, so glad I found your blog! Worked perfectly fine for translating Wishlist, but did not work for 2 other translations – hover text – in the menu (Account / Register). Any idea what could be done different to make it work?
    Thanks a ton!

    1. Hello Betti, thanks so much for your comment! Yes, this is possible – unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  8. Hi. But returned error. (1 passed in / var / www / … on line 288 and exactly 3 expected in) on WordPress 5.1 and WooCommerce 3.5.5

    add_filter( ‘gettext’, ‘theme_translate_woocommerce_strings’, 999, 3 );

    Thank you. I solved my problems

    1. Exactly, thank you Fabiano!

  9. Rodolfo: thanks very much for your snippet.

    It didn’t work in my system environment: WordPress: 4.9.9, WooCommerce: 3.5.4, Theme: DIVI.

    I kept the original functions.php of DIVI unchanged and created a new functions.php inside my DIVI child-theme. This functions.php (in first instance) contained your code – result: PHP-errors:

    Fatal error: Uncaught ArgumentCountError: Too few arguments to function bbloomer_translate_woocommerce_strings()

    So have made the following change to fulfill the (new) requirements for arguments:
    add_filter( ‘gettext’, ‘avistastudios_translate_woocommerce_strings’, 20, 3 );

    Afterwards it worked like a charm.

    1. Sorry Stefan, this has now been fixed (added “3” in the add_filter call as priority)

  10. This seems to cause an error when copied as is…

    Uncaught ArgumentCountError: Too few arguments to function bbloomer_translate_woocommerce_strings(), 1 passed in wp-includes/class-wp-hook.php on line 288 and exactly 3 expected in wp-content/themes/nzebike/functions.php:608

    1. Sorry Moi, this has now been fixed (added “3” in the add_filter call as priority)

  11. Hello,

    this worked just fine but today I had an Ocean WP theme update and of course, all my translations are gone, but when I want to add them back, it is not working and there are these errors:

    Uncaught ArgumentCountError: Too few arguments to function bbloomer_translate_woocommerce_strings(), 1 passed in wp-includes/class-wp-hook.php on line 288 and exactly 3 expected in wp-content/themes/oceanwp/functions.php:948
    Stack trace:
    #0 wp-includes/class-wp-hook.php(288): bbloomer_translate_woocommerce_strings(‘Top Bar’)
    #1 wp-includes/plugin.php(203): WP_Hook->apply_filters(‘Top Bar’, Array)
    #2 wp-includes/l10n.php(182): apply_filters(‘gettext’, ‘Top Bar’, ‘Top Bar’, ‘oceanwp’)
    #3 wp-includes/l10n.php(283): translate(‘Top Bar’, ‘oceanwp’)
    #4 wp-content/themes/oceanwp/functions.php(270): esc_html__(‘Top Bar’, ‘oceanwp’)
    #5 wp-includes/class-wp-hook.php(286): OCEANWP_Theme_Class::theme_setup(”)
    #6 wp-includes/class-wp-hook.php(310): WP_Hook

    Thank you for your reply. I am really miserable. πŸ™

    1. Sorry Petra, this has now been fixed (added “3” in the add_filter call as priority)

  12. Thanks for this amazing snippet. I used this snippet for wpml. I dont like wpml string translate, because it make slow website. And I couldnt translate wordpress site title and tagline without this plugin. This snippet helped to me do it πŸ˜€

    1. Awesome! I’m not a big fan of WPML either πŸ™‚

  13. Thank you πŸ™‚

    1. You’re welcome!

  14. still works

    1. Excellent πŸ™‚

  15. How do I update this to only affect a certain text domain?

    1. Hey Jon, thanks for your comment. You can pass $domain to the function as well: https://codex.wordpress.org/Plugin_API/Filter_Reference/gettext

  16. Hi Rodolfo,
    Thx for the snippet. Works great on my site.
    I am using loco translate but for some reason it simply won’t translate my Single Product Pages, which is where this code comes in very handy.

    However, I am also trying to translate the product meta strings (“tags”, and “category”), but this code doesn’t work for that.

    1. Thank you Richard πŸ™‚ It should work… try with: https://businessbloomer.com/woocommerce-rename-tag-taxonomy/

  17. Does this snippet also work for the WC emails? To translate ‘Subtotal’, ‘Shipping’, ‘Payment method’ etc. On the website this strings are already translated, but in the emails they are still in English.

    1. Hello Kevin, yes it should. Let me know

  18. It works perfectly! thank you so much!!!!

    1. Great πŸ™‚

  19. Hi Rodolfo,
    I had problems with the standard product filters in Spanish , They were only translated for the half. And everything in the MO and PO files was translated.. Did not know where to search anymore. But your wonderful snippet did the trick. 3 strings on a row.. tada!
    Nice side affect was that the string “products” was everywhere, on the site translated to “Tutorials” And that is what I am selling! πŸ™‚

    Thank you very much for all your effort!

    1. Awesome, thank you so much Ella πŸ™‚

  20. The snippet worked for me. However, I replaced ‘bbloomer’ with my initials and it broke the entire site. I then spent 2 hours thinking what went wrong. πŸ™‚

    1. πŸ˜€ hope you sorted that out Yavor!

  21. Not worked for me.. Inserted into functions.php, but simply not translated string for me. Im not sure if is theme related or something else, but not worked. This is code i inserted:

    add_filter( 'gettext', 'bbloomer_translate_woocommerce_strings', 999 );
    function bbloomer_translate_woocommerce_strings( $translated ) {
    // STRING 1
    $translated = str_ireplace( 'Follow Us', 'SUIVEZ-NOUS', $translated );
    return $translated;

    to translate string into footer widget..

    1. Hey Dean, thanks so much for your comment! Unfortunately this looks like custom troubleshooting work and I cannot help here via the blog comments. Thanks a lot for your understanding! ~R

  22. Hi Rodolfo,

    Great support!
    A simple question: How do I translate a specific text string in the login page?
    Thank you very much in advance.

    Regards Erik

    1. Hey Erik, this snippet should work! What have you tried so far?

  23. Hi! can somebody post just a simple example how to add a second string to the code, I dont have a clue how to achieve this with switch statement …

    1. Hey Rob, I just updated the snippet for you πŸ™‚

  24. Hi Rodolfo

    Brilliant simple solution to all the others i’ve used in the past.

    Do have a question, i have ‘Cart’ to change to ‘Booking’ in my secondary header, the text changes onload but then changes back to ‘Cart’ as soon at the entire page loads.

    The menu item is added by the theme options itself if that’s of any issue

    It’s an odd one!

    1. i answered my own problem!

    2. Ahah excellent πŸ™‚

  25. Hi Rodolfo,
    I tried your code, but it doesn’t work for me… I pasted it in fuctions.php along with the code below to translate the shop and checkout. Any ideas why? I am trying to translate the page in English and Spanish.

    function get_woocommerce_shop_polylang() {
    return pll_get_post(get_option(‘woocommerce_shop_page_id’ ) );
    add_filter(‘woocommerce_get_shop_page_id’, “get_woocommerce_shop_polylang”);

    function get_woocommerce_checkout_polylang() {
    return pll_get_post(get_option(‘woocommerce_checkout_page_id’ ) );
    add_filter(‘woocommerce_checkout_page_id’, “get_woocommerce_checkout_polylang”);

    Thank you for your help!

    1. Hey Paloma! If you’re using Polylang you don’t need this snippet as well – it should be sufficient!

  26. Once more a great help! Thanks. However it does not seem to work with special characters. if I put the german word “WΓ€hle” the whole phrase just disapears completly. “Wahle” works fine.
    Any idea how to work around that?

    1. Hey Luise, thanks for your comment. I’m not 100% sure here. Maybe give https://wordpress.org/plugins/say-what/ plugin a go.

  27. Hi Rodolfo Melogli,

    I tried your code ( 4-02-2018 ) & it didn’t work, put that in child theme’s functions.php.

    trying to convert ( VAT Inc. ) to German.

    hope you could help.

    Thanks in Advance

    1. Hey K, I take you managed to work this out πŸ™‚

  28. Thank you!

    I have tried everything and wasted around 1 day trying to fix this problem.

    And yet, your simple code works!

  29. Thank you so much! works like a charm.

  30. Thank you!! This saved me a lot of time digging through my theme.

  31. It worked on all of the woo commerce. But it is not translating the Tax Names. Say If I have a tax name “GST Handling Fee” and I want to change it to ‘HST Expedition Fee’. It is not working.

    1. Hey Dev, thanks for your comment! You can do that from the WooCommerce Tax settings πŸ™‚

    1. Ah, thank you πŸ™‚

  32. Hi Rodolfo,

    Thank you for all the cool videos.

    I have a multilingual Woocommerce site (4 languages). I use polylang, Hyyan WooCommerce Polylang Integration and Loco Translate to manage the different languages.

    I would like to completely change the text of the Woocommerce emails (for example the one for a new user).
    This would involve changing the customer-new-account.php template file and all the related strings in the .po files.

    What would be the best approach to do this especially considering that the plugin could be updated in the future?

    1. Massimo, my snippet is to be used for a string or 2, not for a full translation. Your translation plugins should allow you to translate emails as well, so maybe take a look at their “PRO” version, maybe this is not included in the freemium

  33. Just what I needed! A big thank you for that! πŸ™‚
    Works excellent!

  34. This saved me some trouble with translating some mystical plugin parts, thank you.
    But the thing about is, it searches for ALL strings on your website, not considering the context at all. Let say you I want translate one word like the preposition “of”. Now, the letters “of” may appear in hundreds of words on the website – like ” loft” or “soft” etc. They will all be replaced, which is of course not desirable.
    How can I possibly prevent this unwanted translations?

    Best regards and thanks!

    1. Filip, thanks for your comment! Yes, you should use this snippet very carefully… Instead of translating “of”, which is way too generic, you should for example translate “bag OF strawberries”, which is unique πŸ™‚

  35. Hey,
    i used this code several times before and it worked,
    but now i’m using woocommerce subscription plugin,
    and it did not work,
    I want to translate: year, week, day.
    any other possible way ?
    here is my code:

    add_filter(‘gettext’, ‘translate_reply’);
    add_filter(‘ngettext’, ‘translate_reply’);
    function translate_reply($translated) {
    $translated = str_ireplace(‘year’, ‘Χ©Χ Χ”’, $translated);
    return $translated;

    1. Hey Itayko, not sure here πŸ™‚ Unfortunately I cannot provide custom work here via the blog comments.

  36. Hi!
    The code works well. But I’m wondering how to use it only on English version of my site (home language is Polish). I’m having troubles with Loco Translate and WPML costs $$$ πŸ™‚
    I have created additional custom tab on single product page (thanks to your youtube tutorial!) like this:

    $tabs[‘my_custom_tab’] = array( “title” => __( ‘Karta katalogowa’, ‘woocommerce’ ),

    and I want “Karta katalogowa” to be translated to “Datasheet” when I’m on English version of my site.
    Can I base on other automatic translation and wrap your above translation code in somethig like “if description_tab name is “Description” -> translate, else -> do not translate.
    What do you think? How to refer to other tab title?

    Thanks πŸ™‚

    1. Hey Jacek, thanks for your comment πŸ™‚

      Once you create the string, you can definitely use a translation plugin such as SayWhat, Polylang or other to target that in your own language.

      This snippet is to translate something in a one-language website πŸ™‚

  37. Great! It worked and was real easy! Much appreciated

    1. Awesome! Thanks Arthur πŸ™‚

  38. Hi. This code break whole page when applied to functions.php

    1. Hey Adam, thanks for your comment! This snippet works, I use it on many websites – so maybe you made a syntax error. What error do you get if you enable wp_debug?

  39. Thanks! !

  40. Hi i tried this and it worked just perfectly, question is; Can i edit more than 1 string if yes, how can i do that?

    1. Excellent, thanks Ifeanyi! Yes, that is possible with basic PHP – look into the SWITCH CASE PHP documentation and you should figure a way to achieve what you need πŸ™‚ Hope this helps!

  41. Works perfectly, thank you Rodolfo!

    1. Cool, cheers for the feedback Noelle πŸ™‚

  42. Hi Rodolfo,
    Sorry to bother you again, you pointed me to this article after answering my query/comment on the Woocommerce Emails Visual Hooks page.
    Can I translate more than one string, i.e) from two different Woocommerce Emails within the same function or do I need to repeat your snippet from above for each translation string?

    1. Yes, definitely. You can add the PHP “switch / case” inside the function and have a list of phrases (cases) with their relative translations. I can’t provide this here as this is custom work but hopefully I’ve sent you in the right direction πŸ™‚

    2. Hi,

      Sorry to bother you again. I’m trying to change the text for the completed order email when the customer has chosen the ‘Collect In Store’ shipping option in the cart.
      Is this possible with string translation or is there a different approach?.

    3. Hey Andy, yes, it should be possible. Have you tried it yet?

    4. No because I dont know how to specify/target the collect in store shipping option.

    5. You’ll have to search for that string through the files (with NotePad++ or similar for example), and then use the exact PHP string they use in the snippet πŸ™‚

    6. I’m not sure your understanding the question. The string I would want to customize is in the Completed Order Email, this string “Hi there. Your recent order on %s has been completed. Your order details are shown below for your reference:”

      But I want to change this string specifically for when a customer has bought something via Collect in Store. So when the admin marks it as complete, a custom completed order email is sent to that customer.

    7. Gotcha πŸ™‚ Yes, this is possible of course – but unfortunately this is custom development work and I cannot provide this solution on the blog right now.

      If you would like to get a quote for the fix, feel free to get in touch. Thanks for your understanding!


  43. This way was working previously. On latest WooCommerce it does not work anymore. Any suggestions? Thank you.

    1. Fansi, thanks for your feedback πŸ™‚ This is a WordPress filter, so I find it strange it’s related to WooCommerce latest update. Can you check again and let me know? Thank you!

  44. doesnt work for me. Why is this?

    1. Mira, thanks for your feedback. What string are you trying to translate, can you tell me the link of your website page?

  45. Very nice – I wander if there is much performance issue translating this way or some other reason editing the po would be better..

    1. Yes, of course. I would recommend to translate max 10 strings or the PHP could slow down your website. Above 10 strings I would choose the “po” method! Thanks for your feedback!

Questions? Feedback? Support? Leave your Comment Now!

If you are writing code, please wrap it between: [php]code_here[/php]. Failure to complying with this (as well as going off topic) will result in comment deletion. You should expect a reply in about a week - this is a popular blog but I need to get paid work done first. Please consider joining #BloomerArmada to ask me 1-to-1 WooCommerce questions. Thank you :)

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.