How to find if a customer has not purchased any particular product.

Solved
sagar77
Shopify Partner
5 0 0

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!

 

0 Likes
Ninthony
Shopify Partner
1637 224 613

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

If my solution helped you, please like and accept as solution!
If you'd like to make any edits to your store, please send me a personal message and we can discuss what you'd like to accomplish :D
sagar77
Shopify Partner
5 0 0

Worked like a charm Ninthony. That was great, Thanks! Wasted no time in accepting the answer. 


0 Likes
popofglitter
New Member
1 0 0

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

0 Likes