Hide free products from product recommendations

Hi there,

Is it possible to hide products with “0.00” price from appearing in the recommended products section? Ideally without an app.

https://uk.hottools.com/collections/electrical-styling-tools/products/hot-tools-black-gold-evolve-titanium-straightener

Hello , @nealandwolf

Use this condition in your recommendation products section/snippet code. Inside forloop

{% if product.price > 0 %}

Thanks for the fast reply! Could you take a look at the code below and let me know where to add in? I’ve tried a few different ways but not been able to make it work.

{%- assign recommend_products = true -%}

{% if recommendations.products and recommendations.products_count > 0 %}
{%- assign related_collection = recommendations -%}
{% endif %}

{% comment %}
Check if the utility tag defines related section
{% endcomment %}
{% for tag in product.tags %}
{% if tag contains ‘related’ %}
{%- assign include_collection_handle = tag | split: '
’ | last -%}
{%- assign include_collection = collections[include_collection_handle] -%}
{% if include_collection != empty and include_collection.products_count > 0 %}
{%- assign related_collection = include_collection -%}
{%- assign recommend_products = false -%}
{% break %}
{% endif %}
{% endif %}
{% endfor %}

{%- assign number_of_products = section.settings.related_count -%}
{%- assign per_row = number_of_products -%}
{%- assign number_of_products_to_fetch = number_of_products | plus: 1 -%}
{% case per_row %}
{% when 1 %}
{%- assign grid_item_width = ‘’ -%}
{% when 2 %}
{%- assign grid_item_width = ‘medium-up–one-half’ -%}
{% when 3 %}
{%- assign grid_item_width = ‘small–one-half medium-up–one-third’ -%}
{% when 4 %}
{%- assign grid_item_width = ‘small–one-half medium-up–one-quarter’ -%}
{% when 5 %}
{%- assign grid_item_width = ‘small–one-half medium-up–one-fifth’ -%}
{% when 6 %}
{%- assign grid_item_width = ‘small–one-half medium-up–one-sixth’ -%}
{% endcase %}

{%- if section.settings.show_product_recommendations -%}

{{ section.settings.product_recommendations_heading }}

{% if recommend_products %}
{% comment %} This content is visually hidden and replaced when recommended products show up {% endcomment %}
{% include 'product-grid-item' %}
{% endif %} {% if related_collection.products_count > 1 %}
{%- assign current_product = product -%} {%- assign current_product_found = false -%} {%- assign related_count = 0 -%} {% for product in related_collection.products limit: number_of_products_to_fetch %} {% if product.handle == current_product.handle %} {%- assign current_product_found = true -%} {% else %} {%- assign related_count = related_count | plus: 1 -%} {% unless related_count > number_of_products %} {% if forloop.last and current_product_found %} {% include 'product-grid-item' %} {% else %} {% include 'product-grid-item' %} {% endif %} {% endunless %} {% endif %} {% endfor %}

{% if settings.quick_shop_enable %}
{% for product in related_collection.products limit: number_of_products_to_fetch %}
{% if product.handle != current_product.handle %}
{% include ‘quick-shop-modal’ %}
{% endif %}
{% endfor %}
{% endif %}

{% endif %}
{%- endif -%}

{% schema %}
{
“name”: “Product recommendations”,
“settings”: [
{
“type”: “checkbox”,
“id”: “show_product_recommendations”,
“label”: “Show dynamic recommendations”,
“info”: “Dynamic recommendations change and improve with time. Learn more”,
“default”: true
},
{
“type”: “text”,
“id”: “product_recommendations_heading”,
“label”: “Heading”,
“default”: “You may also like”
},
{
“type”: “range”,
“id”: “related_count”,
“label”: “Number of related products”,
“default”: 5,
“min”: 2,
“max”: 6,
“step”: 1
}
]
}
{% endschema %}

Hello , @nealandwolf

Please see this screenshot

That’s perfect, thank you so much!