Shopify Tutorials

How to Show Custom Data on Product Page using Metafield in Shopify

Hello Shopify Friends,

In this Shopify blog, we will learn How to Show Custom Data on Product Page using Metafield in Shopify.

Metafields in Shopify allow you to add custom fields to your products, allowing you to store and display additional information beyond the default product attributes in Shopify. Metafields allow you to display specialized information differently within your Shopify online store.

Let us learn how you can show custom data to a product page using Metafield in Shopify.

Steps to Show Custom Data on Product Page using Metafield in Shopify:

Step 1: Go to your Shopify admin, and in Shopify admin, click on Settings.

Step 2: After that, click on Custom data and go to Products metafield.

Step 3: Now click on Add definition.

Step 4: Fill up the name of metafield and select the type you want to add. Also, add a description if you want.

Step 5: After selecting the type of metafield, click on Storefronts to show that data in the online store, then Save it.

Step 6: Open any product on your admin, fill up the Metafields option, and Save it.

This is your namespace and key to show data on the product page.

Step 7: Click on the Online store, click Edit code, and search your main product page to add code.

Step 8: Add the below code in your product page 

{% if product.metafields.custom.custom_text.value  %}
     <p> {{ product.metafields.custom.custom_text.value }} </p>
{% endif %}

Step 9:  Now your output looks like the below screenshot

Conclusion:

By following these steps, you can create and utilize metafields to store and display custom data for your products in Shopify.

Related Article – How To Add Products To Shopify?

Share this tutorial to display custom data on the product page using Metafield in Shopify. Stay updated with us for more articles.

Happy Reading!

Click to rate this post!
[Total: 3 Average: 5]
Bharat Desai

Bharat Desai is a Co-Founder at MageComp. He is an Adobe Magento Certified Frontend Developer ? with having 8+ Years of experience and has developed 150+ Magento 2 Products with MageComp. He has an unquenchable thirst to learn new things. On off days you can find him playing the game of Chess ♟️ or Cricket ?.

View Comments

    • Yes, you can do with printing the namespace of the metafield and its value like below

      {% assign product_metafields = product.metafields %}
      {% if product_metafields.size > 0 %}

        {% for metafield in product_metafields %}
      • Namespace: {{ metafield.namespace }}
        Value: {{ metafield.value }}
      • {% endfor %}

      {% else %}

      No metafields found for this product.

      {% endif %}

      {{ metafield.namespace }} will display the namespace of the metafield.
      {{ metafield.value }} will display the value of the metafield.

Recent Posts

How to Add Tooltip in Checkout Shipping Field in Magento 2?

Hello Magento Friends, In today’s blog, I will explain How to Add Tooltip in Checkout…

1 day ago

How to Integrate and Use MongoDB with Laravel?

MongoDB is a popular NoSQL database that offers flexibility and scalability when handling modern web…

2 days ago

NodeJS | Callback Function

In NodeJS, callbacks empower developers to execute asynchronous operations like reading files, handling requests, and…

3 days ago

How to Show SKU in Order Summary in Magento 2?

Hello Magento Friends, In today’s blog, we will learn How to Show SKU in Order…

5 days ago

Best Colors to Use for CTA Buttons

The "Buy Now" and "Add to Cart" buttons serve as the primary call-to-action (CTA) elements…

1 week ago

Magento 2: How to Save Custom Field Value to quote_address for Multi-Shipping Orders

Hello Magento Friends, In Magento 2, the checkout process allows customers to choose multiple shipping…

1 week ago