How to use meta field in shopify products

To create and display a metafield on a Shopify product, follow these steps. Shopify metafields let you store custom data for products, variants, collections, etc.


Step 1: Create a Metafield Definition

  1. Go to your Shopify Admin.

  2. Navigate to Settings > Custom data > Products.

  3. Click "Add definition".

  4. Fill in:

    • Name: e.g., "Author"

    • Namespace and key: e.g., custom.author

    • Content type: Choose the appropriate type (e.g., "Single line text", "URL", etc.)

  5. Choose whether it should appear in the product admin.

  6. Click Save.


Step 2: Add Metafield Value to a Product

  1. Go to Products in the Shopify Admin.

  2. Open any product.

  3. Scroll down to the Metafields section at the bottom.

  4. Enter the value for the field you created (e.g., "John Doe" for the Author).

  5. Save the product.


Step 3: Display the Metafield in the Theme

You’ll need to edit your theme files (via code) or use Online Store 2.0 features like dynamic sources in the theme editor.

Option A: Add via Theme Editor (OS 2.0 Themes)

  1. Go to Online Store > Themes.

  2. Click Customize on your current theme.

  3. Navigate to the Product page.

  4. Add a Text block or select an existing one.

  5. Click the Dynamic source icon (the database-looking symbol).

  6. Choose your metafield (e.g., Author).

  7. Save.

Option B: Add via Code

  1. Go to Online Store > Themes > Edit Code.

  2. Open your product template (usually sections/main-product.liquid or templates/product.liquid).

  3. Insert this where you want the metafield displayed:



{{ product.metafields.custom.author }}
  • Replace custom.author with your namespace.key.

  • Use conditional logic to prevent empty output:


{% if product.metafields.custom.author %} <p><strong>Author:</strong> {{ product.metafields.custom.author }}</p> {% endif %}




Post a Comment

0 Comments