Customise related-products.liquid to ignore some collections

Hello,

I am using the minimal theme and am looking to customise the related-products feature to ignore some of my collections. I want to ‘ignore’ the collections that are at the parent level of my category tree, only ‘including’ child collections e.g. ignore ‘for special occasions’ parent collection, include ‘christmas’ child collection.

Can anyone help with the code that I need to add to achieve this?

Thanks!

{% assign number_of_products = 4 %}
{% assign number_of_products_to_fetch = number_of_products | plus: 1 %}

{% if collection == null or collection.handle == ‘frontpage’ or collection.handle == ‘all’ %}
{% assign found_a_collection = false %}
{% for c in product.collections %}
{% if found_a_collection == false and c.handle != ‘frontpage’ and c.handle != ‘all’ and c.all_products_count > 1 %}
{% assign found_a_collection = true %}
{% assign collection = c %}
{% endif %}
{% endfor %}
{% endif %}

{% if collection and collection.products_count > 1 %}


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

{% assign current_product = product %} {% assign current_product_found = false %} {% for product in collection.products limit: number_of_products_to_fetch %} {%- if product.metafields.inventory.ShappifyHidden == 'true' -%}{%- continue -%}{%- endif -%} {%- include 'bold-product' with product, hide_action: 'skip' -%} {% if product.handle == current_product.handle %} {% assign current_product_found = true %} {% else %} {% unless current_product_found == false and forloop.last %} {% assign grid_item_width = 'post-large--one-quarter medium--one-quarter small--one-half' %} {%- assign product_width = 300 -%} {% assign featured = product %}
{% include 'product-grid-item' %}
{% endunless %} {% endif %} {% endfor %}
{% endif %}