Shopify themes, liquid, logos, and UX
Hi all,
I'm trying to use a product metafield as a "condition" to do some formatting on collection pages. Here's my set up:
Each product has a metafield of "product type". The field is: metafields.custom.prod_format. This is set up as a drop down list that allows me to pick the specific type of project. Only one selection is allowed.
On collections pages, I want some additional metafields to be displayed if the prod_format = "Merchandise". For everything else, a slightly different set of data and formatting.
Here's my code from the card-product.liquid file
{% if card_product.metafields.custom.prod_format == "Merchandise" %}
<p> Product Series:</br>
{{ card_product.metafields.custom.series }} </p>
{% else %}
<p><b> {{ card_product.metafields.custom.series | metafield_text }} Book #
{{ card_product.metafields.custom.number_in_series }}</b></p>
<p><i> {{ card_product.metafields.custom.tagline }} </i></p>
{% endif %}
From what I can tell my issue is in how the card_product.metafields.custom.prod_format is returning because it never hits a situation where the first "if" condition is true. So, despite products having that field set correctly, it never formats those products correctly in the grid. It always formats them in the "else" condition.
When I return card_product.metafields.custom.prod_format in text I get [Merchandise] and not Merchandise, unless I use the | metafield_text tag at the end.
So I'm guessing that the If/else process is seeing [Merchandise] as the value and not Merchandise.
How do I write this so it evaluates correctly?
I've tried:
Nothing works so that the first condition is true.
Any thoughts?
Thanks in advance.
-Justin
Solved! Go to the solution
This is an accepted solution.
I just solved this.
The [value] lead me to think that it was returning an array value.
When I looked, I'd set up the metafield as a "list" instead of a single value. So it WAS an array value after all.
Once I recreated the metafield as a "single value" field...altered the code to reflect the new value it worked.
#facepalm
So yeah. Problem solved.
This is an accepted solution.
I just solved this.
The [value] lead me to think that it was returning an array value.
When I looked, I'd set up the metafield as a "list" instead of a single value. So it WAS an array value after all.
Once I recreated the metafield as a "single value" field...altered the code to reflect the new value it worked.
#facepalm
So yeah. Problem solved.
Starting a B2B store is a big undertaking that requires careful planning and execution. W...
By JasonH Sep 23, 2024By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024