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 %}
      <td>{{ order.id }}</td>
      <td>{{ craft.commerce.customer.firstName }}</td>
      <td>{{ craft.commerce.customer.lastName }}</td>
      <td>{{ item.description }}</td>
      <td>{{ order.email }}</td>
      <td>{{ item.options.evenement }}</td>
      <td>{{ item.note }}</td>
      <td>{{ order.datePaid.localeDate() }}</td>
    {% endfor %}
  {% endfor %}

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

2 Answers 2


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.


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


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


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 %}
  • Thanks Robin, I will try your solution. Let you know if this will work. Feb 24, 2018 at 15:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.