Change WordPress user roles and capabilities Forums How to or FAQ Restrict special Woocommerce report (tabs)

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #5552
    [email protected]
    Participant

    Hi Vladimir,
    where can we restrict special woocommerce reports (tabs) ?

    for example:

    should be ALLOWED
    https://demo.com/wp-admin/admin.php?page=wc-reports&tab=gift_certs

    should be NOT allowed
    https://demo.com/wp-admin/admin.php?page=wc-reports&tab=customers&report=customer_list

    Thanks & Regards
    Dieter

    #5560
    [email protected]
    Participant

    Hi Vladimir,
    can we restrict/handle special URL’s with user role editor?

    Thanks & Regards
    Dieter

    #5561
    Vladimir
    Keymaster

    Hi Dieter,

    URE does not include functionality for editing the list of WooCommerce reports available to user.
    WooCommerce itself offers to use special filter for this purpose:

    
    $reports = apply_filters( 'woocommerce_admin_reports', $reports );
    

    Thus it’s possible to hook a function to this filter and remove from the list prohibited reports.

    You can not restrict special URL(s) with User Role Editor. Custom code is needed also.

    #5562
    [email protected]
    Participant

    Hi Vladimir,
    thank you for feedback and support!

    For first quick solution we have made this …

    add_filter( ‘woocommerce_admin_reports’, ‘custom_reports’ );
    function custom_reports( $reports ) {
    // unset the elements of $reports that you don’t want
    unset($reports[‘customers’]);
    unset($reports[‘stock’]);
    unset($reports[‘orders’]);
    unset($reports[‘taxes’]);
    return $reports;
    }

    In second step we must see how we can make report access for admins.

    Thanks & Regards
    Dieter

    #5563
    Vladimir
    Keymaster

    Hi Dieter,

    You can define admin by few different ways. Select the most suitable for you.
    Insert selected code before the 1st unset(…);

    
    if ( current_user_can( 'manage_woocommerce' ) ) {
    // WooCommerce admin
      return;
    }
    
    
    if ( is_super_admin() ) {
    // WordPress super admin - real super admin for network, but just user with 'delete_users' capability for single site installation
      return;
    }
    
    
    $lib = URE_Lib::get_instance();
    if ( $lib->is_super_admin() ) {
    //  user with 'administrator' role for single site installation and real super admin for network
      return;
    }
    
    #5564
    [email protected]
    Participant

    Hi Vladimir,
    yes that’s works!

    Thanks for your great support!!!

    Thanks & Regards
    Dieter

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.