Skip to content

Instantly share code, notes, and snippets.

@Acephalia
Last active December 3, 2023 22:12
Show Gist options
  • Save Acephalia/fc52c79280dfd453b66928bbdfdfc439 to your computer and use it in GitHub Desktop.
Save Acephalia/fc52c79280dfd453b66928bbdfdfc439 to your computer and use it in GitHub Desktop.
Remove Inventory Tab For Shop Manager User Role
// Remove inventory capabilities for shop manager by u/acephaliax
add_filter('woocommerce_product_data_tabs', 'remove_inventory_tab', 10, 1);
// Add action to include inline CSS for shop_manager
add_action('admin_enqueue_scripts', 'inline_custom_admin_styles');
function remove_inventory_tab($tabs) {
global $post, $product_object;
// Check if the current user has the "shop_manager" role
if (current_user_can('shop_manager')) {
unset($tabs['inventory']);
}
return $tabs;
}
function inline_custom_admin_styles() {
global $post, $product_object;
// Check if the current user has the "shop_manager" role
if (current_user_can('shop_manager')) {
// Inline CSS to hide checkboxes
echo '<style>
/* Hide variable_stock fields */
.show_if_variation_manage_stock {display:none!important;}
</style>';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment