Thank you @bcworkz , this resolved my issue! Here is the final code, for adding a costum response in woocommerce api that retrives data from a costum field for a order, where _team_name_field is the custom field used for this example:
add_filter( 'woocommerce_rest_prepare_shop_order_object', 'my_wc_prepare_shop_order', 10, 3 );
function my_wc_prepare_shop_order( $response, $object, $request ) {
$order_data = $response->get_data();
foreach ( $order_data['line_items'] as $key => $item ) {
$order_data['line_items'][ $key ]['Team_name'] = get_post_meta( $object->get_id(), '_team_name_field', true ) ;
}
$response->data = $order_data;
return $response;
}
-
This reply was modified 3 years, 8 months ago by tommyller.