Skip to content

Instantly share code, notes, and snippets.

@DanWebb
Last active June 21, 2021 21:01
Show Gist options
  • Save DanWebb/4bc6aea733465b727d36 to your computer and use it in GitHub Desktop.
Save DanWebb/4bc6aea733465b727d36 to your computer and use it in GitHub Desktop.
Shopify related products liquid
@satquiel
Copy link

Quick question, would you know how i can change the below to make it show a maximum of only 4 related products?

{% if settings.display_related_products %}
{% capture limit %}{{ settings.products_per_row | plus: 1 }}{% endcapture %}

{% if collection and collection.all_products_count > 4 %}
  {% assign col = collection.handle %}
{% else %}
  {% assign col = product.collections.last.handle %}
{% endif %}

{% for tag in product.tags %}
  {% if tag contains 'meta-related-collection-' %}
    {% assign col = tag | remove: 'meta-related-collection-' %}
    {% assign collection = collections[col] %}
    {% capture limit %}{{ collection.products_count | plus: 1 }}{% endcapture %}
  {% endif %}
{% endfor %}
  
{% if col and collections[col].all_products_count > 0 %}
  <br class="clear" />
  <br class="clear" />
  <h4 class="title center">{{ 'products.product.related_items' | t }}</h4>

{% assign skip_product = product %}
  {% assign products = collections[col].products %}
  {% assign products_per_row = settings.products_per_row %}
  {% include 'product-loop' with settings.product_sidebar %}
{% endif %}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment