Hey,
I have 2 products of the same thing. one used with 2 images (1 picture and one gif) for the hover effect
and another one used with one image only (for another purpose on the home page)
(if its possible) I want to code an if statement that if a customer adds two of the same product then the cart knows its the same product so it doesn’t add twice of the same.
can someone help me with the code and where specifically to add it?
Create only one product and add two images. One of them is normal, and the other is a gif. And this will be the default product that will be shown for the product page. On the main page you will use the same product, only you need to put a check
{% if template == “index” %}
//Home page product
{% endif %}
If there is a {% for%} loop, then you will need to put {% break %} on the first pass. That is, put it at the end. For example as below:
{% for image in product.images %}
-
{% if template == 'index' %}
{% break %}
{% endif %}
{% endfor %}
We don’t know which is your theme and structure of it. Therefore, the above example is from the debut theme. Most likely, the section on your main page is called featured-product. liquid. All changes will need to be made in this file. In the example above, the loop will only run once and only one image will be shown. This is the simplest logic for solving your problem.
In the featured-product.liquid file, the product-form.liquid is included and all changes are made there. We put the check on the main page and added the class.
Can you check it please?