Hide Add to Cart if customer has already purchased a product

Hide Add to Cart if customer has already purchased a product

Nigel_Burke
Shopify Partner
67 2 4

Hi all. I'd like to see if I can hide a products 'Add to Cart' button if they have already bought a product.

 

On the store I am working on all customers have to log in first before they can see/buy products. Is there a way the theme can check their purchase history and replace the 'Add to Cart' button with a message?

 

Thanks in advance for any help. :^)

Replies 8 (8)

gr_trading
Shopify Partner
2045 149 206

Hi @Nigel_Burke 

 

use the below code to achieve the same.

{% if customer.orders_count > 1 %}
    <h1>Order Count is greater than 1</h1>
{% endif %}

 

Hope it will help...

For any custom development WhatsApp or connect at Email ID: support@grtrading.in for quick consultation. | Shopify Free codes
To support Buy Me a Coffee
Nigel_Burke
Shopify Partner
67 2 4

Thanks for getting back to me so quickly. Will this code work on individual product pages? I mean, it will check if the customer has purchased that particular product?

gr_trading
Shopify Partner
2045 149 206

yes, it will everywhere at shopify

For any custom development WhatsApp or connect at Email ID: support@grtrading.in for quick consultation. | Shopify Free codes
To support Buy Me a Coffee
Nigel_Burke
Shopify Partner
67 2 4

Thanks. I struggled to get it to work the way I needed it. However, I manage to get this to work for me. In this case the client will be happy with this...

 

{% for order in customer.orders %}
{% for line_item in order.line_items %}
{% if line_item.title contains product.title %}
<br>
<h4><i class="ad ad-exclamation-triangle" style="color:red;"></i> It looks like you may have already purchased this item.</h4>
<h6>Please check your <a href="/account" style="color:#25ECC0;"><b>Account Downloads <i class="ad ad-download-r"></i></b></a></h6><br>

{% endif %}
{% endfor %}
{% endfor %}

NatalieG1
New Member
6 0 0

Hi Nigel, Any idea how to enable this text on collection pages as well, by replacing 'add to cart' to already bpught??

gr_trading
Shopify Partner
2045 149 206

The logic will be the same to implement this it's just that you need to code it on card-product.liquid page.

 

Please refer to the below video to implement the same.

 

Hope this will help...

For any custom development WhatsApp or connect at Email ID: support@grtrading.in for quick consultation. | Shopify Free codes
To support Buy Me a Coffee
NatalieG1
New Member
6 0 0

Your video is not related to the main question, I dont know whatt did you mean

Nigel_Burke
Shopify Partner
67 2 4

Hi Natalie,

 

I haven't look at this for a while but, yeah, the same logic should work on the collection pages too as mentioned by Gr_trading.

 

You're likely to find a Snippet called something like 'product-card-grid.liquid'. This is where the add-to-cart buttons should be for the theme you are working on. The coding would need to reside in here.

 

Hope that helps.