Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save acanza/9c4bd114cc1f8c5b328c to your computer and use it in GitHub Desktop.
Save acanza/9c4bd114cc1f8c5b328c to your computer and use it in GitHub Desktop.
//* Crea rol empleado de tienda
add_action( 'init', 'add_shop_staff_rol' );
function add_shop_staff_rol(){
$shop_role = get_role( 'shop_manager' );
add_role( 'shop_staff', __( 'Empleado de tienda', 'woocommerce' ), $shop_role->capabilities );
}
//* Oculta algunas secciones del panel de ajustes de WooCommerce al rol de usuario 'shop_staff'
function hide_wc_menu_items() {
global $current_user;
//* Get the current user role
$user_roles = $current_user->roles;
$user_role = array_shift($user_roles);
//* Set up the sections list to hide
$remove = array( 'wc-settings', 'wc-status', 'wc-addons', );
if ( 'shop_staff' == $user_role ) {
remove_submenu_page( 'woocommerce', 'wc-settings' );
remove_submenu_page( 'woocommerce', 'wc-status' );
remove_submenu_page( 'woocommerce', 'wc-addons' );
remove_submenu_page( 'woocommerce', 'edit.php?post_type=shop_coupon' );
remove_submenu_page( 'edit.php?post_type=product', 'product_attributes' );
remove_submenu_page( 'edit.php?post_type=product', 'edit-tags.php?taxonomy=product_shipping_class&post_type=product' );
}
}
add_action( 'admin_menu', 'hide_wc_menu_items', 99, 0 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment