如何更改 WooCommerce 订阅中的注册费文本? [英] How do I change sign-up fee text in WooCommerce Subscriptions?
问题描述
到目前为止,我已经尝试将以下代码添加到我的 functions.php 中,但没有成功:
So far i've tried adding the following code to my functions.php with no luck:
<?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' );
?>
这些功能都不起作用,而且我是更改订阅等插件内部结构的新手.
Neither of these functions are working and I am new to changing the internals of a plugin like Subscriptions.
推荐答案
您使用了错误的过滤器.woocommerce_subscriptions_sign_up_fee
过滤器仅用于更改实际数字.gettext
过滤器用于翻译字符串.
You are using the wrong filter. The woocommerce_subscriptions_sign_up_fee
filter is for changing the actual number only. The gettext
filter is about translating strings.
试试这个:
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 );
在我的例子中,这改变了字符串:
In my example this changed the string:
'$111.10/月 5 个月,免费试用 3 个月,注册费 $22.00'
进入
5 个月 111.10 美元/月,3 个月免费试用和其他 22.00 美元"
woocommerce_subscriptions_product_price_string
过滤器位于 class-wc-subscriptions-product.php
中的 get_price_string()
函数中.
The woocommerce_subscriptions_product_price_string
filter is located in class-wc-subscriptions-product.php
in the function get_price_string()
.
这篇关于如何更改 WooCommerce 订阅中的注册费文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!