Conversations about creating, managing, and using metafields to store and retrieve custom data for apps and themes.
Is there a way of creating custom fields for products, that would be available in order/create webhook? Product's metafields don't work because for the order webhook you can only get metafields assosiated to an order, not the products that the order consists of. That makes little sense to me as when would one add metafields to an order if the webhook is triggered instantly after the order is being created (after checkout).
I would think that this is fairly simple scenario... I have some extra information associated to each product. It's natural that I would like that information to be available in the order/create webhook.
Thanks for the feedback. At this time, you won't be able to drill down to product-specific metafields on orders because technically, they're line item resources. Feedback noted though, I'll pass that along!
Cheers.
Alex | Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit the Shopify Help Center or the Shopify Blog
Hi,
Any update on this issue? I really need to access to my products metafields within the orders/create webhook. Can you please update us on this matter?
Thanks
Yeah, the problem with line_itmes is that they don't exist before products are put to cart. Ok, so metafields aside, is there a way, any way to pass product's custom information to order/create webhook?
Hey Kamil,
Not at this time, unless you have enough control over the order creation to place line item properties on the line items to reflect the metafield values you want to include.
Alex | Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit the Shopify Help Center or the Shopify Blog
Hmm, seems to be the only way I guess. I'd need a piece of js on the checkout page to modify the cart (add properties to line_items) based on products' metafields. The problem with that though is that for each product I would have to do a separate request for it's metafields. In the docs I don't see an option to do a bulk request to fetch metafields of multiple products at once. Do you know if that's possible, Alex?
Unfortunately you're mostly correct in that you'll need to request each one individually using REST. I don't know how much it helps you, but you can at least get many product metafields at once usingthe GraphQL admin API:
{
products(first:50) {
edges {
node {
metafields(first:10) {
edges {
node {
key
value
valueType
}
}
}
}
}
}
}
Alex | Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit the Shopify Help Center or the Shopify Blog
Yeah, that is what I was afraid of. Actually you can use REST for obtaining all metafields of a given product (GET /admin/products/#{product_id}/metafields.json). Thanks anyway Alex. Please do concider of implementing a way to reach product's metafields from the order webhook (by setting the proper metafield_namespaces for webhook of course).
I just wanted to chime in and say I also really wish that product metafields were included in the order webhook response.
I have an idea for a workaround until they are available: use a hidden Product property, assigned on the product page, to hold the metafield. To do this, add a hidden input field that assigned the metafield value to a property on the line item. Something like this (my example uses a field called "internal_id" inside a namespace of "product_metadata"):
<input id="_internal_id" type="hidden" name="properties[_internal_id]" value="{{ product.metafields.product_metadata.internal_id }}">
Note that if you don't want this data to show on the Cart screen, you might need to change your template code to ignore certain properties (e.g. by ignoring anything that starts with an underscore). For more info, see Hide line item properties (optional) on this page.
In the webhook, each line item will have a properties array like so:
"properties": [{ "name": "_internal_id", "value": "abc123" }]
I have created the line item property, now I want to recieve it in order/fullfilled webhook, but I am getting empty properties array. It is showing on product page, but not able to recieve on webhook.
I found that "Send Test Notification" button does not send the custom line items, but if we create order like a user on store website so it does send. I don't know if shopify developers knows that or its a bug. Its not documented anywhere, so adding this comment, if anybody encounters same issue.
Thanks