2

I am creating an online shop using wordpress and woocommerce and came across the following question:

How can I translate the text in the WooCommerce Cart Sidebar Widget?

I was able to translate some of the text by writing the following code into my functions.php in my child theme:

add_filter('gettext', 'translate_text'); 
add_filter('ngettext', 'translate_text');

function translate_text($translated) { 
    $translated = str_ireplace('Text to translate', 'Translation', $translated); 
    return $translated; 
}

Some of the text gets translated using the code above, while other strings are not affected by it. I've noticed that mostly strings within a <span> tag are not translated, although there is one within a <a> tag aswell.

How can I translate the remaining text?

Thanks

ediheld
  • 233
  • 3
  • 13

1 Answers1

1

I just solved the problem:

All text-elements can be translated by the following code:

add_filter('gettext', 'translate_text'); 
add_filter('ngettext', 'translate_text');

function translate_text($translated) { 
    $translated = str_ireplace('Text to translate', 'Translation', $translated); 
    return $translated; 
}

The only thing to notice is that the changes are only visible after you refresh the cart (e.g. by removing all products and adding them again).

ediheld
  • 233
  • 3
  • 13