Skip to content

Instantly share code, notes, and snippets.

@nord
Last active November 3, 2020 07:44
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nord/1db3499fdad6fce76627c307e98f3e1e to your computer and use it in GitHub Desktop.
Save nord/1db3499fdad6fce76627c307e98f3e1e to your computer and use it in GitHub Desktop.
Code snippet for Shopify Plus checkout.liquid theme file to capture and validate VAT numbers and set business customers as tax exempt when applicable. Used by Sufio for Shopify app (www.sufio.com/shopify). Read more at http://sufio.com/articles/shopify/selling/vat-eu-customers-shopify/vat-exempt-eu/
<!-- Shopify checkout -- capture and validate VAT numbers and set business customers as tax exempt when applicable. Used by Sufio for Shopify (www.sufio.com/shopify). -->
<div class="additional-checkout-fields" style="display:none">
<div class="field field--optional field--vat-number">
<div class="field__input-wrapper">
<label class="field__label" for="checkout_vat_number">VAT number</label>
<input placeholder="VAT number" autocomplete="vat number" data-backup="checkout_vat_number" class="field__input" aria-labelledby="error-for-vat_number" size="30" type="text" name="checkout[vat_number]" id="checkout_vat_number">
</div>
</div>
</div>
<script type="text/javascript">
if (window.jQuery) {
jquery = window.jQuery;
} else if (window.Checkout && window.Checkout.$) {
jquery = window.Checkout.$;
}
jquery(function() {
if (jquery('.section--shipping-address .section__content .fieldset').length) {
var vat_number_field = jquery('.field--vat-number');
jquery('.section--shipping-address .section__content .fieldset').append(vat_number_field);
var form = jquery('.section--shipping-address .section__content .fieldset').parents('form');
jquery('button[type=submit]', form).one("click", function() {
var email = jquery('input[name="checkout[email]"]').val();
var vat_no = jquery('input[name="checkout[vat_number]"]').val();
if ((email) && (vat_no)) {
jquery.ajax({
type : "GET",
dataType: "jsonp",
url: "{{ shop.url }}/apps/sufio/customer-vat/",
data: { email: email, vat_no: vat_no },
success: function(data) {
// Proceed to the next step after successfully sending the VAT number
jquery('button[type=submit]', form).click();
}
});
} else {
return true;
}
// Proceed to the next step after one second
setTimeout( function () {
jquery('button[type=submit]', form).click();
}, 1000);
return false;
});
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment