How to translate a string in Woocommerce ?

In this tutorial we’ll learn how to quickly translate a string in Woocommerce. With the help of this functionality we can replace any string with any other string. This is a general purpose functionality and can be used for multiple purposes.

To see what it can do lets have an example, this will be the cart screen when there is no product.


Here you can see the empty cart message i.e. “Your cart is currently empty.”. Now let’s say I want to replace it with the text ‘Empty Cart’. To do this add the following lines of code at the end of functions.php file of your theme.

add_filter('gettext', 'translate_text');

add_filter('ngettext', 'translate_text');

function translate_text($translated) {

     $translated = str_ireplace('Your cart is currently empty', 'Empty cart', $translated);

     return $translated;


Save the file and refresh the empty cart page. You’ll see the cart message has been changed.


In this way, you can replace almost every string with any other.

Editorial Staff

ThemeLocation Provides Wordpress & Woocommerce development & Customization services. Have a Project? Contact To discuss

Leave a Reply

Your email address will not be published. Required fields are marked *