Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@nayemDevs
Last active January 29, 2024 08:39
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nayemDevs/1fc0c4840fc6da5ce08c8ac5d0bcd721 to your computer and use it in GitHub Desktop.
Save nayemDevs/1fc0c4840fc6da5ce08c8ac5d0bcd721 to your computer and use it in GitHub Desktop.
Creating a shortcode to show vendor biography anywhere on your page
<?php
/**
* Plugin Name: Dokan Vendor Biography Shortcode
*/
add_shortcode( 'dokan_vendor_bio', 'dokan_vendor_bio_shortcode' );
function dokan_vendor_bio_shortcode() {
$vendor = dokan()->vendor->get( get_query_var( 'author' ) );
$store_info = $vendor->get_shop_info();
if ( empty( $store_info['vendor_biography'] ) ) {
return;
}
printf( '%s', apply_filters( 'the_content', $store_info['vendor_biography'] ) );
}
// user vendor bio shortcode on single product page
add_shortcode( 'dokan_vendor_bio_single', 'dokan_vendor_bio_shortcode_single' );
function dokan_vendor_bio_shortcode_single() {
global $product;
$seller = get_post_field( 'post_author', $product->get_id());
$author = get_user_by( 'id', $seller );
$vendor = dokan()->vendor->get( $seller );
$store_info = dokan_get_store_info( $author->ID );
if ( !empty( $store_info['vendor_biography'] ) ) { ?>
<span class="details">
<?php printf( $vendor->get_vendor_biography() ); ?>
</span>
<?php
}
}
@vynl-xx
Copy link

vynl-xx commented Apr 10, 2020

Hi, I've put this in my functions.php file in my child theme (we're using Marketo theme and Dokan Pro), but I can't get the shortcode to work. Am I using the correct shortcode . . .[vendor_biography]? And can I use it anywhere on the site? Your help is much appreciated, thank you.

@vynl-xx
Copy link

vynl-xx commented Apr 10, 2020

Aha, I think I had the wrong shortcode, should it be [dokan_vendor_bio]? And how can I get that to work on every page of my site please?

@nayemDevs
Copy link
Author

It should work on every page of your site if there is any vendor data like single product page :)

@vynl-xx
Copy link

vynl-xx commented Apr 27, 2020

Thank you

@Shini-D
Copy link

Shini-D commented Apr 28, 2020

Hi, I was looking for a way to do this same thing for the store categories. I want to show them in the product page.

I have this code as reference:

add_shortcode( 'store-name-product', 'seller_name_on_single' );
function seller_name_on_single(){
	global $product;
	$seller = get_post_field( 'post_author', $product->get_id());
	$author  = get_user_by( 'id', $seller );
	$vendor = dokan()->vendor->get( $seller );

	$store_info = dokan_get_store_info( $author->ID );

	if ( !empty( $store_info['store_name'] ) ) { ?>
		<span class="store-name">
			<?php printf( 'Sold by: <a href="%s">%s</a>', $vendor->get_shop_url(),  $vendor->get_shop_name() ); ?>
		</span>
		<?php
	}
}

I guess I only need to change the get_shop_name() for get_shop_something? and print:

<?php printf( 'Store categories: %s', $vendor->get_shop_something? ); ?>

I hope you can help me

@BlackHeartur666
Copy link

Hello, this shortcode doesn't work. Blank space :)

@nayemDevs
Copy link
Author

@Blackheart its working fine when you have vendor bio and used the correct short code. I have just checked :)

@BlackHeartur666
Copy link

Hi @nayem I'm using the [dokan_vendor_bio] shortcode and bio is completed. Last version of Dokan, Elementor up-to-date (your script about vendor name works fine. Maybe is it an Elementor issue?

@nayemDevs
Copy link
Author

Im not sure, it should work fine after saving the page. Did you insert it on functions.php correctly? I am using elementor latest.

@BlackHeartur666
Copy link

Yes, just copy past
image

@enriquemillaldeo
Copy link

it doesn't work for me, I copied the shortcode in the sidebar of a single product, from a seller with a biography and nothing, it appears empty

@rodriguezavellan
Copy link

Show the seller name and Biography vendor in a single product page
https://gist.github.com/rodriguezavellan/b74537530ecd54151f01daaae610f48f

@daihlo
Copy link

daihlo commented Jun 8, 2020

If I add this code to my child function.php it crashes the site.

@rodriguezavellan
Copy link

use the plugin "snippets", there you can try this code without change directly the function.php

@guicz
Copy link

guicz commented Sep 29, 2020

This worked for me and I used to put the store bio in the sidebar of a single store Elementor template.

add_shortcode( 'dokan_vendor_bio', 'dokan_vendor_bio_shortcode' ); function dokan_vendor_bio_shortcode() { $store_user = get_userdata( get_query_var( 'author' ) ); $store_info = dokan_get_store_info( $store_user->ID ); if ( empty( $store_info['vendor_biography'] ) ) { return; } printf( '%s', apply_filters( 'the_content', $store_info['vendor_biography'] ) ); }

Elementor 3.0.10 and Dokan 3.0.8

@tomaslanzarini
Copy link

Hello. code is not working for me.
I tried anyway but it is blank.
I'm using the astra theme, and the latest version of elementor pro and dokan pro.
My product page is made in elementor.
Can someone help me?

@nayemDevs
Copy link
Author

Hello @tomaslanzarini,

The code is working fine for me. Kindly make sure that you have inserted the code on your functions.php without the <?php tag and inserted the shortcode correctly.

@tomaslanzarini
Copy link

tomaslanzarini commented Oct 7, 2020

yes, everything is correct.
I added the code through the "snippets" plugin and called the shortcode by elementor through the specific widget.

could it be an incompatibility with my theme? I use astra. thanks for the attention

@tomaslanzarini
Copy link

tomaslanzarini commented Oct 8, 2020

I finally got it through the following code :)

/**

  • Plugin Name: Dokan Vendor Biography Shortcode
    */
    add_shortcode( 'dokan_vendor_bio', 'dokan_vendor_bio_shortcode' );
    function dokan_vendor_bio_shortcode() {
    global $product;
    $seller = get_post_field( 'post_author', $product->get_id());
    $author = get_user_by( 'id', $seller );
    $vendor = dokan()->vendor->get( $seller );

     $store_info = dokan_get_store_info( $author->ID );
    
     if ( !empty( $store_info['vendor_biography'] ) ) { ?>
         <span class="details">
                 <?php printf( $vendor->get_vendor_biography() ); ?>
             </span> 
         <?php
     }
    

    }

the challenge now is to insert the vendor image ( profile image ) , but it is difficult.

@nayemDevs
Copy link
Author

Hello,

Great, my code was only for the store page not for the product page. However, I will add your code on the snippet so that people who need can use it ...

@nayemDevs
Copy link
Author

Guys, I created a new youtube channel- https://www.youtube.com/channel/UCi_pjYuycQCC705hdSv52qA . You can subscribe and suggest me if you need any tutorial :)

Cheers!

@Deexterous
Copy link

This code is not working after the latest update. Any suggestions? kulavillage.com is my site

@daihlo
Copy link

daihlo commented May 25, 2021

This still doesnt work for me.

Used the code at the top of this page using snippet plugin, activated it, then in elementor placed a shortcode block on my vendor store page above products - with shortcode [dokan_vendor_bio]
Nothing happens.

@Gurtop
Copy link

Gurtop commented Nov 9, 2021

Hi!
Seller biography on dokan product page made with elemental, no works (
Help?

@DavisMorten
Copy link

Works perfectly fine for me. THX mate! :)

@fdead0
Copy link

fdead0 commented Feb 4, 2023

I want to add vendor signature field somewhere in setting>store section in vendor dashboard and how to use it's short code to print it on invoice???

@asansano
Copy link

asansano commented Jan 29, 2024

think the $store_info array changed a bit. we changed line 8 to $store_info = dokan_get_store_info($vendor->id); you might want to update your code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment