Since WooCommerce 4.1, there is now an easy way to edit the “You may also like…” WooCommerce string that appears on the Single Product Page, thanks to a brand new “PHP filter”. Kudos to Damien Carbery for reporting this new method.
So, as usual, simply copy/paste the snippet below in your child theme’s functions.php and it will do what it says on the tin. Enjoy!
PHP Snippet: Reword / Translate “You may also like…” Title @ Single Product Page
/**
* @snippet Translate "You may also like..." - Woo Single Product
* @how-to businessbloomer.com/woocommerce-customization
* @author Rodolfo Melogli, Business Bloomer
* @compatible WooCommerce 9
* @community https://businessbloomer.com/club/
*/
add_filter( 'woocommerce_product_upsells_products_heading', 'bbloomer_translate_may_also_like' );
function bbloomer_translate_may_also_like() {
return 'Customers also purchased...';
}
The new way is to use the Woocommerce filter hook: ‘woocommerce_product_cross_sells_products_heading’
Appreciate that, but your filter is for the cross-sells section on the Cart page. Mine is still working, and it’s for the Single Product Page
Thanks for that solution. Easy and perfect text change.
Great!
Works like a charm, as always with your snippets π
Thank you!
In version Version 4.9.1 it should be:
Cheers!
Cross sells are on the Cart page though?
I was looking so much for the cross sells snippet! This was very useful comment above.
Thank you all.
Nice
From WooCommerce 3.0 there is a filter to change this string: ‘woocommerce_product_upsells_products_heading’
No need for ‘gettext’ filter any more! ‘gettext’ filter is a dangerous one because it is called hundreds of times for each post.
The filter function can accept 3 parameters, the third is the text ‘domain’ (which would be ‘woocommerce’ for this string). You could check that string before calling str_ireplace().
I saw this morning that WPBeaches.com has mentioned this snippet. I informed them about the filter too.
Excellent, thanks Damien!
Hi there! I’ve used your snippet on a website I’m working on and it works (almost) great using ‘You may also like&hellip’. If you don’t use “&hellip”, it doesn’t work.
I say “almost” because something weird happen to me: there is a “;” at the end of the translated sentence whatever I choose to write!! I’ve tried many possibilities but without success. How can I get rid of this ; please?
Here is the piece of the snippet: $translated = str_ireplace( ‘You may also like&hellip’, ‘MEILLEUR CHOIX POUR VOUS’, $translated );
Thanks!
The semicolon is part of “&hellip” so you need to include that as well. It’s an HTML symbol
Should this code also work on the cross-sell during in the cart page?
Or does that require different code?
No, it’s different. You need to target that different string
Hi, how I can hide “You may also like⦔ text if products are out of stock?
Thanks
Hey Mimmo, 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!
Please use … to … otherwise this is not working.
“…”
It’s in the snippet notes indeed
How does it work if I have a non-English blog? For example in German? Unfortunately the snippet doesn’t work there.
Hello Samuel – did you try to use the string in German instead of “You may also like” inside the snippet?
Thanks, this is very helpful! Still works like a charm as of 07/20/19.
Thanks!
Hi,
Thanks for the upsell snippet. Is there any snippet to change the text in the cross-sell cart “You may be interested in⦔?
Thanks.
Alex
Hi Alex! Yes: https://businessbloomer.com/translate-single-string-woocommerce-wordpress/
Still working on the 7th of August 2018!
Thank you very much!
Awesome π
its working still. I tried in latest woocommerce.
π
Yes ! this worked perfectly for the cross-sells (the related products on product pages), but it doesnt work on UP-SELLS text (which is the same ‘you may be interested in…”
This is what i did, and breaks my site:
Hey Veronica, thank you so much for your comment! Why does the above break your site – what error did you get?
Still going! π
Awesome π
It is working. π
tnx
Great π
Hello, I am having the same problem, but even a bit more complicated: I am running a theme (Bridge) with woocommerce mulitilanguage preinstalled. problem is that the text “You may also like..” is automatically translated into dutch. But this translation sucks and I want to change it. Do you have an idea where i can change this?
Thanks guys!
Thanks for your comment Nathan! In this case, I’d recommend reading this guide from WooThemes, and possibly install the Loco plugin or edit the .po Dutch file: https://docs.woothemes.com/document/woocommerce-localization/. Hope this helps π
your are awesome!!!! thanks Rodolfo
Thank you Mo! π
Thanks Rodolfo,
It’s really annoying that “You may also like” is hard-coded to WooCommerce and hence so difficult to change to something more useful, but your solution above provides a neat work around.
But just one small problem: The actual text is “You may also like…” (with three full-stops at the end) and so whatever you translate the string into also ends up with three full-stops at the end! I have tried adding the full-stops into the string to be translated, but this breaks it and it doesn’t work at all.
Any ideas as to how to get rid of the dot dot dot after whatever string I have replaced “You may also like” with please?
James π
Hooray, I’ve just answered my own question. The actual text string to be translated is “You may also like…” with the “…” bit being the cause of the dot dot dot at the end.
To get rid of the dots, the code should therefore be:
// Change “You may also like” into “Wear with”
add_filter(‘gettext’, ‘translate_like’);
add_filter(‘ngettext’, ‘translate_like’);
function translate_like($translated) {
$translated = str_ireplace(‘You may also like…’, ‘Wear with’, $translated);
return $translated;
}
James π
Ok, that didn’t work π
Everywhere I have typed “…” in the above post, change this to “& h e l l i p ;” but without the speech marks and spaces between each letter/symbol.
Perhaps you can update your code to make this clearer?
Thanks for your feedback James, I will update the snippet now. R
Thanks, but how to translate ‘related products’ string?
https://www.businessbloomer.com/translate-single-string-woocommerce-wordpress/