customer

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

Where and when is it defined

The customer object is global in the sense that you can access it all layout, template and snippet files. However, the object is only defined when a customer is logged-in. You can verify if a customer is logged-in with this code:

{% if customer %}
  Customer is logged in. You can access the customer
  attributes such as {{ customer.first_name }}.
{% endif %}

If one is able to view a store page that lives under /accounts then one is logged-in, therefore you don't need to check if customer is defined in the templates /customers/account.liquid, /customers/order.liquid and /customers/addresses.liquid before you access the variable's attributes.

The customer variable can also be accessed in email templates, on the order status page of the checkout, as well as in apps such as >Order Printer.

Attributes

customer.accepts_marketing

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

customer.addresses

Returns an array of all addresses associated with a customer. See customer_address for a full list of available attributes.

Input
{% for address in customer.addresses %}
  {{ address.street }}
{% endfor %}
Output
56 Vân côi, Phường 7, Quận Tân Bình, Tp. Hồ Chí Minh
65 Trần Quốc Hoàn, Quận Tân Bình, Tp. Hồ Chí Minh

customer.addresses_count

Returns the number of addresses associated with 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 associated with an order is also tied to a customer account. Returns false if it is not. Helpful in email templates. In the theme, that will always be true.

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, not including test orders.

Input
Your last order was placed on: {{ customer.last_order.created_at | date: "%B %d, %Y %I:%M%p" }}
Output
Your last order was placed on: June 28, 2016 03:12PM

customer.name

Returns the full name of the customer.

customer.orders

Returns an array of all orders placed by the customer.

Input
{% for order in customer.orders %}
{{ order.id }}
{% endfor %}
Output
#1088
#1089
#1090

customer.orders_count

Returns the total number of orders a customer has placed.

customer.tags

Returns the list of tags associated with the customer.

Input
{% for tag in customer.tags %}
{{ tag }}
{% endfor %}
Output
haravan haravan-partner

customer.total_spent

Returns the total amount spent on all orders.

results matching ""

    No results matching ""