Shopify is a powerful eCommerce platform that provides many features to manage your online store. One of the most flexible tools Shopify offers is Metafields, which allows you to store and manage custom data for products, orders, customers, and other resources. In this article, we will walk you through the basic steps to set up and use Shopify Metafields to store custom data for your store.
What Are Shopify Metafields?
Shopify Metafields are custom fields that allow you to store extra information beyond what is provided by Shopify by default. They can be used to store additional data for products, orders, collections, and customers, enabling you to add unique and specific information that fits your business needs.
For example:
-
Product Data: Material type, size guides, additional specifications.
-
Order Data: Gift messages, special instructions.
-
Customer Data: Loyalty points, custom preferences.
These metafields consist of three parts:
- Namespace: This groups the metafield (e.g., “custom_fields”).
- Key: The unique name for the metafield (e.g., “material_type”).
- Value: The actual data or information you wish to store (e.g., “Cotton”).
Step 1: Understanding Shopify Metafields
Before diving into adding and using metafields, it’s important to understand the structure of a metafield. Each metafield in Shopify is composed of three main elements:
- Namespace: A category or label to organize your metafields. Think of it as a folder to group similar types of data together (e.g., product_details, custom_fields).
- Key: A unique name for the metafield, which identifies the specific data you're storing (e.g., material_type, care_instructions).
- Value: The actual information you want to store in the metafield (e.g., “Cotton,” “Machine wash cold”).
Step 2: Creating Metafields in Shopify
To get started with Shopify Metafields, follow these basic steps to create custom fields that you can store your data in.
1. Log in to Shopify Admin
-
Go to your Shopify Admin Panel at www.shopify.com and log in to your store.

2. Navigate to the Resource You Want to Add Metafields To
Shopify allows you to add metafields to various resources such as products, collections, customers, orders, and more. Let’s start with a product:
-
From the Shopify Admin, click on Products.

3. Choose the Item to Add a Metafield To
-
Select a product that you want to add custom data to, for example, “Black t shirt”

4. Find the Metafields Section
-
Scroll down on the product details page to find the Metafields section. If it is not visible, you may need to enable it by clicking Add definition.

5. Create a New Metafield Definition
-
Namespace: Give your metafield a category name, such as custom_fields.
-
Key: Define the unique key for the metafield, such as material_type.
-
Type: Choose the type of data you're storing (e.g., Text, Number, Boolean, etc.).
-
Save the metafield definition.

Step 3: Adding Custom Data to Your Metafield
Once you have created the metafield definition, you can add the actual data.

1. Enter Data for the Metafield
For the product you’ve chosen, you can now add data for the metafield. For example:
-
For material_type, enter “Cotton”.
-
For care_instructions, you might enter “Machine wash cold, tumble dry low”.
2. Save Your Changes
Once you've entered the necessary data, click Save to save the information.

Step 4: Displaying Metafields on Your Storefront
The next step is displaying the metafield data to your customers on your storefront. To do this, you will need to add Liquid code to your theme files.
1. Access Your Theme Files
-
Go to Online Store > Themes in your Shopify Admin.
-
Click Actions > Edit Code on the theme you are using.


2. Locate the Template File
To display metafields on product pages, you will most likely need to modify the product template.
-
In the theme editor, search for the file product.json (or a similar file) located under the Sections or Templates directory.

3. Insert Liquid Code to Display the Metafields
Now that you’re in the template file, you can add the following Liquid code to display your custom data.
Example:
{{ product.metafields.custom.custom_fields }}
For example, to display the material type and care instructions for the product, add the following code:
<p> Material: {{ product.metafields.custom_fields.material_type }} </p>
<p> Care Instructions: {{ product.metafields.custom_fields.care_instructions }} </p>
This will display the material type (e.g., Cotton) and care instructions (e.g., Machine wash cold, tumble dry low) on the product page.
4. Save and Preview the Changes
After adding the code, save the changes and preview your product page on your storefront. You should now see the custom metafield data being displayed.
Step 5: Example of Storing and Displaying Custom Product Information
Let’s go through a full example of adding and displaying custom product information using Shopify Metafields.
1. Create Metafields for Custom Product Information
-
Go to Products > Add product (or choose an existing product).
-
Under the Metafields section, click Add definition.
-
Create two metafields:
-
Namespace: custom_fields
-
Key: material_type (Type: Text)
-
Key: care_instructions (Type: Text)
2. Enter Custom Data for the Product
-
Material Type: Cotton
-
Care Instructions: Machine wash cold, tumble dry low
3. Display the Data on the Product Page
In your theme files ( product-template.liquid ), add this code to display the metafields:
Example:
<p> Material: {{ product.metafields.custom_fields.material_type }} </p>
<p> Care Instructions: {{ product.metafields.custom_fields.care_instructions }} </p>
Save the changes and preview your product page. The metafields data should appear on the frontend.
Step 6: Using Shopify Metafields for Orders and Customers
You can also use metafields to store custom data for orders and customers.
1. Create Metafields for Orders
-
Go to Settings > Metafields.
-
Choose Orders from the list and click Add definition.
-
Add a metafield such as:
-
Namespace: order_details
-
Key: gift_message (Type: Text)
2. Add the Gift Message to an Order
-
Go to Orders in Shopify Admin.
-
Select an order and add the gift message (e.g., "Happy Birthday!").
3. Display the Gift Message on the Order Confirmation Page
To show the gift message on the order confirmation page, add the following code to the order confirmation template:
Example:
<p> Gift Message: {{ order.metafields.order_details.gift_message }} </p>
Best Practices for Using Shopify Metafields
- Stay Organized: Use a consistent naming convention for your namespaces and keys (e.g., product_details, order_notes) to avoid confusion.
- 2. Choose the Right Data Type: Always choose the appropriate data type (Text, Number, Date) based on the kind of information you're storing.
- Keep Data Clear and Relevant: Don’t overload your store with unnecessary metafields. Store only essential and relevant data.
- Validate Data: Ensure the data entered into metafields is accurate before displaying it on the storefront.
Conclusion
Shopify Metafields are a powerful way to store custom data for your store, products, orders, and customers. By following the steps outlined in this article, you can start adding and displaying important custom information, making your store more tailored to your business needs and providing a better shopping experience for your customers.
Whether it’s adding extra product details, offering special customizations on orders, or keeping track of customer preferences, Shopify Metafields allow you to extend the functionality of your store without complex development.