Remove Unnecessary Options from WooCommerce Admin Menu
Explanation
If you're looking to tidy up your WooCommerce admin menu by removing some of the options you don't use, this code snippet is just what you need. It allows you to hide specific menu items from the WooCommerce section in your WordPress admin panel.
Here's how it works:
- The code hooks into the WordPress admin menu system using admin_menu. This lets you customize the menu items.
- It first checks if WooCommerce is active on your site. If not, it stops the process to avoid errors.
- You'll see a list of menu items like Dashboard, Orders, Coupons, etc. Each line is a command to remove a specific menu item.
- To remove an item, simply uncomment the line by deleting the // at the beginning of the line. For example, to remove the Orders menu, change // remove_submenu_page('woocommerce', 'edit.php?post_type=shop_order'); to remove_submenu_page('woocommerce', 'edit.php?post_type=shop_order');
Important: The code also checks if the user has the right permissions to manage WooCommerce. If not, it will block access to the page with a message.
This customization helps you keep your admin panel clean and focused on the options you actually use, making it easier to manage your store.
Code
<?php
// Hook into the 'admin_menu' action to modify the WooCommerce admin menu
add_action('admin_menu', 'wp_dudecom_customize_woocommerce_admin_menu', 99);
function wp_dudecom_customize_woocommerce_admin_menu() {
// Check if WooCommerce is active
if (!class_exists('WooCommerce')) {
return;
}
// Remove specific WooCommerce menu items
// Uncomment the lines for the menu items you want to remove
// Remove WooCommerce Dashboard
// remove_submenu_page('woocommerce', 'wc-admin&path=/');
// Remove Orders
// remove_submenu_page('woocommerce', 'edit.php?post_type=shop_order');
// Remove Coupons
// remove_submenu_page('woocommerce', 'edit.php?post_type=shop_coupon');
// Remove Reports
// remove_submenu_page('woocommerce', 'wc-reports');
// Remove Settings
// remove_submenu_page('woocommerce', 'wc-settings');
// Remove Status
// remove_submenu_page('woocommerce', 'wc-status');
// Remove Extensions
// remove_submenu_page('woocommerce', 'wc-addons');
}
// Ensure the user has the capability to manage WooCommerce
add_action('admin_init', 'wp_dudecom_check_user_capabilities');
function wp_dudecom_check_user_capabilities() {
if (!current_user_can('manage_woocommerce')) {
wp_die(__('You do not have sufficient permissions to access this page.'));
}
}
?>
Instructions
File Location: Add the code to your theme's functions.php
file or a custom plugin file.
Prerequisites:
- Ensure WooCommerce is installed and activated on your WordPress site.
- Have access to your WordPress admin panel and file editor.
Implementation Steps:
- Log in to your WordPress admin panel.
- Navigate to Appearance > Theme Editor if you are editing the
functions.php
file. Alternatively, use an FTP client or file manager to access your WordPress files if you are using a custom plugin. - Open the
functions.php
file of your active theme or your custom plugin file. - Copy and paste the provided code snippet into the file.
- Decide which WooCommerce menu items you want to remove. Uncomment the corresponding lines by deleting the
//
at the beginning of each line for the items you wish to hide. - Save the changes to the file.
- Refresh your WordPress admin panel to see the changes in the WooCommerce menu.
Note: Ensure you have the capability to manage WooCommerce, as the code includes a permission check that restricts access if you lack the necessary permissions.
Need help with implementation or more advanced functionality? Visit wp-dude.com for expert WordPress support.