We've currently got Subscriptions setup on a site which works a charm, but my main issue is outputting the price of the subscription, after the user has subscribed.

From the docs/templates I can even see how this is possible?!

You can get it via:

{% set subscriptions = craft.subscriptions.user(currentUser) %}

{% for subscription in subscriptions %}
    {{ subscriptionPlanData.plan.amount }}
{% endfor %}

But if for example, the plan is £300.00 then it outputs as 30000 and when formatted, it comes out like 30,000.00 using {{ subscriptionPlanData.plan.amount|number_format(2, '.', ',') }}

I can't see anyway of showing the user, how much they've paid in a human format without hacking around the number.

up vote 4 down vote accepted

Stripe stores the amount in cents. If you want to format it from the subscriptionPlanData.plan.amount variable in your template you would need to divide by 100 first.

{{ (subscriptionPlanData.plan.amount / 100)|currency }}

I could be wrong here as I've not used subscriptions with Commerce yet, but using the filter |currency worked perfectly for me when outputting the correct format after having tried |replace and |number.

  • I thought that might have worked, but sadly it still just output £30,000.00 :( – Jason Mayo Oct 8 at 14:22

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.