Hide specific woocommerce order action button for role

Viewed 46

Could anyone assist with a PHP snippet to hide the 'processing' action button for a specific role, on the admin order list? The shop_manager uses a tablet and has a habit of accidentally tapping the button and changing the order status when scrolling.

The code here looks like a good start, just have to remove the product condition and add the user role condition. Hide a specific action button conditionally in Woocommerce admin Orders list

EDIT: This is what I hacked together from bits of code and it seems to be working! I'm no dev though, so if you spot anything I should be doing differently I'm open to feedback.

add_filter( 'woocommerce_admin_order_actions', 'custom_admin_order_actions', 900, 2 );
function custom_admin_order_actions( $actions ){

    if( ! $actions['processing'] ) return $actions;

    if( is_user_logged_in() ){
        $user = wp_get_current_user();
        $user_roles = $user->roles;
    } else $user_roles = array();
    
        if ( in_array( 'shop_manager', $user_roles ) )
            unset($actions['processing']);

    return $actions;
}
0 Answers
Related