Onome Mine Adamu
Onome Mine Adamu

Reputation: 35

Change subtitle “Related Products” in WooCommerce single product pages

By default, WooCommerce uses the words “related product” when showing the related products below a single product view.

I wish to change these words, supplementing it with the preferred text of my client.

/wp-content/plugins/woocommerce/i18n/languages/woocommerce.pot

     #: templates/single-product/rating.php:42
     msgid "%s customer review"
     msgid_plural "%s customer reviews"
     msgstr[0] ""
     msgstr[1] ""

     #: templates/single-product/related.php:51
     msgid "Related Products"
     msgstr ""

     #: templates/single-product/review-meta.php:28
     msgid "Your comment is awaiting approval"
     msgstr ""

To

      #: templates/single-product/related.php:51
      msgid "Related Products"
      msgstr "Customers who rented this item also rented:"

I also have tried editing wp-content/plugins/woocommerce/templates/single-product/related.php file around line 12.

From

  <h2><?php esc_html_e( 'Related products', 'woocommerce' ); ?></h2>

To

  <h2><?php esc_html_e( 'Customers who rented this item also rented:', 'woocommerce' ); ?></h2>

I also added this code to the function.php file:

    function custom_related_products_text( $translated_text, $text, $domain ) {
     switch ( $translated_text ) {
     case 'Related products' :
     $translated_text = __( 'Customers who rented this item also rented:', 'woocommerce' );
     break;
     }
     return $translated_text;
     }
    add_filter( 'gettext', 'custom_related_products_text', 20, 3 );

But it does not seem to be working

    <h2><?php esc_html_e( 'Customers who rented this item also rented:', 'woocommerce' ); ?></h2>

    msgid "Related Products"
    msgstr "Customers who rented this item also rented:"


    function custom_related_products_text( $translated_text, $text, $domain ) {
    switch ( $translated_text ) {
      case 'Related products' :
    $translated_text = __( 'Customers who rented this item also rented:', 'woocommerce' );
    break;
   }
   return $translated_text;
   }
   add_filter( 'gettext', 'custom_related_products_text', 20, 3 );

Related product text is supposed to change to

Customers who rented this item also rented:

Upvotes: 1

Views: 3254

Answers (1)

LoicTheAztec
LoicTheAztec

Reputation: 253784

This is working for me on different themes and will change the "Related products" subtitle:

add_filter(  'gettext',  'change_related_products_title', 10, 3 );
add_filter(  'ngettext',  'change_related_products_title', 10, 3  );
function change_related_products_title( $translated, $text, $domain  ) {
     if( $text === 'Related products' && $domain === 'woocommerce' ){
         $translated = esc_html__( 'Customers who rented this item also rented:', $domain );
     }
     return $translated;
}

Code goes in function.php file of your active child theme (or active theme). Tested and works.

enter image description here

If it still doesn't work you can override woocommerce the template file via your theme like explained on this answer: Rename Related Products title in Woocommerce 3

Upvotes: 2

Related Questions