Skip to content

Instantly share code, notes, and snippets.

@nord
Last active January 3, 2017 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nord/fe461e38bea86510211dea89bd1cd530 to your computer and use it in GitHub Desktop.
Save nord/fe461e38bea86510211dea89bd1cd530 to your computer and use it in GitHub Desktop.
Code snippet for customers/account.liquid theme file to capture and validate VAT numbers on the customer account page 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 customer account -- 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="vat-number-display">
{% if customer.metafields.sufio.vat_number %}
VAT Number: {{ customer.metafields.sufio.vat_number }}
<br />
<a href="#" class="vat-edit-link">Edit</a>
{% else %}
<a href="#" class="vat-edit-link">Add VAT number</a>
{% endif %}
</div>
<div class="vat-number-form" style="display:none">
<form>
<label for="vat_reg_no">VAT Registration Number</label>
<input class="vat_reg_no" type="text" name="customer[note][VAT Registration Number]" placeholder="VAT Registration Number" value="{{ customer.metafields.sufio.vat_number }}" />
<input type="submit" value="Save" class="btn">
</form>
</div>
<script type="text/javascript">
$('a.vat-edit-link').click( function() {
$('.vat-number-display').hide();
$('.vat-number-form').show();
return false;
});
$('.vat-number-form form').submit( function() {
var vat_reg_no = $('input.vat_reg_no').val();
$.ajax({
type : "GET",
dataType: "jsonp",
url: "/apps/sufio/customer-vat/",
data: { email: "{{ customer.email }}", vat_no: vat_reg_no, update: true },
success: function(data) {
location.reload();
}
});
return false;
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment