Have your say in Community Polls: What was/is your greatest motivation to start your own business?

Can't link a metadata url with liquid code.

Solved

Can't link a metadata url with liquid code.

wordtothewriter
Visitor
2 0 0

I've been searching forums for answers all day with zero luck.

 

I have a client (an author) who wants Amazon links to her books on her Shopify store, and she wants the button to look like the "add to cart" button. 

 

I've created a metafield so I can input the appropriate link for each product. But I can't get the link to work in custom liquid with the metafield, only the direct Amazon URL. 

 

I've set up the metafield on Shopify: custom.amazon_link

 

Here's what I have:

 

{{ 'Buy on Amazon' | link_to: 'product.metafields.custom.amazon_link.value.', target: '_blank', class: 'button button--full-width' }}

 

I've tried it that way and without "value" and neither work.

 

What am I doing wrong???

Accepted Solution (1)

Platoria
Shopify Partner
13 1 6

This is an accepted solution.

Hii,
It looks like you're close, but the syntax for accessing metafield values and using them within a Liquid template can be a bit tricky.

{% if product.metafields.custom.amazon_link %}
  <a href="{{ product.metafields.custom.amazon_link }}" target="_blank" class="button button--full-width">Buy on Amazon</a>
{% endif %}

 

This should work as long as the metafield is correctly set up and contains a valid URL. If the button still doesn't work, make sure that the metafield custom.amazon_link is correctly populated with the appropriate Amazon URLs for each product.

On a related note, if you're struggling with gathering reviews, you might want to try Platoria. We provide real ratings and AI summaries of reviews for your products effortlessly even when you have NO REVIEWS. We've helped dozens of bookstores in the past so see you soon 🙂


 

- Platoria — Lacking Reviews? Display AI review summaries for products, even if they have ZERO reviews!
- Start with our Free Plan today

View solution in original post

Replies 3 (3)

Platoria
Shopify Partner
13 1 6

This is an accepted solution.

Hii,
It looks like you're close, but the syntax for accessing metafield values and using them within a Liquid template can be a bit tricky.

{% if product.metafields.custom.amazon_link %}
  <a href="{{ product.metafields.custom.amazon_link }}" target="_blank" class="button button--full-width">Buy on Amazon</a>
{% endif %}

 

This should work as long as the metafield is correctly set up and contains a valid URL. If the button still doesn't work, make sure that the metafield custom.amazon_link is correctly populated with the appropriate Amazon URLs for each product.

On a related note, if you're struggling with gathering reviews, you might want to try Platoria. We provide real ratings and AI summaries of reviews for your products effortlessly even when you have NO REVIEWS. We've helped dozens of bookstores in the past so see you soon 🙂


 

- Platoria — Lacking Reviews? Display AI review summaries for products, even if they have ZERO reviews!
- Start with our Free Plan today
wordtothewriter
Visitor
2 0 0

YOU ARE MY HERO!!! That worked perfectly. THANK YOU!!!!!!!

Platoria
Shopify Partner
13 1 6

🤠I'm really glad!!  Please make sure to mark my answer as 'Accepted Solution.' This will help other people facing similar problems as well.


- Platoria — Lacking Reviews? Display AI review summaries for products, even if they have ZERO reviews!
- Start with our Free Plan today