2 Ways to Change “You may also like”, “Related products” and “You may be interested in” headings

WooCommerce related products and upsells custom heading

In related.php, up-sells.php and cross-sells.php templates

The first and the easiest way is just replace the default WooCommerce templates which are:

All you have to do is to find these files in WooCommerce plugin’s template directory in duplicate them into your theme’s woocommerce directory. I hope you’re familiar with this process.

Once you do it, just change the heading texts in the new files.

Without WooCommerce Templates Replacement

But it is always better to avoid overriding the plugin templates if possible. Because every time you update your WooCommerce plugin you have to check every template you replaced in case there were some major changes. In some cases it could lead to PHP warnings or even to errors.

But what should we do then? Because there is no hook provided for related and upsell product titles! 😕

Please open the files right now – do you see esc_html_e() function in both of them? It means that we can hook those translations with gettext filter! 🕺

The code for your functions.php:

add_filter( 'gettext', 'misha_custom_related_products_text', 20, 3 );
function misha_custom_related_products_text( $translated_text, $text, $domain ) {

	if( $translated_text == 'Related products' // for Related products
	|| $translated_text == 'You may also like…' || // for Upsells
	|| $translated_text == 'You may be interested in…' ) { // for Cross-sells
		$translated_text = 'Do not miss these products too'; // new title
	}

	return $translated_text;

}

Keep in mind that this is a translation hook and it is going to change the text everywhere on your website. If this hook does more than expected, you can also add two conditions there:

So your condition may look like:

if( $translated_text == 'Related products' && $domain == 'woocommerce' && is_product() ) { 

And that’s all. But please do not change these text strings with jQuery 😁

See also

Misha Rudrastyh

Misha Rudrastyh

I develop websites since 2008, so it is total of 13 years of experience, oh my gosh. Most of all I love love love to create websites with WordPress and Gutenberg, some ideas and thoughts I share throughout my blog.

Need some developer help? Contact me