Liquid, JavaScript, themes, sales channels
Hi
I'm trying to tidy up my invoice, but I've got a little stuck. The code below gives me a table with a subtotal, discount and total.
When there isn't a discount, the table goes all out of whack! What do I do to the code?
<table class="table-tabular" style="margin: 0 0 1.5em 0;">
<tr> {% if discounts_savings != 0 %}
<td>Sub Total</td>
<td>{% for discount in discounts %}{{ discount.savings | times: -1 | plus: subtotal_price | money }}{% endfor %}</td>
{% else %}
<td>{{ subtotal_price | money }}</td>
{% endif %}
{% for discount in discounts %}
<tr>
<td>Includes discount "{{ discount.code }}"</td>
<td>{{ discount.savings | money }}</td>
</tr>
{% endfor %}
<tr>
<td><strong>Total price:</strong></td>
<td><strong>{{ total_price | money }}</strong></td>
</tr>
{% if total_paid != total_price %}
<tr>
<td><strong>Total paid:</strong></td>
<td><strong>{{ total_paid | money }}</strong></td>
</tr>
<tr>
<td><strong>Outstanding Amount:</strong></td>
<td><strong>{{ total_price | minus: total_paid | money }}</strong></td>
</tr>
{% endif %}
</table>
Solved! Go to the solution
This is an accepted solution.
Hi
See if this helps
<table class="table-tabular" style="margin: 0 0 1.5em 0;">
<tr> {% if discounts_savings != 0 %}
<td>Sub Total</td>
<td>{% for discount in discounts %}{{ discount.savings | times: -1 | plus: subtotal_price | money }}{% endfor %}</td>
{% else %}
<td>Sub Total</td>
<td>{{ subtotal_price | money }}</td>
{% endif %}
{% for discount in discounts %}
<tr>
<td>Includes discount "{{ discount.code }}"</td>
<td>{{ discount.savings | money }}</td>
</tr>
{% endfor %}
<tr>
<td><strong>Total price:</strong></td>
<td><strong>{{ total_price | money }}</strong></td>
</tr>
{% if total_paid != total_price %}
<tr>
<td><strong>Total paid:</strong></td>
<td><strong>{{ total_paid | money }}</strong></td>
</tr>
<tr>
<td><strong>Outstanding Amount:</strong></td>
<td><strong>{{ total_price | minus: total_paid | money }}</strong></td>
</tr>
{% endif %}
</table>
Regards
Peter
This is an accepted solution.
Hi
See if this helps
<table class="table-tabular" style="margin: 0 0 1.5em 0;">
<tr> {% if discounts_savings != 0 %}
<td>Sub Total</td>
<td>{% for discount in discounts %}{{ discount.savings | times: -1 | plus: subtotal_price | money }}{% endfor %}</td>
{% else %}
<td>Sub Total</td>
<td>{{ subtotal_price | money }}</td>
{% endif %}
{% for discount in discounts %}
<tr>
<td>Includes discount "{{ discount.code }}"</td>
<td>{{ discount.savings | money }}</td>
</tr>
{% endfor %}
<tr>
<td><strong>Total price:</strong></td>
<td><strong>{{ total_price | money }}</strong></td>
</tr>
{% if total_paid != total_price %}
<tr>
<td><strong>Total paid:</strong></td>
<td><strong>{{ total_paid | money }}</strong></td>
</tr>
<tr>
<td><strong>Outstanding Amount:</strong></td>
<td><strong>{{ total_price | minus: total_paid | money }}</strong></td>
</tr>
{% endif %}
</table>
Regards
Peter
Sorted now. Thanks Peter.
Your welcome. Glad it sorted the issue.
Portrait of Stephen positioned next to an image of planet Earth, with the Stephen's World ...
By JasonH Mar 18, 2024Digital marketers and app developers have tracked activity in apps and websites for yea...
By Ollie Mar 13, 2024February was an exciting month with Shopify Editions, informative webinars, and more! F...
By JasonH Mar 7, 2024