How to insert condition for metafield Vendor in code on product page?

How to insert condition for metafield Vendor in code on product page?

FrancescoMi89
Explorer
66 1 21

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

Replies 2 (2)

Lucid_Polygon
Shopify Partner
349 63 96

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.

- Was my reply helpful? Click Like to let me know!
- Was your question answered? Click Accept as Solution

James_FoxEcom
Shopify Partner
75 14 20

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 }}

James_FoxEcom_0-1669821645609.png

 

Find my answer helpful? Give it a like 🙂
Try Foxify now - #1 Conversion-focused page builder.
Proudly made by FoxEcom.com - Smart & hyperefficient front-end solutions for SMBs. Impact sales, costs, and revenue all at once.