Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Hello, I need to insert a condition only when metafield Vendor is used. I'll be more specific. I created this code on product page in order to create a link to the vendor page:
{%- when 'text' -%} <p class="brand-product-page product__text{% if block.settings.text_style == 'uppercase' %} caption-with-letter-spacing{% elsif block.settings.text_style == 'subtitle' %} subtitle{% endif %}" {{ block.shopify_attributes }}> <a href="/collections/{% if block.settings.text contains "&" %}{{ block.settings.text | replace: "'", "" | replace: "ò", "o" | replace: "à", "a" | replace: " & ", "-" | downcase }}{% elsif block.settings.text == "EDG" %}enzo-de-gasperi{% else %}{{ block.settings.text | replace: " ", "-" | replace: "'", "" | replace: "ò", "o" | replace: "à", "a" | downcase }}{% endif %}"> {{- block.settings.text -}} </a> </p>
The code works, but of course every time i insert a text section it add a link, so I wanted to add a condition on metafield vendor, because this code is used for text with metafield vendor. I tried to use:
{% if product.metafields.vendor %}{% endif %}
But it give me an error, I suppose "product.metafields.vendor" does not extist, could you help me? Thank you
Do you have a meta field called vendor?
If you are using the vendor field given by Shopify (on the right sidebar of the product page), then it's not a meta field. It's just a vendor field. You can access it via {{ product.vendor }}
so
{% if product.vendor %}{% endif %}
If you have found the answer helpful, please like my reply and mark the question as solved. Thank You.
A metafield requires Namespace and key, you just have a ".vendor" so it is an incorrect format, see my attachment.
"global" is namespace and "vendor" is key, to get its value use this code:
{{ product.metafield.global.vendor.value }}
Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025Learn how to increase conversion rates in every stage of the customer journey by enroll...
By Shopify Mar 5, 2025