The code I used over the years (example below) hasn't worked for awhile. Tried some other code posted on here, but no joy. It seems WC has changed how to filter/translate and each text changed needs to be separate. Is that correct? Originally had 11 text changes using this code...
Would appreciate some code to perform text changes in WC 5.0 Thanks!
add_filter('gettext', 'translate_text');
add_filter('ngettext', 'translate_text');
function translate_text($translated) {
$translated = str_ireplace('Products', 'Prints', $translated);
$translated = str_ireplace('Product', 'Print', $translated);
$translated = str_ireplace('Product Categories', 'Prints', $translated);
return $translated;
}
The WordPress hooks
gettext
andngettext
haven't changes since a while and work on translatable strings, work independently from WooCommerce versions…The correct way to make it work with
gettext
andngettext
hooks is (simplifying a bit and adding some missing function arguments):If some strings are not translated, it can be because they have some context added. In this case the hook
gettext_with_context
is required like:Code goes in functions.php file of the active child theme (or active theme). Tested and works.