Redirecting woocommerce register page to membership register page

I want to redirect when not logged in users go to woocommerce login/register page, to membership login/register page. How can I do that?

  • Abdul Wajed

    Hi eTech,

    I hope you are well today. :slight_smile:

    The following function should help you to achieve the redirection:

    add_action( 'wp', 'woo_redirect_m2p' );
    function woo_redirect_m2p() {
      if ( is_page('my-account') && !is_user_logged_in() ) {
          wp_redirect( home_url('register') );
          die();
      }
    }

    You can add this to your theme's functions.php file, before the closing PHP tag, or, if it's something you'll want no matter which theme you're using, you can add those codes as mu-plugins. To use mu-plugins, go to /wp-content/ and find the folder with name 'mu-plugins'. If there is no folder in that name, then create a folder, name it 'mu-plugins', create a file inside that, give any name you like and paste the code in there. You don't need to activate that plugin. Mu-plugins means must use plugins, so it will be activated automatically always. If you use mu-plugins then add a PHP start tag at the beginning of the code.

    Hope this helps! Please let me know if you need any further assistance. :relaxed:

    Have a nice day.
    Cheers!
    Wajed

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.