Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rename Related Products title in Woocommerce 3

I used to have the following function working to change to Related Products text in Woocommerce.

function my_text_strings( $translated_text, $text, $domain ) {
    switch ( $translated_text ) {
        case 'Related Products' :
            $translated_text = __( 'Related Books', 'woocommerce' );
            break;
    }
    return $translated_text;
}
add_filter( 'gettext', 'my_text_strings', 20, 3 );

It always worked perfectly, but as of Woocommerce version 3.0 or so, this function no longer works.

How should I fix this in order to make it working in the version 3.0 and up?

like image 858
Joe Bloggs Avatar asked Aug 15 '17 08:08

Joe Bloggs


People also ask

How do I change the related product title in WooCommerce?

try to open up your wp-content/plugins/woocommerce/templates/single-product/related. php file. Change the 'Related Products' to whatever you want but remember that is. Changing 'Related Products' into 'other text' in the related.

What are WooCommerce related products?

Related products are displayed automatically by WooCommerce by a random choice. You can increase the possibility of displaying certain products together by grouping them in the same categories or tags. Related products show other products marked with the same categories or tags.


1 Answers

Try this, it's working with me

add_filter(  'gettext',  'wps_translate_words_array'  );
add_filter(  'ngettext',  'wps_translate_words_array'  );
function wps_translate_words_array( $translated ) {
     $words = array(
                // 'word to translate' = > 'translation'
               'Related Products' => 'Check out these related products',  
     );
     $translated = str_ireplace(  array_keys($words),  $words,  $translated );
     return $translated;
}
like image 167
Mo'men Mohamed Avatar answered Sep 25 '22 08:09

Mo'men Mohamed