How can i create a button that appears/dissapears based on a metafield value being given?
I can achieve this with text/ links, however as soon as i try to style a button, no matter which way i try, the button remains (I’m using Dawn Theme.) Heres what i’m trying to achieve:
{% if product.metafields.custom.b2b_buy_now_button != blank %}
{% endif %}
i’ve searched all over and can’t find the answer.
Thanks so much for any help!
@SurfBumStanley Hi, I hope you are doing well.
look like your code is correct. could you share the screenshot what was the exaclty output you need.
Hi @SurfBumStanley
I checked the code and it seems fine, but I don’t know why it’s not working. Can you tell me where you added the code and share with me the screenshot of your product metafield?
So I need a button where i can input a URL to a different B2B platform. (kind of like an Add to cart button, but with links i specify. I’m using metafields with individual URLS to direct, and not all products will have a link.
The problem is, the button always shows if i wrap it in a div, even with no value in the product metafield.
Thanks for looking! I’ve been searching everywhere for a solution but can’t see anything similar. The gold button is the one i’ve manually added.
If the metafield type is a boolean it should only be {% if product.metafields.custom.b2b_buy_now_button %}
there’s also {% if product.metafields.custom.b2b_buy_now_button**.value** != blank %}
Additionaly validate the metafield is what you think it is and just output it directly
“
b2b_buy_now_button : {{ product.metafields.custom.b2b_buy_now_button }}
”
or again try with .value.
Thanks Paul, it’s not a boolean as such, just a different URL for each product. I’ll have a play with the other output method although have already tried something similar which resulted in the same problem I was having before.