Hiding add to cart for non log in customer

Hi all,

Sorry if this have been answered before but I cant find it.

I managed to hide pricing for non log in customer but if they add item to card they can still see the pricing.

So what I want to do is hide the “add to cart” button for non log in customer so they cant see the pricing in the card.

Please help, thanks.

Hi @biolase

If you want to hide add to cart button form product page then you have to follow this:

  1. Go to Section->product-template.liquid file and find name=“add” (that’s your add to cart button) now add condition like this:
{% if customer %}
 //Add your existing add to cart code here
{% endif %}

So now add to cart button only show if user login. If you want to do on collection page then you have to do same in Snippet->product-grid.liquid or Snippet->product-cart.liquid.

Would it be possible to do this in the Dawn theme?

Yes you can try on Dawn theme also. may be different file only code is same

Do you have any idea which file I would need to put this code in?

  1. Go to Online Store->Theme->Edit code
  2. Section->main-product.liquid->find for class “product-form__buttons” which is your add to cart button and add above condition just before this line

best regard

1 Like

Thanks so much for helping with this. Unfortunately, when I add this code, the add to cart buttons is still visible. I’ve attached a photo of this section, do you see a problem or have any other suggestions on why this might be happening?

Thanks!

given code it for product page not product grid,

for product grid you have to check snippet->product-grid.liquid file or may be its different then need to check code

I’m not sure I follow. So the code I shared, that is not the problem? For dawn the product grid is main-product-collection-grid. What should I look for in this snippet?

Need to check in code, add me staff: jasoliyabrijesh123@gmail.com

and let me know

bets regard

Thanks a lot Jasoliya, It worked great for me!

Have a great day!

Mike