How to change the price string in WooCommerce Subscriptions

, , ,

If you are selling subscriptions with WooCommerce, you are probably using WooCommerce Subscriptions to do so. And if you are using it, you already know the structure of the price string for subscription products.

It’s really hard to create a valid price string when you are selling subscriptions. There are a lot of factors to consider, like free trials, intervals, etc.
The developers handle this properly, but sometimes, it’s not correct for what you sell or your store workflow.

You can change the price string, but it could be more complex than it seems.

In this article we’ll cover three code samples to change the price string in three different cases.

How does it work?

We’ll use the PHP function str_replace to handle the changes. We will use arrays of product IDs when necessary to change the string only on some products.

All the snippets need to be added in the file functions.php located in wp-content/themes/your-theme-name/, at the end of the file.

The example is on a product that is renewed every 3 months, without a free trial or sign-up fee.

Change the string globally

In the first example we’ll change the string for all the subscription products in the store. The code to do so is:

The two filters used will change the price string everywhere, both in the product single page and the cart page.

Change the string only on some products

This example will change the price string only on the product single page and only on some products:

Handle complex strings

In some cases, in example if you have a free trial or/and a sign-up fee, the price string will be more complex.
If this is your case, you can copy/paste the line where we use str_replace and change the words to change the other parts of the string, like in this example:

40 replies
  1. Donald Overlander
    Donald Overlander says:

    The above website will go in and out of availability (shopping cart wise) at different points in the year.

    The problem I am encountering is with WooCommerce AJAX reloads on the check out page.

    Everywhere else in the site my overload for woocommerce_subscription_price_string works beautifully, however on the check out page it works(yay!) but is then overridden when the checkout page ajax fires and I end up with the “normal” woocommerce_subscription_price_string result.

    Any thoughts on how to overcome this? (I have currently disabled the ajax on checkout and things are ‘working’ but not happy)


    • Nicola Mustone
      Nicola Mustone says:

      Hi Donald,
      it looks like a cache issue. The cart is saved in transients to speed up the thing.

      The error could be from your theme or simply from the old cache. Try to delete the transients in WooCommerce > System Status > Tools and/or try to switch your theme to something else.

      Have a great week!

  2. Beth
    Beth says:

    Thank you Nicola, this is exactly what I’ve been looking for! I agree with Donald that it works beautifully, but does not seem to be working in my cart either. I’ve cleared my cache and transients, even switched themes to no avail. Any other thoughts?

    Thanks again, great snippet!

  3. Andrew Curtin
    Andrew Curtin says:

    Whats the best way to change the order of the price string. For example I want to put the Sign-up fee before the monthly rate.


  4. JM Darter
    JM Darter says:

    We have annual subscriptions and are planning on increasing our rate for 2016. By increasing the product, new subscriptions will be increased but not old ones correct? We need to hire someone to assist us if there are any solutions, can you advise on developers?

  5. Courtney Hobbs
    Courtney Hobbs says:

    I would be interested to know if this code still works / apply’s to current versions of WooCommerce? It’s exactly what I have needed and I have scoured the internet for a similar thing and came up empty.

    I have implemented it as stated above however it doesn’t seem to take any effect.

    Any help anyone can offer would be much appreciated! Been pulling my hair out over this for months!

    Thanks so much!

    • Nicola Mustone
      Nicola Mustone says:

      Hi Courtney,
      Yes, it’s still up to date and should work.

      Please check your code and make sure that it is correct. I’d also try with a different theme to make sure that nothing is conflicting with it.

      • Courtney
        Courtney says:

        Hey Nicola!

        Thanks so much for getting back to me 🙂

        I have checked the theme however it still doesn’t seem to be working. Is there anything else obvious that I might be missing?

        Thanks so much for all your help – much appreciated!

  6. Courtney Hobbs
    Courtney Hobbs says:

    Hey Nicola

    I finally got it to work. I didn’t realise it was for payments on every 3rd month. How do I set it for payments that are every month?

    Also is there a way to change the “free trial” text?


    • Nicola Mustone
      Nicola Mustone says:

      Hi Courtney,
      On line 3 I use the every 3 months string as first argument for str_replace. You simply need to change that with what you want to change.

      Same for the free trial text.

  7. J. Gunderson
    J. Gunderson says:

    How about targeting the subscription price string, but not the total subscription price string? My customers are able to order multiples of a product in 2,3, and 6 month intervals so it’s confusing for them to see the following in the cart:

    Price: $52.80 every 2 months

    Total: $211.40 every 2 months

  8. Simon Roskrow
    Simon Roskrow says:

    Hi Nicola

    Finally got round to trying it (you shared the link to here from my WooCommerce ticket), and I’ve managed to make it work pretty much first time – thanks!

    I can now change (some of) the string text, and it now reads:

    “From: $300.00 per month for 2 months with a $395.00 initial payment.”

    I would ideally like it to read “Initial payment of $395, followed by two monthly payments of $300.”

    Is this possible?

    Many thanks, Simon.

  9. John
    John says:


    What if i just want to change to just the price itself?

    $0.00 for 12 months and a $120.00 sign-up fee


    How can i change that? Thanks!

  10. Melvin Reynolds
    Melvin Reynolds says:

    What if you have two different types of subscriptions? One where it is just the subscription itself, and one where there are a console cost and a 1-month free trial along with the subscription. Originally I used a filter which I am attaching but it changes the format of all the subscriptions strings on the site and it doesn’t make sense if I have a subscription option that’s only the subscription itself. All of the other subscriptions can use that filter but the only thing that should show for that one is “$19.99/month.”

    • Nicola Mustone
      Nicola Mustone says:

      Hi Melvin,
      There’s not a specific hook for single products, so you need to check by yourself what product you’re working on.

      You can try to add global $product; at the beginning of the snippet and that should give you access to the current product so you can check what its ID is and eventually change the string.

      • Melvin Reynolds
        Melvin Reynolds says:

        Maybe this is something obvious and I’m drawing a blank but when you are creating an array to only access specific products, how do you find the product id to use in the array parameters. I see in the above example that they use (45, 90, 238). How would you find those product numbers to use in your own coding?

  11. Edwin Hansen
    Edwin Hansen says:

    Is it possible to only show the max price, we are using the subscriptions to sell jewelery. Customers can choose to buy it in 3 times or in 1 time. The 1 time is the max price as an variable set for 1 month subsription, the 2 times is set for 2 month, the allready pay the first month with an ideal payment, the next to months go by subscription. We like to see the max price, because on our facebook we use an advertisement program but is only displays the min variable price.

    • Nicola Mustone
      Nicola Mustone says:

      Hi Edwin,
      The price string is very customizable, so you can choose any format you want.

      Within the product object you can find the max price, so you can use global $product to get access to that and then show the max price only in the string.

  12. Mark
    Mark says:

    Hi Nicola, Is it possible for this code to only be applicable to the collection/product pages and not the cart page?


Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply