如何改变WooCommerce订阅签约费的文本?

问题描述 投票:4回答:1

到目前为止,我已经尝试添加以下代码到我的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' );
?>

无论这些功能都工作,我是新来的改变,比如订阅插件的内部。

php woocommerce subscriptions
1个回答
5
投票

您正在使用错误的过滤器。该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()

© www.soinside.com 2019 - 2024. All rights reserved.