简体   繁体   中英

Show a menu Item based on specific User role in Woocommerce

I need help showing a specific menu item if user role is "Affiliate". Menu Item is "Affiliate Dashboard" Don't want to use any plugin for such task. Site is under maintenance mode so I can't show the site, However I've attached screenshot. Please take a look and help me out. Thanks 在此处输入图片说明

Just write a if condition for do this..Example

if(Auth::user()->has('Affiliate')) {
   <a href="/affiliate-dashboard">Affiliate Dashboard</a>

}

But it's only possible when your user have assigned specific role

The following code will hide "Affiliate Dashboard" menu item if the current user role is not "affiliate":

The code:

add_action( 'wp_head', 'show_hide_affiliate_menu_item', 500 );
function show_hide_affiliate_menu_item() {
    if( ! current_user_can( 'yith_affiliate' ) )
        echo '<style> .top-bar-nav #menu-item-11874 { display: none !important } </style>'; 
}

Code goes in function.php file of your active child theme (or active theme). It should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM