Solved

What can I do if my Shopify invoice table distorts without a discount?

AmyEmms
Visitor
3 0 4

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.

Screen Shot 2021-02-24 at 12.20.18.png

 

When there isn't a discount, the table goes all out of whack! What do I do to the code?

Screen Shot 2021-02-24 at 12.23.51.png

 

<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>

Accepted Solution (1)

peterloane
Shopify Partner
44 5 14

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 

View solution in original post

Replies 3 (3)

peterloane
Shopify Partner
44 5 14

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 

AmyEmms
Visitor
3 0 4

Sorted now. Thanks Peter. 

peterloane
Shopify Partner
44 5 14

Your welcome. Glad it sorted the issue.