Last active
November 11, 2022 16:05
-
-
Save lukecav/18176ae543d33dee12b61997904b6bc0 to your computer and use it in GitHub Desktop.
Remove the Limit Orders aettings tab for Shop Managers in WooCommerce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'woocommerce_settings_tabs_array', 'remove_woocommerce_setting_tabs', 200, 1 ); | |
function remove_woocommerce_setting_tabs( $array ) { | |
// Declare the tabs we want to hide | |
$tabs_to_hide = array( | |
'limit-orders' => 'Order Limiting', | |
); | |
// Get the current user | |
$user = wp_get_current_user(); | |
// Check if user is a shop_manager | |
if ( isset( $user->roles[0] ) && $user->roles[0] == 'shop_manager' ) { | |
// Remove the tabs we want to hide from the array | |
$array = array_diff_key($array, $tabs_to_hide); | |
// Loop through the tabs we want to remove and hook into their settings action | |
foreach($tabs_to_hide as $tabs => $tab_title) { | |
add_action( 'woocommerce_settings_' . $tabs , 'redirect_from_tab_page'); | |
} | |
} | |
return $array; | |
} | |
function redirect_from_tab_page() { | |
// Get the Admin URL and then redirect to it | |
$admin_url = get_admin_url(); | |
wp_redirect($admin_url); | |
exit; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://stackoverflow.com/questions/36779307/hide-a-woocommerce-setting-tab
https://wordpress.org/plugins/limit-orders/
https://wordpress.org/support/topic/show-tab-only-for-administrators/