7

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.

SnareChops
  • 13,175
  • 9
  • 69
  • 91
Rishi
  • 73
  • 1
  • 4
  • Welcome to Stack Overflow! So how are they not working? What is the result? Are there errors? It is easier to help when given more information about how it is failing. – scottysmalls Jan 26 '16 at 01:36
  • Removing excess tags – SnareChops Jan 26 '16 at 03:51
  • Possible duplicate of [How do I change the price string in woocommerce subscriptions](https://stackoverflow.com/questions/21118763/how-do-i-change-the-price-string-in-woocommerce-subscriptions) – Ian Feb 07 '19 at 14:45

1 Answers1

8

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().

James Jones
  • 3,850
  • 5
  • 25
  • 44
  • 1
    This is correct, however I would like to suggest to include a conditional statement `if ( $include['sign_up_fee'])`. So that it would not try to replace what is not there ;) – Reigel Gallarde Jan 26 '16 at 04:28
  • Is this usable for changing the string text "month" (the period of the subscriptions? @Reigel – M3o Jan 31 '20 at 14:21