I have seen this post- https://community.shopify.com/c/Shopify-Design/If-logged-in-customer-has-ordered-a-product-before/m-... to see if any customer has purchased any product. I want to do the exact opposite, I want a condition to check if any customer has not purchased a specific product. The problem I am facing is for a new customer who has 0 orders. For this customer this for loop won't work as he has 0 orders, so it will never go in this for loop.
{% for order in customer.orders %}
{% endfor %}
This is what I want to do(in the attachment). I want to show add to cart button if a customer has not purchased any particular product.
Can anybody suggest me a solution?
Thanks in advance!
Solved! Go to the solution
This is an accepted solution.
Use customer.orders_count
{% if customer.orders_count == 0 %} <div class="add-to-cart"> Add to Cart </div> {% else %} {% for order in customer.orders %} Whatever else you want to do here. {% endfor %} {% endif %}
Here's a reference to the customer object:
https://help.shopify.com/en/themes/liquid/objects/customer#customer-orders_count
Hello. So I get questions from my customers all the time asking if there is a way to find out if they HAVEN'T ordered a paticular glitter / product from me? I've called in and asked and I kinda researched it a little bit but nothing. I thought maybe in Analytics or somewhere in customers account but no. I can see what they have ordered but need to know what they HAVEN'T ORDERED , like a list or something.
Thank you
Pop Of Glitter LLC
User | Count |
---|---|
444 | |
188 | |
139 | |
61 | |
42 |