你可以使用删除子菜单页面 https://developer.wordpress.org/reference/functions/remove_submenu_page/
function action_admin_menu() {
// Contains the URI of the current page.
$current_url = $_SERVER['REQUEST_URI'];
// Make sure wc-admin / customers page will still work
if ( strpos( $current_url, 'customers' ) == false) {
remove_submenu_page( 'woocommerce', 'wc-admin' );
}
}
add_action( 'admin_menu', 'action_admin_menu', 99, 0 );
EDIT:同时发布新版本的 WooCommerce 后,访问某些页面时上述答案似乎存在问题,可以通过使用以下方法解决:
function strposa( string $haystack, array $needles, int $offset = 0 ) : bool {
foreach ( $needles as $needle ) {
if ( strpos( $haystack, $needle, $offset ) !== false ) {
return false; // stop on first true result
}
}
return true;
}
function action_admin_menu() {
// Contains the URI of the current page.
$current_url = $_SERVER['REQUEST_URI'];
// Pages that must remain accessible
$should_still_work = array( 'customers', 'analytics', 'marketing' );
// Make sure some wc-admin pages will still work
if ( strposa( $current_url, $should_still_work ) ) {
remove_submenu_page( 'woocommerce', 'wc-admin' );
}
}
add_action( 'admin_menu', 'action_admin_menu', 99, 0 );
在此更新的答案中使用:在 strpos 中使用数组作为针 https://stackoverflow.com/a/9220624/11987538
Related:
- 在 WordPress 管理仪表板中更改 WooCommerce 产品菜单标题 https://stackoverflow.com/questions/61106895/change-woocommerce-products-menu-title-in-wordpress-admin-dashboard
- 在 WordPress 管理仪表板上的 WooCommerce 中删除“添加订单”的子菜单 https://stackoverflow.com/questions/64465539/remove-submenu-for-add-order-in-woocommerce-on-wordpress-admin-dashboard/
- 如何重命名 WordPress 管理仪表板上的 WooCommerce 选项卡下的菜单选项卡 https://stackoverflow.com/questions/60445980/how-to-rename-a-menu-tab-under-woocommerce-tab-on-wordpress-admin-dashboard
- 禁用(删除)WooCommerce 4.3.x 中的营销菜单选项 https://stackoverflow.com/questions/63068812/disable-remove-the-marketing-menu-option-in-woocommerce-4-3-x