• Resolved niikk

    (@niikk)


    Hello,

    We want to change a simple thing I guess. in the admin product overview where every product is listed, there is by default a column from dokan called “Author”. There is the author name visible of the product. However, we want to change or add a new column in order to display the vendor store-name of the product instead of the author. Author is useless for us because its far easier to understand from who a product is when it displays the store-name.

    How can we do that? Should be simple I guess, because all information are available. Only go provide the info in a column need some custom code. I guess this should be a standard feature…

    cheers

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter niikk

    (@niikk)

    Currently we are trying with that code but does not work:

    add_filter( 'manage_edit-product_columns', 'show_product_order',15 );
    function show_product_order($columns){
    
       //add column
       $columns['vendor_store_name'] = __( 'Vendor'); 
    
       return $columns;
    }
    
    function get_dokan_vendor_shop_name_from_product_test( $product_id ) {
        if( empty($product_id) ) return;
        $seller = get_post_field( 'post_author', $product_id );
        $author = get_user_by( 'id', $seller );
        $vendor = dokan()->vendor->get( $seller );
        $store_info = dokan_get_store_info( $author->ID );
    }
    
    add_filter( 'manage_product_posts_custom_column', 'vendor_product_column', 10, 2 );
    
    function vendor_product_column( $column, $postid ) {
    if ( $column == 'vendor_store_name' ) {
    $product = new WC_Product($postid);
    echo get_post_meta( $postid, $store_info, true );
    }
    }
    • This reply was modified 3 years, 10 months ago by niikk.

    Hello @niikk ,

    The author field is using the default author field of WordPress so you are unable to change it’s content directly. You can remove/unset it and add a new column as you have tried.

    I am not sure about the middle part of your code. Here is my approach to get the store name in the product list column –

    add_filter( 'manage_edit-product_columns', 'custom_admin_products_store_name_column', 9999 );
     
    function custom_admin_products_store_name_column( $columns ){
       $columns['vendor_store_name'] = __( 'Vendor'); 
       return $columns;
    }
     
    add_action( 'manage_product_posts_custom_column', 'custom_admin_products_store_name_column_content', 10, 2 );
     
    function custom_admin_products_store_name_column_content( $column, $product_id ){
    
    	$seller = get_post_field( 'post_author', $product_id);
    	$store_info = dokan_get_store_info( $seller );
    	$store_name = $store_info['store_name'];
    
        if ( $column == 'vendor_store_name' ) {
    		echo __($store_name);
    		
    	}
    }

    I hope the information helps.

    Thank you ??

    Thread Starter niikk

    (@niikk)

    Hello @rur165

    This is awesome! Nice. But I can not click the storename in order to filter for all products from the same store. (Same as the default Dokan “Author” column does)

    I guess I have to use something like that. In which Dokan file can I see how you did that for the author column?

    function apply_my_custom_product_filters( $query ) {
    
    global $pagenow;
    
    if ( $query->is_admin && $pagenow == 'edit.php' && isset( $_GET['my_filter'] ) && $_GET['my_filter'] != '' && $_GET['post_type'] == 'product' ) {
    
      // Create meta query array and add to WP_Query
      $meta_key_query = array(
        array(
          'key'     => '_my_meta_value',
          'value'   => esc_attr( $_GET['my_filter'] ),
        )
      );
      $query->set( 'meta_query', $meta_key_query );
    
    }
    
    }
    
    add_action( 'pre_get_posts', 'apply_my_custom_product_filters' );

    Hello @niikk ,

    If you look closely, you will notice that Dokan is using the default author post-column as the posts area of WordPress. I could not locate a specific code related to this column details addition so my guess is that the default author filter code from WordPress is working here.

    I can suggest a quick solution to this use case. It might not be the best one but works for me –

    First getting the structure of the product filter URL –
    $vendor_products = get_admin_url() . 'edit.php?post_type=product&author=' . $seller;

    Then using it as URL on previous column content –

    if ( $column == 'vendor_store_name' ) {
    		printf('<a href="%s">%s</a>', $vendor_products, $store_name);		
    }

    I hope you find it useful.

    Thank you ??

    Thread Starter niikk

    (@niikk)

    Hello @rur165

    This works nice! Thanks.

    Why you think its not the best one?

    Cheers

    Hello @niikk ,

    There could be other ways to get the product edit page and author slug directly instead of hard coding to complete the URL.

    There is nothing wrong or bad when implemented on a specific site. From plugin wise it might not be the best one.

    Thank you ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Show “vendor” store name instead of “author” in product backend’ is closed to new replies.