Tagged: related products, translation, woocommerce
HI
I am currently using this code in my functions.php to change the text of my related products section in woocommerce.
It works fine but now I have also an english translation on the site. Is it possible to get some code change the text on the english pages from ANDRE MEDLEMSKABER to OTHER MEMBERSHIPS? It’s not found in the string translations.
// Change WooCommerce "Related products" text
add_filter('gettext', 'change_rp_text', 10, 3);
add_filter('ngettext', 'change_rp_text', 10, 3);
function change_rp_text($translated, $text, $domain)
{
if ($text === 'Related products' && $domain === 'woocommerce') {
$translated = esc_html__('ANDRE MEDLEMSKABER', $domain);
}
return $translated;
}
thanks
Nancy
Hey Munford,
Thank you for the inquiry.
We edited the filter a bit:
// Change WooCommerce "Related products" text for different languages
add_filter('gettext', 'change_rp_text', 10, 3);
add_filter('ngettext', 'change_rp_text', 10, 3);
function change_rp_text($translated, $text, $domain)
{
if ($text === 'Related products' && $domain === 'woocommerce') {
$locale = get_locale();
if ($locale === 'da_DK') {
$translated = esc_html__('ANDRE MEDLEMSKABER', $domain);
} elseif ($locale === 'en_US') {
$translated = esc_html__('OTHER MEMBERSHIPS', $domain);
}
}
return $translated;
}
Best regards,
Ismael