Is there a way to hide a product page section based on a metafield value in Shopify 2.0?

Is there a way to hide a product page section based on a metafield value in Shopify 2.0?

KarissaN
Tourist
6 0 1

Hello,

I am updating my site to Shopify 2.0 and taking advantage of the sections available on a product page. I need the same sections on all with the exception of a handful. Is there a way to hide sections based on a metafield value?

 

Karissa

Replies 3 (3)

arshia_sheikh
Shopify Partner
80 17 20

Hi @KarissaN Hope you are doing Well 
Yes, You need to Wrap Section Html Inside Liquid Condition 

LitExtension
Shopify Partner
4914 1005 1182

Hi @KarissaN,

You need to go to the file containing the sections and add the following code. Example for 'Collection list' section, located in sections/collection-list.liquid file of Dawn theme.

Screenshot.png

Code:

{%- assign check = true -%}
{%- if request.page_type == 'product' and product.metafields.my_fields.value == 'value'-%}
  {%- assign check = false -%}
{%- endif -%}
{%- if check -%}

<!-- content section  -->

{%- endif -%}

with 'product.metafields.my_fields.value == value' is the condition of metafields.

Hope it is clear to you.

 

LitExtension - Shopping Cart Migration Expert
Check out our Shopify migration app to migrate your online store to Shopify
Contact us:
- Email: contact@litextension.com
cybko
Shopify Partner
44 0 10

This is great, but I have a follow up question.

If the section is like a text section, I assume it can't be hidden unless you hide *all* text sections based on a metafield, so how do you hide a specific text section? Can you do it in the json template?