如何更改“有优惠券?” Woocommerce 结账页面中的文本

Gre*_*aya 5 php wordpress checkout gettext woocommerce

我正在尝试翻译“有优惠券吗?” 使用以下代码在 Woocommerce 结账页面中显示文本:

\n\n
function custom_strings_translation( $translated_text, $text, $domain ) {\n  switch ( $translated_text ) {\n    case \'HAVE A COUPON?\' : \n        $translated_text =  __( \'TIENES UN CUP\xc3\x93N?\', \'__x__\' );\n        break;\n}\n\n  return $translated_text;\n}\nadd_filter(\'gettext\', \'custom_strings_translation\', 20, 3);\n
Run Code Online (Sandbox Code Playgroud)\n\n

但它不起作用。

\n\n

请有人告诉我为什么?

\n

Loi*_*tec 2

\n

它不起作用,因为文本不是大写并且您没有使用正确的变量。

\n
\n\n

有两种方法可以更改此文本(第二种方法似乎是最好的)

\n\n

gettext1)这样使用过滤器钩子:

\n\n
add_filter(\'gettext\', \'custom_strings_translation\', 20, 3);\nfunction custom_strings_translation( $translated_text, $text, $domain ) {\n    if( $text == \'Have a coupon?\' ){\n        $translated_text =  __( \'Tienes un cup\xc3\xb3n?\', $domain );\n    }\n    return $translated_text;\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

代码位于活动子主题(或活动主题)的 function.php 文件中。经过测试并有效。

\n\n
\n\n

2)使用woocommerce_checkout_coupon_message过滤器钩子可以让你进行更多的改变:

\n\n
add_filter( \'woocommerce_checkout_coupon_message\', \'custom_checkout_coupon_message\', 20, 1 );\nfunction custom_checkout_coupon_message( $notice ) {\n    return __( \'Tienes un cup\xc3\xb3n?\', \'woocommerce\' ) . \' <a href="#" class="showcoupon">\' . __( \'Haga clic aqu\xc3\xad para ingresar su c\xc3\xb3digo\', \'woocommerce\' ) . \'</a>\'\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

代码位于活动子主题(或活动主题)的 function.php 文件中。经过测试并有效。

\n\n
\n\n

有关的:

\n\n\n