The text strings ‘You may also like’ and ‘You may be interested in’ in WooCommerce can be changed with the gettext filter…

 

add_filter( 'gettext', 'bt_translate_like' );
add_filter( 'gettext', 'bt_translate_like_cart' );
/**
 * @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
 */
function bt_translate_like( $translated ) {
	$translated = str_ireplace('You may also like…', 'Complete the look ', $translated);
	return $translated;
}
 
function bt_translate_like_cart( $translated ) {
	$translated = str_ireplace('You may be interested in…', 'Complete the look… ', $translated);
	return $translated;
}


Change to your desired text by changing the text in the second part of the single quoted string – in the above it is ‘Complete the look…’

ref

2 Comments

  1. Damien Carbery on May 19, 2020 at 9:06 am

    Another idea is to create a .MO file with only 1 string in it. I wrote about how to do this a while back: https://www.damiencarbery.com/2018/12/change-hardcoded-woocommerce-strings/

  2. Damien Carbery on May 19, 2020 at 7:24 am

    You can use the ‘woocommerce_product_upsells_products_heading’ filter to change the ‘You may also like…’ string. It would be more efficient to do this. I’ll let Rodolfo know about this filter too.

    For the ‘You may be interested in…’, it doesn’t have a filter (I’ll submit a PR for this) so ‘gettext’ is needed. When I experimented with ‘gettext’ back in 2014 (https://www.damiencarbery.com/2014/01/change-wordpress-strings-with-gettext-filter/) I found that the filter is called *a lot* for each page load (almost 600 times in an admin page!) so a filter function needs to be very efficient. The filter function can accept 3 parameters. The third is the string ‘domain’ – ‘woocommerce’ here. I suggest using it and checking for it before calling str_ireplace() – it should reduce the number of times the filter function is called.

Leave a Comment