3
votes

I'm using Dokan Multivendor Plugin by weDevs and have an issue with some custom code..

Here is the code which helps you to display Vendor Name On The Product Thumbnail In Dokan:

    //woocommerce
/*
Show Seller name on the product thumbnail
For WooCommerce 

*/

add_action( 'woocommerce_after_shop_loop_item_title','sold_by' );
function sold_by(){
?>
    </a>
    <?php
        global $product;
        $author     = get_user_by( 'id', $product->post->post_author );
        $store_info = dokan_get_store_info( $author->ID );
        if ( !empty( $store_info['store_name'] ) ) { ?>
                <span class="details">
                    <?php printf( 'Sold by: <a href="%s">%s</a>', dokan_get_store_url( $author->ID ), $author->display_name ); ?>
                </span>
        <?php 
    } 

}

But I need to display Store Name instead of Vendor Name On The Product Thumbnail..

Trying to change this string to achieve this goal:

<?php printf( 'Sold by: <a href="%s">%s</a>', dokan_get_store_url( $author->ID ), $author->display_name ); ?>

To this one:

<?php printf( 'Sold by: <a href="%s">%s</a>', dokan_get_store_url( $author->ID ), $author->store_name ); ?>

but it doesn't work..

1

1 Answers

3
votes

Try this , I am assuming you are using WooCommerce V3.0+

    add_action( 'woocommerce_after_shop_loop_item_title','sold_by' );
    function sold_by(){
    ?>
        </a>
        <?php
            global $product;
            $seller = get_post_field( 'post_author', $product->get_id());
 $author     = get_user_by( 'id', $seller );

            $store_info = dokan_get_store_info( $author->ID );
            if ( !empty( $store_info['store_name'] ) ) { ?>
                    <span class="details">
                        <?php printf( 'Sold by: <a href="%s">%s</a>', dokan_get_store_url( $author->ID ), $author->display_name ); ?>
                    </span>
            <?php 
        } 

    }