less than a minute read • Updated 44 minutes ago
Add a Tax Exemption Checkbox to Checkout
How to add a tax-exempt checkbox to checkout that sets a tax ID automatically, for stores that don't need customers to enter their own tax ID.
Overview
If you want customers to be able to mark themselves tax-exempt without entering a specific tax ID, you can add a checkbox that sets a static tax ID value when checked and refreshes the taxes. First enable the exemption on your taxes (see Exempt customers with a tax ID).
Steps
$("body").on("click", "[name='x:tax_exempt']", function () {
const taxId = this.checked ? "123456789" : "";
$('[name$="tax_id"]').val(taxId).trigger("change.fc");
const taxAddress = FC.json.shipping_address.has_shippable_products
? FC.json.shipping_address
: FC.json.billing_address;
FC.cart.getTaxes({ address: taxAddress });
});When the customer checks the box, Foxy sets the hidden tax ID fields to the static value and recalculates taxes, removing the exempted taxes.
Notes
This snippet does not support multiship-enabled stores.
Adjust the static tax ID value as needed for your store.