Shopify- How to show related products using meta fields without app
to show related products or custom product list within single product page, copy the below code and paste it in your blade template or custom liquid file and replace "related_products" with your custom meta field key.
<div class="related-products">
{% assign related_products = product.metafields.custom.related_products.value %}
<div class="related-products">
<h3>Related Products</h3>
<div class="related-products-list">
{% for recommended in related_products %}
<div class="related-product">
<a href="{{ recommended.url }}" class="related-product-link">
<div class="related-product-image">
{% if recommended.featured_image %}
<img src="{{ recommended.featured_image.src | img_url: 'medium' }}" alt="{{ recommended.title }}">
{% else %}
<img src="{{ 'no-image.png' | asset_url }}" alt="No image available">
{% endif %}
</div>
<div class="related-product-details">
<h4 class="related-product-title">{{ recommended.title }}</h4>
<p class="related-product-price">{{ recommended.price | money }}</p>
<form action="/cart/add" method="post" class="product-form">
<input type="hidden" name="id" value="{{ recommended.variants.first.id }}">
<button type="submit" class="btn-custom-sdd">Add to Cart</button>
</form>
</div>
</a>
</div>
{% endfor %}
</div>
</div>
</div>
Comments
Post a Comment