I’m looking to bring on a virtual assistant to help manage support tickets. This virtual assistant will need to have reading access to limited areas of WooCommerce (Subscriptions).
I’m using ‘user role editor‘ to remove all capabilities that are not needed. Unfortunately, a single capability (edit_shop_orders) gives access to functions that I do not want the agent to have access to. I’m forced to give the agent this capability to have access to the subscription menu in the back end.
What I am trying to do:
Remove the ‘Suspend’ and ‘Cancel’ button access from a particular user role (va_support)
My current code(not working):
function change_va_support_role(){
global $wp_roles;
$wp_roles->remove_cap( 'va_support', 'suspend_subscriptions' );
$wp_roles->remove_cap( 'va_support', 'cancel_subscriptions' );
}
add_action('init', 'change_va_support_role');
I am assuming I’ve entered incorrect capabilities, but I can’t seem to find them anywhere.
I understand that I can probably easily hide these buttons with CSS, but that can just be reversed and will not be user role dependent. I’m open to solving this issue another way if there is!
2
Answers
As of now, there is no filter where handling this action trigger. You may add a filter on your own for handling this.
/woocommerce-subscriptions/includes/admin/class-wcs-admin-post-types.php inside this function around Line# 330 –
public function parse_bulk_actions()
In theme, you can check the current user has the role then return true/false accordingly. You may be aware that when updating the plugin, the changes will be lost. But as far as checking the code, there is no filter just before triggering these functions.
Using Javascript / jQuery the following will remove all “hovered” action buttons, for a specific user role, on the subscriptions admin dashboard from the status column:
Code goes in functions.php file of your active child theme (or active theme). Tested and works.