I want to show some extra content only when my product has certain metafield values. The problem is that my conditional check isn’t working properly and the content shows up everywhere.
Main Product Template
{% if product.metafields.testimonial %}
{% include 'customer-feedback' %}
{% endif %}
Feedback Template (customer-feedback.liquid)
{% assign feedback = product.metafields.testimonial %}
{% assign writer = 'customer_name' %}
{% assign writer = 'customer_photo' %}
{% assign writer = 'detailed_review' %}
<div> Content appears here </div>
Can someone help me figure out what’s wrong with my logic? I have set up the testimonial metafields in my admin panel but the conditional statement doesn’t seem to work as expected.
yeah, namespaces can be tricky. I’d check if the metafield has actual content with {% unless product.metafields.testimonial.detailed_review == blank %}
. the blank check works way better than assuming the namespace exists. also, double-check your metafield keys match exactly what’s in admin - they’re case sensitive.
Your metafield namespace check is too broad. When you use {% if product.metafields.testimonial %}
, Shopify returns the entire namespace object even with empty field values, so your condition always evaluates to true. I hit this exact issue last month. Check for the specific metafield value instead of just the namespace. Try {% if product.metafields.testimonial.detailed_review %}
or whatever your actual metafield key is. Also, in your feedback template you’re assigning string values instead of actual metafield data. Should be {% assign writer = product.metafields.testimonial.customer_name %}
not {% assign writer = 'customer_name' %}
. Those quotes make it a literal string rather than pulling the metafield value.