Answers.Body: <p>Something like this should work:</p>
  
  <pre><code>{# Grab the currently logged in users past orders %}
  {% set pastOrders = craft.commerce.orders.customer(craft.commerce.customer).find() %}
  
  {% set uniqueSKUs = [] %}
  
  {# loop through the orders #}
  {% for order in pastOrders %}
  
      {# loop through the line items #}
      {% for item in order.lineItems %}
  
          {# did we find a unique one? #}
          {% if item.purchasable.sku not in uniqueSKUs %}
  
              {# add it to the list #}
              {% set uniqueSKUs = uniqueSKUs|merge([item.purchasable.sku]) %}
  
          {% endif %}
      {% endfor %}
  {% endfor %}
  
  &lt;h1&gt;Unique SKUs for customer ID {{ craft.commerce.customer.id }}:&lt;/h1&gt;
  
  &lt;ul&gt;
      {% for sku in uniqueSKUs %}
          &lt;li&gt;{{ sku }}&lt;/li&gt;
      {% endfor %}
  &lt;/ul&gt;
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-07-29T19:21:33.353Z
Answers.LastActivityDate: 2016-07-29T19:21:33.353Z
Answers.UserDisplayName: Brad Bell
Body: <p>I'm trying to figure out a way from Twig to get a distinct list of products purchased by a user. Help?</p>
  
Tags: <plugin-craftcommerce>
Title: How can I get a list of unique products a Craft Commerce customer has purchased?
ThreadText: # How can I get a list of unique products a Craft Commerce customer has purchased?
  
  (Asked by: username_0 on 2016-07-29)
  
  I'm trying to figure out a way from Twig to get a distinct list of products purchased by a user. Help?
  
  **Tags:** plugin-craftcommerce
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2016-07-29. Score: 5 | Accepted answer
  
  Something like this should work:
  
  ```
  {# Grab the currently logged in users past orders %}
  {% set pastOrders = craft.commerce.orders.customer(craft.commerce.customer).find() %}
  
  {% set uniqueSKUs = [] %}
  
  {# loop through the orders #}
  {% for order in pastOrders %}
  
      {# loop through the line items #}
      {% for item in order.lineItems %}
  
          {# did we find a unique one? #}
          {% if item.purchasable.sku not in uniqueSKUs %}
  
              {# add it to the list #}
              {% set uniqueSKUs = uniqueSKUs|merge([item.purchasable.sku]) %}
  
          {% endif %}
      {% endfor %}
  {% endfor %}
  
  <h1>Unique SKUs for customer ID {{ craft.commerce.customer.id }}:</h1>
  
  <ul>
      {% for sku in uniqueSKUs %}
          <li>{{ sku }}</li>
      {% endfor %}
  </ul>
  
  ```
  
  
  ---
  
  