Toggle tax exemption status from the checkout

While FoxyCart does support the ability for a customer to be tax exempt - it relies on them entering a tax ID value on the checkout as part of their address. If you don't need the customer to provide their specific tax ID value, but still want them to be able to set that they're tax exempt, you can use the following snippet. It specifically adds a checkbox as a custom checkout field, which if checked will set the hidden tax ID fields with a static value and trigger the taxes to be refreshed.

Note: The following snippet does not currently support multiship enabled stores

Step 1: Configuring taxes

To allow customers to become tax exempt, you need to enable a setting on the relevant taxes for your store. For each tax that you want to support tax exemption for, edit it within the FoxyCart administration's tax section, and check the “exempt customers with a tax id” option.

Step 2: Applying the snippet

The following steps all happen on the “Configuration” section of your store's FoxyCart administration.

Part 1: Javascript

Look for the “Add custom header and footer code to your templates” option, and if it's not yet enabled, enable it. Within the “footer” textarea of that option, paste the following code:

<script>
$("body").on("click", "[name='x:tax_exempt']", function() {
	var tax_id = (this.checked) ? "123456789": "";
	$('[name$="tax_id"]').val(tax_id).trigger("change.fc");
	var tax_address = (FC.json.shipping_address.has_shippable_products) ? FC.json.shipping_address : FC.json.billing_address;
	FC.cart.getTaxes({address: tax_address});
});
</script>

Part 2: HTML

Look for the “Add custom form fields to your checkout” option, and if not enabled, enable it. Within the “custom checkout fields” textarea, paste the following code:

<div class="fc-form-group">
    <div class="col-md-8 col-md-offset-3">
        <div class="fc-input-group-container fc-input-group-container--checkbox">
            <label class="fc-input-group-container__title fc-form-label">
                <input type="checkbox" name="x:tax_exempt" value="Yes" {% if billing_address.tax_id or shipping_address.tax_id %}checked{% endif %} class="fc-form-control fc-form-control--tax-exempt">
                Yes, I am tax exempt
            </label>
        </div>
    </div>
</div>

Part 3: Tax ID field

As you don't want to capture an actual Tax ID from the customer, you'll want to set it to be a hidden field. That is it's default state though, so you may not need to make any changes here. Look for the “Customize which checkout fields are shown and required” option at the bottom of the configuration section. If it's not enabled - then you don't need to make any changes and can continue on. If it is enabled, make sure that “tax id” is set to “hidden”.

Part 4: Save

With all the changes complete, click the Update button at the bottom of the page to apply the changes.

Step 3: Test

If you now head to your checkout, you'll be able to toggle the tax exemption status of the current cart session using the checkbox. The checkbox should also be pre-checked if the tax ID is prepopulated from the cart session.

Site Tools