New Shopify Certification now available: Liquid Storefronts for Theme Developers

Creating a clearance carousel based on a custom metafield attribute

InventoryHero
Shopify Partner
36 0 8

 

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 %}

 

 

 

Mike Belanger | Web & App Developer | UX Design & Marketing Specialist
InventoryHero - Automatically Discount Weak Inventory
https://apps.shopify.com/inventory-hero
https://inventoryhero.app

Ottawa, ON, Canada
Replies 3 (3)
Made4uo-Ribe
Shopify Partner
4243 981 1196

Hi @InventoryHero 

 

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 %}

 

Please don't forget to 

Like

 and 

Mark Solution 

to the post that helped you. Thanks!
Sip, savor, and support – your

Coffee Tip

 helps us keep coding magic.❤️❤️❤️
Need a knowledgeable developer? Come and visit us at

Made4uo.com


miguelmcunha
Visitor
3 0 0

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!

Made4uo-Ribe
Shopify Partner
4243 981 1196

Hi @miguelmcunha 

 

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?

Please don't forget to 

Like

 and 

Mark Solution 

to the post that helped you. Thanks!
Sip, savor, and support – your

Coffee Tip

 helps us keep coding magic.❤️❤️❤️
Need a knowledgeable developer? Come and visit us at

Made4uo.com