Gre*_*aya 5 php wordpress checkout gettext woocommerce
我正在尝试翻译“有优惠券吗?” 使用以下代码在 Woocommerce 结账页面中显示文本:
\n\nfunction 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);\nRun Code Online (Sandbox Code Playgroud)\n\n但它不起作用。
\n\n请有人告诉我为什么?
\n\n\n\n它不起作用,因为文本不是大写并且您没有使用正确的变量。
\n
有两种方法可以更改此文本(第二种方法似乎是最好的):
\n\ngettext1)这样使用过滤器钩子:
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}\nRun Code Online (Sandbox Code Playgroud)\n\n代码位于活动子主题(或活动主题)的 function.php 文件中。经过测试并有效。
\n\n2)使用woocommerce_checkout_coupon_message过滤器钩子可以让你进行更多的改变:
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}\nRun Code Online (Sandbox Code Playgroud)\n\n代码位于活动子主题(或活动主题)的 function.php 文件中。经过测试并有效。
\n\n有关的:
\n\n\n