system
December 24, 2020, 7:32am
1
Need the subtotal of all rows in a loop. I can’t seem to find a way to complete this expression to add up all the line item amounts into a single subtotal.
{% set amount = ‘{{ item.item_quantity * item.item_price }}’ %}
{% for item in module.line_item %}
<tr style=“height: 48px;”>
<td class=“hidden”>{{ item.stripe_price_api_id }}</td>
<td >{{ item.line_item_description }}</td>
<td style=“text-align: right;”>{{ item.item_quantity }}</td>
<td style=“text-align: right”>${{ item.item_price }}</td>
<td style=“text-align: right”>${{ amount }}</td>
</tr>
{% endfor %}
system
December 24, 2020, 7:20pm
2
Answered:
{% for item in module.line_item %}
{% set amount = item.item_quantity * item.item_price %}
{% set total = total + amount %}
<tr style=“height: 48px;”>
<td class=“hidden”>{{ item.stripe_price_api_id }}</td>
<td >{{ item.line_item_description }}</td>
<td style=“text-align: right;”>{{ item.item_quantity }}</td>
<td style=“text-align: right”>${{ item.item_price }}</td>
<td style=“text-align: right”>${{ item.item_quantity * item.item_price }}</td>
</tr>
{% endfor %}
<!-- Line Item Subtotal -->
<tr style=“height: 24px;”>
<td><strong>{{ module.total_label }}</strong></td>
<td></td>
<td style=“text-align: right;”>Subtotal</td>
<td style=“text-align: right;”><strong>
{% for item in module.line_item %}
{% set amount = item.item_quantity * item.item_price %}
{% set total = total + amount %}
{% if loop.last %}
${{ total }}
{% endif %}
{% endfor %}
</strong></td>
</tr>