gpt4 book ai didi

php - 如何更改 WooCommerce 订阅中的注册费文本?

转载 作者:可可西里 更新时间:2023-10-31 22:52:39 28 4
gpt4 key购买 nike

到目前为止,我已经尝试将以下代码添加到我的 functions.php 中,但没有成功:

<?php
function my_text_strings( $translated_text, $text, $domain ) {
switch ( $translated_text ) {
case 'Sign-up Fee' :
$translated_text = __( 'bin deposit', 'woocommerce-subscriptions' );
break;
case 'Apply Coupon':
$translated_text = __( 'Enter Coupon', 'woocommerce' );
break;
}
return $translated_text;
}
add_filter( 'gettext', 'my_text_strings', 20, 3 );
?>
<?php
function my_signupfee_string( $pricestring ) {

$newprice = str_replace( 'sign-up fee', 'bin deposit', $pricestring );
return $newprice;

}

add_filter( 'woocommerce_subscriptions_sign_up_fee', 'my_signupfee_string' );
?>

这些功能都不起作用,而且我不熟悉更改订阅等插件的内部结构。

最佳答案

您使用了错误的过滤器。 woocommerce_subscriptions_sign_up_fee 过滤器仅用于更改实际数量。 gettext 过滤器用于翻译字符串。

试试这个:

function change_subscription_product_string( $subscription_string, $product, $include )
{
if( $include['sign_up_fee'] ){
$subscription_string = str_replace('sign-up fee', 'something else', $subscription_string);
}
return $subscription_string;
}
add_filter( 'woocommerce_subscriptions_product_price_string', 'change_subscription_product_string', 10, 3 );

在我的示例中,这改变了字符串:

“5 个月 111.10 美元/月,3 个月免费试用和 22.00 美元注册费”

进入

“每月 111.10 美元,为期 5 个月,免费试用 3 个月,其他费用为 22.00 美元”

woocommerce_subscriptions_product_price_string 过滤器位于 class-wc-subscriptions-product.php 中的 get_price_string() 函数中。

关于php - 如何更改 WooCommerce 订阅中的注册费文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35005462/

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