user3816812
user3816812

Reputation: 45

Disabling Woo Commerce Wordpress Tool Bar For Customers

I've got a site that has woocommerce on. When a new customer buys from the site they create an account.

When the account is created they become a Customer (in user roles).

This is great as they have limited access, however they can view the Wordpress toolbar located above the site.

Does anyone know how i can remove this.

I've tried multiple 'displace admin toolbar' plugins and tried adding custom code to the functions file but nothing has worked.

Any help would be appreciated

Thanks

Upvotes: 0

Views: 1241

Answers (2)

Howli
Howli

Reputation: 12469

While Iago's answer will remove the admin bar, they would still have access to the dashboard by typing in site.com/wp-admin. If you use the:

// Customers won't see the bar, only administrators.
add_action('after_setup_theme', 'remove_admin_bar');

function remove_admin_bar() {
 if (!current_user_can('administrator') && !is_admin()) {
        show_admin_bar(false);
    }
}

along with the following:

if (is_admin()) 
{
    $user = wp_get_current_user();
    if (in_array('customer', $user->roles)) 
    {
        wp_redirect(get_home_url());
    }
}

while a customer is logged in the admin bar is hidden and if the customer tries to view the dashboard then they will be redirected to the homepage of the website.

Upvotes: 0

Iago
Iago

Reputation: 1214

Use this function at the end of your functions.php:

// Customers won't see the bar, only administrators.
add_action('after_setup_theme', 'remove_admin_bar');

function remove_admin_bar() {
 if (!current_user_can('administrator') && !is_admin()) {
        show_admin_bar(false);
    }
}

Source: WooCommerce Article

Upvotes: 1

Related Questions