skip to Main Content

How to remove specific order meta-boxes from order edit pages.

The following works on legacy orders, but not with High-Performance Order Storage (HPOS):

remove_meta_box( 'woocommerce-order-items', 'shop-order', 'normal' ); // Removes products/items meta box for technicians
remove_meta_box( 'woocommerce-order-actions', 'shop-order', 'normal' ); // Removes products/items meta box for technicians
remove_meta_box( 'woocommerce-order-notes', 'shop-order', 'normal' ); // Removes order note meta box for technicians
remove_meta_box( 'order_custom', 'shop-order', 'normal' );

Any help is appreciated.

2

Answers


  1. Chosen as BEST ANSWER

    Below code seems to hide only, but does not actually remove it.

    function itsm_add_meta_boxes() {
    echo '<style>
                    #woocommerce-order-items, #woocommerce-order-actions, #wpo_wcpdf-data-input-box, #woocommerce-order-notes, #order_custom { 
                        display: none !important; 
                    }
                </style>';
    }
    add_action( 'add_meta_boxes', 'itsm_add_meta_boxes', 11 );
    

    Any other suggestions?


  2. For High-Performance Order Storage Metaboxes removal (compatible with legacy orders too), you need to use something a bit different as "shop-order" 2nd argument only works for legacy orders.

    Also by default in WooCommerce, Order actions and Order notes Metaboxes 3rd argument is "side" (but not "normal").

    Try the following:

    use AutomatticWooCommerceInternalDataStoresOrdersCustomOrdersTableController;
    
    add_action( 'add_meta_boxes', 'admin_order_custom_metabox' );
    function admin_order_custom_metabox() {
        $screen = class_exists( 'AutomatticWooCommerceInternalDataStoresOrdersCustomOrdersTableController' ) && wc_get_container()->get( CustomOrdersTableController::class )->custom_orders_table_usage_is_enabled()
            ? wc_get_page_screen_id( 'shop-order' )
            : 'shop_order';
    
        remove_meta_box( 'woocommerce-order-items', $screen, 'normal' ); // Removes Order items meta box
        remove_meta_box( 'woocommerce-order-actions', $screen, 'side' ); // Removes products/items meta box
        remove_meta_box( 'woocommerce-order-notes', $screen, 'side' ); // Removes order note meta box
        remove_meta_box( 'order_custom', $screen, 'normal' ); // Removes Custom fields meta box
    }
    

    Code goes in functions.php file of your child theme (or in a plugin). Tested and works.

    If you have changed manually some metaboxes location via drag and drop, you will need to adjust the 3rd argument to "normal" or "side".

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search