Support

Account

Home Forums General Issues Redirect Woocommerce Customer based on value assigned to his profile

Solved

Redirect Woocommerce Customer based on value assigned to his profile

  • SO if customer 1 = BEK
    redirect him to /order-bek page

    if customer 2 = MJ
    redirect him to /order-mj page

    and so on …

    add_action(‘wp’, ‘dc_check’);

    function dc_check( $atts ) {
    if(is_user_logged_in()){
    $current_user_id = ‘user_’.get_current_user_id();
    $user_dc = get_field(‘distribution_center’, $current_user_id);
    if( $user_dc == ‘BEK’ ) {
    echo ‘NEED TO REDIRECT HIM TO SPECIFIC PAGE AFTER LOGIN ‘;
    }
    }

    }

  • I Got it worked 🙂 … Its working now

    function wpdocs_my_login_redirect( $url, $request, $user ) {

    if ( $user && is_object( $user ) && is_a( $user, ‘WP_User’ ) ) {
    $dc = get_field(‘distribution_center’, ‘user_’.(int) $user->ID);
    if ( $user->has_cap( ‘administrator’ ) ) {
    $url = admin_url();
    }
    if ( $user->has_cap( ‘customer’ ) && $dc == ‘BEK’ ) {

    $url = home_url( ‘/order-guide-bek/’ );
    }

    else {
    $url = home_url( ‘/members-only/’ );
    }
    }
    return $url;
    }

    add_filter( ‘login_redirect’, ‘wpdocs_my_login_redirect’, 10, 3 );

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.