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

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

Hi @Charlo-007

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 %}

Product Category: {{ category }}

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

    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.