【问题标题】:Change subtitle “Related Products” in WooCommerce single product pages在 WooCommerce 单品页面中更改副标题“相关产品”
【发布时间】:2018-12-23 16:42:50
【问题描述】:

默认情况下,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:"

我也尝试在第 12 行附近编辑 wp-content/plugins/woocommerce/templates/single-product/related.php 文件。

来自

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

相关产品文字应该改为

租用此项目的客户也租用了:

【问题讨论】:

    标签: php wordpress woocommerce product gettext


    【解决方案1】:

    这对我来说适用于不同的主题,并将更改“相关产品”副标题:

    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 文件中。经过测试并且可以工作。

    如果它仍然不起作用,您可以通过您的主题覆盖 woocommerce 模板文件,如此答案中所述:Rename Related Products title in Woocommerce 3

    【讨论】:

    • 工作。您知道我们如何将“结帐”更改为“完成预订”
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多