I am building an ionic app with Woocommerce.
I have seen some stackoverflow questions on this but they are actually not answering the question so I am raising this again.
I have been able to send order to the database but I need to add one more meta to the database and this data is the most important.
According to this link, the meta property is readonly hence not usable.
I want to know how I can achieve this either by adding extra parameter to the order line_item
or by some wordpress or web hook.
I am using a JS implementation with WooCommerce API V3.
To save a metadata to a line_item (product that is in a order), you can hook the
woocommerce_new_order_item
action.Hook it like this:
As you said that you using the WC API, you maybe want to add this field to the API return... to do it, use the following code:
Now your API will return the
_my_metadata
with the line item.PS.: If you don't save your custom metadata with the
_
, WC will show the metadata in some places that you may not want to. With the_
the metadata will be hidden.