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

php, woocommerce, wordpress

Solution

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.

Problem

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

Original source