How to Dynamically Hide Empty Metafield Sections, Blocks & Tabs in Shopify

How to Dynamically Hide Empty Metafield Sections, Blocks & Tabs in Shopify

mohammed_joynal
Shopify Partner
19 0 1

Want to hide empty sections, blocks, or tabs in Shopify? In this tutorial, I’ll show you how to use Liquid code to make sure only relevant content appears on your product pages.

🎥 Watch here: https://youtu.be/lmwSaVsbAB0

 

#Shopify #ShopifyTutorial #Ecommerce"

Reply 1 (1)

EcomGraduates
Shopify Partner
840 71 121

The key is to wrap each area that pulls in a metafield with an if statement that checks whether the metafield actually has a value 

exmaple

{% if product.metafields.custom.ingredients != blank %}
  <div class="product-tab">
    <h4>Ingredients</h4>
    <p>{{ product.metafields.custom.ingredients }}</p>
  </div>
{% endif %}

 

That way the whole block just doesn’t render if there’s no value. You can do the same for blocks in a section by adding a conditional check around the entire block or inside the block’s output.


 If this fixed your issue, likes and accepting as a solution are highly appreciated
|  Build an online presence with our custom-built Shopify Theme: EcomifyTheme
|  Check out our reviews: Trustpilot Reviews
|  We are Shopify Partners: EcomGraduates Shopify Partner