Conditional display an element on product page

Conditional display an element on product page

PeakFlava
Visitor
2 0 0

I create a metafield fo promos to put on my product page.

 

some of my products hvae promos, others don't.

In the product page template on the theme editor, I added the offer block to display the metafield.

 

How do I add conditionoal logic on the element to display it only when there is something in the metafield?

 

thanks.

Replies 2 (2)

PaulNewton
Shopify Partner
7236 637 1499

Hi @PeakFlava to avoid code use an alternate template

https://help.shopify.com/en/manual/online-store/themes/os20/theme-structure/templates#create-a-new-t... 

For coding roughly it's {% if product.metafields.namespace.key.value != blank %} ... {% endif %}

Read the liquid docs here https://shopify.dev/api/liquid/objects/metafield 

 

 

If you need deeper customization then contact me for services
Contact info in forum signature.
ALWAYS please provide context, examples: store url, theme name, post url(s) , or any further detail in ALL correspondence.

Good Luck.

Contact paull.newton+shopifyforum@gmail.com for the solutions you need


Save time & money ,Ask Questions The Smart Way


Problem Solved? ✔Accept and Like solutions to help future merchants

Answers powered by coffee Thank Paul with a Coffee for more answers or donate to eff.org


PeakFlava
Visitor
2 0 0

Thanks Paul,

 

I found a way to do it with coding on the theme liquid file. I used a new template in the meantime until i figure it out.

 

Thanks again