Move Vendor Biography tab on the Dokan Single Store page

·

·

,

Many Dokan users want to move or replace the Vendor Biography tab with the Products tab and keep it in the first position of the single store page.

In this article, I’m going to show the way how to do it safely through the child theme directory, and the customization will not lose by an update.

So, let’s jump into the code —–

Remove default contents

Replacing Vendor Biography page content with the Products page, both page contents need to remove at the first stage.

/**
 * 
 * Remove default contents
 * 
 */
function remove_default_contents(){
    remove_filter( 'template_include', [ dokan_pro()->store, 'load_vendor_biography_template' ], 99 );
    remove_filter( 'template_include', [ dokan()->rewrite, 'store_template' ], 99 );
}
add_action( 'init', 'remove_default_contents' );

Load Vendor Biography Page Content

After the replacement, the Vendor Biography contents need to load on the Products page

/**
 * 
 * Replace Products Page Content
 * 
 */
function load_vendor_biography_template( $template ) {
    $custom_store_url = dokan_get_option( 'custom_store_url', 'dokan_general', 'store' );
    $store_name = get_query_var( $custom_store_url );
    if( ! empty( $store_name ) ){
        return dokan_locate_template( 'vendor-biography.php', '', DOKAN_PRO_DIR . '/templates/', true );
    }
    return $template;
}
add_filter( 'template_include', 'load_vendor_biography_template', 99 );

Load Products Page Content

As the above, the Product Page contents need to load on the Vendor Biography page

/**
 * 
 * Replace Vendor Biography Page Content
 * 
 */
function load_vendor_products_template( $template ) {
    if( get_query_var( 'products' ) ){
        return dokan_locate_template( 'store.php' );
    }
    return $template;
}
add_filter( 'template_include', 'load_vendor_products_template', 99 );

Rewrite Store Tabs

The above code has replaced the content of those pages, but without replacing the page/tab title, page contents will not make any sense. So, the below code will do the job.

/**
 * 
 * Rewrite Store Tabs
 * 
 */
function rewrite_store_tabs( $tabs, $store_id ){
    $tabs['products']['title'] = __( 'Vendor Biography', 'dokan' );
    $tabs['vendor_biography']['title'] = __( 'Products', 'dokan' );
    $tabs['vendor_biography']['url'] = dokan_get_store_url( $store_id ) . 'products';
    return $tabs;
}
add_filter( 'dokan_store_tabs', 'rewrite_store_tabs', 11, 2 );

Replace the Vendor Biography Page URL

If the URL and the page contents are different, then visitors could find the site unfinished. So, to represent a complete site to them, let’s change the vendor biography page URL by the below code.

/**
 * 
 * Override Vendor Biography Query Variable
 * 
 */
function load_products_query_var( $query_vars ) {
    $query_vars[] = 'products';
    return $query_vars;
}
add_action( 'dokan_query_var_filter', 'load_products_query_var', 11, 2 );

/**
 * 
 * Override Vendor Biography Rewrite Rules
 * 
 */
function load_products_rewrite_rules( $store_url ) {
    add_rewrite_rule( $store_url . '/([^/]+)/products?$', 'index.php?' . $store_url . '=$matches[1]&products=true', 'top' );
}
add_action( 'dokan_rewrite_rules_loaded', 'load_products_rewrite_rules' );

After adding the above code, re-save the permalinks from the WordPress Admin Dashboard > Settings > Permalinks screen.

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x