Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more
Hey,
I noticed that the checkout.customer.orders_count parameter can return 0 as a value and I can't find out why this is happening.
I am using the following script on the order status page to push the value of checkout.customer.orders_count into the dataLayer:
<script> window.dataLayer = window.dataLayer || []; {% if checkout.customer %} window.dataLayer.push({ user_properties:{ customer_id: "{{- checkout.customer.id | json -}}", customer_email: {{- checkout.email | json -}}, customer_first_name: {{- checkout.billing_address.first_name | json -}}, customer_last_name: {{- checkout.billing_address.last_name | json -}}, {%- if checkout.customer.phone -%} customer_phone: {{- checkout.customer.phone | json -}}, {%- elsif checkout.billing_address.phone -%} customer_phone: {{- checkout.billing_address.phone | json -}}, {%- else -%} customer_phone: {{- checkout.shipping_address.phone | json -}}, {%- endif -%} customer_city: {{- checkout.billing_address.city | json -}}, customer_zip: {{- checkout.billing_address.zip | json -}}, customer_address_1: {{- checkout.billing_address.address1 | json -}}, customer_address_2: {{- checkout.billing_address.address2 | json -}}, customer_country: {{- checkout.billing_address.country | json -}}, customer_country_code: {{- checkout.billing_address.country_code | json -}}, customer_province: {{- checkout.billing_address.province | json -}}, customer_province_code: {{- checkout.billing_address.province_code | json -}}, customer_order_count: "{{- checkout.customer.orders_count | json -}}", customer_total_spent: "{{- checkout.customer.total_spent | times: 0.01 | json -}}", customer_tags: {{- checkout.customer.tags | json -}}, visitor_type: "logged_in", } }); {% else %} window.dataLayer.push({ visitor_type: "guest" }); {% endif %} </script>
For some Shopify stores this script works perfectly fine and the customer_orders_count returns correct values. For other stores, the majority of values will be 0.
Does anyone have an idea what the issue is?
Thanks ✌️