Skip to content

Commit

Permalink
fix: add vendor info in restful wc_order is fixed #334 (#342)
Browse files Browse the repository at this point in the history
* fix: add vendor info in restful wc_order is fixed #334

* fix: rename function name
  • Loading branch information
saimonh3 authored and sabbir1991 committed Aug 13, 2018
1 parent 7fe9394 commit 8d41e63
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2756,3 +2756,35 @@ function dokan_pro_buynow_url() {
return $link;
}

/**
* Add vendor info in restful wc_order
*
* @param object $response
*
* @return object
*/
function dokan_add_vendor_info_in_rest_order( $response ) {
foreach ( $response as $data ) {
if ( isset( $data['line_items'] ) ) {
$product_id = $data['line_items'][0]['product_id'];
$author_id = get_post_field( 'post_author', $product_id );
}
}

$store = dokan()->vendor->get( $author_id );
$data = $response->get_data();

$data['store'] = array(
'id' => $store->get_id(),
'name' => $store->get_name(),
'shop_name' => $store->get_shop_name(),
'url' => $store->get_shop_url(),
'address' => $store->get_address()
);

$response->set_data( $data );

return $response;
}

add_filter( 'woocommerce_rest_prepare_shop_order_object', 'dokan_add_vendor_info_in_rest_order', 10, 1 );

0 comments on commit 8d41e63

Please sign in to comment.