Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #1465228

    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

    • This topic was modified 1 month ago by Munford.
    #1465390

    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

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.