更改相关产品标题,在WooCommerce中添加产品名称 [英] Change Related Products Heading adding the product name in WooCommerce
本文介绍了更改相关产品标题,在WooCommerce中添加产品名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这段代码,试图将相关产品"翻译成这些将与PRODUCT NAME一起使用".
I have this code which is an attempt in translating "Related products" into "These will go well with PRODUCT NAME".
这是我的代码:
add_filter( 'gettext', 'change_related_products_title', 10, 3 );
function change_related_products_title( $translated, $text, $domain ) {
$ptitle = get_page_by_title( 'Product Title', OBJECT, 'product' );
if( $text === 'Related products' && $domain === 'woocommerce' ){
$translated = esc_html__( 'These go well with '.$ptitle.' ', $domain);
}
return $translated;
}
它所显示的全部是这些都可以配合使用",仅此而已.请帮助.
All it shows is "These go well with" and nothing more. Help please.
推荐答案
使用 get_the_title()
代替:
get_page_by_title(),例如:
add_filter( 'gettext', 'change_related_products_title', 10, 3 );
function change_related_products_title( $translated, $text, $domain ) {
if( $text === 'Related products' && $domain === 'woocommerce' ){
$translated = esc_html__( 'These go well with', $domain ) . ' ' . esc_html( get_the_title() );
}
return $translated;
}
代码进入您的活动子主题(或活动主题)的functions.php文件中.经过测试,可以正常工作.
Code goes in functions.php file of your active child theme (or active theme). Tested and works.
这篇关于更改相关产品标题,在WooCommerce中添加产品名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文