The customer object contains information about a customer who has a customer account.

Where and when is it defined

The customer object is global: you can access it in all layout, template and snippet files. It is only defined when a customer is logged in. Use this code to check whether a customer is logged in:

{% if customer %}
  The customer is logged in. You can access customer
  properties such as {{ customer.first_name }}.
{% endif %}

Anyone who can see a shop page under /account is logged in. So in the templates customers/account.liquid, customers/order.liquid and customers/addresses.liquid you do not need to check whether customer is defined before you access its attributes.

The customer variable is also available in email templates, on the order status page of the checkout and in apps such as order printers.

Attributes

customer.accepts_marketing

Returns true if the customer accepts marketing, false if not.

customer.addresses

Returns an array of all addresses of a customer. See customer_address for all available attributes.

{% for address in customer.addresses %}
  {{ address.street }}
{% endfor %}
Example Street 22, Suite 200
Sample Road 12
Main Square 1

customer.addresses_count

Returns the number of addresses of a customer.

customer.default_address

Returns the default customer address.

customer.email

Returns the email address of the customer.

customer.first_name

Returns the first name of the customer.

customer.has_account

Returns true if the email address of the customer is tied to a customer account, false if not.

A customer can complete a checkout without creating an account. If the customer has no account in the shop, customer.has_account is false in email templates and at checkout.

If the customer has an account and enters an email address tied to it during checkout, customer.has_account is true. The email address is matched to the account whether or not the customer logged in.

customer.id

Returns the ID of the customer.

customer.last_name

Returns the last name of the customer.

customer.last_order

Returns the last order placed by the customer, excluding test orders.

Your last order was placed on: {{ customer.last_order.created_at | date: "%B %d, %Y %I:%M%p" }}
Your last order was placed on: April 25, 2014 01:49PM

customer.name

Returns the full name of the customer.

customer.orders

Returns an array of all orders placed by the customer.

{% for order in customer.orders %}
  {{ order.name }}
{% endfor %}
#1088
#1089
#1090

customer.orders_count

Returns the total number of orders placed by a customer.

customer.phone

Returns the phone number of the customer.

customer.tags

Returns the list of tags of the customer.

{% for tag in customer.tags %}
  {{ tag }}
{% endfor %}
wholesale regular-customer VIP

customer.tax_exempt

Returns whether the customer is exempt from taxes.

customer.total_spent

Returns the total amount spent on all orders.

More properties

VersaCommerce also provides these properties on the customer object:

Properties Returns
metafields, billing_address, shipping_address, accepts_newsletter, has_avatar?, logged_in, logged_in?, firstname, lastname Storefront customer metadata, addresses and account state