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

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

martybeany
Visitor
3 0 0

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 %}
<li class="order-details-count">
<span class="order-details-title">Order Count:</span>
<span class="order-details-text">{{ customer.orders_count | default: 1 }}</span>
</li>
{% 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?


Replies 5 (5)

Matusalab
Shopify Partner
35 3 4

hey @martybeany,


Check if {{ customer }} or {{ order.customer }} is available by outputting it directly in the invoice template
<pre>{{ customer | json }}</pre>
<pre>{{ order.customer | json }}</pre>
This will print out the customer object and let you see whether the orders_count field is included in the output

Please let me know if it works by giving it a Like or marking it as a solution!
If you need further assistance, please head over to
https://www.matusalab.dev/ or reach out to me via www.mtslabrh97@gmail.com
martybeany
Visitor
3 0 0

I added this to the invoice template

 

<pre>{{ customer | json }}</pre>
<pre>{{ order.customer | json }}</pre>

 

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

Matusalab
Shopify Partner
35 3 4

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.

Please let me know if it works by giving it a Like or marking it as a solution!
If you need further assistance, please head over to
https://www.matusalab.dev/ or reach out to me via www.mtslabrh97@gmail.com
martybeany
Visitor
3 0 0

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? 

Matusalab
Shopify Partner
35 3 4

try to contact to shopify tech support team

Please let me know if it works by giving it a Like or marking it as a solution!
If you need further assistance, please head over to
https://www.matusalab.dev/ or reach out to me via www.mtslabrh97@gmail.com