Globally scoping product custom field

Highlighted
Tourist
5 0 1

I'm trying to render out some custom field data on a product but due to the way Shopify creates different urls for a single product I'm struggling with how to globally scope the custom field in my liquid template (I'm not a developer). 

 

I currently have a single product but it appears in multiple locations 

 

1. https://cuttingedgeknives.myshopify.com/products/masakage-yuki-bunka (The canonical version) 

2. https://cuttingedgeknives.myshopify.com/collections/masakage-yuki/products/masakage-yuki-bunka 

 

On the collections version (#2) I have custom fields rendering out content (Performance, Beauty etc) but they don't render out on the canonical version of the page and I'm not sure how to modify the custom field code below to scope the collection code to render on both versions of the page. 

 

Can anyone help and tell what I should be writing to get the product content rending on both versions of the product page? 

 

Many thanks!

 

Code posted is from a section include in my theme. 

 

{% if collection.metafields.custom_fields["performance"] != blank %}
	<h3 class="custom-field--title">Performance</h3>
  	{{ collection.metafields.custom_fields["performance"] }}
{% endif %}

{% if collection.metafields.custom_fields["beauty"] != blank %}
	<h3 class="custom-field--title">Beauty</h3>
	{{ collection.metafields.custom_fields["beauty"] }}
{% endif %}

{% if collection.metafields.custom_fields["comfort"] != blank %}
	<h3 class="custom-field--title">Comfort</h3>
	{{ collection.metafields.custom_fields["comfort"] }}
{% endif %}

{% if collection.metafields.custom_fields["durability"] != blank %}
	<h3 class="custom-field--title">Durability</h3>
	{{ collection.metafields.custom_fields["durability"] }}
{% endif %}

{% if collection.metafields.custom_fields["ease_of_care"] != blank %}
	<h3 class="custom-field--title">Ease of Care</h3>
	{{ collection.metafields.custom_fields["ease_of_care"] }}
{% endif %}

{% if collection.metafields.custom_fields["value_for_money"] != blank %}
	<h3 class="custom-field--title">Value for money</h3>
	{{ collection.metafields.custom_fields["value_for_money"] }}
{% endif %}
0 Likes
Highlighted
Shopify Partner
1197 162 323

You can get access to the collection object by looping through the products collections:

 

{% for collection in product.collections %}
  {% if collection.metafields.custom_fields["performance"] %}
    <h3 class="custom-field--title">Performance</h3>
    {{ collection.metafields.custom_fields["performance"] }}
    {% break %}
  {% elsif collection.metafields.custom_fields["beauty"] %}
    <h3 class="custom-field--title">Beauty</h3>
    {{ collection.metafields.custom_fields["beauty"] }}
    {% break %}
  {% endif %}
{% endfor %}

etc

If my solution helped you, please like and accept as solution!
If you'd like to make any edits to your store, please send me a personal message and we can discuss what you'd like to accomplish :D
0 Likes