TransWikia.com

Commerce Subscription Prices

Craft CMS Asked on April 15, 2021

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?

One Answer

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) }}

Answered by CraftQuest on April 15, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP