Home Forums WoodMart support forum Remove or hide theme metaboxes from post types for specific role

Remove or hide theme metaboxes from post types for specific role

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #460351

    studio84digital
    Participant

    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

    #460491

    Luke Nielsen
    Keymaster

    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

    #460500

    studio84digital
    Participant

    Thanks Luke. Can I add this in the if statement like I gave you, so it only happens for a non-admin user?

    #460597

    Luke Nielsen
    Keymaster

    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

    #460630

    studio84digital
    Participant

    Hey Luke, it does not work in or out the if statement. Do you have another solution please?

    #460902

    Luke Nielsen
    Keymaster

    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

    #460907

    studio84digital
    Participant

    Hey Luke, that works for the products thx. What to add to remove it for the pages and posts as well?

    #461260

    Luke Nielsen
    Keymaster

    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

    #461272

    studio84digital
    Participant

    That works, thx Luke!

    #461325

    Luke Nielsen
    Keymaster

    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

Viewing 10 posts - 1 through 10 (of 10 total)

The topic ‘Remove or hide theme metaboxes from post types for specific role’ is closed to new replies.