Is there any way to exclude swatches from showing below products for three specific collections?
I have multiples collection, I need to hide it only in 3 collection.
Is there any way to exclude swatches from showing below products for three specific collections?
I have multiples collection, I need to hide it only in 3 collection.
Hello there,
If you’re looking for an alternative solution to hide color swatches for specific collections in Shopify, you can use JavaScript or Liquid code. Here’s an example using Liquid code:
1.Identify the handle or ID of the three specific collections where you want to hide the color swatches.
2.Open the product-template.liquid file in your Shopify theme editor.
3.Locate the section of code that renders the color swatches. This code might vary depending on your theme, but it typically involves a loop that iterates over the available product options.
4.Wrap the code that renders the color swatches with a conditional statement to check if the current product belongs to one of the specified collections. If it does, skip rendering the color swatches.
Here’s an example of how the code might look like:
{% unless product.collections contains 'collection-handle-1' or product.collections contains 'collection-handle-2' or product.collections contains 'collection-handle-3' %}
{% for option in product.options %}
{% if option.name == 'Color' %}
{% endif %}
{% endfor %}
{% endunless %}
In the above code, replace ‘collection-handle-1’, ‘collection-handle-2’, and ‘collection-handle-3’ with the actual handles or IDs of your three specific collections.
5.Save the changes and preview your store. The color swatches should now be hidden for the specified collections.
Note: This solution requires modifying the Liquid code in your theme files. If you’re not familiar with Liquid or feel uncomfortable making these changes, it’s recommended to reach out to a Shopify developer for assistance or create a backup of your theme before making any modifications.
Locate the collection template file. The name of the file may vary depending on your theme, but common names include collection.liquid or collection-template.liquid. Look for the file that controls the layout of your collection pages.
Within the collection template file, find the section of code that displays the product swatches. This code will be specific to your theme and may involve snippets or include files. Look for code related to the rendering of swatches or product variants.
Wrap the code responsible for displaying swatches within an if statement that checks for the collection handle or ID. Here’s an example:
{% unless collection.handle == 'collection-handle-1' or collection.handle == 'collection-handle-2' or collection.handle == 'collection-handle-3' %}
{% endunless %}
Replace 'collection-handle-1', 'collection-handle-2', and 'collection-handle-3' with the actual handles or IDs of your three collections. This code will conditionally display the swatches only if the collection is not one of the specified three.
I put the id like this and it does not work
{% unless product.collections contains ‘1893474895937’ …