Issue
According to this post, custom post type, hide or disable the trash button in publish meta box, this is specifically removing for post. I couldn't find any post solutions relating to remove 'Move to trash' under woocommerce order action. Does this code apply same to removing this button on woocommerce?
function my_custom_admin_styles() {
?>
<style type="text/css">
.post-type-inhoud form #delete-action{
display:none;
}
</style>
<?php
}
add_action('admin_head', 'my_custom_admin_styles');
How do I apply this to woocommerce removing 'move to trash' button under order action and only specifically for shop manager.
Solution
To prevent deleting post/order/custom post is capability per user role. To prevent shop_manager role from deleting orders you must remove that capability. All other solutions will visualy work but someone who knows his stuff still can delete order if he wants. So place the following function in your functions.php
function wp23958_remove_shop_manager_capabilities() {
$shop_manager = get_role( 'shop_manager' ); // Target user role
//List of capabilities which we want to edit
$caps = array(
'delete_shop_orders',
'delete_private_shop_orders',
'delete_published_shop_orders',
'delete_others_shop_orders',
);
// Remove capabilities from our list
foreach ( $caps as $cap ) {
$shop_manager->remove_cap( $cap );
}
}
add_action( 'init', 'wp23958_remove_shop_manager_capabilities' );
Bonus How to know what capabilities current user have
function wp32985_check_user_capabilities() {
$data = get_userdata( get_current_user_id() );
if ( is_object( $data) ) {
$current_user_caps = $data->allcaps;
// print it to the screen
echo '<pre>' . print_r( $current_user_caps, true ) . '</pre>';
}
}
add_action( 'init', 'wp32985_check_user_capabilities' );
Answered By - Martin Mirchev
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.