I need to add custom column for order items and show specific product meta in this column.
I mean something like image below,
I can't find any action from woocommerce to add this column!
Asked
Active
Viewed 9,935 times
2

LoicTheAztec
- 229,944
- 23
- 356
- 399

Mo Saeedi
- 575
- 1
- 5
- 15
2 Answers
12
You can use the following code:
// Add custom column headers here
add_action('woocommerce_admin_order_item_headers', 'my_woocommerce_admin_order_item_headers');
function my_woocommerce_admin_order_item_headers() {
// set the column name
$column_name = 'Test Column';
// display the column name
echo '<th>' . $column_name . '</th>';
}
// Add custom column values here
add_action('woocommerce_admin_order_item_values', 'my_woocommerce_admin_order_item_values', 10, 3);
function my_woocommerce_admin_order_item_values($_product, $item, $item_id = null) {
// get the post meta value from the associated product
$value = get_post_meta($_product->post->ID, '_custom_field_name', 1);
// display the value
echo '<td>' . $value . '</td>';
}
I've commented it so it should be clear enough, but in a nutshell this code adds a custom column, named "Test Column", and this column pulls the value from the custom field of the product, called "_custom_field_name".

Marin Atanasov
- 3,266
- 3
- 35
- 39
-
Thanks,Thanks,Thanks..., you save me a lot of times! thanks again :D – Mo Saeedi Sep 03 '14 at 14:21
-
The only problem with this code is that it pulls in the current meta value of the product ... rather than the meta value that was (potentially) captured during checkout. – Garconis Jan 05 '17 at 15:08
-
@Marin Atanasov if i need to edit the custom meta value from the order line item, how can i do that? – Rezoan Oct 10 '20 at 04:57
-
Is there a way to also remove the default woocommerce columns, Cost, qty, total, tax? – Tassos Voulgaris Jul 14 '21 at 08:39
2
Since WooCommerce 3.0 you are not allowed to call the product_id directly. You need to replace this:
$product_id = $_product->get_id();
$value = get_post_meta($product_id, '_custom_field_name', 1);
This will do the trick and remove all errors and notices.

Antoine Henrich
- 180
- 1
- 13