Skip to content

Instantly share code, notes, and snippets.

@WillBrubaker
Last active November 22, 2022 13:34
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save WillBrubaker/7edd45085b7666a13f53 to your computer and use it in GitHub Desktop.
Save WillBrubaker/7edd45085b7666a13f53 to your computer and use it in GitHub Desktop.
Remove WooCommerce submenu items for Shop Managers
<?php
/*
Don't copy the opening php tag
*/
/*
Removes submenu items from WooCommerce menu for 'Shop Managers'
available submenu slugs are:
wc-addons - the Add-ons submenu
wc-status - the System Status submenu
wc-reports - the Reports submenu
edit.php?post_type=shop_order - the Orders submenu
edit.php?post_type=shop_coupon - the Coupons submenu
Shop Managers lack the capability of 'update_core', so remove based on that capability
*/
function wooninja_remove_items() {
$remove = array( 'wc-settings', 'wc-status', 'wc-addons', );
foreach ( $remove as $submenu_slug ) {
if ( ! current_user_can( 'update_core' ) ) {
remove_submenu_page( 'woocommerce', $submenu_slug );
}
}
}
add_action( 'admin_menu', 'wooninja_remove_items', 99, 0 );
@banhduclac
Copy link

banhduclac commented Sep 14, 2016

perfect thank you !

@lukecav
Copy link

lukecav commented Oct 21, 2016

Nice share thanks!

@felizarraga
Copy link

Thank you very much! Great job, thanks for sharing.

@Doubleasam
Copy link

works perfectly thumbs up man

@kanlukasz
Copy link

great and smart solution

@pixelpad-io
Copy link

pixelpad-io commented Jul 17, 2018

I did something similar! Note: this does cause some issues when functions rely on these submenus existing. For example, when I updated woocommerce - there was a request to update the database as well. Updating this database would not work until I figured out I needed to enable the wc-settings submenu again.

@ashik726
Copy link

great task...................

@ashik726
Copy link

could you check the link http://prntscr.com/mmmp9w ..? I cann't remove "pdf invoice" sub menu. i've added code below. please help me

`function wooninja_remove_items() {
$remove = array( 'wc-settings', 'wc-status', 'wc-addons','wwpp-wholesale-roles-page','shop_coupon','wpo_wcpdf_options_page', );
foreach ( $remove as $submenu_slug ) {
if ( ! current_user_can( 'update_core' ) ) {
remove_submenu_page( 'woocommerce', $submenu_slug );
}
}
}

add_action( 'admin_menu', 'wooninja_remove_items', 99, 0 );`

@arif-ilmigo
Copy link

good and perfect!

@climbya15748
Copy link

really helpful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment