I’m trying to update the code below so that my customers see the tax of the orders seperate for the products and shipping. But it isn’t working out. Can someone please help me with this:
To display the tax of orders separately for products and shipping, you will need to make some changes to the code.
First, you will need to calculate the tax for each line item and the shipping separately. You can do this by using the line_item.tax_lines and shipping_line.tax_lines arrays and summing up the price attribute for each tax line.
Then, you will need to update the template to display the tax for each line item and shipping separately. Here’s an updated template that should work:
Thanks Ki2la, when I try this. It is not completely working maybe I still do something wrong? Please see the preview of the overview where we want to show the tax. But it still says 0,-
{% for line_item in line_items %}
{% for tax_line in line_item.tax_lines %}
{% if line_item.line_price == shipping_price %}
{% assign shipping_tax_price = shipping_tax_price | plus: tax_line.price %}
{% else %}
{% assign product_tax_price = product_tax_price | plus: tax_line.price %}
{% endif %}
{% endfor %}
{% endfor %}
…
Totale BTW voor producten:
{{ product_tax_price | money }}
{% if shipping_address %}
Totale BTW voor verzending:
{{ shipping_tax_price | money }}
{% endif %}
…
Totale BTW:
{{ tax_price | money }}
{% if shipping_address %}
Verzending:
{{ shipping_price | money }}
Totale BTW voor verzending:
{{ shipping_tax_price | money }}
{% endif %}
Totaal incl. BTW voor producten:{{ product_price | money }}
{% if shipping_address %}
Totaal incl. BTW voor verzending:{{ shipping_price | money }}
{% endif %}
Totaal incl. BTW:{{ total_price | money }}
Here, we calculate the tax for each line item, and if the line item is a shipping line item, we add the tax to the shipping_tax_price variable; otherwise, we add it to the product_tax_price variable. We then show these values in the table by adding two new rows: one for product tax and one for shipping tax.
Try this, if it is not working, please wait for someone else to reply to it. Pardon me