How to Display a Variant Metafield Value in the Cart?

I want to display a variant metafield value in the cart when a product is added. A variant metafield (not a product metafield) has been created in Shopify Admin → Settings → Custom Data → Variants, but I’m not sure how to make this value appear in the cart.

How can I pass the metafield value to the cart and display it correctly?

Should I use product properties in the form, or is there another way to achieve this?

Any help would be greatly appreciated! :rocket:

Hi @SEMRAA making a variants metafield show in the cart typically requires an advanced theme customization modifying the cart templates and or the themes javascript too.

Some themes may have settings or blocks for the cart that would let you use a dynamic source :bomb: BUT that would be more for store level metafields.

Grossly this is because the cart templates don’t really ingest variants data because when a variant is put in a cart it is an “item” in the architecture.

This is the same reason a collection metafield isn’t a dynamic source in product templates.

If you need this customization for the themes cart then contact me for services.
Contact info in forum signature.
ALWAYS please provide context, examples: store url, theme name, post url(s) , use case and business logic, or any further detail in ALL correspondence.

Thanks for your response!

I understand that Shopify’s cart system doesn’t automatically process variant metafields and that implementing this in the cart may require custom theme modifications.

For additional context:

Store URL: I prefer to keep it private.

Theme Name: [Your theme name, e.g., “Dawn Theme”]

What I have tried so far:

Passed the metafield value as a properties field in the product form like this:


Attempted to display it in cart.liquid using:

{%- if item.properties["Workshop Konumu"] != blank -%}
  

**Workshop Location:** {{ item.properties["Workshop Konumu"] }}

{%- endif -%}

Checked if the metafield exists in the product variant using Liquid.

Despite these attempts, the value still does not appear in the cart.

My goal is to display a variant metafield value in the cart, as it contains important information (e.g., workshop location).

Before considering custom theme modifications, is there an alternative approach I should try?

I would appreciate any further guidance!

No it’s not the goal is to show a line item property, that in turn uses a variants metafield value as it’s value.

Step back and go through the very separate and distinct parts:

  • First make sure the variant metafield is even working by just trying to statically show it’s value on a page , no input involved.
  • Then make sure a line item property works with static text, no metafield involved.
  • More than likely you not associating the input with the actual product form.
  • Associate an input to a form either by the input being a child of the form, or using the form attribute on with the form ID.

Good Luck.

You’re absolutely right; the goal is to dynamically show a line item property that pulls a variant’s metafield value. I followed the steps you mentioned and successfully got the metafield value to show in the cart, but I ran into a problem with dynamic updates. Here’s what I did and where I’m stuck:

What Works So Far:

1.Confirmed the Variant Metafield Works

I successfully displayed the metafield value on the page (statically).

2.Confirmed Line Item Properties Work

I added the following hidden input inside the product form in PageFly:


This correctly passes the metafield value to the cart.

The Issue:

The first time a variant is selected, the correct Workshop Konumu (location) metafield value is stored and sent to the cart.

But when a new variant is selected, the form doesn’t update dynamically. Instead, it keeps the previous location value in the hidden input.

This means that the cart always receives the first selected variant’s metafield value, rather than updating it with each selection change.

Possible Causes (Based on Your Advice)

The input is inside the form, so it should be properly associated.

The issue seems to be that PageFly does not dynamically update the input’s value when the variant selection changes.

This might be due to how PageFly handles forms—perhaps it’s not fully re-rendering the input when a new selection is made.

What I Need Help With:

How can I force the hidden input’s value to update dynamically each time a variant is selected, ensuring that the cart receives the latest metafield value?

Would adding an event listener in JavaScript that updates the input value when a new variant is selected be the best approach?

Thanks for any insights!