Wordpress login page redirecting to Woocommerce My-Account Page for Normal Users

user8070092 picture user8070092 · Jul 12, 2017 · Viewed 8.5k times · Source

I am in a deep trouble. Please help me to find a solution for the following.

I have wordpress site which uses Woocommerce Plugin. Normally Woocommerce doesn't allow normal Users (Customer,User - These are roles that you can Select from Wordpress Admin Area > Add new User > Role). The problem is that only Administrator(Role) privilege guys have the access to see the Admin area dashboard and full settings.

I need all users to enter into dashboard area without redirecting to my-account page . Because now when users with Role Customer or something like, tried to enter login credentials of admin, they are getting redirected to my-account page. Only Administrator privilege role has the capability of entering the dashboard and settings.

So I searched in google and found the following link:

WooCommerce admin bar and dashboard access - Role editor page link

I tried the following link by writing the following code in functions.php , but now I can't see admin settings, please see the screenshot that I can see when entering as a normal user.

Normal User Login

I need all users access to see admin area dashboard and admin area settings (able to see Post, Page, Settings etc) and donot want to redirect to my-account page.

please help to find a solution for this, since I am struggling with this for a long time.

Answer

LauraTheExplorer picture LauraTheExplorer · Jan 19, 2018

I spent a lot of time looking for the answer to this one and it can be found in the class-wc-admin.php file under the prevent_admin_access function.

Add the following code:

add_filter( 'woocommerce_prevent_admin_access', '__return_false' );

To your functions PHP file and it will stop it blocking users who do not have: 'edit_posts', 'manage_woocommerce', 'view_admin_dashboard' from accessing the dashboard.

For good measure you can also add this which overrides the account permalink to be your admin page - which may be relevant.

function my_account_permalink($permalink) {

    return admin_url();
}

add_filter( 'woocommerce_get_myaccount_page_permalink', 'my_account_permalink', 1);