• christoph-ED

    (@webagenturerding)


    there are some problems with setting up:

    1. If affiliate is registerd he also have the customer role, should only have the affiliate role
    2. If a affiliate Login he gets redirected to the my-account instead of affiliate dashboard
    3. in the affiliate dashboard the menu is missing if i click on eg. generate links so he cant go back to the dashboard. it looks like the menu is not dislay in the endpoints from affiliate-dashboard

    The page I need help with: [log in to see the link]

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Support Juan Coronel

    (@juaancmendez)

    Hi Christoph,
    we hope you’re doing well!

    1. This is by default, the plugin only adds the affiliate role, and the customer role is added by WooCommerce. However, to remove the customer role when registering an affiliate, add this code to the functions.php of your active theme:

    if ( defined( 'YITH_WCAF' ) && ! function_exists( 'yith_wcaf_new_affiliate_remove_customer_role' ) ) {
        function yith_wcaf_new_affiliate_remove_customer_role( $id ) {
            $user = get_user_by('id', $id);
            $user->remove_role( 'customer' );
        }
        
        add_action( 'yith_wcaf_new_affiliate', 'yith_wcaf_new_affiliate_remove_customer_role', 10, 1 );
    }

    2. In order to achieve that, add this code too:

    if( ! function_exists( "yith_wcaf_redirect_to_affiliate_dashboard" ) ) {
    
        function yith_wcaf_redirect_to_affiliate_dashboard()
        {
       
         return home_url('/affiliate-dashboard');
       
        }
       
        add_filter( 'login_redirect', 'yith_wcaf_redirect_to_affiliate_dashboard' );
        add_filter( 'woocommerce_login_redirect', 'yith_wcaf_redirect_to_affiliate_dashboard' );
       
       }

    3. In order to fix that, try with this code:

    if ( defined( 'YITH_WCAF' ) ) {
        add_filter( 'yith_wcaf_show_dashboard_links', '__return_true' );
        add_filter( 'yith_wcaf_show_dashboard_links_withdraw', '__return_true' );
    }

    We will be attentive to your response.

    Best regards.

    Thread Starter christoph-ED

    (@webagenturerding)

    Hi it works except the first one.

    Do i have to change “customer” to “kunde”, cause its the german role name for customer?

    2+3 works great thx.

    Plugin Support Juan Coronel

    (@juaancmendez)

    Hi Christoph,
    thanks for your reply!

    You can try with that role name, in my case the customer role is called “customer” but we think that by default, these data are saved in English. However, you can verify it by going to the wp_user_meta table of your database, filtering by a specific id that has that role, and verify the value(s) that the wp_capabilities key has (for example
    a:1:{s:8:”customer”;b:1;})

    Check it out and tell us any news, please.

    Have a nice day!

    Thread Starter christoph-ED

    (@webagenturerding)

    thx for ur fast reply.

    yes its customer so the 1. snippet dont work.

    Thread Starter christoph-ED

    (@webagenturerding)

    and now … all login go to affiliate-dashboard but only the affiliate role should redirect to this.

    Plugin Support Juan Coronel

    (@juaancmendez)

    Hi Christoph,

    The first code should work. We have tested it and it works correctly. The customer role on your site is probably called something else.
    On the other hand, we have made corrections to be able to perform the redirects as you wish. Try this new code and let us know if it works for you:

    if ( !function_exists('my_login_redirect') ) {
        function my_login_redirect( $redirect_to, $request, $user ) {
            if ( isset( $user->roles ) && is_array( $user->roles ) ) {
                if ( in_array( 'administrator', $user->roles ) ) {
                    return $redirect_to;
                } elseif ( in_array( 'yith_affiliate', $user->roles ) ) {
                    return home_url( '/affiliate-dashboard' );
                } else {
                    return home_url();
                }
            } else {
                return $redirect_to;
            }
        }
         
        add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );
    }
    
    if ( !function_exists('filter_woocommerce_login_redirect') ) {
        function filter_woocommerce_login_redirect( $redirect, $user ) { 
            if ( isset( $user->roles ) && is_array( $user->roles ) ) {
                if ( in_array( 'administrator', $user->roles ) ) {
                    return $redirect;
                } elseif ( in_array( 'yith_affiliate', $user->roles ) ) {
                    return home_url( '/affiliate-dashboard' );
                } else {
                    return $redirect;
                }
            } else {
                return $redirect;
            }
        }; 
                 
        add_filter( 'woocommerce_login_redirect', 'filter_woocommerce_login_redirect', 10, 2 );
    }

    We will be attentive to your response.

    Best regards.

    • This reply was modified 2 years, 10 months ago by Juan Coronel.
    Thread Starter christoph-ED

    (@webagenturerding)

    Thx that snippet looks pretty good.

    for 1) i give it another try.

    Plugin Support Juan Coronel

    (@juaancmendez)

    Hi Christoph,
    thanks for your reply.

    Just to be sure, are you verifying that the Affiliate role is only added in new affiliates or in those that you already had previously created? It only works when a new affiliate is registered.

    We will be attentive to your response.

    Have a nice day.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Redirecten, User Role and Affiliate Dashboard’ is closed to new replies.