Dynamically Require Tax ID

The following functionality allows you to dynamically require the tax ID depending on the country of the customer.

Add Javascript

From the configuration section of your store's FoxyCart administration, under “checkout” enable the “Add custom header and footer code” and within the footer textarea, paste the following:

<script type="text/javascript">
function requireTaxID() {
 	var country = (FC.json.shipping_address.has_shippable_products) ? FC.json.shipping_address.country : FC.json.billing_address.country;
 	var tax_required = FC.json.required_fields.indexOf("billing_tax_id");
	if (country != "US" && tax_required == -1) {
		FC.json.required_fields.push('billing_tax_id');
		FC.json.config.template_config.custom_checkout_field_requirements['billing_tax_id'] = "required";
		FC.checkout.renderCustomerShipping();
		FC.checkout.renderCustomerBilling();
	} else if (country == "US" && tax_required > -1) {
		FC.json.required_fields.splice(tax_required, 1);
		FC.json.config.template_config.custom_checkout_field_requirements['billing_tax_id'] = "optional";
		FC.checkout.renderCustomerShipping();
		FC.checkout.renderCustomerBilling();
	}
}
if (FC.json.context == "checkout") {
	FC.client.on("customer-address-change", requireTaxID);
	FC.client.on("ready", requireTaxID);
}
</script>

Site Tools