• Resolved whitneyr

    (@whitneyr)


    FYI: I have done extensive research on this topic.

    I have a members only site running woo commerce.

    1. I would like users to be redirected to the home page (https://mydomain.com) after login and registration. Currently users are directed to their account page.

    The woocommerce site lists the following fix. However, I’ve had no luck with it.

    /*
     * goes in theme functions.php or a custom plugin
     *
     * By default login goes to my account
     **/
    add_filter('woocommerce_login_widget_redirect', 'custom_login_redirect');
    
    function custom_login_redirect( $redirect_to ) {
         $redirect_to = 'https://anypage.com';
    }

    2. Is there a way to moderate Registration. Meaning if a user registers, they are held in a queue until I can approve them.

    Thank you kindly.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Hi,

    not sure about 2, but I can help on issue 1.

    I believe the fix they suggest only works if you are using the login widget on your site. If it’s the login form directly you need to do something different.

    This how I did manage to redirect the user after woocommerce logged in.

    You just need to add an <input type=”hidden” name=”redirect” value=”<?php echo get_home_url(); ?>” /> to your login form and set the value attribute with the url you want to redirect to.

    Please make sure you are not editing the form-login.php file directly on woocommerce, if you need you can add a copy of this file on your theme directory (my-theme/woocommerce/myaccount/form-login.php) and do whatever you need to do here.

    Hope this is helpful.

    Thread Starter whitneyr

    (@whitneyr)

    Very helpful!
    This worked like a charm!

    Thread Starter whitneyr

    (@whitneyr)

    One more thing.
    I tried to do this in the same file for the registration.
    I want to forward to the home page after the customer registers for the first time. Instead it goes to the my acct page.

    Any idea on how to get this to work?

    Thank you!

    hi
    Is it important add this code to specific place?
    I did it in my copy of form-login.php (Karma theme) and it doesn`t seem to work for me.

    If you want it to work on the normal login form for woocommerce, you should change the filter hook to woocommerce_login_redirect and add a return statement containing the url variable.

    add_filter('woocommerce_login_redirect', 'ras_login_redirect');
    
    function ras_login_redirect( $redirect_to ) {
         $redirect_to = 'https://anypage.com';
         return $redirect_to;
    }

    All of this should of course go in your themes functions file.

    Hi, i tried adding at the bottom of templates/form-login.php in many ways the code you gave ( <input type=”hidden” name=”redirect” value=”<?php echo get_home_url(); ?>” /> ) but no result. Could someone please give the exact code for redirection to homepage? My site url is https://i-gen.gr/ if needed.
    I would appreciate any answer from anyone.

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