1

I need to be able to output the price of a subscription after the user has subscribed. I'm using the Stripe Gateway. This post indicates to use {{ subscriptionPlanData.plan.amount }} but that doesn't seem to work for Commerce 3.

Commerce 2 Subscription Prices

The code below works but only after you refresh the payment history for the subscription in the admin, which seems to be a manual task.

{% set payments = subscription.getAllPayments() %}
      {% if payments %}
           {% for payment in payments %}
                ${{ payment.paymentAmount|number_format(2, '.', ',') }}
           {% endfor %}
      {% endif %}

Any idea how to get that payment history to automatically refresh after a subscription? Since that includes taxes, etc. that might be the best solution?

2

You can use

{{ subscription.subscriptionData.plan.amount }}

to get the price of the plan the customer subscribed to.

That returns in cents so you'll need to convert and format it.

{{ (subscription.subscriptionData.plan.amount / 100) | currency('USD', stripZeros=true) }}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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