Accessing the Returns for an Order in Liquid

steveler
Visitor
2 0 0

When displaying a customer's order (via the customer's account page, i.e. in customers/order.liquid) I need to also display which items in the order have been returned.

 

I'm able to get to access an order.refunds object which has some brief info about the refunds on the order. This gives me "Internal error" the first time I access its subcomponents (but then I can access them).

 

When I look at the info that is provided for each refund, I can see an id and a quantity, but the id doesn't correspond with a line item. So, there's no way for me to match the refunded items back again.

 

How can I access and display refunds for each order?

 

Steve

Reply 1 (1)

Modi_Mayur
Shopify Partner
4 0 0

You can try this one:

 

 {%- for line_item in order.line_items -%}
   {%- if line_item.fulfillment -%}
    <div class="fulfillment">
      {%- assign created_at = line_item.fulfillment.created_at | time_tag: format: 'date' -%}
      <span>{{ 'customer.order.fulfilled_at_html' | t: date: created_at }}</span>

        {%- if line_item.fulfillment.tracking_url -%}
          <a href="{{ line_item.fulfillment.tracking_url }}">
            {{ 'customer.order.track_shipment' | t }}
          </a>
        {%- endif -%}
        <span>
          {{ line_item.fulfillment.tracking_company }}
          {%- if line_item.fulfillment.tracking_number -%} #{{ line_item.fulfillment.tracking_number }} {%- endif -%}
        </span>
    </div>
  {%- endif -%}
  {% for line in order.subtotal_line_items %}      
    {% if line_item.id == line.id %}
      {% if line.refunded_quantity > 0 %}<div class="fulfillment"><span class="order-list__item-refunded">Refunded {{ line.refunded_quantity | default:0 }}</span></div>{% endif %}
    {% endif %}
  {% endfor %}
{% endfor %}

 

 

It's working in Dawn theme after add above code:

 

Order-1016-–-modishop-1.png