Order Printer (Legacy) App - Quantity Displayed Wrongly

Order Printer (Legacy) App - Quantity Displayed Wrongly

metaterra
Shopify Partner
5 0 2

If customer orders 4 qty of the same product and request to refund 1 qty, nett qty should be 3 but our template would still display as 4.

Our script is as below. Can anyone help please? Thank you!

<tbody>
{% for line_item in fulfilled_line_items %}
{% unless line_item.quantity == 0 %}
<tr>
<td>{{ line_item.quantity }} x</td>
<td><b>{{ line_item.title }}</b>
{% for property in line_item.properties %}
{% if property.first contains '_io_' %}{% continue %}{% endif %}
{% if property.last == blank  %}{% continue %}{% endif %}
<br>{{ property.first }}: {{ property.last }} {% endfor %}
</td>
{% if line_item.tax_lines %}
<td>
{% for tax_line in line_item.tax_lines %}
{{ tax_line.price | money }} {{ tax_line.title }}<br/>
{% endfor %}
</td>
{% endif %}
<td>{{ line_item.sku }}</td>
<td>{{ line_item.price | money }}</td>
</tr>
{% endunless %}
{% endfor %}
</tbody>

Replies 3 (3)

Finer
Shopify Partner
2669 559 931

@metaterra is this the code from the order confirmation or from the order refund?
The code you are showing, checks for all fulfilled items.

So even if the customers requests a refund, the number of the prior fulfilled items would still be the same.

- Did my answer help? Mark my post with a like
- Did I solve your problem? Mark my post as an accepted solution.
- You need professional help? Contact our Shopify Partner Agency
VipulBudhiraja
Explorer
61 5 7

To update the template so it reflects the net quantity after partial refunds, follow these steps:

Solution

  1. Adjust the Template to Display Net Quantity:
    • Use a custom variable to calculate the net quantity based on refunded items.
    • Modify quantity in the loop to account for any refunds.

Here’s the modified code:

liquid
Copy code
<tbody> {% for line_item in fulfilled_line_items %} {% unless line_item.quantity == 0 %} {%- assign net_quantity = line_item.quantity - line_item.refunded_quantity -%} <tr> <td>{{ net_quantity }} x</td> <td><b>{{ line_item.title }}</b> {% for property in line_item.properties %} {% if property.first contains '_io_' %}{% continue %}{% endif %} {% if property.last == blank %}{% continue %}{% endif %} <br>{{ property.first }}: {{ property.last }} {% endfor %} </td> {% if line_item.tax_lines %} <td> {% for tax_line in line_item.tax_lines %} {{ tax_line.price | money }} {{ tax_line.title }}<br/> {% endfor %} </td> {% endif %} <td>{{ line_item.sku }}</td> <td>{{ line_item.price | money }}</td> </tr> {% endunless %} {% endfor %} </tbody>

Explanation:

  • {% assign net_quantity = line_item.quantity - line_item.refunded_quantity %} calculates the adjusted quantity by subtracting refunded items.
  • Display net_quantity instead of line_item.quantity in the template, showing the correct number after partial refunds.

Note:

Ensure that refunded_quantity is available in line_item data, or set up a back-end process to track and update this field.


Experience personalized shopping and real-time support with the Debales AI Chatbot on Shopify! Engage customers effortlessly and help them find the right products—let’s chat!

Please let us know if our reply is helpful by giving it a Like or marking it as a Solution!

 
metaterra
Shopify Partner
5 0 2

@VipulBudhiraja Thank you for the suggestion.

 

How do we ensure that refunded_quantity is available in line_item data, or set up a back-end process to track and update this field?

I've tried replacing the existing code with yours and it doesn't seem to work as yet.