Is there a way to retrieve and loop through all the available tax rates that have been set up in Commerce 1?

I had thought I could loop through the adjusters like so;

{% for adjustment in cart.adjustments %}
    {{ adjustment.name }}
{% endfor %}

In fact, I'm doing this on one site with no problems but having just tried the same thing on another project I am running into errors. I'm guessing because no adjustments exist unless there is actually a cart object.

I am trying to retrieve its value in order to display the price including tax on my product page template. For this particular case I only have 1 tax rate, so there is no problem with regionality. I figured that I could loop through the adjuster, check the name and retrieve the value.

If there's another way to do this I'm all ears!

up vote 2 down vote accepted

Commerce 2

{% set allTaxRates = craft.commerce.taxRates.allTaxRates() %}

{% for taxRate in allTaxRates %}
    {{ taxRate.name }}<br>
{% endfor %}

taxRate will be an instance of craft\commerce\models\TaxRate


Commerce 1

If you're looking to get all of the tax rates setup in Commerce from a template, something like this should work:

{% set allTaxRates = craft.commerce.getTaxRates() %}

{% for taxRate in allTaxRates %}
    {{ taxRate.name }}<br>
{% endfor %}

taxRate will be an instance of Commerce_TaxRateModel.

  • Thanks Brad. Is there a link to the docs for this? I knew there must be a way to do it but couldn't find anything. – foamcow Jun 15 at 15:10
  • 1
    Nope... just looked at the code. We've got a big push to improve the Commerce 2 docs we're working on, though. – Brad Bell Jun 15 at 22:21

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.