Home Forums Theme Support Dokan Display Product vendors name

This topic is: not resolved

Tagged: 

This topic contains 6 replies, has 2 voices, and was last updated by  towhid 3 years, 11 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #51721

    Anna
    Member
    Post count: 8

    Hi!

    I want to display the vendors name alongside the Product name and price in the shop page (the thumbnails of products). I found this (pasted below) from woocommerce but i’m guessing the tag for vendors is wrong. Could you help?

    /**
    * Print the product’s vendor name before the product title in the loop.
    *
    * @return void
    */
    function wc_vendors_name_loop() {
    $vendors = get_the_terms( get_the_ID(), ‘shop_vendor’ );

    if ( $vendors && ! is_wp_error( $vendors ) ) {
    foreach ( $vendors as $vendor ) {
    $all_vendors[] = $vendor->name;
    }

    $vendors = join( “, “, $all_vendors );

    echo ‘‘ . $vendors . ‘‘;
    }
    }
    add_action( ‘woocommerce_before_shop_loop_item_title’, ‘wc_vendors_name_loop’, 20 );

    #51781

    towhid
    Participant
    Post count: 4505

    Hello Anna,

    Did you try above code? Did you get any error? Can you please let me know the name of the theme you are using for your site now

    Thanks

    #51784

    Anna
    Member
    Post count: 8

    Hi!

    I tried it and i got no error. I'm using the dokan theme 🙂

    #51794

    towhid
    Participant
    Post count: 4505

    Hello Anna,

    I need to test this code for me. Please allow me some time.

    Thanks

    #51997

    towhid
    Participant
    Post count: 4505

    Hello Anna,

    Please navigate to `plugins/woocommerce/templates/single-product/content-product.php and this line
    do_action( 'woocommerce_after_shop_loop_item_title' );

    After that line paste below code.

    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 echo $store_info['price']; ?>
    	                <?php echo $store_info['store_name']; ?>
    	            </span>
    	        <?php  }

    Thanks

    #52725

    Anna
    Member
    Post count: 8

    Thanks, that worked like a charm! 🙂

    Is there a way to get the Vendor name to link to their shop as well?

    Thanks!

    #52796

    towhid
    Participant
    Post count: 4505

    Hello Anna,

    Then, you have to try this following code instead of the previous code which I have given to you.

    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 echo $store_info['price']; ?>
                        <?php printf( '<a href="%s">%s</a>', dokan_get_store_url( $author->ID ), $author->display_name ); ?>
                    </span>
     		<?php } ?>

    Please let me know the result when done

    Thanks

Viewing 7 posts - 1 through 7 (of 7 total)

The topic ‘Display Product vendors name’ is closed to new replies.