Shopify themes, liquid, logos, and UX
Hi guys,
I'm trying to create a custom section on my homepage to create a clearance carousel for any products that have the meta field "invhero_discounted_product" set to "true". But, despite having a product with that attribute, my homepage carousel is still blank.
<h2>Clearance</h2>
{% for product in all_products %}
{% if product.metafields.custom.invhero_discounted_product.value == true %}
<div class="carousel-item">
<img src="{{ product.image.url }}" alt="{{ product.title }}">
<div class="carousel-caption">
<h3>{{ product.title }}</h3>
<p>{{ product.price }}</p>
<a href="{{ product.url }}" class="btn btn-primary">View Product</a>
</div>
</div>
{% endif %}
{% endfor %}
You use the all_product wrong. Please refer to the documentation here.
Instead of using all_product, I would suggest to create a collection and add those products in your collection.
The below reference code has the collection named "sample collection"
{% for product in collections['sample-collection'].products %}
{% if product.metafields.custom.invhero_discounted_product.value == true %}
<div class="carousel-item">
<img src="{{ product.image.url }}" alt="{{ product.title }}">
<div class="carousel-caption">
<h3>{{ product.title }}</h3>
<p>{{ product.price }}</p>
<a href="{{ product.url }}" class="btn btn-primary">View Product</a>
</div>
</div>
{% endif %}
{% endfor %}
Hi!
I was just wondering if this
'sample-collection'
can be a variable from a metafield and if it is a product metafield and the carousel is in a product page (for product A let's assume) how would make the carousel present the products in the collection refered in product A's metafield?
Thanks in advance!
Sorry your question seems to be far different from the original question. Mind posting a new question so it helps other people as well with the same query as you?
User | RANK |
---|---|
186 | |
168 | |
80 | |
55 | |
45 |
Transform this holiday season into a shopping spree. Plus, learn how to effortlessly open ...
By Jasonh Dec 8, 2023Make the shift from discounts to donations, and witness your business not only thrive fina...
By Holly Dec 4, 2023On our Shopify Expert Marketplace, you can find many trusted third party developers and fr...
By Arno Nov 27, 2023