[Resolved] Add Custom Field to WooCommerce Order Details
This support ticket is created 5 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
Tell us what you are trying to do? I have added a custom field to each WooCommerce each using the Custom Fields in Types. This field has an image reference number. I would like that field to show with the product information on the order details. It could be in the email notification I get as store owner, or the order details in the dashboard. Whichever is easier.
Is there any documentation that you are following?
Where I get lost is that documentation seems to be related to adding a custom field to the order/checkout process. Which is not what I want or need. I have added a custom field to the product, which I use for administration and the customer does not see while placing their order. I want that field, however, to show up on the order email in the information about that particular product. It is my personal reference number (in this case it tells me where in my archives to find the specific image they are purchasing), different than a SKU (which is why I can't just use the SKU).
Your products have a custom field, and you want to display this custom field in the emails sent by WooCommerce about the order or in the admin dashboard on the order edit screen.
That really sounds like a question for WooCommerce, the only information that is really pertinent to Toolset is that you should know that Types stores custom fields in wp_postmeta with a 'wpcf-' prefix, otherwise they are like a native custom field.
If you aim to manipulate either the order edit screen or the order emails, the relevant sections of that link I provided before still seem appropriate.
What's missing is that you need to duplicate the custom field you store on the product in the order, so that it is available to the order edit screen or order emails.
You need to start at the section in that link with the text "Finally, let’s save the new field to order custom fields using the following code:".
The value of the custom field you save you need to retrieve from the product contained in the order. Here is an example of how to get the product id from the order id, which you can then use to retrieve your custom post meta for that product: https://stackoverflow.com/a/45124188/1180189
So there are a few pieces to put together, but that's what is involved.
I tried a couple things from that page and links but at this time implementing them seems above my skillset. I may need to pay someone to do it for me. Should we mark this ticket as closed?
Nigel is away for holidays, but I'll be happy to follow up on this ticket.
If you'd like to hire a professional to assist you with custom programming tasks, you can check out our list of recommended contractors at: https://toolset.com/contractors/
You're welcome to mark this ticket as resolved and open a new one for different question/concern.