'How can I hide stripe from WordPress admin side for specific user role?

I am using User Role Editor and trying to hide this stripe gateway for specific user enter image description here

enter image description here

What should I check in settings of user editor role so that I can see orders but not the stripe.



Solution 1:[1]

It appears that the "Stripe Gateway" plugin you're using doesn't offer the ability to selectively allow or deny use by role. Testing a few of these today, I haven't found one that does. So the (great) User Role Editor plugin may not be able to help you accomplish this task. But don't despair! There are other ways :-)

If I understand correctly, you want to hide the Stripe settings from one ore more roles/users (so the live API keys are secure), right? It's easiest to remove it from a role.

Actually, there are two steps involved. One is to hide the "Stripe Gateway" menu that you mention, naturally, but Stripe settings are also found under the WooCommerce Payment tab. We would need need to hide that tab for the user/role also.

There may be a more elegant solution but I can offer a suggestion that accomplished this task.

  1. To hide the unwanted 'Stripe" menu, install the Adminimize plugin and activate.
  2. Then Dashboard - Settings - Adminimize - Menu Options
  3. The screen that appears will show in table format on the left, all the Dashboard menus and this should include your "Stripe Gateway". On the right is a list of roles .
  4. Find your unwanted "Stripe Gateway" menu in the Adminimize table and for the Shop Manager role on the right of the table tick the "Deactivate for Shop Manager" settings checkbox.
  5. Remember to scroll down and click the "Update Options" button to save the plugin settings.

Hopefully that menu has now disappeared for that role in the Dashboard.

Now I couldn't find the exact Stripe plugin that you're using but illustrate with another to produce the screencap here illustrating what I've written (link to screencap). Adminimize - hiding a menu from Shop manager role

The second step is to remove the Payment tab for the WooCommerce Shop Managers role. This has been answered here. Using the code from that post, add the following to your child theme's functions.php (if you're using a child theme).

    add_filter( 'woocommerce_settings_tabs_array', 'remove_woocommerce_setting_tabs', 200, 1 );
function remove_woocommerce_setting_tabs( $tabs ) {
    // Declare the tabs we want to hide
    $tabs_to_hide = array(
        'Payments',
        );


    // 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
        $tabs = array_diff($tabs, $tabs_to_hide);
    }

    return $tabs;
}

The result is illustrated here (link to screencap). Hiding a tab in WooCommerce

I'm sure there are more experienced WooCommerce people who can provide a better answer but I hope this helps.

Solution 2:[2]

SO I have created this :

add_action( 'admin_menu', 'remove_admin_menu_items', 999 );

function remove_admin_menu_items() {

    // global $woocommerce;
    global $submenu;
    $current_user = wp_get_current_user();
    $role = $current_user->roles;
    // To hide settings by role :any_new_role
    if ($role[0] == 'any_new_role') {
        // users menu
        unset( $submenu['users.php'][5] ); // removes list of users
        unset( $submenu['users.php'][15] ); // removes edit your profile
   
        remove_menu_page('wc_stripe'); // Hiding stripe gateway settings
        remove_menu_page('woocommerce'); // Hiding woocommerce settings
        remove_menu_page('automatewoo'); // Hiding automatewoo settings
        remove_menu_page('jetpack'); // Hiding jetpack settings
    }

}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 user14331147