<p>Not all orders will necessarily have a craft user associated with the order.</p>

<p>But all orders must have a billing address, so:</p>

<p><code>order.billingAddress.firstName</code> and <code>order.billingAddress.lastName</code> will get you what you need.</p>

CC BY-SA 3.0
2018-02-25T07:52:00.663Z
2018-02-25T07:52:00.663Z
Jeremy Daalder
<p>I never used Craft commerce so this answer could be totally wrong but just from looking at the docs the <a href="https://craftcommerce.com/docs/order-model#customerid" rel="nofollow noreferrer">Order Model</a> has the attribute <code>customerId</code> and the <code>customer</code> attribute that stores the <a href="https://craftcommerce.com/docs/customer-model" rel="nofollow noreferrer">Customer Model</a> </p>

<blockquote>
  <p><a href="https://craftcommerce.com/docs/order-model#customerid" rel="nofollow noreferrer">customerId</a></p>
  
  <p>The customer record for this order. You can also use customer to get the customer model which can tell you which craft user made the order, as well as access the addresses for this customer.</p>
</blockquote>

<p>The <code>customer model</code> contains a <a href="https://craftcommerce.com/docs/customer-model#user" rel="nofollow noreferrer">user</a> attribute that stores the default Craft <a href="https://craftcms.com/docs/templating/usermodel" rel="nofollow noreferrer">User Model</a> or null</p>

<blockquote>
  <p><a href="https://craftcommerce.com/docs/customer-model#user" rel="nofollow noreferrer">user</a> </p>
  
  <p>Returns a User Model if the customer is logged in, or null if the customer is a guest.</p>
</blockquote>

<p>So theoretically you should do something like</p>

<pre><code>{% set customer = order.customer %}
{% if customer is not null %}
    {% set user = customer.user %}
    {% if user is not null %}
        {{ user.firstName }} {{ user.lastName }}
    {% endif %}
{% endif %}
</code></pre>

CC BY-SA 3.0
2018-02-24T15:52:28.910Z
Thanks Robin, I will try your solution. Let you know if this will work.
John Stevens
CC BY-SA 3.0
2018-02-24T14:17:24.367Z
2018-02-24T14:17:24.367Z
Robin Schambach
<p>I want to output a list of all orders of all customers, including customers first name and last name. But can't get these two elements. </p>

<p>What I have now is:</p>

<pre><code>{% set pastOrders = craft.commerce.orders.find() %}
{% for order in pastOrders %}
    {% for item in order.lineItems %}
    &lt;tr&gt;
      &lt;td&gt;{{ order.id }}&lt;/td&gt;
      &lt;td&gt;{{ craft.commerce.customer.firstName }}&lt;/td&gt;
      &lt;td&gt;{{ craft.commerce.customer.lastName }}&lt;/td&gt;
      &lt;td&gt;{{ item.description }}&lt;/td&gt;
      &lt;td&gt;{{ order.email }}&lt;/td&gt;
      &lt;td&gt;{{ item.options.evenement }}&lt;/td&gt;
      &lt;td&gt;{{ item.note }}&lt;/td&gt;
      &lt;td&gt;{{order.orderStatus.name}}&lt;/td&gt;
      &lt;td&gt;{{ order.datePaid.localeDate() }}&lt;/td&gt;
    &lt;/tr&gt;
    {% endfor %}
  {% endfor %}
</code></pre>

<p>But as you may guess, I've got an error in both fields firstName lastName</p>

<plugin-craftcommerce>
Fetching Customer firstName lastName
# Fetching Customer firstName lastName

(Asked by: username_0 on 2018-02-24)

I want to output a list of all orders of all customers, including customers first name and last name. But can't get these two elements. 
What I have now is:
{% set pastOrders = craft.commerce.orders.find() %}
{% for order in pastOrders %}
    {% for item in order.lineItems %}
    
      {{ order.id }}
      {{ craft.commerce.customer.firstName }}
      {{ craft.commerce.customer.lastName }}
      {{ item.description }}
      {{ order.email }}
      {{ item.options.evenement }}
      {{ item.note }}
      {{order.orderStatus.name}}
      {{ order.datePaid.localeDate() }}
    
    {% endfor %}
  {% endfor %}

But as you may guess, I've got an error in both fields firstName lastName

**Tags:** plugin-craftcommerce

---

## 2 answers

### Answer by username_1 on 2018-02-25. Score: 3 | Accepted answer

Not all orders will necessarily have a craft user associated with the order.

But all orders must have a billing address, so:

`order.billingAddress.firstName` and `order.billingAddress.lastName` will get you what you need.


---

### Answer by username_2 on 2018-02-24. Score: 1

I never used Craft commerce so this answer could be totally wrong but just from looking at the docs the Order Model has the attribute customerId and the customer attribute that stores the Customer Model 

customerId
The customer record for this order. You can also use customer to get the customer model which can tell you which craft user made the order, as well as access the addresses for this customer.

The customer model contains a user attribute that stores the default Craft User Model or null

user 
Returns a User Model if the customer is logged in, or null if the customer is a guest.

So theoretically you should do something like
{% set customer = order.customer %}
{% if customer is not null %}
    {% set user = customer.user %}
    {% if user is not null %}
        {{ user.firstName }} {{ user.lastName }}
    {% endif %}
{% endif %}

> **Comments:**
> **username_0**: Thanks Robin, I will try your solution. Let you know if this will work.  

---

