Access Link Metafield using Custom Liquid on a Product Page

Topic summary

Issue: Couldn’t access values from a product metafield of type “link” in a Custom Liquid block to render multiple dealer/distributor buy buttons.

  • Context: Store used mainly as a catalog; up to five external buy buttons needed on product pages.

  • Symptoms: The metafield object existed and printed, but a for-loop over it produced no output. Attempted to use item.text and item.url directly without success.

  • Key detail: Shopify metafields with complex types (like link or lists of links) expose their usable data via the .value property. Iterating over the metafield object itself won’t yield items.

  • Solution: Loop over product.metafields.custom.featured_dealer_links.value.
    Example: {% for item in featured_links.value %}{{ item.text }}{% endfor %}.

  • Outcome: Buttons render correctly; values (item.url and item.text) are accessible when using .value in the loop.

  • Status: Resolved. No remaining open questions. Attachments (screenshots) were provided but not essential to the fix.

Summarized with AI on December 19. AI used: gpt-5.

Hello everyone, and thank you for taking the time for looking at my issue. I have a client who will be using Shopify as mostly a catalog, and we will be generating up to five different buy buttons that link directly to the product page for our featured dealers and distributors.

I have created a custom metafield, chose its type as link, and created some dummy data in a part. Then, I went to the theme customization panel (using a copy of Dawn) and added a custom liquid box to my product pages.

When I try to run a loop to output the buttons, I seem to not be able to access any of the values inside the link object. Basic error checking is showing the metafield exists, but I’m drawing blank on why I cannot seem to get access to the values themselves. If anyone has any idea what I’m doing wrong a helping hand would be greatly appreciated! Code below:

{% if product.metafields.custom.featured_dealer_links %}
  {{product.metafields.custom.featured_dealer_links }} <!-- this works and shows the object -->
  <h2>Test</h2>
  {% assign featured_links = product.metafields.custom.featured_dealer_links %}
  {% if featured_links %}
    <p>Metafield exists!</p> <!-- metafield exists triggers -->
  {% endif %}
  {% for item in featured_links %} 
    {{ item.text | link_to: item.url, class: 'button button--full-width' }} <--does not display -->
  {% endfor %}
{% endif %}

And some screenshots of the backend attached.

Thanks again for taking the time to look at my issue. I for the life of me cannot seem to access the values. It appears link is just a fancy JSON object… yet I’m drawing blank. Thanks again for your time, I’m sure I’ve overlooked something simple but I’m new to Shopify dev.

Update: SOLVED

After messing with my code further, I stumbled upon the solution. I hope this is helpful to anyone else using the link type in the future.

{% if product.metafields.custom.featured_dealer_links %}
 
  {% assign featured_links = product.metafields.custom.featured_dealer_links %}
  
    {% for item in featured_links**.value** %}
      <a href="{{ item.url}}" class="button button--full-width">{{ item.text }}</a>
    {% endfor %}
{% endif %}

My for loop turned out to be the issue. I had to add .value to featured_links! Once I did that, everything fell into place. I was able to access the values in the loop. I had earlier tried to add .value to the actual link/button, but it was actually needed right in the for loop.

2 Likes