• Resolved rohan066

    (@rohan066)


    I’m building a multivendor woocommerce WordPress website using the Dokan plugin.
    When logged-in users want to access (home_url)/wp-admin.
    Admins get redirected to the wp-dashboard, customers get redirected to woocommerce my account page and a vendor gets redirected to the home page. I want the vendor to get redirected to the page (home_url)/dashboard instead of the home page.

    To solve this, I used this code snippet in function.php

    /**
     * Custom redirection for different user roles.
     */
    function custom_user_redirect() {
        if ( is_user_logged_in() ) {
            $user = wp_get_current_user();
            
            if ( in_array( 'administrator', (array) $user->roles ) ) {
                // Redirect administrators to wp-dashboard.
                wp_redirect( home_url( '/wp-admin/' ) );
                exit();
            } elseif ( in_array( 'customer', (array) $user->roles ) ) {
                // Redirect customers to the WooCommerce My Account page.
                wp_redirect( home_url( '/my-account/' ) );
                exit();
            } elseif ( in_array( 'vendor', (array) $user->roles ) ) {
                // Redirect vendors to the custom dashboard page.
                wp_redirect( home_url( '/dashboard/' ) );
                exit();
            }
        }
    }
    
    
    add_action( 'login_redirect', 'custom_user_redirect' );
    

    but still, vendors are getting redirected to the home page instead of redirecting ( home_url( ‘/dashboard/’ ). how to solve this issue?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hello @rohan066,

    I hope you are doing well. Please try the below snippet to resolve your issue, and let me know.

    function custom_dokan_customer_migration_redirect( $url ) {
    $new_redirect_url = 'website.url/dashbaord'; // Use your desired URL.
    return $new_redirect_url;
    }
    add_filter( 'dokan_customer_migration_redirect', 'custom_dokan_customer_migration_redirect' );

    If you need any other assistance, please contact us.

    Best regards,

    Thread Starter rohan066

    (@rohan066)

    @gausulazam, Thank you for your reply. I have solved the issue using this snippet.

    //woocommerce user dashboard customization
    function my_account_custom_design(){
        echo do_shortcode('[INSERT_ELEMENTOR id="1146"]');
    }
    
    add_action('woocommerce_account_dashboard','my_account_custom_design');
    
    function custom_user_redirect() {
        if ( is_user_logged_in() ) {
            $user = wp_get_current_user();
            
             // Check if user is logged in and trying to access wp-admin
        if (strpos($_SERVER['REQUEST_URI'], 'wp-admin') !== false && !current_user_can('administrator') && in_array( 'seller', (array) $user->roles )) {
            // Redirect users with roles other than administrator
            wp_redirect(home_url('/seller-account/')); // Redirect to home page or any other URL
            exit();
        }
        
        if (strpos($_SERVER['REQUEST_URI'], 'wp-admin') !== false && !current_user_can('administrator') && in_array( 'customer', (array) $user->roles )) {
            // Redirect users with roles other than administrator
            wp_redirect(home_url('/my-account/')); // Redirect to home page or any other URL
            exit();
        }
            
          
        }
    }
    
    add_action( 'init', 'custom_user_redirect' );
    GausulAzam

    (@gausulazam)

    Hello?@rohan066,

    I am glad to know that your issue has been?resolved. I appreciate your effort in finding a possible solution and adding the?required code?to this forum for future?reference.

    Best regards,

    Plugin Support Tanvir Hasan

    (@tanvirh)

    Hi @rohan066

    Since the issue is resolved we will consider this topic as resolved. If you encounter any future challenges or have additional queries, please don’t hesitate to create a new topic.

    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘the vendor should redirected to the (home_url)/dashboard instead of home page’ is closed to new replies.