Hello Andre,
If you can query the product ID, then query the post_author for the products post ID. That’s the vendor. From there, the world is yours!
function my_custom_orders_api_fields($payload) {
$post = $order->id;
$items = $order->get_items();
foreach ( $items as $item ) {
$product_id = $item['product_id'];
}
$vendor_id = get_post_field( 'post_author', $product_id );
$shop_name = get_user_meta( $vendor_id, ‘pv_shop_name’, true );
$payload[‘loja’][‘nome’] = $shop_name;
return $payload;
}
add_filter( ‘woocommerce_api_order_response’, ‘my_custom_orders_api_fields’,