How to stop certain products from showing in "You May Also Like" list?

Topic summary

A store owner wants to exclude specific products (shipping insurance, route protection) from appearing in the “You May Also Like” recommendations section.

Solution provided:

  • Tag the unwanted products with a specific identifier (e.g., “Insurance”)
  • Modify the related-products.liquid theme file to skip products containing that tag
  • Insert conditional logic using {% if recommendation.tags contains "Insurance" %} with {% continue %} to exclude tagged items

Implementation details:

  • The code should be added within the {% for recommendation in recommendations.products %} loop
  • Multiple tags can be excluded using the “or” operator: {% if recommendation.tags contains "Insurance" or recommendation.tags contains "Hide" %}
  • This allows flexible control over which products appear in recommendations

Status: The original poster confirmed the solution worked successfully. One participant requested help with different theme code structure but later resolved it independently.

Summarized with AI on November 2. AI used: claude-sonnet-4-5-20250929.

Is there a code to stop “Shipping” and “Insurance” products from showing up in the “You May Also Like” list?

Please see attached screenshot, we do not want the “Route Protection” showing up as a product in the list…

@EC23 , First you will need to add “shipping” and “Insurance” tags to these products, then we will go the section that control the related product section, in dawn for example it is related-products.liquid and add the code to exclude them, for example :

{% if  recommendation.tags contains "Insurance" %}
 {% continue %} 
{% else %}
{% endif %}

This will skip any products that contain the tag insurance, again I don’t have access to your theme code , it would be better if you share it to provide you with the code.

1 Like

Here is my related-products.liquid code…please let me know where to add it…

{{ ‘component-card.css’ | asset_url | stylesheet_tag }}
{{ ‘component-price.css’ | asset_url | stylesheet_tag }}
{{ ‘section-related-products.css’ | asset_url | stylesheet_tag }}

{% if section.settings.image_shape == ‘blob’ %}
{{ ‘mask-blobs.css’ | asset_url | stylesheet_tag }}
{%- endif -%}

{%- style -%}
.section-{{ section.id }}-padding {
padding-top: {{ section.settings.padding_top | times: 0.75 | round: 0 }}px;
padding-bottom: {{ section.settings.padding_bottom | times: 0.75 | round: 0 }}px;
}

@media screen and (min-width: 750px) {
.section-{{ section.id }}-padding {
padding-top: {{ section.settings.padding_top }}px;
padding-bottom: {{ section.settings.padding_bottom }}px;
}
}
{%- endstyle -%}

{% if recommendations.performed and recommendations.products_count > 0 %}

{{ section.settings.heading }}

    {% for recommendation in recommendations.products %}
  • {% render 'card-product', card_product: recommendation, media_aspect_ratio: section.settings.image_ratio, image_shape: section.settings.image_shape, show_secondary_image: section.settings.show_secondary_image, show_vendor: section.settings.show_vendor, show_rating: section.settings.show_rating %}
  • {% endfor %}
{% endif %} {% if section.settings.image_shape == 'arch' %} {% render 'mask-arch' %} {%- endif -%}

{% schema %}
{
“name”: “t:sections.related-products.name”,
“tag”: “section”,
“class”: “section”,
“settings”: [
{
“type”: “paragraph”,
“content”: “t:sections.related-products.settings.paragraph__1.content”
},
{
“type”: “inline_richtext”,
“id”: “heading”,
“default”: “You may also like”,
“label”: “t:sections.related-products.settings.heading.label”
},
{
“type”: “select”,
“id”: “heading_size”,
“options”: [
{
“value”: “h2”,
“label”: “t:sections.all.heading_size.options__1.label”
},
{
“value”: “h1”,
“label”: “t:sections.all.heading_size.options__2.label”
},
{
“value”: “h0”,
“label”: “t:sections.all.heading_size.options__3.label”
}
],
“default”: “h1”,
“label”: “t:sections.all.heading_size.label”
},
{
“type”: “range”,
“id”: “products_to_show”,
“min”: 2,
“max”: 10,
“step”: 1,
“default”: 4,
“label”: “t:sections.related-products.settings.products_to_show.label”
},
{
“type”: “range”,
“id”: “columns_desktop”,
“min”: 1,
“max”: 5,
“step”: 1,
“default”: 4,
“label”: “t:sections.related-products.settings.columns_desktop.label”
},
{
“type”: “color_scheme”,
“id”: “color_scheme”,
“label”: “t:sections.all.colors.label”,
“info”: “t:sections.all.colors.has_cards_info”,
“default”: “background-1”
},
{
“type”: “header”,
“content”: “t:sections.related-products.settings.header__2.content”
},
{
“type”: “select”,
“id”: “image_ratio”,
“options”: [
{
“value”: “adapt”,
“label”: “t:sections.related-products.settings.image_ratio.options__1.label”
},
{
“value”: “portrait”,
“label”: “t:sections.related-products.settings.image_ratio.options__2.label”
},
{
“value”: “square”,
“label”: “t:sections.related-products.settings.image_ratio.options__3.label”
}
],
“default”: “adapt”,
“label”: “t:sections.related-products.settings.image_ratio.label”
},
{
“type”: “select”,
“id”: “image_shape”,
“options”: [
{
“value”: “default”,
“label”: “t:sections.all.image_shape.options__1.label”
},
{
“value”: “arch”,
“label”: “t:sections.all.image_shape.options__2.label”
},
{
“value”: “blob”,
“label”: “t:sections.all.image_shape.options__3.label”
},
{
“value”: “chevronleft”,
“label”: “t:sections.all.image_shape.options__4.label”
},
{
“value”: “chevronright”,
“label”: “t:sections.all.image_shape.options__5.label”
},
{
“value”: “diamond”,
“label”: “t:sections.all.image_shape.options__6.label”
},
{
“value”: “parallelogram”,
“label”: “t:sections.all.image_shape.options__7.label”
},
{
“value”: “round”,
“label”: “t:sections.all.image_shape.options__8.label”
}
],
“default”: “default”,
“label”: “t:sections.all.image_shape.label”,
“info”: “t:sections.all.image_shape.info”
},
{
“type”: “checkbox”,
“id”: “show_secondary_image”,
“default”: false,
“label”: “t:sections.related-products.settings.show_secondary_image.label”
},
{
“type”: “checkbox”,
“id”: “show_vendor”,
“default”: false,
“label”: “t:sections.related-products.settings.show_vendor.label”
},
{
“type”: “checkbox”,
“id”: “show_rating”,
“default”: false,
“label”: “t:sections.related-products.settings.show_rating.label”,
“info”: “t:sections.related-products.settings.show_rating.info”
},
{
“type”: “header”,
“content”: “t:sections.related-products.settings.header_mobile.content”
},
{
“type”: “select”,
“id”: “columns_mobile”,
“default”: “2”,
“label”: “t:sections.related-products.settings.columns_mobile.label”,
“options”: [
{
“value”: “1”,
“label”: “t:sections.related-products.settings.columns_mobile.options__1.label”
},
{
“value”: “2”,
“label”: “t:sections.related-products.settings.columns_mobile.options__2.label”
}
]
},
{
“type”: “header”,
“content”: “t:sections.all.padding.section_padding_heading”
},
{
“type”: “range”,
“id”: “padding_top”,
“min”: 0,
“max”: 100,
“step”: 4,
“unit”: “px”,
“label”: “t:sections.all.padding.padding_top”,
“default”: 36
},
{
“type”: “range”,
“id”: “padding_bottom”,
“min”: 0,
“max”: 100,
“step”: 4,
“unit”: “px”,
“label”: “t:sections.all.padding.padding_bottom”,
“default”: 36
}
]
}
{% endschema %}

@EC23 , First, did you add the tags to the products you want to exclude?

Yes…added an Insurance tag to the Route protection product

1 Like

Hi @EC23
You can put the code from @Abdosamer in this part

{% for recommendation in recommendations.products %}
  {% if  recommendation.tags contains "Insurance" %}
   {% continue %} 
  {% else %}
   - {% render 'card-product',
    card_product: recommendation,
    media_aspect_ratio: section.settings.image_ratio,
    image_shape: section.settings.image_shape,
    show_secondary_image: section.settings.show_secondary_image,
    show_vendor: section.settings.show_vendor,
    show_rating: section.settings.show_rating
    %}
  
  {% endif %}
{% endfor %}
1 Like

@EC23 , locate this piece of code :

{% for recommendation in recommendations.products %}
          - {% render 'card-product',
                card_product: recommendation,
                media_aspect_ratio: section.settings.image_ratio,
                image_shape: section.settings.image_shape,
                show_secondary_image: section.settings.show_secondary_image,
                show_vendor: section.settings.show_vendor,
                show_rating: section.settings.show_rating
              %}
          

        {% endfor %}

Replace it with this code:

{% for recommendation in recommendations.products %}
          {% if recommendation.tags contains "Insurance" %}
           {% continue %}
           {% else %}
          - {% render 'card-product',
                card_product: recommendation,
                media_aspect_ratio: section.settings.image_ratio,
                image_shape: section.settings.image_shape,
                show_secondary_image: section.settings.show_secondary_image,
                show_vendor: section.settings.show_vendor,
                show_rating: section.settings.show_rating
              %}
          
          {% endif %}
        {% endfor %}
4 Likes

Perfect…Thank you SO much!!!

2 Likes

@EC23 Thanks for posting this question.

@Abdosamer This is amazing and super helpful! I do have a question. I have separate theme template for 4 products. Specifically on those products I want to have the recommended section show products from the default product template. I already used your previously code to remove the ones I tagged from the recommendations.

{% for recommendation in recommendations.products %}
          {% if recommendation.tags contains "NotRec" %}
           {% continue %}
           {% else %}
          - {% render 'card-product',
                card_product: recommendation,
                media_aspect_ratio: section.settings.image_ratio,
                image_shape: section.settings.image_shape,
                show_secondary_image: section.settings.show_secondary_image,
                show_vendor: section.settings.show_vendor,
                show_rating: section.settings.show_rating
              %}
          

          {% endif %}
        {% endfor %}

Here is my site with the default product template and this is the four products that have their own Product template theme because they are just for that partnership.

Any suggestions?

Never mind. I was able to figure out a way.

Your Coffy is very tasty we taste this Coffy at last time i like this Coffy this is really amazing Coffy many peoples like this Coffy you can see onhttp://generalliabalityinsure.com/

Perfect solution and very well explained. Thank you!

One note for anyone else who reads this - if you want to set up your shop such that more than one tag will hide products from “Related Products”, just add an “or” operator at the end of the “if” statement in the first line of added code.

For example, you may not want all products with a given tag to be hidden, but instead want the ability to hide some products from a tag group as needed. In this case, you can create a generic “Hide” tag and add it to the first line of code with the “or” operator to accomplish this. This can be added to the first line of the code as shown in the following example:

{% if recommendation.tags contains "Insurance"  or recomendation.tags contains "Hide"%}

This code will cause products with either “Insurance” or “Hide” to be hidden from Related Products. This allows you to have effective and accurate tags for each product to ensure maximum functionality, while also giving you the ability to spot-hide individual products as needed. Additionally, you can continue adding “or” statements to the first line of code, as needed, for each tag you want to have hidden from "Recommended Items’ in this manner.

Hey thanks so much for helping. I’ve been trying to do this but realised my code is different. Can you please show me where exactly to insert that code?? Here’s my code for related-products-new.liquid

{%- liquid
assign arrows_style = settings.arrow_style
assign arrows_style_class = “”
assign use_one_and_half_layout = settings.use_two_and_half_layout
assign hide_border = settings.show_border
if arrows_style == “Left-Right”
assign arrows_style_class = " slider-section–arrows-sides"
endif
if arrows_style == “Bottom-Centered”
assign arrows_style_class = " slider-section–arrows-bottom"
endif
-%}
{% if section.settings.enable %}

{{ 'products.general.related_products_title' | t }}

{%- liquid assign count = 0 assign current_product_title = product.title assign max_products_count = section.settings.max_products_count for collection in product.collections if collection.handle != "all" and collection.handle != "frontpage" for product in collections[collection.handle].products if product.title != current_product_title if count < max_products_count assign count = count | plus: 1 echo "
" render "product-grid-item-new" with product: product echo "
" else break endif endif endfor endif if count >= max_products_count break endif endfor -%}
{% if count <= 0 %} {% endif %}
{% render 'icon-arrow-down' %}
{% render 'icon-arrow-down' %}
{% endif %}

{% schema %}
{
“name”: “Related Products”,
“settings”: [
{
“type”: “checkbox”,
“id”: “enable”,
“label”: “Enable”,
“default”: true
},
{
“type”: “range”,
“id”: “max_products_count”,
“label”: “Products limit”,
“min”: 5,
“max”: 30,
“step”: 1,
“default”: 5
}
]
}
{% endschema %}