Yes this is possible using a custom function hooked in woocommerce_add_order_item_meta
action hook.
add_action('woocommerce_add_order_item_meta','adding_custom_data_in_order_items_meta', 1, 1 );
function adding_custom_data_in_order_items_meta( $item_id, $values, $cart_item_key ) {
// The corresponding Product Id for the item:
$product_id = $values[ 'product_id' ];
$custom_meta_value = $values['my_custom_field1_key'];
// or $custom_meta_value = $_POST['my_custom_field_key'];
// or $custom_meta_value = get_post_meta( $values[ 'product_id' ], '_some_meta_key', true );
if ( !empty($custom_meta_value) )
wc_add_order_item_meta($item_id, 'custom_meta_key', $custom_meta_value, true);
// And so on …
}
But as your question is not detailed and you are not showing any code related to how this custom data is set in your products or passed to the cart object, is not possible to help more that that.
Update related to your answer: (See in the linked answer with a working real example):
Adding user custom field value to order items details
So, as in this linked answer, you will need to create first a product attribute because in your code, wc_add_order_item_meta($item_id, 'The Meta', $the_meta );
is not correct as the second argument has to be a meta_key
slug without uppercase and space characters, so 'The Meta'
is not convenient and not recommended...
This product attribute creation name will be (regarding your answer code): 'The Meta'
and the slug 'the_meta'
.
Then you will have to set it in each related product with a mandatory value (just any value, as this value is going to be replaced by your custom value below).
So once done, your code will be:
add_action('woocommerce_add_order_item_meta','adding_custom_data_in_order_items_meta', 10, 3 );
function adding_custom_data_in_order_items_meta( $item_id, $values, $cart_item_key ) {
if ( isset($values['meta1']) && isset($values['meta2']) ) {
$custom_value = $values['meta1'] . '.' . $values['meta2'];
wc_add_order_item_meta($item_id, 'pa_the-meta', $custom_value );
}
}
Then you will get this kind of display in your Orders items ('XXXX' is your custom value here):
The Meta: XXXX