I have special roles on my site. I use easy digital download. My user has access to the download page. I want the metabox not to see the number of sales. Can I hide this metabox for this role or user?

Of course, now that I had to, I deleted it with CSS 😔 (display : none) Thank you in advance for your guidance.


The Download stats Metabox has a check for view_product_stats capability in EDD codes. in /easy-digital-downloads/includes/admin/downloads/metabox.php Line:42

if ( current_user_can( 'view_product_stats', get_the_ID() ) ) {
    /** Product Stats */
        sprintf( __( '%1$s Stats', 'easy-digital-downloads' ),
        edd_get_label_singular(), edd_get_label_plural() ),

You can simply remove the view_product_stats capability for Your special user role.

global $wp_roles;
$wp_roles->remove_cap( 'your_special_role', 'view_product_stats' );

I think Hector's answer is most appropriate in this situation given that he has created a special user role that you can target with his code.

For others that don't have custom user roles but would like to hide certain metaboxes, you can do something like what I do to ensure that no one below an Editor level can access some specific metaboxes:

// Removes certain Metaboxes
function remove_post_metaboxes() {
if ( !current_user_can( 'edit_others_posts' ) ) { // Enter your desired Capability to target specific Roles
    remove_meta_box( 'formatdiv','post','side' ); // Format Metabox
    remove_meta_box( 'categorydiv','post','side' ); // Category Metabox
    remove_meta_box( 'adv-tagsdiv','post','side' ); // Tags (Simple Tags) Metabox
    remove_meta_box( 'st-clicks-tags','post','advanced' ); // Tags (Simple Tags) Metabox
    remove_meta_box( 'edit-flow-notifications','post','advanced' ); // EditFlow UserGroups Notifications Metabox
add_action( 'do_meta_boxes', 'remove_post_metaboxes');

SO you decide which Capability to target (since WP prefers that you use current_user_can instead of targeting specific Roles), then you just need to know the name of the metabox (use something like Inspect Element while in a Post where you see the metabox you want removed/hidden to find its name - the example above is the ones I remove for all non-Editors) and then if you want it removed from Posts or Pages, as well as where it normally resides. Add this to your Child Theme's functions.php file.

More information here: https://developer.wordpress.org/reference/functions/remove_meta_box/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.