Liquid, JavaScript, themes, sales channels
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.
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.
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
Are you ready to take your business to the next level? Look no further than the latest ...
By SarahF_Shopify Apr 15, 2024We’re keeping the ball rolling to make sure you’re always ahead of the game. So buckle ...
By JasonH Apr 8, 2024Portrait of Stephen positioned next to an image of planet Earth, with the Stephen's World ...
By JasonH Mar 18, 2024