Discount script example
This page was printed on Aug 26, 2019. For the current version, visit https://help.shopify.com/en/manual/apps/apps-by-shopify/script-editor/examples/vat-script.
This example uses a line item script to offer a discount based on the country of the customer. It also includes example Liquid code to provide information to the customer about the discount.
This example uses a fictional VAT tax that has the following rules:
- Customers who reside in a union of countries are charged VAT taxes on all products sold.
- Customers who purchase products and have them exported to non-union country do not have to pay the VAT tax (in other words, sales to these customers are zero-rated).
- Prices of products in the store include the VAT tax (that is All taxes are included in my prices setting is enabled for the store's tax settings.
In the storefront, all customers see the VAT included in the prices of products. When items are added to the cart, the VAT included price is shown:
At checkout, the shipping country is checked by the script. If the country is a non-union country, then the total price is reduced by the amount of the VAT:
In the following example, the country of the customer is checked. If the customer lives in a country where the VAT does not apply, then the total price of the order is reduced by the VAT amount.
The following Liquid code works with the above script to explain the changes in the cart.
Add this code to checkout.liquid:
Add the following code to your English locale file:
Learn more about: