最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

woocommerce offtopic - Filter orders in Admin area based on logged in user

programmeradmin1浏览0评论

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?

发布评论

评论列表(0)

  1. 暂无评论