• Hi

    I have add in fonction.php this

    add_filter(‘woocommerce_login_redirect’, ‘ras_login_redirect’);

    function ras_login_redirect( $redirect_to ) {
    global $current_user, $wpdb;
    $role = $wpdb->prefix . ‘capabilities’;
    $current_user->role = array_keys($current_user->$role);
    $role = $current_user->role[0];

    if($role==”adminsitrator”){
    $redirect_to = ‘https://anypage.com’;
    return $redirect_to;
    }else{
    $redirect_to = ‘https://anotherpage.com’;
    return $redirect_to;
    }
    }

    But it s look like it can t take the current user role

    Any Idea ?

    Regards

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi !

    Have you try $current_user->roles[0] ?

    role with a “s” …

    Thread Starter Aill3urs

    (@aill3urs)

    Yip and it s not that ??
    Thanks

    Oups !

    You wrote “admin’si’trator” in your condition

    maybe trying with “admin’is’trator”

    :p

    Thread Starter Aill3urs

    (@aill3urs)

    Yip i see after but same problem doesn t work ??

    So, i propose you comment thess 2 lines

    $role = $wpdb->prefix . 'capabilities';
    $current_user->role = array_keys($current_user->$role);

    and keep this one

    $role = $current_user->roles[0];

    without forgot the ‘s’ at tthe end of role, and add just next

    ‘echo $current_user->roles[0];’

    Just to ses what happens

    Because I can’t figure out the utility of neither $role = $wpdb->prefix . ‘capabilities’; in your part of code nor array_keys witch return only an array of keys (without associated values) from the input parameter array …

    see https://fr2.php.net/manual/en/function.array-keys.php

    Moderator bcworkz

    (@bcworkz)

    Using roles in conditional statements is ill advised. It is recommended you base conditionals on capabilities. Any capability solely belonging to the Administrator will do, though ideally it should relate to the task at hand.

    if( current_user_can('activate_plugins')) /*do something only admin can do*/;

    Doing so could reduce your function to a single ternary line.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Woocommerce Redirect’ is closed to new replies.