Is there a function for finding out if the user is "shop_manager" in WP / woocommerce

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

thanks

+4
source share
3 answers

No, there is no built-in function since the shop_manager role comes from WooCommerce and not from WordPress, but this can be achieved with the 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 helpful.

+3
source

In fact, yes there is!

 current_user_can( 'manage_woocommerce' ); 

Docs:

current_user_can ($ opportunity)

'manage_woocommerce'

+5
source

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 } } 
+1
source

Source: https://habr.com/ru/post/1491626/


All Articles