Dokan Vendor Class

File: Vendor.php
Usage: includes/Vendor/Manager.php : 131
Namespace: namespace WeDevs\Dokan\Vendor;
Location : dokan-lite\includes\Vendor\Vendor.php

Dokan vendor class. The vendor class handles individual vendor data. Through this class, we set up, store, and find vendor information.

Note: Our vendor class instance in “dokan()->vendor->get()” Dokan vendor manager method. So, we will use this method to reach our vendor class methods.

Vendor Class Api #

  • Get single vendor data: #
dokan()->vendor->get( $vendor );
  • Check if is a vendor: #
dokan()->vendor->get( $vendor )->is_vendor();
  • Check if the selling capacity is enabled #
dokan()->vendor->get( $vendor )->is_enabled();
  • Check if the current vendor is a featured vendor. #
dokan()->vendor->get( $vendor )->is_featured();
  • Get current vendor shop information. #
dokan()->vendor->get( $vendor )->get_shop_info()
  • Get current vendor shop information. #
dokan()->vendor->get( $vendor )->get_info_part( $item );
  • Get current vendor orders. #
dokan()->vendor->get( $vendor )->get_orders( $args );
  • Get the total sales amount of the current seller. #
dokan()->vendor->get( $vendor )->get_total_sales();
  • Get the total earning amount of the current seller. #
dokan()->vendor->get( $vendor )->get_earnings( $formatted, $on_date );
  • Get the total balance of the current seller. #
dokan()->vendor->get( $vendor )->get_balance( $formatted, $on_date );
  • Get the raing info of current seller. #
dokan()->vendor->get( $vendor )->get_rating();



Vendor Class Method References #

Method : __construct( object | int $vendor )

Method type
non-static

Description #
Get single-vendor data by vendor id or vendor user object. This means it returns a total vendor’s object from where you can extract any information.

Parameters #

  • $vendor
    ( Object | integer ) Vendor user id or full user object.
    ( Default ) Null.

Returns #
( object ) vendor instance or vendor/user full object.


Hooks #
dokan_vendor ( action )

More information #

Usage #

// Get vendor id and current vendor data.
$vendor_id = get_current_user_id();
$vendor    = dokan()->vendor->get( $vendor_id );
print_r( $vendor );


Output #
Returns Vendor() object.

Method : is_vendor()

Method type #
non-static

Description #
Check if the current user has the capability of “dokandar” then our user will be the actual vendor.

Parameters #
Parameters not found in this method.

Returns #
( Boolean ) Return true/false after checking our current user is a vendor or not.

Hooks #
Hooks are not found in this method.

More information #

Usage #

// Get the user id & check our current user is vendor or not then execute our code.
$vendor_id = get_current_user_id();
$vendor    = dokan()->vendor->get( $vendor_id )->is_vendor();

if ( $vendor ) {
    // code to be executed.
} else {
    // code to be executed.
}

Traditional function #

// Get the user id & check our current user is vendor or not then execute our code.
$vendor_id = get_current_user_id();
$vendor    = dokan_is_user_seller( $vendor_id );

if ( $vendor ) {
    // code to be executed.
} else {
    // code to be executed.
}


Method : is_enabled()

Method type #
non-static

Description #
Check if the selling capacity is enabled for this vendor.

Parameters #
Parameters not found in this method.

Returns #
( Boolean ) Return true/false after checking the sales capability of our current seller.

Hooks #
Hooks are not found in this method.

More information #

Usage #

// Get the vendor & checked our current vendor can sell product then execute our code.
$vendor_id          = get_current_user_id();
$is_selling_enabled = dokan()->vendor->get( $vendor_id )->is_enabled();

if ( $is_selling_enabled ) {
    // code to be executed.
} else {
    // code to be executed.
}

Traditional function #

// Get the user id & check our current user is vendor or not then execute our code.
$vendor_id          = get_current_user_id();
$is_selling_enabled = dokan_is_seller_enabled( $vendor_id );;

if ( $vendor ) {
    // code to be executed.
} else {
    // code to be executed.
}

Method type #
non-static

Description #
Check if the vendor is marked as featured.

Parameters #
Parameters not found in this method.

Returns #
( Boolean ) Return true/false after checking the featured capabilities of our current seller.

Hooks #
Hooks are not found in this method.

More information #

Usage #

// Get the vendor & checked our current vendor is a featured vendor.
$vendor_id          = get_current_user_id();
$is_featured_vendor = dokan()->vendor->get( $vendor_id )->is_featured();

if ( $is_featured_vendor ) {
    // code to be executed.
} else {
    // code to be executed.
}

Method : get_shop_info()

Method type #
non-static

Description #
Get vendor store information.

Parameters #
Parameters not found in this method.

Returns #
( Array ) Return vendor store information in an array.

Hooks #
Hooks are not found in this method.

More information #

Usage #

// Get the current vendor shop information here.
$vendor_id = get_current_user_id();
$shop_data = dokan()->vendor->get( $vendor_id )->get_shop_info();

print_r( $shop_data ); // show current vendor shop data in an array


Output #
Returns vendor shop info array().

Method : get_info_part( string $item )

Method type #
non-static

Description #
Retrieve vendor store info part from complete store data.

Parameters #

  • $item
    ( String ) Key name of vendor shop.
    ( Required )

  • Returns #
    ( Mixed ) Return a part of vendor store data & it can be single, array, integer etc.

    Hooks #
    Hooks are not found in this method.

    More information #

    Usage #

    // Get a part of the shop information from the current vendor.
    $vendor_id = get_current_user_id();
    $shop_name = dokan()->vendor->get( $vendor_id )->get_info_part( 'store_name' );
    
    echo $shop_name; // Tasty Coffee Shop.


    Output #
    Returns vendor shop info part.

    Method : get_orders( array $args )

    Method type #
    non-static

    Description #
    Retrieve current vendor all orders data by using this method.

    Parameters #

  • $args
    ( Array ) Vendor order arguments.
    ( Optional )

  • Returns #
    ( Object ) Return wc_get_order object.

    Hooks #
    Hooks are not found in this method.

    More information #

    Usage #

    // Get current vendor all orders data here.
    $vendor_id = get_current_user_id();
    
    $args = [
        'seller_id' => $vendor_id,
        'status'    => 'all',
        'paged'     => 1,
        'limit'     => 5,
        'date'      => null,
    ];
    
    $vendor_orders = dokan()->vendor->get( $vendor_id )->get_orders( $args );
    
    return $vendor_orders; // Return current vendor all orders.


    Output #
    Returns order object.

    Method : get_total_sales()

    Method type #
    non-static

    Description #
    Retrieve total sales amount from the current seller.

    Parameters #
    Parameters not found in this method.

    Returns #
    ( Float ) Return current vendor sales floating amount.

    Hooks #
    Hooks are not found in this method.

    More information #

    Usage #

    // Get total selling amount of current vendor.
    $vendor_id             = get_current_user_id();
    $vendor_selling_amount = dokan()->vendor->get( $vendor_id )->get_total_sales();
    
    echo $vendor_selling_amount; // 7947.0000


    Output #
    Returns the seller’s total sales amount in floating numbers.

    Method : get_earnings( bool $formatted = true, string $on_date = ” )

    Method type #
    non-static

    Description #
    Retrieve the total earnings of the current seller.

    Parameters #

  • $formatted
    ( Boolean ) Show formatted vendor earnings.
    ( Optional )
  • $on_date
    ( String ) Set date of vendor earnings.
    ( Optional )

  • Returns #
    ( Float ) Return current vendor earnings floating amount.

    Hooks #
    dokan_get_formatted_seller_earnings ( filter )
    dokan_get_seller_earnings ( filter )

    More information #

    Usage #

    // Get total earning amount of current vendor.
    $vendor_id       = get_current_user_id();
    $vendor_earnings = dokan()->vendor->get( $vendor_id )->get_earnings( true, '1 Sep 2021');
    
    echo $vendor_earnings; // $635.00


    Output #
    Returns the seller’s total earning amount in floating numbers.

    Method : get_balance( bool $formatted = true, string $on_date = ” )

    Method type #
    non-static

    Description #
    Retrieve the total balance of the current seller.

    Parameters #

  • $formatted
    ( Boolean ) Show formatted vendor balance.
    ( Optional )
  • $on_date
    ( String ) Set date of vendor balance.
    ( Optional )

  • Returns #
    ( Float ) Return seller balance in floating number.

    Hooks #
    dokan_get_formatted_seller_balance ( filter )
    dokan_get_seller_balance ( filter )

    More information #

    Usage #

    // Get total balance of current vendor.
    $vendor_id      = get_current_user_id();
    $vendor_balance = dokan()->vendor->get( $vendor_id )->get_balance( true, '1 Sep 2021');
    
    echo $vendor_balance; // $264.00


    Output #
    Returns the seller’s total balance in floating numbers.

    Method : get_rating()

    Method type #
    non-static

    Description #
    Get the vendor rating info by this method.

    Parameters #
    Parameters not found in this method.

    Hooks #
    dokan_seller_rating_value ( filter )

    Returns #
    ( Array ) Return current seller’s rating info in an array.

    More information #

    Usage #

    // Get the rating data of current vendor.
    $vendor_id     = get_current_user_id();
    $vendor_rating = dokan()->vendor->get( $vendor_id )->get_rating();
    
    return $vendor_rating; // Array ( [rating] => 3.00 [count] => 1 )


    Output #
    Returns the seller’s rating info.

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    Dokan Vendor Class