Изменить подзаголовок «Сопутствующие товары» на страницах отдельных продуктов WooCommerce - PullRequest
0 голосов
/ 23 декабря 2018

По умолчанию WooCommerce использует слова «связанный продукт» при отображении связанных продуктов под одним представлением продукта.

Я хочу изменить эти слова, дополнив его предпочтительным текстом моего клиента.

/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 ""

К

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

Я также попытался отредактировать файл wp-content/plugins/woocommerce/templates/single-product/related.php в строке 12.

С

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

К

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

Я также добавил этот код в файл function.php:

    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 );

Но, похоже, он не работает

    <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 );

Предполагается, что связанный текст продуктаизменить на

Клиенты, которые арендовали этот предмет, также арендовали:

1 Ответ

0 голосов
/ 23 декабря 2018

Это работает для меня на разные темы и изменит подзаголовок «Сопутствующие товары»:

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;
}

Код помещается в файл function.php вашей активной дочерней темы (или активной темы).Протестировано и работает.

enter image description here

Если это все еще не работает, вы можете переопределить woocommerce файл шаблона через вашу тему, как объяснено в этом ответе: Переименовать название продукта в Woocommerce 3

...