Creating Tax Exempt Products with Drupal Commerce

The taxation rules that come with Drupal Commerce out of the box calculate VAT or sales tax for each line item without any conditions, so every item in the order is taxed. This works for many situations but if you have items which need to be tax exempt you're in trouble. But there is a relatively painless way around it using some rules and fields.

To start with create a new field on your product entity called Tax Exempt. Set it to be a Boolean, single on/off checkbox.

Create a field called Tax Exempt

Make sure the default value is not checked, we don't want things to be tax exempt by default. Also remember to hide this field in the Manage Display settings.

Now we have to set up the taxation rules to handle this. Make sure the Tax and Tax UI modules are turned on. Two tax types will be enabled by default: VAT and Sales tax. We're going to start by setting up a generic sales tax. Right now we're going to charge this sales tax for everything. Realistically in the United States, you need to only collect sales tax in the state you're doing business in. For more on this topic check out another post in our Drupal Commerce Tax Series, Conditional State Sales Tax.

Create a new tax, we'll call it Generic Sales Tax. Give it a rate of .07, this translates to 7%.

Create a new generic tax rate

We can click configure component and add our conditions. First we need to bring the Tax Exempt field into scope. In Rules you have to check for a field before you can query it. Our first rule will be to get to the Product entity.

Condition: Entity has field.

Data selector: commerce-line-item
Field: commerce_product

Rule condition: entity has field commerce-product

This gives us access to the product through rules. Our next rule will give us access to the Tax Exempt field.

Condition: Entity has field

Data selector: commerce-line-item:commerce-product
Field: field_tax_exempt (or whatever you called your field)

Rule condition: entity has field Tax Exempt

Now that we have access to our Tax Exempt field we can make sure tax exempt items are not taxed.

Condition: Data to compare

Data selector: commerce-line-item:commerce-product:field-tax-exempt
Operator: Equals
Data value: (checked)
Negate
What this does is create a NOT Data comparison. So as long as the product does not have the Tax Exempt field checked tax will be calculated.

Rule condition: field Tax Exempt is not checked

With these conditions taken into account when calculating sales tax from a line item creating tax exempt products is as easy as checking a box. Here are all of the tax exempt conditions together.

All conditions for exempting products from taxation

For information on how to handle sales tax by state see our article Handling Sales Tax Based on Order Address with Drupal Commerce.