Remove or hide theme metaboxes from post types for specific role
-
Dear,
I’m using the following code in functions.php to disable metaboxes for each post type if user is not administrator:
if(!function_exists('remove_meta_boxes')){
function remove_meta_boxes() {
if( !current_user_can('administrator') ){
remove_meta_box('woocommerce-product-360-images','product','side'); // 360 gallery
remove_meta_box('woodmart_sguide_dropdown_template','product','side'); // woodmart size guide
remove_meta_box('xts_product_metaboxes','product','normal'); // woodmart product metabox
remove_meta_box('xts_page_metaboxes','page','normal'); // woodmart page and post metabox
}}}
add_action('do_meta_boxes','remove_meta_boxes');
It works for the size guide but the xts product and page metaboxes keep showing.
screenshot: https://media.studio84.be/Wnum6ZKQ
How can I disable this the right way?
Thanks in advance.
Regards, Bart
Hello,
Try to add the following PHP code snippet to the child theme functions.php file to do this.
remove_action( 'init', 'woodmart_register_product_metaboxes', 100 );
If there’s anything else we can do, please get in touch.
Kind Regards
Thanks Luke. Can I add this in the if statement like I gave you, so it only happens for a non-admin user?
Hello,
Yep, I think you can use it in the if statement. Let me know the results.
Don’t hesitate to let me know if you need any further help or any other info.
Kind Regards
Hey Luke, it does not work in or out the if statement. Do you have another solution please?
Hello,
Try to use the below one code. Enter it into the functions.php
file in your child theme.
add_action( 'init', function () {
if ( ! current_user_can('administrator') ) {
remove_action( 'init', 'woodmart_register_product_metaboxes', 100 );
}
}, 50);
Thanks for your time and have a great day.
Kind Regards
Hey Luke, that works for the products thx. What to add to remove it for the pages and posts as well?
Hello,
Please add the below active to the above condition that I shared before.
remove_action( 'init', 'woodmart_register_page_metaboxes', 100 );
Please let us know if there is anything further we can assist you with!
Kind Regards
Hello,
You are welcome!
Don’t hesitate to reach out if you have any more questions or concerns. We’re thankful that you took the time to share your concerns with us.
Have a good day!
Kind Regards
The topic ‘Remove or hide theme metaboxes from post types for specific role’ is closed to new replies.