SectionAI is free + 20K tokens if you're a The4 customer, Free plan is available Install App  

Header background

API show metafields for Product Variants

Annie

Written by Annie

Last updated

1082 views

On this page


This is a new feature added in the new update from EComus, Unsen, Kalles 4 and Gecko 6. Variant metafields can display different information depending on the selected variant. You can use the metafields object to display the information on you product page using simple Liquid code.

Step 1: Create metafield

Please click Settings > Custom data > Variants.

11.png

Click add definition.

  • Name: any name you want

  • Namespace and key: theme.variant

  • Select content type: select Single-line text or Multi-line text.

Please check this image:

12.png

You can follow this video to config it:

Step 2: Add metafield content to product variants

Click on Products > Variants > Edit. Then scroll the page to Metafields and fill the content that you want.

Step 3: Add to Theme customize

3.1. In the Product Information

To show Variants in the Product Information, go to Product Page > Product Main > add Custom Liquid Blocks.

Then paste this code liquid below.

Note: My namespace and key is "variant.metafields.theme.variant", you need to change your namespace and key here to show.

For Ecomus theme:

{%- if product.variants.size > 1 -%}
{%- assign selected_variant = product.selected_or_first_available_variant -%}
<hdt-varaint-toogle-info product-id="{{ product.id }}">
  {%- for variant in product.variants -%}
    {%- if variant.metafields.theme.variant != blank -%}
    <div variant-id="{{ variant.id }}"{% unless selected_variant.id == variant.id %} hidden{% endunless %}>
        {{ variant.title }}: {{ variant.metafields.theme.variant.value }}
    </div>
    {%- endif -%}
  {%- endfor -%}
</hdt-varaint-toogle-info>
{%- endif -%}

For Kalles, Unsen, Gecko theme:

{%- for variant in product.variants -%}

 {%- if variant.metafields.theme.variant != blank -%}

 <div data-variant-toggle="{{variant.id}}">{{variant.title}}: {{ variant.metafields.theme.variant }}</div>

 {%- endif -%}

 {%- endfor -%}
21.webp

Result:

3.2. In a Product Tab

To show Variants in the Product Tab, please add the Tab Custom Liquid block and paste this code below, you need to change the namespace and key by yours. With the product tabs, it requires this "data-variant-tab" code.

For Ecomus theme:

{%- if product.variants.size > 1 -%}
{%- assign selected_variant = product.selected_or_first_available_variant -%}
<hdt-varaint-toogle-info product-id="{{ product.id }}">
  {%- for variant in product.variants -%}
    {%- if variant.metafields.theme.variant != blank -%}
    <div variant-id="{{ variant.id }}"{% unless selected_variant.id == variant.id %} hidden{% endunless %}>
        {{ variant.title }}: {{ variant.metafields.theme.variant.value }}
    </div>
    {%- endif -%}
  {%- endfor -%}
</hdt-varaint-toogle-info>
{%- endif -%}

For Kalles, Unsen, Gecko theme:

{%- for variant in product.variants -%}

 {%- if variant.metafields.theme.variant != blank -%}

 <div data-variant-tab data-variant-toggle="{{variant.id}}">{{variant.title}}: {{ variant.metafields.theme.variant }}</div>

 {%- endif -%}

 {%- endfor -%}
31.webp

Result:

🎁 Exclusive Deals for The4 Customers

SectionAI

🤖 SectionAI – Build Sections with AI

Generate Shopify sections from text or wireframes.
The4 users get +20,000 bonus tokens when verifying their theme license.

  • ✅ No-code section builder
  • ✅ Works with your The4 theme
  • ✅ Build FAQs, banners, product grids & more
🚀 Try Free – Claim Tokens
EComposer

🎉 EComposer – Free 6-Month Plan

Build landing pages, sales funnels, and more with drag & drop.
The4 users get 6 months free (save $114).

  • ✅ 100+ templates ready to use
  • ✅ Build any Shopify page
  • ✅ No coding required
🔓 Get 6 Months Free

Enjoy a free 3-day trial. Then get your first month for $1. Try Now

We uses cookies to ensure you get the best experience on our website.