• Resolved nicolomonili

    (@nicolomonili)


    After installing Woocommerce i noticed that a certain WordPress user role no longer sees the WordPress admin bar.

    I use another plugin to allow or disallow certain user roles to see the admin bar, and i believe Woocommerce has some logic to hide the admin bar.

    I wanted to have confirmation on this, also because when a user tries to view the WordPress login page he is automatically redirected to the “my account” page, so I think it is Woocommerce that has this logic.

    Thank you

Viewing 12 replies - 1 through 12 (of 12 total)
  • Thread Starter nicolomonili

    (@nicolomonili)

    Looking at the code it seems that woocommerce hides the bar.
    File: /woocommerce/includes/wp-user-functions.php

    /**
     * Prevent any user who cannot 'edit_posts' (subscribers, customers etc) from seeing the admin bar.
     *
     * Note: get_option( 'woocommerce_lock_down_admin', true ) is a deprecated option here for backwards compatibility. Defaults to true.
     *
     * @param bool $show_admin_bar If should display admin bar.
     * @return bool
     */
    function wc_disable_admin_bar( $show_admin_bar ) {
    	/**
    	 * Controls whether the WooCommerce admin bar should be disabled.
    	 *
    	 * @since 3.0.0
    	 *
    	 * @param bool $enabled
    	 */
    	if ( apply_filters( 'woocommerce_disable_admin_bar', true ) && ! ( current_user_can( 'edit_posts' ) || current_user_can( 'manage_woocommerce' ) ) ) {
    		$show_admin_bar = false;
    	}
    
    	return $show_admin_bar;
    }
    add_filter( 'show_admin_bar', 'wc_disable_admin_bar', 10, 1 ); // phpcs:ignore WordPress.VIP.AdminBarRemoval.RemovalDetected
    
    Plugin Support Shameem R. a11n

    (@shameemreza)

    Hi @nicolomonili,

    You’re correct. WooCommerce does have a logic to hide the admin bar for users who don’t have the “edit_posts” or “manage_woocommerce” capabilities. This prevents subscribers, customers, and other similar roles from seeing the admin bar.

    The function wc_disable_admin_bar is responsible for this. If you want certain user roles to see the admin bar, they need to have either “edit_posts” or “‘manage_woocommerce” capabilities.

    As for the redirection to the “my account” page, WooCommerce automatically redirects users who are not logged in to the “my account” page when they try to view the WordPress login page.

    I hope this clarifies your concern. If you have any other questions, feel free to ask.

    Thread Starter nicolomonili

    (@nicolomonili)

    Ok thanks for the reply.

    However, I think it would be interesting and correct to allow this functionality to be configurable by the user, therefore letting the user choose whether to enable this thing or not. Especially for those who need to manage the admin bar based on certain rules.

    Thread Starter nicolomonili

    (@nicolomonili)

    I solved it like this:

    add_filter( 'woocommerce_disable_admin_bar', '__return_false' );

    in this way it is the other plugin that I use that takes care of managing the admin bar

    Hi @nicolomonili,

    Thank you for sharing your solution with us and the WooCommerce community. I’m glad to know you were able to resolve the issue. Just so you know – we will now close this ticket as solved. If you have any other questions or issues, please feel free to open a new ticket and we’ll be happy to assist you.

    Thank you for choosing WooCommerce and have a great day!

    Thread Starter nicolomonili

    (@nicolomonili)

    Plugin Support ckadenge (woo-hc)

    (@ckadenge)

    Hey @nicolomonili,

    Glad to hear it – thanks for letting us know!

    I’ll mark this thread as resolved now. If you have any further questions, I recommend creating a new thread.

    a7xfanben

    (@a7xfanben)

    add_filter( 'woocommerce_disable_admin_bar', '__return_false' );

    Was this only added to the file for /woocommerce/includes/wp-user-functions.php?

    I’ve been having the same issue and fixed it by deleting some of the code in that file. However, updating WooCommerce just brings it back and I don’t want to have to edit the plugin file every time it updates.

    Thread Starter nicolomonili

    (@nicolomonili)

    @a7xfanben Don’t edit the theme file directly, use a plugin, such as Code Snippets https://it.www.ads-software.com/plugins/code-snippets/

    a7xfanben

    (@a7xfanben)

    Thanks for the tip. I’d prefer not to add a plugin just to fix the problems that existing plugins are causing.

    Plugin Support omarfpg a11n

    (@omarfpg)

    Hi @a7xfanben,

    However, updating WooCommerce just brings it back and I don’t want to have to edit the plugin file every time it updates.

    Thanks for the tip. I’d prefer not to add a plugin just to fix the problems that existing plugins are causing.

    Another way to go is using a child theme where you can add code directly into your theme’s functions.php. I hope this helps!

    Cheers!
    -OP

    a7xfanben

    (@a7xfanben)

    Another way to go is using a?child theme?where you can add code directly into your theme’s functions.php. I hope this helps!

    Hi, that is just what I did yesterday and it worked! Thanks!

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Admin Bar is not visible’ is closed to new replies.