How to translate a string in Woocommerce

If you want to translate some string in woocommerce than you don’t need to translate the whole installation of wordpress or any other translation plugin. You just add some line of php code to achieve this. Here we will achieve this. Let’s have a look. Add following lines code at the end of your theme’s functions.php file of your active child theme (or theme) and Save the file to translate a string in Woocommerce.

Here is default view of cart page when cart is empty:

After translate a string in Woocommerce , Here is view of cart page when cart is empty:

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;

}
Scroll to Top