默认情况下,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 );
相关的产品文字应更改为
租用此商品的客户也租了:
答案 0 :(得分: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