Skip to content

Instantly share code, notes, and snippets.

@goxmedia
Forked from woogist/functions.php
Created September 30, 2019 16:06
Show Gist options
  • Save goxmedia/6192072c40a8be481d8fe82b9f48df1f to your computer and use it in GitHub Desktop.
Save goxmedia/6192072c40a8be481d8fe82b9f48df1f to your computer and use it in GitHub Desktop.

Revisions

  1. WooThemes revised this gist Nov 17, 2014. 1 changed file with 8 additions and 5 deletions.
    13 changes: 8 additions & 5 deletions functions.php
    Original file line number Diff line number Diff line change
    @@ -10,21 +10,24 @@ function wc_custom_user_redirect( $redirect, $user ) {
    // Get the first of all the roles assigned to the user
    $role = $user->roles[0];

    $dashboard = admin_url();
    $myaccount = get_permalink( wc_get_page_id( 'myaccount' ) );

    if( $role == 'administrator' ) {
    //Redirect administrators to the dashboard
    $redirect = admin_url();
    $redirect = $dashboard;
    } elseif ( $role == 'shop-manager' ) {
    //Redirect shop managers to the dashboard
    $redirect = admin_url();
    $redirect = $dashboard;
    } elseif ( $role == 'editor' ) {
    //Redirect editors to the dashboard
    $redirect = admin_url();
    $redirect = $dashboard;
    } elseif ( $role == 'author' ) {
    //Redirect authors to the dashboard
    $redirect = admin_url();
    $redirect = $dashboard;
    } elseif ( $role == 'customer' || $role == 'subscriber' ) {
    //Redirect customers and subscribers to the "My Account" page
    $redirect = get_permalink( wc_get_page_id( 'myaccount' ) );
    $redirect = $myaccount;
    } else {
    //Redirect any other role to the previous visited page or, if not available, to the home
    $redirect = wp_get_referer() ? wp_get_referer() : home_url();
  2. WooThemes revised this gist Nov 17, 2014. 1 changed file with 11 additions and 2 deletions.
    13 changes: 11 additions & 2 deletions functions.php
    Original file line number Diff line number Diff line change
    @@ -13,12 +13,21 @@ function wc_custom_user_redirect( $redirect, $user ) {
    if( $role == 'administrator' ) {
    //Redirect administrators to the dashboard
    $redirect = admin_url();
    } elseif ( $role == 'shop-manager' ) {
    //Redirect shop managers to the dashboard
    $redirect = admin_url();
    } elseif ( $role == 'editor' ) {
    //Redirect editors to the dashboard
    $redirect = admin_url();
    } elseif ( $role == 'customer' ) {
    //Redirect customers to the "My Account" page
    } elseif ( $role == 'author' ) {
    //Redirect authors to the dashboard
    $redirect = admin_url();
    } elseif ( $role == 'customer' || $role == 'subscriber' ) {
    //Redirect customers and subscribers to the "My Account" page
    $redirect = get_permalink( wc_get_page_id( 'myaccount' ) );
    } else {
    //Redirect any other role to the previous visited page or, if not available, to the home
    $redirect = wp_get_referer() ? wp_get_referer() : home_url();
    }

    return $redirect;
  3. WooThemes created this gist Nov 17, 2014.
    26 changes: 26 additions & 0 deletions functions.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    <?php
    /**
    * Redirect users to custom URL based on their role after login
    *
    * @param string $redirect
    * @param object $user
    * @return string
    */
    function wc_custom_user_redirect( $redirect, $user ) {
    // Get the first of all the roles assigned to the user
    $role = $user->roles[0];

    if( $role == 'administrator' ) {
    //Redirect administrators to the dashboard
    $redirect = admin_url();
    } elseif ( $role == 'editor' ) {
    //Redirect editors to the dashboard
    $redirect = admin_url();
    } elseif ( $role == 'customer' ) {
    //Redirect customers to the "My Account" page
    $redirect = get_permalink( wc_get_page_id( 'myaccount' ) );
    }

    return $redirect;
    }
    add_filter( 'woocommerce_login_redirect', 'wc_custom_user_redirect', 10, 2 );