Ad

How Can I Iterate Through The Order Array On Shopify?

- 1 answer

Right so... not sure if there's a way to do this but figured I'd give it a shot.

On our Shopify store, customers have an account with which they can see all of their orders (in a link array);

and so on...

Rather than clicking on those links, I'm trying to figure out a way to output the individual order information on the main store.com/account page.

Like:

Order 0001

  • Product one
  • Product two

Order 0002

  • Product one
  • Product two

Order 0003

  • Product one
  • Product two

and so on..

Possible?

Ad

Answer

Yes, you can.

Here is the code:

{% for order in customer.orders %}
  <tr>
    <td>{{ order.name | link_to: order.customer_url }}</td>
    <td>{{ order.created_at | date: format: 'short' }}</td>
    <td>{{ order.financial_status_label }}</td>
    <td>{{ order.fulfillment_status_label }}</td>
    <td>{{ order.total_price | money }}</td>
  </tr>

  {% for line_item in order.line_items %}
    <tr>
      <td>{{ line_item.title | link_to: line_item.product.url }}</td>
      <td>{{ line_item.sku }}</td>
      <td>{{ line_item.price | money }}</td>
      <td>{{ line_item.quantity }}</td>
      <td>{{ line_item.quantity | times: line_item.price | money }}</td>
    </tr>
  {% endfor %}
{% endfor %}

You have to loop the customer orders in the account page first: {% for order in customer.orders %}

After that you have to loop the line items in each order, so you need another loop inside the order loop: {% for line_item in order.line_items %}

And that's pretty much it, the rest are additional outputs like sku, price, quantity, total...

Ad
source: stackoverflow.com
Ad