Add to cart button hidden unless logged in, except for SALE section

Hoping someone out there can lend some light on this…

We run a b2b style site that you can browse as a regular customer but unless you are an account holder with us and logged in you cannot add anything to your cart or checkout. This is done via some code we added to hide the add to cart button unless logged in. Everything works great but we have recently added a ‘sale’ collection to our site which will be for damaged/discontinued/ex demo products and we are looking to open this up to all customers regardless of whether they are an account holder or not.

Is there a way that we can continue to hide the add to cart button for all other sections whilst having this ‘sale’ collection fully shoppable even if the customer is logged out?

Any information/help on this would be greatly apprecaited.

Thank you in advance!

Hi @tomhorton ,

Yes, it is entirely possible.

You can set the condition to display it. Refer code:

{% assign check_collection = false %}
{% for collection in product.collections %}
    {% if collection.handle == 'Handle sale collection' %}
      {% assign check_collection = true %}
      {% break %}
    {% endif %}
{% endfor %}
{% if check_collection == true %}

{% else %}

{% endif %}

or more simply, you just need to add a tag for the products you want to display add to cart and add the following code:

{% if product.tags contains 'tag product' %}

{% else %}

{% endif %}

Hope it helps!

Thank you for your reply on this! I have had a look but I can’t seem to find where abouts to place either of these bits of code to make them work, could you please advise roughly where it would need to go? I can supply our product-template.liquid code if that helps? Thank you for your time!

Hi @tomhorton ,

Yes, please send me the file code and site link. I will check it.

For sure, I will send you a dm now for this, much appreciated!

Hi @tomhorton ,

You can follow the instructions below:

  • Step 1: Add code here:

  • Step 2: Add ‘SALE!’ tag for each product, it will work fine.

Hope it helps!

Hi @tomhorton ,

Please go to sections > product-template.liquid file and add code at line: 148 and 201