Skip to content

Instantly share code, notes, and snippets.

@liamtarpey
Last active March 26, 2017 05:03
Show Gist options
  • Save liamtarpey/7a6385257cfd4cb0790c to your computer and use it in GitHub Desktop.
Save liamtarpey/7a6385257cfd4cb0790c to your computer and use it in GitHub Desktop.
Shopify Related Products
@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