I have a booking store which uses custom user roles to separate different user types. One of the user types is an 'agent' who makes orders on behalf of end-customers.
I've successfully set up the admin backend to only show WC -> Orders but I now need to ensure that they can only edit or cancel orders that they themselves have created. I attempted to do this by restricting all posts on the site:
add_action('pre_get_posts', 'query_set_only_author' );
function query_set_only_author( $wp_query ) {
global $current_user;
if( is_admin() && !current_user_can('edit_others_posts') ) {
$wp_query->set( 'author', $current_user->ID );
add_filter('views_edit-post', 'fix_post_counts');
add_filter('views_upload', 'fix_media_counts');
}
}
This caused all orders to disappear completely from the user's order list. Is there any way to do this?