Posted on

WooCommerce: Change “You may also like…” Text

Apparently, there is no easy way to edit the “You may also like…” WooCommerce string as they don’t provide us with a “PHP filter”.

Thankfully, we can take advantage of a WordPress function called “gettext” – so here’s a quick workaround for you!

PHP snippet: Edit / Translate “You may also like…” @ Single Product Page


/**
 * @snippet       Trsnslate "You may also like..." Text - WooCommerce
 * @how-to        Watch tutorial @ https://businessbloomer.com/?p=19055
 * @sourcecode    https://businessbloomer.com/?p=595
 * @author        Rodolfo Melogli
 * @testedwith    WooCommerce 3.5.1
 */

add_filter( 'gettext', 'bbloomer_translate_like' );

function bbloomer_translate_like($translated) {
$translated = str_ireplace('You may also like…', 'Wear with', $translated);
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, WordCamp speaker and Internet marketer, Rodolfo Melogli has worked as a WooCommerce freelancer since 2011. He helps entrepreneurs and developers overcome their WooCommerce nightmares :) Rodolfo is the organiser of WordCamp Dublin, the Dublin WooCommerce Meetup, the Dublin Ecommerce Meetup and the Dublin WordPress Meetup. He enjoys interacting with people, travelling and chasing tennis & soccer balls. Of course, he loves pizza too.

18 thoughts on “WooCommerce: Change “You may also like…” Text

  1. Still working on the 7th of August 2018!
    Thank you very much!

    1. Awesome ๐Ÿ™‚

  2. its working still. I tried in latest woocommerce.

  3. 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:

    add_filter('gettext', 'translate_like');
    add_filter('ngettext', 'translate_like');
    function translate_like($translated) {
    $translated = str_ireplace('You may be interested in…', 'Customers Also Bought:', $translated);
    return $translated;
    }
    
    1. Hey Veronica, thank you so much for your comment! Why does the above break your site – what error did you get?

  4. Still going! ๐Ÿ™‚

  5. It is working. ๐Ÿ˜€
    tnx

  6. 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!

    1. 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 ๐Ÿ™‚

  7. your are awesome!!!! thanks Rodolfo

    1. Thank you Mo! ๐Ÿ™‚

  8. 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 ๐Ÿ™‚

    1. 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 ๐Ÿ™‚

    2. 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?

    3. Thanks for your feedback James, I will update the snippet now. R

Questions? Feedback? Support? Leave your Comment Now!
If you're writing code, please wrap it between: [php] code_here [/php]

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.