Skip to content
Advertisement

Pass custom product meta data to the order in Woocommerce 3

In Woocommerce, I’m attempting to add a piece of custom meta to my products and I would like to pass it through to orders.

We have a substantial amount of products and they are accountable to different cost centers so I need a select box inside the product admin that we can choice the cost centers that passes a value into an order this does not need to be viewed by the customer but needs to be viewable by admin in the orders and also in the order exports each month for accounting.

This is what I have so far, this will display the select box in product edit pages (admin):

JavaScript

But it is not passing the value in to an order.

How can I pass this custom field value to the order?

Advertisement

Answer

I have revisited a bit your code. The following will save your product custom field “Cost centre” as hidden order item meta data, visible only in Admin Order edit pages on each item:

JavaScript

Code goes in functions.php file of your active child theme (or active theme). Tested and works.

enter image description here

Export: (In StackOverFlow, the rule is one question for one answer).

The WordPress/Woocommerce basic order export don’t allow to export order items

You will need to use a third party plugin and depending on the chosen plugin, you will have to add your order item custom field _cost_centre for your export based on the plugin possibilities.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement