Re: Is it possible to have a collection of variants?

Is it possible to have a collection of variants?

JonathanDu
New Member
8 0 0

I have products with variants. I'd like to have a collection that includes non-default variants of products. 

The result will be a collection page with the images of variants (they would all have the same name, each of its own product, like a specific format, for example) and that when you click on an image you'll be sent to the product page with that specific variant picked, not the default variant.

Is this possible? If so, how?

Replies 2 (2)

NomtechSolution
Astronaut
1245 113 155

To create a collection page that includes non-default variants of products and links to the respective product pages with the specific variant pre-selected, you can follow these steps:

  1. In the Shopify Admin panel, go to "Products" and select the product you want to create non-default variants for.

  2. Create the desired variants for the product. Each variant should represent a specific format, as you mentioned. Make sure to assign distinct images to each variant.

  3. Once you have created the variants, go to "Collections" and create a new collection or edit an existing one.

  4. Add the product to the collection by clicking on the "Add products" button and selecting the desired product.

  5. On the collection page template, locate the section where the product images are rendered. Typically, this involves working with the liquid file responsible for rendering the collection template (e.g., collection.liquid or similar).

  6. Within the collection template, iterate through the products and render the variant images instead of the default product image. You can access the variant images using the appropriate liquid code. For example:

 

{% for product in collection.products %}
  {% for variant in product.variants %}
    {% if variant.image %}
      <a href="{{ product.url }}?variant={{ variant.id }}">
        <img src="{{ variant.image.src }}" alt="{{ variant.title }}">
      </a>
    {% endif %}
  {% endfor %}
{% endfor %}

 

Hey_Jak
Shopify Partner
131 9 25

How To Create Collections Of Variants in Shopify by Heyjak. Here is a free solution:

❤️ Buy me a coffee
- Check my youtube: Hey Jak
Was your question answered? Mark it as an Accepted Solution.