Display product metafield value in cart drawer

Hi community!

We have a store where many products are made to order and we want to display a custom availability message:

  • on the product page above the Add to Cart / Buy Now buttons (DONE via theme product template (Impulse theme))
  • in cart drawer under each cart item product title (NOT WORKING).

So I am trying to display a metafield value under each product title in the cart drawer using the following in cart-item.liquid:

<div class="cart__item-details">
<div class="cart__item-title">
<a href="{{ product.url }}" class="cart__item-name">
{{ product.product.title }}
</a>
**{{ item.product.metafields.custom.product_availability.value }} xxx**

The metafield value does not display. The ‘xxx’ displays exactly where we want the metafield data to display.

If I change cart type to ‘page’ and edit main-cart.liquid then I can get the metafield value to display successfully like this:

<div data-products class="cart__page-col">
{% for item in cart.items %}
{%- render 'cart-item', product: item -%}
**{{ item.product.metafields.custom.product_availability.value }}**
{%- endfor -%}
</div>

However it renders the metafield value in a weird place as appears below, not inside, the item rendered section. It appears in between each product in the cart.

We would much prefer to keep cart drawer though anyway. But next best option would be to revert to cart page if we can work out how to display the metafield value just under the cart item title.

Is it actually possible to display metafield values within Cart Drawer? Or are we doing it wrong?

Thank you!

Have you figured this out @AndrewCal ?

I did get it to work on the Impulse Theme 7.2.0.

If you want your product metafield to show up under the title:

  1. In cart_item.liquid search for:
{{ product.title }}
  1. Under {{ product.title }} add:
{% if product.product.metafields.namespace1.key1 %}
{{ product.product.metafields.namespace1.key1 }}
{% endif %}

I made mine conditional since not all my products have this metafield.

Notice the product.product at the beginning of the metafield declaration.
This is what actually misled me at first since I was using item.product.

The way Impulse is coded, you have to use product.product instead.

In the main_cart.liquid you can see that they use the variable product for the value item.

{%- render 'cart-item', product: item, sizes: '150px', -%}

I hope this can help anyone looking to add metafields to their cart page or cart drawer on Impulse.

Thanks David, this helped we work out it also works if you want to display a variant metafield in cart - prefix with product:

product.variant.metafields.namespace.key.value