There are times you don’t want to translate the whole installation of 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.
It doesn’t matter whether you want to rename a string in the original language (English, usually), or change the default translated string in a different language. Either way, and thankfully, there’s a little PHP snippet that will work for you instantly. Enjoy!
PHP Snippet: How to Translate or Rename a Single String of Text (WooCommerce Plugin)
Please note that the ‘woocommerce’ === $domain part in the below snippet gives you exclusive access to WooCommerce plugin strings. With that line, you can’t translate strings generated by your theme or other plugins. Feel free to remove it, but be careful because you may end up translating a lot of additional stuff that maybe you didn’t really want to.
Also, the ! is_admin() check is making sure that translation is only executing on the frontend, so the WordPress dashboard will be excluded. This is a good performance trick, also.
Finally, please note the difference between $translated and $untranslated: if you run a store in English language, you can use any of the two because $translated = $untranslated.
/**
* @snippet Translate a String in WooCommerce (English to English)
* @how-to Get CustomizeWoo.com FREE
* @author Rodolfo Melogli
* @compatible WooCommerce 4.5
* @community https://businessbloomer.com/club/
*/
add_filter( 'gettext', 'bbloomer_translate_woocommerce_strings', 999, 3 );
function bbloomer_translate_woocommerce_strings( $translated, $untranslated, $domain ) {
if ( ! is_admin() && 'woocommerce' === $domain ) {
switch ( $translated ) {
case 'Sale!':
$translated = 'On Offer';
break;
case 'Product Description':
$translated = 'Product Specifications';
break;
// ETC
}
}
return $translated;
}
On the other hand, if you run a mono-lingual store in a language that is not English, $translated should be the string in your language while $untranslated is the original string in English – which means that if you want to do a renaming from Spanish to Spanish, you should use $untranslated. Kinda complex to explain, so I recommend trial/error.
/**
* @snippet Translate a String in WooCommerce (English to Spanish)
* @how-to Get CustomizeWoo.com FREE
* @author Rodolfo Melogli
* @compatible WooCommerce 4.6
* @community https://businessbloomer.com/club/
*/
add_filter( 'gettext', 'bbloomer_translate_woocommerce_strings', 999, 3 );
function bbloomer_translate_woocommerce_strings( $translated, $untranslated, $domain ) {
if ( ! is_admin() && 'woocommerce' === $domain ) {
switch ( $untranslated ) {
case 'Sale!' :
$translated = 'Rebaja!';
break;
case 'Product Description' :
$translated = 'DescripciΓ³n del producto';
break;
// ETC
}
}
return $translated;
}
How to Find The Correct WooCommerce String
Sometimes the code above does not work because you’ve selected the wrong string of text. It’s not as straight forward as it seems, because “frontend” strings (the ones you see on the website as a user) might differ from “backend” ones (the ones inside the code).
For this reason, you should always be familiar with the WooCommerce PHP files and search for the string before applying the snippet above. Here are some examples of the CORRECT strings you should translate:
// an easy one to translate
'Pay for order'
// a weird one, note the %s placeholder for product name
// on the frontend you would see the product name...
// ...but on the backend you see this:
'Sorry, "%s" is no longer in stock so this order cannot be paid for. We apologize for any inconvenience caused.'
How I can use getttext based on billing country?
You can try with WC()->customer->get_billing_country(), but please test it on staging first
Hi,
I cannot get these text changed that are in the wp_terms table:
outofstock
featured
rating-4
rating-5
I tried loco translate and your snippet, but both without succes. And i need to change it, because i want to use it in a filter on the frontend.
Please check the screenshots:
https://snipboard.io/QZASdE.jpg
https://snipboard.io/IELJWD.jpg
Any ideas? Many thanks
Hello Bram, are you sure they come from WooCommerce and not a third party (filter) plugin? Maybe the error is there. Otherwise, please share the code you used (as well as telling me what widget you’re using there) and I’ll take a look
Works as expected in December 2022 π Thank you!
Nice!
Perfect, thank you!
Cool
Works perfectly to change a translated string!
Awesome
Working on the other cases but, not being able to make it work for string ‘has been added to your cart.’ Referred to Woocommerce the string is ‘%s has been added to your cart.’ found on $added_text = ….
Here is my code for the switch case
Does not work for added to your cart
this filter worked for the text
Nice!
Hi there,
Thanks for your post. I tried to translate the Text above the Billing form, but the text doesn’t change at all. We’re using a German WooCommerce system. Is there anything wrong with the code?
Works for me. Try disabling all plugins but Woo and see if it works, so that you can find out which plugin is causing this problem by reactivating them one by one
Thank you! For your great tutorial. There is a reason why after installed woocommerce I try to change the language in italian in general setting of my website and after save the language cames back in english
No idea! Try changing the language of your user instead
Hello Rodolfo, i want to ask a question.
I need to translate woocommerce’s default pagination url structure “page”
category/child-category/page/4/
category/child-category/page/5/
category/child-category/page/7/
.
.
.
How can i change this structure to something else like “category/child-category/new-pagination/7/”
I would be very happy if you could help with this. Thank you, have a nice day.
Hi Mehmet, 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!
Amazing, Thank You!
You’re welcome!
I used your snippet “Add Privacy Policy Checkbox @ Checkout” and want to translate the text that this snippet returns to Spanish (in other words, I want to translate the “I’ve read and accept the Privacy Policy’ and the “Please acknowledge the Privacy Policy”). Can I use this snippet to translate the texts from the other snippet?
Hey Carmen, thanks for your comment! In order to make a string translatable you have to wrap it in a __() function: https://codex.wordpress.org/I18n_for_WordPress_Developers#Translatable_strings – hope this helps π
I am trying to replace “View Cart”, “Out of Stock” and “Featured” in a Kalium Shop Theme (child of Kalium theme) to Catalan (other texts are correctly translated) but your snippet doesn’t work.
Main WP language is Catalan and I use:
The last } is on its place in the functions.php, I just lost it when I did copy-paste from my file to my comment.
Are they Woo strings or Kalium strings maybe?
like a charm, thank you so much
Yay
WordPress Version: 5.5.1
Woocommerce Version: 4.5.2
Did not work for Billing Address Text on Checkout page
Share your code please
Hi Rodolfo,
Unfortunately the snippet isn’t working for the “customer reviews” text. Is there any other solution for that?
Thank you
It works, you just need to find the correct string
Yeah, this was the string I needed:
. Thanks!
Awesome
gettext() not work for me!
I need rename label “Dimensions (in)” in Shipping tab of Product Data.
I find it!
$text = ‘Dimensions (%s)’;
Thank’s!
Nice
Great article.
One question however,
what if I would like the translated to be linked to a page or something?…how do you go about that??
This is for text strings only. But you can try to put some a href HTML inside the translated string, not sure if that’d work though
Bonjour Rodolfo,
Landed here from Google’s quest for my question β from ‘n Product’ to ‘n Object,’ woocommerce changed text.
I’m trying to create restaurant online order menu. So, they tried to change the ‘Package’ text to ‘Object’ but no luck on the Shop page. And without success I tried process above. I appreciate your support.
Hi there, 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!
When I add the snippet the goal is achieved: The Dutch word “Uitverkocht” becomes “Wachtlijst”. However all other translations in WooCommerce (and in the backend) switch back to English. All the buttons turn to English for example. When I remove the snippet the store is completely in Dutch again, but the word I wanted to translate: uitverkocht to wachtlijst, is now back to uitverkocht again. I’m sure it’s a simple mistake I make, I just don’t see it. I would very much appreciate your help.
Should be $translated = ‘Wachtlijst’;
Thaaaaanks for the code my friend!!! Helped a tonnn
Nice!
Darn it. Wish I could say that …..
Here’s what I used, and it’s not working somehow.
This is the url in question.
https://akadeemia.hrsolutions.ee
The word “ITEM” should be translated into “TOODET”
Loco translate has not been helpful either, that’s how I ended up with your solution, only to find that it doesn’t work for me….
In this case, the function that generates that/those string/s is in the admin, so you have to remove the !is_admin() check
Thanks a lot! Somehow, that does not work either…. π
OK, so I got it to work finally with the following code added to what I ‘borrowed’ from you.
Works like a charm! And just wanted to share.
Thanks
Ah good
Hi Rodolfo,
Landed here from Google search for my query – woocommerce change text from ‘n Product’ to ‘n Item’.
I’m trying to build an online ordering menu for restaurant. So, tried to change the text ‘Product’ to ‘Item’ but no luck in Shop page. I even tried above method without a success. I would appreciate your help.
Thank you for your contribution.
Hum
Hey Hum, it could be a theme or a third party plugin string, and also there might be more than that (singular/plural). This snippet must work, but you need to do more work to make it function in this case
Hey there, I am actually also building an online shop for a restaurant in these dire times! And I tried to change You may also like… to Wine Pairing but no change on the website. Looking now whether it might be a theme thing.
Thx!
Try with https://businessbloomer.com/woocommerce-change-may-also-like-text/
Hi Rodolfo,
Does it works with the colum title text in woocommerce orders page? I’m talking about the “Billing” string in my site (the only word that it’s left in translation): https://i.gyazo.com/0ef910abdf088a0f1fd1851c3ebb15b0.png
Thanks a lot!
It should, but it’s not always 100% reliable
Thank you for posting this filter Rodolfo. I used it to translate the “Description” tab label to “More Info” in the product description display. Your filter was smart enough to NOT translate the word “Description” if the word falls within part of the product description.
However the filter didn’t work to change the word “Sold” in the sold out badge, to “Sold Out.” Maybe that’s a different scope.
Hey Carol π Yes, you’ll need to see how the string is “coded” inside that plugin, maybe it’s “Sold!” instead or something like that
Thank you very much, Rodolfo! So much easier than yet another plugin!
Ah! Thank you!
Great article, thank you. Your suggestion is perfect.
Thanks!
thanks bro… It works…
Hope to get more useful tutorials from you…
Great!
Hi Rodolfo,
Thanks for these tutorials. I’ve already managed to translate the up-sell and related products titles so thanks for that. Now I have two questions.
1. I’m doing something wrong when trying to translate the cross-sell text ‘You may be interested in’ (Or in Dutch ‘Je bent misschien ook geΓ―nteresseerd in’ to ‘Maak de look compleet’.
2. How to remove the three dots from cross sell and up-sell titles
This is the php snippet I use for the cross sell text. I’ve tried translating from original Woocommerce English to Dutch and from Dutch to Dutch.
Hopefully you can pinpoint the problem I’m missing.
Hi Christian, take a look at https://businessbloomer.com/woocommerce-change-may-also-like-text/ – as you can see you have to target the full string, and some times this comes with the 3 dots attached to it (hellip in HTML)
Works like a dream – thank you so much for this
Excellent
Thank you very much for this awesome and easy code π
Welcome!
hi,
every single tip or how-to i’ve tested actually works. and although some may be technical, you clearly know how to explain and break down processes, codes or integration. and for being roaming boards and tech pages for years, i can tell you it’s a rare thing. many thanks for sharing.
i’m having a bit of a bug with the woocommerce connection page, a php-warning-hook-line-286 error. could you check it out and tell me if you can fix it, and at what cost?
Hello John, thanks so much for your comment! Yes, this is definitely possible – if you’d like to get a quote, feel free to contact me here
This worked great. Thank’s!
Awesome!
Hello Mr Rodolfo.
Thanks for share your code.
I was using your great snippet to change some lines in checkout
But second line is not working for my case.
// Town-city >> Localidad / Ciudad > Departamento // OK
$translated = str_ireplace( ‘LOCALIDAD / CIUDAD’, ‘DEPARTAMENTO’, $translated );
// State / County > RegiΓ³n / Provincia > Ciudad ///// Not working β²
$translated = str_ireplace( ‘REGIΓN / PROVINCIA’, ‘CIUDAD’, $translated );
I think error is because of “Γ” letter.. I dont know what to do..
Thanks…
Hi Andrew, try to find the file where the string is generated from, and copy/paste it. Maybe that’ll work
Hi Rodolfo, thank you for the code snippet, however Iβm working with the plugin βDeposits For WooCommerceβ, where some strings seemingly donβt want to be translated. Iβve tried multiple solutions (including yours) but none of them seem to be working. Understandably, I donβt want to edit the text in the plugin itself as those edits get deleted when thereβs a new update. The text is as follows:
I want to change both instances of βPay Depositβ and βPay Full Amountβ. Is there anything in this code snippet that prevents users to override the translation?
Hey Jordy, they seem to have a space before and after the string, so maybe you need to include that in the translation – give it a go
Hi Rodolfo, thank you for the code snippet, however I’m working with the plugin “Deposits For WooCommerce”, where some strings seemingly don’t want to be translated. I’ve tried multiple solutions (including yours) but none of them seem to be working. Understandably, I don’t want to edit the text in the plugin itself as those edits get deleted when there’s a new update. The text is as follows:
Pay Deposit
Pay Full Amount
Pay Deposit
Pay Full Amount
I want to change both instances of “Pay Deposit” and “Pay Full Amount”. Is there anything in this code snippet that prevents users to override the translation?
Excuse me, I forgot to read the policy on writing code, I’ll post my question again but with the wrap. You may delete this comment
I also translates the admin text. For example if i want to translate price word then it translate price word in product column in dashboard. Then I use
if(!is_admin() || is_checkout() || is_cart()) but it generates error. Error :
Fatal error: Uncaught Error: Maximum function nesting level of ‘256’ reached, aborting!
Error: Maximum function nesting level of ‘256’ reached, aborting!
Hello Zakir, 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!
thanks for your hint, not sure why it did not work in your case but it works for me. Hope you’ve worked it out.
Hello
perfect Snippet – thxs
but seems not working with special characters – like accent characters in french (Γ©, Γ , Γ¨β¦)
how can i do this ?
thxs for your help
Not sure!
this is a life saver, thank you very much
Thanks!
Hello Rodolfo,
Your hints, tips and snippets have been a great help but I can not get this one to work, I have the latest versions of WordPress and Woocommerce and use the Deli theme. If I put it directly in the functions.php file it breaks the site, using the Themes Customisations plugin it has no effect at all!
Thanks
Terry
Hello Terry, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom troubleshooting work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Brilliant, thanks! π
You’re welcome!
This didn’t wok form me on the attribute text
Hello 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!
Rodolfo, you are my god now π
Cheers!
Thanks man, I was breaking head here with the plugin WooCommerce Subscription, which changes the button at the checkout.
You’re welcome!
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!
Thanks!
Great Snippet! Works easily!
Is there any way to translate strings only at specific urls?
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!
Thanks Rodolfo,
great snipet and so easy to use π
Thanks!
Finally, a snippet that worked. THANK YOU!
Awesome!
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!
Excellent π
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!
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
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
Solution:
add_filter( ‘gettext’, ‘theme_translate_woocommerce_strings’, 999, 3 );
Thank you. I solved my problems
Exactly, thank you Fabiano!
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.
Sorry Stefan, this has now been fixed (added “3” in the add_filter call as priority)
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
Sorry Moi, this has now been fixed (added “3” in the add_filter call as priority)
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. π
Sorry Petra, this has now been fixed (added “3” in the add_filter call as priority)
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 π
Awesome! I’m not a big fan of WPML either π
Thank you π
You’re welcome!
still works
Excellent π
How do I update this to only affect a certain text domain?
Hey Jon, thanks for your comment. You can pass $domain to the function as well: https://codex.wordpress.org/Plugin_API/Filter_Reference/gettext
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.
Thank you Richard π It should work… try with: https://businessbloomer.com/woocommerce-rename-tag-taxonomy/
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.
Hello Kevin, yes it should. Let me know
It works perfectly! thank you so much!!!!
Great π
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!
Ella
Awesome, thank you so much Ella π
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. π
π hope you sorted that out Yavor!
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:
to translate string into footer widget..
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
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
Hey Erik, this snippet should work! What have you tried so far?
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 …
Hey Rob, I just updated the snippet for you π
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!
i answered my own problem!
Ahah excellent π
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!
Hey Paloma! If you’re using Polylang you don’t need this snippet as well – it should be sufficient!
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?
Thanks
Hey Luise, thanks for your comment. I’m not 100% sure here. Maybe give https://wordpress.org/plugins/say-what/ plugin a go.
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
Hey K, I take you managed to work this out π
Thank you!
I have tried everything and wasted around 1 day trying to fix this problem.
And yet, your simple code works!
Fantastic π
Thank you so much! works like a charm.
Awesome π
Thank you!! This saved me a lot of time digging through my theme.
Excellent π
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.
Hey Dev, thanks for your comment! You can do that from the WooCommerce Tax settings π
I lov u
Ah, thank you π
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?
Thanks,
Massimo
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
Just what I needed! A big thank you for that! π
Works excellent!
Great!!! π
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!
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 π
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;
}
Hey Itayko, not sure here π Unfortunately I cannot provide custom work here via the blog comments.
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 π
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 π
Great! It worked and was real easy! Much appreciated
Awesome! Thanks Arthur π
Hi. This code break whole page when applied to functions.php
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?
Thanks! !
You’re welcome!
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?
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!
Works perfectly, thank you Rodolfo!
Cool, cheers for the feedback Noelle π
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?
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 π
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?.
Hey Andy, yes, it should be possible. Have you tried it yet?
No because I dont know how to specify/target the collect in store shipping option.
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 π
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.
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!
~R
This way was working previously. On latest WooCommerce it does not work anymore. Any suggestions? Thank you.
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!
doesnt work for me. Why is this?
Mira, thanks for your feedback. What string are you trying to translate, can you tell me the link of your website page?
Very nice – I wander if there is much performance issue translating this way or some other reason editing the po would be better..
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!