Display number of orders a customer has made on the invoice/receipt/packing slip

I used to have this and it stopped working some time ago.
This is the code snippet I used and it displayed eg, [Order Count: 15] on the invoice

{% if customer %}

  • Order Count: {{ customer.orders_count | default: 1 }}
  • {% endif %}

    For some time now it hasn’t worked and I want it to work again. I have seen another discussion that this variable should work and it’s dated March 2024

    {{ order.customer.orders_count }}

    But it doesn’t work.

    So what’s the solution? The data exists because I can look at a customer in shopify and it shows me how many orders they have made. I just want this number to show on the invoice. What do I do?

    hey @martybeany ,

    Check if {{ customer }} or {{ order.customer }} is available by outputting it directly in the invoice template

    {{ customer | json }}
    {{ order.customer | json }}

    This will print out the customer object and let you see whether the orders_count field is included in the output

    I added this to the invoice template

    {{ customer | json }}
    {{ order.customer | json }}

    It generated 2 identical outputs: (personal info replaced with xxx)

    {"id":3186859769988,"created_at":"2020-04-13T09:06:11.000+01:00","name":"xxxxx","email":"xxxxxx@icloud.com","phone":"+xxxxx6163","first_name":"xxx","last_name":"xxx","orders_count":1,"tax_exempt":false,"note":null,"tags":["repeat"],"default_address":{"id":6415828910233,"customer_id":3186859769988,"first_name":"xxx","last_name":"xxx","company":"","address1":"xxx road ","address2":"","city":"Trowbridge","province":"England","country":"United Kingdom","zip":"xxx","phone":"","name":"xxx","province_code":"ENG","country_code":"GB","country_name":"United Kingdom","default":true},"state":"enabled","total_spent":0}
    

    The key info here being: “orders_count”:1," and “total_spent”:0
    This specific customer has placed 60 orders so I don’t think this is working

    The {{ customer.orders_count }} field in Shopify represents the total number of fulfilled orders for a customer and does not include the current order unless it has been fulfilled. This is likely why you’re seeing an incorrect count.

    They have previously placed 59 orders but it says “orders_count”:1,"

    I just don’t get it, is shopify broken or this function not available?

    try to contact to shopify tech support team

    Any update? My guess is that, in order to get number of orders, it involves expense join SQL query. As a result, the orders_count never works.

    It’s 2026 and that still doesn’t work. Shopify should either deprecate this query or do something about it.

    @tiagos_souza it’s not that it should be deprecated, it’s just that the packing slip/invoice exposes very limited variables, primarily shop and order. Customer variables are exposed in templates like the order confirmation, so

    {{ customer.orders_count }}

    is definitely possible there. Checked it just now and it’s there. Just letting you know.