Skip to content

Commit

Permalink
feat: add dokan_get_vendor_by_product function (#510)
Browse files Browse the repository at this point in the history
  • Loading branch information
saimonh3 authored and sabbir1991 committed Jan 10, 2019
1 parent 51f2338 commit b248c1d
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions includes/product-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -554,3 +554,31 @@ function dokan_bulk_product_status_change() {
}

add_action( 'template_redirect', 'dokan_bulk_product_status_change' );

/**
* Dokan get vendor by product
*
* @param int|object $id Product ID or Product Object
*
* @since 2.9.8
*
* @return object
*/
function dokan_get_vendor_by_product( $id ) {

if ( ! $id ) {
return null;
}

if ( $id instanceof WC_Product ) {
$id = $id->get_id();
}

$vendor_id = get_post_field( 'post_author', $id );

if ( ! $vendor_id ) {
return null;
}

return dokan()->vendor->get( $vendor_id );
}

0 comments on commit b248c1d

Please sign in to comment.