要(仅)禁用特定用户角色的Admin WooCommerce"Home"页面,我们可以隐藏WooCommerce"Home"子菜单项,并将相关请求重定向到WooCommerce"Orders"页面:
add_action( 'admin_head', 'disable_admin_woocommerce_home_fur_css' );
function disable_admin_woocommerce_home_fur_css() {
$targeted_role = 'administrator'; // Here define the user role
if ( current_user_can( $targeted_role ) ) :
?><style> li.toplevel_page_woocommerce ul li.wp-first-item {display:none !important;}</style><?php
endif;
}
add_action( 'admin_menu', 'disable_admin_woocommerce_home_for_user_role', 999 );
function disable_admin_woocommerce_home_for_user_role() {
global $submenu;
$targeted_role = 'administrator'; // Here define the user role
if ( current_user_can( $targeted_role ) ) {
if ( isset($_GET['page']) && $_GET['page'] == 'wc-admin' && ! isset($_GET['path']) ) {
wp_redirect( admin_url('edit.php?post_type=shop_order') );
exit();
}
}
}
它将允许store 经理访问分析部分.
代码位于您的子主题的unctions.php文件中(或在插件中).经过测试,效果良好.