Solved

Short Code For Shopify Product Page ( Main-Product.liquid )

Savannah-Charlo
New Member
6 0 0

Hey!

 

I am currently utilizing the {{ product.metafields.eato.ISAC}} metafield to categorize our products, and we need assistance with implementing code to display specific categories based on this metafield.

 

Below are the criteria for the code:

 

  • If the {{ product.metafields.eato.ISAC}} metafield is equal to "BIO000000", the product category should be displayed as "General".
  • If the {{ product.metafields.eato.ISAC}} metafield is equal to "BIO023000", the product category should be displayed as "Adventurers".
  • If the {{ product.metafields.eato.ISAC}} metafield is equal to "BIO002010", the product category should be displayed as "American".

 

Thanks

Accepted Solution (1)

Xipirons
Shopify Partner
136 23 29

This is an accepted solution.

Hi @Savannah-Charlo 

 

Here's how you can display specific product categories based on the {{ product.metafields.eato.ISAC }} metafield value in Shopify Liquid:

 

 

{% assign isac_value = product.metafields.eato.ISAC %}

{% if isac_value == "BIO000000" %}
  {% assign category = "General" %}
{% elsif isac_value == "BIO023000" %}
  {% assign category = "Adventurers" %}
{% elsif isac_value == "BIO002010" %}
  {% assign category = "American" %}
{% else %}
  {% assign category = "Other" %}
{% endif %}

<p>Product Category: {{ category }}</p>

 

 

Here's how it works:

  1. We first assign the value of the {{ product.metafields.eato.ISAC }} metafield to a variable called isac_value using the assign tag
  2. We then use an if/elsif/else statement to check the value of isac_value:
    • If it equals "BIO000000", we assign "General" to the category variable.
    • If it equals "BIO023000", we assign "Adventurers" to the category variable.
    • If it equals "BIO002010", we assign "American" to the category variable.
    • If it doesn't match any of the above, we assign "Other" to the category variable.
  3. Finally, we output the value of the category variable inside a <p> tag to display the product category.

You can place this code in your product template file (e.g. product.liquid) where you want to display the category.

 

Make sure to replace eato with your actual metafield namespace if it's different.
 
This code will check the value of the {{ product.metafields.eato.ISAC }} metafield and display the corresponding category based on the specified criteria.

Was this helpful? Like or Accept solution - Buy me a coffee
- Contact me: Xipirons | WhatsApp
- Shopify Developer based in France, helping online merchants succeed

View solution in original post

Reply 1 (1)

Xipirons
Shopify Partner
136 23 29

This is an accepted solution.

Hi @Savannah-Charlo 

 

Here's how you can display specific product categories based on the {{ product.metafields.eato.ISAC }} metafield value in Shopify Liquid:

 

 

{% assign isac_value = product.metafields.eato.ISAC %}

{% if isac_value == "BIO000000" %}
  {% assign category = "General" %}
{% elsif isac_value == "BIO023000" %}
  {% assign category = "Adventurers" %}
{% elsif isac_value == "BIO002010" %}
  {% assign category = "American" %}
{% else %}
  {% assign category = "Other" %}
{% endif %}

<p>Product Category: {{ category }}</p>

 

 

Here's how it works:

  1. We first assign the value of the {{ product.metafields.eato.ISAC }} metafield to a variable called isac_value using the assign tag
  2. We then use an if/elsif/else statement to check the value of isac_value:
    • If it equals "BIO000000", we assign "General" to the category variable.
    • If it equals "BIO023000", we assign "Adventurers" to the category variable.
    • If it equals "BIO002010", we assign "American" to the category variable.
    • If it doesn't match any of the above, we assign "Other" to the category variable.
  3. Finally, we output the value of the category variable inside a <p> tag to display the product category.

You can place this code in your product template file (e.g. product.liquid) where you want to display the category.

 

Make sure to replace eato with your actual metafield namespace if it's different.
 
This code will check the value of the {{ product.metafields.eato.ISAC }} metafield and display the corresponding category based on the specified criteria.

Was this helpful? Like or Accept solution - Buy me a coffee
- Contact me: Xipirons | WhatsApp
- Shopify Developer based in France, helping online merchants succeed