Skip to content

Instantly share code, notes, and snippets.

@terwey
Created June 9, 2019 12:19
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 terwey/bf92e8ac0945904fc529b7642fcf44c3 to your computer and use it in GitHub Desktop.
Save terwey/bf92e8ac0945904fc529b7642fcf44c3 to your computer and use it in GitHub Desktop.
Squarespace hack for adding taxes in Javascript.

Squarespace hack for adding taxes in Javascript.

This allows for showing your local taxrate (as is mandatory in most EU countries) on the store without needing to set the entire site to include taxes (which would also calculate taxes for outside-EU).

Trick is to take your price including VAT (e.g. €50): 50 / 1.19 = 42.01 and use this amount in the Inventory. Configure the tax-rules to set 19% where applicable (shipping from Germany to e.g. Netherlands requires 19% VAT anyway to a private person) and set to 0% to countries non-EU.

The cart will then reflect the correct pricing, and with this snippet (Settings -> Advanced -> Code Injection) inside the Footer will fix the storefront too.

NB: Be sure to disable AJAX Loading, this can be found in Design -> Site Styles because else it'll only work on Refresh and not initial load. This is a known bug in Squarespace.

<script>
  document.addEventListener('DOMContentLoaded', window.addEventListener('mercury:load', addTaxes(19)));
  
// add taxes, pass integer as percentage
function addTaxes(taxes) {
    var taxrate = "1." + taxes;
	document.querySelectorAll('.product-price .sqs-money-native').forEach(function(e) {
      if (!e.getAttribute('tax-added')) {
      	e.innerText = Math.ceil(e.innerText * taxrate); 
	    e.setAttribute('tax-added', 'true');
      }
	});
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment