Answers.Body: <p>You want to use the <a href="https://craftcms.com/docs/3.x/dev/filters.html#group" rel="nofollow noreferrer"><code>group</code> Twig filter in Craft</a>. You can group the orders by customer and then output them with two for-loops.</p>
  <p>Here's some example code using only the customer ID and order ID:</p>
  <pre><code>{% set orders = craft.orders.completed(true).limit(null).orderBy('dateOrdered desc').all() %}
  {% set ordersByCustomerId = orders | group(order =&gt; order.customerId) %}
  
  {% for customer, customerOrders in ordersByCustomerId %}
      &lt;h2&gt;{{ customer }}&lt;/h2&gt;
  
      {% for order in customerOrders %}
          {{ order.id }}&lt;br&gt;
      {% endfor %}
  
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-04T16:15:58.917Z
Answers.LastActivityDate: 2022-02-04T16:15:58.917Z
Answers.UserDisplayName: CraftQuest
Body: <p>Is it possible to print a list of customers but display a customer only once even when he/she ordered multiple times?</p>
  <pre><code>    {% set orders = craft.orders.completed(true).limit(null).orderBy('dateOrdered desc').all() %}
      {% for order in orders %}
         &lt;li&gt;
           {{ order.billingAddress.firstName}}
           {{ order.billingAddress.lastName}}
         &lt;/li&gt;
      {% endfor %}
  </code></pre>
  <p>This works but it prints the names for each order. I want to print the customer only once.</p>
  
Tags: <plugin-craftcommerce>
Title: Commerce show customer only once even with multiple orders
ThreadText: # Commerce show customer only once even with multiple orders
  
  (Asked by: username_0 on 2022-02-04)
  
  Is it possible to print a list of customers but display a customer only once even when he/she ordered multiple times?
  
  ```
      {% set orders = craft.orders.completed(true).limit(null).orderBy('dateOrdered desc').all() %}
      {% for order in orders %}
         <li>
           {{ order.billingAddress.firstName}}
           {{ order.billingAddress.lastName}}
         </li>
      {% endfor %}
  
  ```
  
  This works but it prints the names for each order. I want to print the customer only once.
  
  **Tags:** plugin-craftcommerce
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-02-04. Score: 2 | Accepted answer
  
  You want to use the [`group` Twig filter in Craft](https://craftcms.com/docs/3.x/dev/filters.html#group). You can group the orders by customer and then output them with two for-loops.
  
  Here's some example code using only the customer ID and order ID:
  
  ```
  {% set orders = craft.orders.completed(true).limit(null).orderBy('dateOrdered desc').all() %}
  {% set ordersByCustomerId = orders | group(order => order.customerId) %}
  
  {% for customer, customerOrders in ordersByCustomerId %}
      <h2>{{ customer }}</h2>
  
      {% for order in customerOrders %}
          {{ order.id }}<br>
      {% endfor %}
  
  {% endfor %}
  
  ```
  
  
  ---
  
  