How do I change sign-up fee text in WooCommerce Subscriptions?

二次信任 提交于 2019-12-23 15:10:21

问题


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.


回答1:


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.

Try this:

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 / month for 5 months with a 3-month free trial and a $22.00 sign-up fee'

into

'$111.10 / month for 5 months with a 3-month free trial and a $22.00 something else'

The woocommerce_subscriptions_product_price_string filter is located in class-wc-subscriptions-product.php in the function get_price_string().



来源:https://stackoverflow.com/questions/35005462/how-do-i-change-sign-up-fee-text-in-woocommerce-subscriptions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!