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

Yes, in this tutorial I would like to show you how to change the default headings of related products, upsells and cross sells sections.

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 love WordPress, WooCommerce and Gutenberg so much. 10 yrs of experience.

Need some custom developer help? Let me know

Follow Misha

Need some help with WooCommerce?

If you need some professional developer help, I will be happy to assist you.

Contact me Who I am?

Leave a comment

php js HTML CSS Code