Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display dokan vendor name on Woocommerce single product pages

With woocommerce I am using Dokan plugin and I am trying to display the vendor name, rating and vendor location on single product pages.

I tried this code to display vendor name but no luck:

//show store name
add_action( 'woocommerce_single_product_summary', 'show_store_name', 20 );
function show_store_name() {
    printf( '<b>Seller Name:</b> <a href="%s">%s</a>', dokan_get_store_url( $author->ID ), $store_info['store_name'] );
}

Any help is appreciated.

like image 950
Raskolt Avatar asked Jul 03 '18 00:07

Raskolt


People also ask

How do I customize my Dokan store?

If you have a folder named Dokan, inside your theme or child theme, then the system will pick the template from there and ignore the templates inside the plugin folder. If your theme name is Avada and you are using a child theme, then the store template location will look like wp-content/themes/avada-child/dokan/store.

Does Dokan work with WooCommerce?

Dokan is the best front end multi-vendor marketplace on WordPress, powered by WooCommerce. It helps you to build your own marketplace similar to Amazon, Shopify, eBay, Magento like marketplaces in under 30 minutes.


1 Answers

I don't use dokan plugin. Here is the way to get the (post) author ID and to make your code work:

add_action( 'woocommerce_single_product_summary', 'display_author_name', 20 );
function display_author_name() {
    // Get the author ID (the vendor ID)
    $vendor_id = get_post_field( 'post_author', get_the_id() );
    // Get the WP_User object (the vendor) from author ID
    $vendor = new WP_User($vendor_id);

    $store_info  = dokan_get_store_info( $vendor_id ); // Get the store data
    $store_name  = $store_info['store_name'];          // Get the store name
    $store_url   = dokan_get_store_url( $vendor_id );  // Get the store URL

    $vendor_name = $vendor->display_name;              // Get the vendor name
    $address     = $vendor->billing_address_1;           // Get the vendor address
    $postcode    = $vendor->billing_postcode;          // Get the vendor postcode
    $city        = $vendor->billing_city;              // Get the vendor city
    $state       = $vendor->billing_state;             // Get the vendor state
    $country     = $vendor->billing_country;           // Get the vendor country

    // Display the seller name linked to the store
    printf( '<b>Seller Name:</b> <a href="%s">%s</a>', $store_url, $store_name );
}

Code goes in function.php file of your active child theme (or active theme). This should work now.

But I don't know how to get vendor rating and location. You should better ask Dokan support.

The code is based on this related thread.

like image 111
LoicTheAztec Avatar answered Oct 10 '22 03:10

LoicTheAztec