The code below will add a custom column in order details view in the order items table like in the image below. If you have created a child theme then add the code in the function.php file of your child theme.
// Add custom column name in table header
add_action('woocommerce_admin_order_item_headers', 'my_woocommerce_admin_order_item_headers');
function my_woocommerce_admin_order_item_headers() {
// write column name
$column_name = 'Column A';
// display the column name
echo '<th>' . $column_name . '</th>';
}
// Add custom column values in table
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 custom field value using product id
$custom_field_Data = get_post_meta($_product->post->ID, '_custom_field_name', 1);
// print the value
echo '<td>' . $custom_field_Data . '</td>';
}
Great work!
ReplyDeletestay blessed and keep sharing awesome content.