Add to cart button for customers only

SunnySideWorld
New Member
1 0 0

Hello! I'm pretty good now with modifying my code but I got a problem I can't find the solution.

When I put ''if customer'' to my "add to cart button" in my ''product-template.liquid", it changes the way that visitors see the products thumbnails image.
By example, when you are logged in, you click on the thumbnail, and it replaces the principal image (which is good).
When you are not logged in, you click on the thumbnail, it opens in a ''new window''. 

My ultimate goal is to enable ''add to cart'' button for customers only WITHOUT changing the navigation of the pictures. 

I don't understand where to find the relation between my ''add to cart'' button and thumbnail images. 
Everything works perfectly until I edit my code with this: 

  {% if customer %}<button type="submit" name="add"
                  {% unless current_variant.available %} aria-disabled="true"{% endunless %}
                  aria-label="{% unless current_variant.available %}{{ 'products.product.sold_out' | t }}{% else %}{{ 'products.product.add_to_cart' | t }}{% endunless %}"
                  class="btn product-form__cart-submit{% if section.settings.enable_payment_button and product.selling_plan_groups == empty %} btn--secondary-accent{% endif %}"
                  {% if settings.enable_ajax %}aria-haspopup="dialog"{% endif %}
                  data-add-to-cart>
                  <span data-add-to-cart-text>
                    {% unless current_variant.available %}
                      {{ 'products.product.sold_out' | t }}
                    {% else %}
                      {{ 'products.product.add_to_cart' | t }}
                    {% endunless %}
                  </span>
                  <span class="hide" data-loader>
                    {% include 'icon-spinner' %}
                  </span>
                </button>{% endif %}

 

Could someone help me please?

0 Likes