WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce - excelling eCommerce
Woocommerce: Admin Redirect - disable for non Customers (10 posts)

  1. daddia
    Member
    Posted 1 year ago #

    Since installing woocommerce, when a user with a role other than Administrator e.g. Subscriber, logs in via the WP login page they are redirected from the /wp-admin/profile.php to the /my-account/ page.

    I have tried several ways however can't seem to disable the redirect.

    Essentially, what I'm hopping to achieve is:
    a) if a user with role Customer logs on, they are directed to /my-account/
    b) if a user with stardard WP role logs on, they are directed to /wp-admin/ as per stardard WP.

    So, I guess two questions to resolve this?

    1. How do I disable the automatic redirect?

    2. How can I add a conditional redirect based on role?

    Please help.

    http://wordpress.org/extend/plugins/woocommerce/

  2. boldt
    Member
    Posted 1 year ago #

    I do not know how to do it exactly but inside woocommerce_function.php is a fucntion: function woocommerce_process_login() and at the bottom is a line: wp_redirect(get_permalink(woocommerce_get_page_id('myaccount')));

    Solution number one is to change the word 'myaccount' to something else.
    I cannot recommend this because it is a nightmare to keep track on own changes every time there is an official update.

    Solution number 2 may be!
    May be it is possible to cancel the function woocommerce_process_login() and replace it with your own.

    There is a system of elimination/replacing of functions in the theme- system parent/child. if a plugin function is considered to be a child theme function, then you should be able to copy the function in to your theme functions.php and add your changes here.

    but now I'm guessing

  3. toto
    Member
    Posted 1 year ago #

    what about that:
    /**
    * Login and Registration
    *
    * @see woocommerce_process_login()
    * @see woocommerce_process_registration()
    */
    add_action( 'init', 'woocommerce_process_login' );
    See All hooks Here

    Can we use this action to change woocommerce redirection:
    add_action( 'init', 'woocommerce_process_login' );

  4. goingnutz
    Member
    Posted 1 year ago #

    anyone managed to resolve the super annoying issue above, no administrators can login into wordpress dashboard via wp-admin since i activated this stupid woocommerce plugin! Come woothemes get your act together.

  5. DizzyDi
    Member
    Posted 1 year ago #

    I am having this problem too.

    I only have 1 use set up (Admin) and I cannot access my Dashboard. It redirects to Woocommerce My Account.

    I don't know what to do.

    Please help.

  6. Alex Su
    Member
    Posted 1 year ago #

    Hi DizzyDi,

    I don't know where you installed your WordPress. As my experience, I run my WordPress on a server which uses cPanel. And it is very confusing because when you quickinstall WordPress, the default username you set up is not administrator. That's why you can't access the Dashboard.

    The simplest solution I learned is:
    1. Install a WordPress on your local machine.
    2. Go to its database at localhost/phpmyadmin.
    3. Export wp_usermeta and wp_users from your local machine.
    4. Override wp_usermeta and wp_users on your remote server with the two you get from your local machine.
    5. Log in with the username and password.

    Now the username you use is the administrator and you can access the Dashboard.

    Hope this helps!

  7. SherrisOffice
    Member
    Posted 1 year ago #

    If you login to your site via FTP and change the name of the woocommerce folder inside your plugins folder (wp-content>plugins) to something else, it will disable the plugin and you can at least access your dashboard. That's as far as I have gotten though - anyone else come up with a solution?

  8. SqueezyDee
    Member
    Posted 1 year ago #

    I have a multisite and it seems that woocommerce replaces default wordpress user roles with their own. Each site that I have activated woocommerce the roles have been changed of deleted.

    I don't know if this is related but if anybody know how to resolve this please let me know.

    Thanks

  9. ollybach
    Member
    Posted 1 year ago #

    maybe this helps someone.
    i kind of had the same issue (wanting to redirect admins to the dashboard and everybody else to the my-account page) so i came up with this one
    (to put in your own functions file)

    /**remove wooocommerce's own login processing to replace with our own to enable redeirection by role */
    	remove_action('init','woocommerce_process_login');
    	add_action('init','msci_woo_after_login_redirect');
    	/**the below is a copy of woocommerce_process_login with a couple of bits added */
    	function msci_woo_after_login_redirect() {
    		global $woocommerce;
    
    		if ( ! empty( $_POST['login'] ) ) {
    
    			$woocommerce->verify_nonce( 'login' );
    
    			try {
    				$creds = array();
    
    				if ( empty( $_POST['username'] ) )
    					throw new Exception( '<strong>' . __( 'Error', 'woocommerce' ) . ':</strong> ' . __( 'Username is required.', 'woocommerce' ) );
    				if ( empty( $_POST['password'] ) )
    					throw new Exception( '<strong>' . __( 'Error', 'woocommerce' ) . ':</strong> ' . __( 'Password is required.', 'woocommerce' ) );
    
    				if ( is_email( $_POST['username'] ) ) {
    					$user = get_user_by( 'email', $_POST['username'] );
    
    					if ( isset( $user->user_login ) )
    						$creds['user_login'] 	= $user->user_login;
    					else
    						throw new Exception( '<strong>' . __( 'Error', 'woocommerce' ) . ':</strong> ' . __( 'A user could not be found with this email address.', 'woocommerce' ) );
    				} else {
    					$creds['user_login'] 	= $_POST['username'];
    				}
    
    				$creds['user_password'] = $_POST['password'];
    				$creds['remember']      = true;
    				$secure_cookie          = is_ssl() ? true : false;
    				$user                   = wp_signon( $creds, $secure_cookie );
    
    				if ( is_wp_error( $user ) ) {
    					throw new Exception( $user->get_error_message() );
    				} else {
    					/**********************************************************************************************
    					*	added to original function to redirect depending on user roles]
    					***********************************************************************************************/
    					/*********************************************************************
    					*	set your redirects depending on user role
    					*	note: some users may have more than one role in which case you may want
    					*	to run a foreach loop or something
    					*	instead of using $roleRedirect[$user->roles[0]] below
    					***********************************************************************/
    					$roleRedirect['super_admin']='/wp-admin';
    					$roleRedirect['administrator']='/wp-admin';
    					/**********************************************************************************************
    					*	END->[added to original function to redirect depending on user roles]
    					**********************************************************************************************/
    
    					if ( ! empty( $_POST['redirect'] ) ) {
    						$redirect = esc_url( $_POST['redirect'] );
    					} 
    
    					/**********************************************************************************************
    					*	added to original function to redirect depending on user roles]
    					***********************************************************************************************/
    					elseif(isset($roleRedirect[$user->roles[0]])){
    						$redirect = esc_url($roleRedirect[$user->roles[0]]);
    					}
    					/**********************************************************************************************
    					*	END->[added to original function to redirect depending on user roles]
    					**********************************************************************************************/
    					elseif ( wp_get_referer() ) {
    						$redirect = esc_url( wp_get_referer() );
    					} else {
    						$redirect = esc_url( get_permalink( woocommerce_get_page_id( 'myaccount' ) ) );
    					}
    
    					wp_redirect( apply_filters( 'woocommerce_login_redirect', $redirect, $user ) );
    					exit;
    				}
    			} catch (Exception $e) {
    				$woocommerce->add_error( $e->getMessage() );
    			}
    		}
    	}

    may not be perfect but may be a starting point.....dunno

  10. Scott
    Member
    Posted 1 year ago #

    For a possible solution for redirects on woocommerce login/registration forms see

    https://github.com/woothemes/woocommerce/commit/014e31952828377bf7a1ebf4e812a43d0bcefa67#commitcomment-3351995

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic