Skip to content

Instantly share code, notes, and snippets.

@bentasm1
Last active June 24, 2016 09:42
Show Gist options
  • Save bentasm1/a5950f0e5aeaeb034080 to your computer and use it in GitHub Desktop.
Save bentasm1/a5950f0e5aeaeb034080 to your computer and use it in GitHub Desktop.
Redirect Vendors to Vendor Dashboard @ login
/* Redirect Vendors to Vendor Dashboard on Login */
add_filter('woocommerce_login_redirect', 'login_redirect', 10, 2);
function login_redirect( $redirect_to, $user ) {
// WCV dashboard -- Uncomment the 3 lines below if using WC Vendors Free instead of WC Vendors Pro
// if (class_exists('WCV_Vendors') && WCV_Vendors::is_vendor( $user->id ) ) {
// $redirect_to = get_permalink(WC_Vendors::$pv_options->get_option( 'vendor_dashboard_page' ));
// }
// WCV Pro Dashboard
if (class_exists('WCV_Vendors') && class_exists('WCVendors_Pro') && WCV_Vendors::is_vendor( $user->id ) ) {
$redirect_to = get_permalink(WCVendors_Pro::get_option( 'dashboard_page_id' ));
}
return $redirect_to;
}
@benlumley
Copy link

(this has been merged into the above now)

Alt version that doesn't hard code the URL - comment in out the right bit for WCV pro / regular.

No need for the else block either - think it's better to return what comes in untouched - by default it will be my-account, but could be anything else if the url has been amended etc.

add_filter('woocommerce_login_redirect', 'login_redirect', 10, 2);
function login_redirect( $redirect_to, $user ) {
    // WCV dashboard
    // if (class_exists('WCV_Vendors') && WCV_Vendors::is_vendor( $user->id ) ) {
    //  $redirect_to = get_permalink(WC_Vendors::$pv_options->get_option( 'vendor_dashboard_page' ));
    // }
    // WCV Pro Dashboard
    if (class_exists('WCV_Vendors') && class_exists('WCVendors_Pro') && WCV_Vendors::is_vendor( $user->id ) ) {
        $redirect_to = get_permalink(WCVendors_Pro::get_option( 'dashboard_page_id' ));
    }
    return $redirect_to;
}

@bentasm1
Copy link
Author

Thanks Ben! I've merged yours so that it's now the standard way to do it. It's updated across all the sites as well. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment