Ad

Retrieve Customer Order Product ID Shopify

- 1 answer

I have created a page which will be accessible only if they purchase this certain product. My problem is I am not sure how to retrieve the customer Order product list ID.

for example customer A, purchased product A & B, then customer A would be able to access page A & B

I tried this but it what it retrieves is the order ID's not the product ID's of the orders made by the customer

{% for order in customer.orders %}
{{ order.id }}
{% endfor %}
Ad

Answer

Order object in Shopify contains information about purchased products in line_item. You should do something like this:

{% for order in customer.orders %}
  {% for line_item in order.line_items%}
     {{ line_item.product_id }}
  {% endfor %}
{% endfor %}

You can find information about line_item object in the official documentation: https://help.shopify.com/themes/liquid/objects/line_item

Ad
source: stackoverflow.com
Ad