how to exclude/ hide a specific product category from general Product_card edit.

dorot44
New Member
4 0 0

hi all, I am trying to add an image from my asset folder to my product_card. But will like to exclude a particular category.  I used this code 

<img src="{{'swatch.image.jpg' | file_url }}" style="height:34px;" >

which added the image to all my products on the collection page. However, I will like to exclude a particular category that does not need this image. 

I tried to add   {% unless product.tags contains 'brass' %} but it did not work.  Any help on how to fix this problem? thanks

 

Replies 5 (5)
PaulNewton
Shopify Partner
3501 234 686

@dorot44 So your code more or less looks like the following?

{% unless product.tags contains 'brass' %}
 <img src="{{'swatch.image.jpg' | file_url }}" style="height:34px;" >
{% endif %}

 

Depending on theme it may actually be current_product or some other alias variable the theme uses in collection templates when looping over products, or it uses ajax, or does not use product_card .

There's also being sure products do not actually contain that string not just the word , so brassware would also match as a type of false negative.

Or target the collection directly 

{% if collection.handle != 'brass' %}
 <img src="{{'swatch.image.jpg' | file_url }}" style="height:34px;" >
{% endif %}
{% unless collection.handle contains 'brass' %}
 <img src="{{'swatch.image.jpg' | file_url }}" style="height:34px;" >
{% endunless %}

 

 

What important thing did you learn this Black Friday?


Answers powered by coffee Buy Paul a ☕ Coffee for more answers or donate to eff.org

Problem Solved? ✔Accept and Like solutions to help future merchants

Confused? Busy? Buy a custom solution paull.newton+shopifyforum@gmail.com
dorot44
New Member
4 0 0

thanks for the response. It didn't seem to work when I targeted the collection only. I'm using the debut theme

PaulNewton
Shopify Partner
3501 234 686

@dorot44 wrote:

It didn't seem to work 


"seem", be specific what steps did you take, how did you modify the provided code to fit your use case, do you have an example url, etc.

What important thing did you learn this Black Friday?


Answers powered by coffee Buy Paul a ☕ Coffee for more answers or donate to eff.org

Problem Solved? ✔Accept and Like solutions to help future merchants

Confused? Busy? Buy a custom solution paull.newton+shopifyforum@gmail.com
dorot44
New Member
4 0 0

the collection is called Brass jewellery collection. So I changed the name as: (see below) to exclude the collection.

{% unless collection.handle contains 'brass jewellery collection' %}
<img src="{{'swatch.image.jpg' | file_url }}" style="height:34px;" >
{% endunless %}

 

I put this code right above:  {% include 'product-price-listing', product: product, show_vendor: show_vendor %} as this is where I want the image to show in the snippet:  product.card.grid.liquid.

But it did not exclude the brass jewellery collection. The image showed up under all products in the collection page. 

PaulNewton
Shopify Partner
3501 234 686

@dorot44 wrote:

the collection is called Brass jewellery collection. So I changed the name as: (see below) to exclude the collection.

{% unless collection.handle contains 'brass jewellery collection' %}
<img src="{{'swatch.image.jpg' | file_url }}" style="height:34px;" >
{% endunless %}

 


While that's a good attempt there's a catch with handles in that they get "handleized" which is the name as you see it in that collections url

so brass jewellery collection becomes brass-jewellery-collection with dashes(-) and thus may not be a match when using the contains operator as you want to be less specific.

Using just contains would be more like {% unless collection.handle contains 'brass' %}

A more specific working match would be 

{% unless collection.handle == 'brass -jewellery-collection' %}
<img src="{{'swatch.image.jpg' | file_url }}" style="height:34px;" >
{% endunless %}

 

What important thing did you learn this Black Friday?


Answers powered by coffee Buy Paul a ☕ Coffee for more answers or donate to eff.org

Problem Solved? ✔Accept and Like solutions to help future merchants

Confused? Busy? Buy a custom solution paull.newton+shopifyforum@gmail.com