Is there a function for knowing if user is ‘shop_manager’ in WP / woocommerce

I want to know if the shop_manager is logged-in WP/woocommerce. I know the function is_admin(), but do you know a way to use something like this ‘is_shop_manager()’ ?

Thanks

Related posts

Leave a Reply

3 comments

  1. No, there is not any direct inbuilt function as shop_manager role is coming from WooCommerce & not from WordPress, but it can be achieved with following code:

    function is_shop_manager() {
        $user = wp_get_current_user();
        if ( isset( $user['roles'][0] ) && $user['roles'][0] == 'shop_manager' ) {
            return true;    // when user is shop manager
        } else {
            return false;   // when user is not shop manager
        }
    }
    
    if ( is_shop_manager() ) {
        // write code for shop_manager here
    }
    

    Hope this will be useful.

  2. Fixed code:

    function is_shop_manager() {
        $user = wp_get_current_user();
    
        if ( isset( $user->roles[0] ) && $user->roles[0] == 'shop_manager' ) {
            return true;    // when user is shop manager
        } else {
            return false;   // when user is not shop manager
        }
    }