What Are Metafields
Shopify metafields are key-value pairs attached to products, variants, collections, customers, and orders. They let you store unlimited custom data without external databases.
A sustainable fashion brand needs carbon footprint tracking. With metafields, you store the data directly on the product and query via Storefront API. No external infrastructure needed.
How Metafields Work
Every metafield has a namespace (category) and key (name):
Namespace: "sustainability"
Key: "carbon_footprint_kg"
Value: "2.34"
Data types supported: string, integer, decimal, boolean, date, json, url, file.
Setting Up Metafields
Method 1: Admin UI - Go to Settings → Custom Data → Create Definition
Method 2: Bulk CSV - Use bulk operations to import multiple metafield values
Method 3: GraphQL API - Programmatic creation for developers
Real-World Use Cases
Dynamic Product Bundling: Store bundle components as JSON metafield, render dynamically
Conditional B2B Pricing: Store wholesale tier pricing, show to B2B customers
SEO Structured Data: Store recipe info, create schema.org JSON-LD automatically
Inventory Sync: Track WMS location, sync status, external SKU references
Querying Metafields
Use Storefront API to fetch:
product(handle: "wool-sweater") {
metafields(namespace: "sustainability", first: 10) {
edges { node { key value } }
}
}
Or in Liquid templates:
{{ product.metafields.sustainability.carbon_footprint_kg }}
Best Practices
- Use specific data types (not all strings)
- Follow namespace.key naming convention
- For complex data, use json type instead of multiple fields
- Private namespaces for sensitive data (not visible in Storefront API)
- Set read permissions appropriately
Common Pitfalls
Don't store variant-level options as metafields (use variant options instead). Don't duplicate data already in Shopify. Don't expect metafields to sync automatically with external systems—build sync jobs.
Performance Considerations
Metafields add ~100 bytes per field to product JSON. Avoid 100+ metafields per resource. Query only needed namespaces in GraphQL.
Frequently Asked Questions
Can I migrate existing custom data into metafields?
Yes. Use bulk operations or GraphQL batch mutations. Plan 2-4 weeks for 10,000+ products.
Are metafields included in storage quota?
No. They count toward resource limits but not file storage.
Can I query metafields from customer records?
Yes, identically. Store loyalty tier, referral code, subscription status.
What's the difference between metafields and custom attributes?
Metafields are Shopify's version. More flexible than WooCommerce, less than headless CMS.
How do I track metafield changes?
Use Admin API webhooks to log to your database.
Can I use metafields for multi-language data?
Yes, manually. Use translations.description_de, translations.description_fr, etc.