到目前为止,我已经尝试添加以下代码到我的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 );
在我的例子这改变了字符串:
“$ 111.10 /月5个月,3个月的免费试用和$ 22.00的注册费”
成
“$ 111.10 /月5个月,3个月的免费试用和$ 22.00别的东西”
该woocommerce_subscriptions_product_price_string
过滤器位于在功能class-wc-subscriptions-product.php
get_price_string()
。