Metafields across all products (existing and new)

wealthman
New Member
6 0 0

I would like to add a metafield to all products - existing products will get it when I add the metafield, and future products should automatically have the metafield with the default value when created.

I added an app that seemed to allow adding a "global" metafield across products, but when I created a new product, it didn't have that metafield.

Is this possible or does the metafield needed to be added to each future product when it is created.

I essentially want to change the "schema" for all products.

 

Replies 2 (2)

LitExtension
Shopify Partner
4860 1001 1135

Hi @wealthman

You can use this snippet like this to solve your problem.

{%- assign data = product.metafields.accentuate.your_name_space != blank -%}

    {{ data }}

{% else %}

    {{ default_data }}

{% endif %}

Hope this helps.

LitExtension - Shopping Cart Migration Expert
Check out our Shopify migration app to migrate your online store to Shopify
wealthman
New Member
6 0 0

My problem is more on the data storage and assignment side and less on the front-end display.

If I had a database with a table for products, I would add a column to handle the new field; and that field would be available to all products in future for assignment.

In contrast, it seems the metafields have to be assigned to any new products when they are created. It seems inefficient if every product needs to have that metafield.

I'm not sure, but I think the answer lies around "global" metafields. I can't find any information on this though, except for what 3rd party apps cover.

This resources by Shopify doesn't mention anything about global metafields @ https://shopify.dev/docs/admin-api/rest/reference/metafield