gpt4 book ai didi

php - 如何更改 Woocommerce 结帐页面中的 "Have a coupon?"文本

转载 作者:可可西里 更新时间:2023-10-31 23:44:47 25 4
gpt4 key购买 nike

我正在尝试翻译“Have a coupon?”使用此代码在 Woocommerce 结帐页面中输入文本:

function custom_strings_translation( $translated_text, $text, $domain ) {
switch ( $translated_text ) {
case 'HAVE A COUPON?' :
$translated_text = __( 'TIENES UN CUPÓN?', '__x__' );
break;
}

return $translated_text;
}
add_filter('gettext', 'custom_strings_translation', 20, 3);

但它不起作用。

谁能告诉我为什么?

最佳答案

It doesn't work because the text is not in capitals and you are not using the right variable.

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

1) 以这种方式使用 gettext 过滤器钩子(Hook):

add_filter('gettext', 'custom_strings_translation', 20, 3);
function custom_strings_translation( $translated_text, $text, $domain ) {
if( $text == 'Have a coupon?' ){
$translated_text = __( 'Tienes un cupón?', $domain );
}
return $translated_text;
}

代码进入事件子主题(或事件主题)的 function.php 文件。经过测试并有效。


2) 使用 woocommerce_checkout_coupon_message 过滤器钩子(Hook)可以让您进行更多更改:

add_filter( 'woocommerce_checkout_coupon_message', 'custom_checkout_coupon_message', 20, 1 );
function custom_checkout_coupon_message( $notice ) {
return __( 'Tienes un cupón?', 'woocommerce' ) . ' <a href="#" class="showcoupon">' . __( 'Haga clic aquí para ingresar su código', 'woocommerce' ) . '</a>'
}

代码进入事件子主题(或事件主题)的 function.php 文件。经过测试并有效。


相关:

关于php - 如何更改 Woocommerce 结帐页面中的 "Have a coupon?"文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52508477/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com