phpcsswordpresswoocommerceaffiliate

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 enter image description here


Solution

  • 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.