How to Remove a Filter from the Admin List Table?

I can see that it’s implemented inside the class
WC_Admin_List_Table_Orders which extends WC_Admin_List_Table.

Yes, that’s correct.

And the orders list table is setup via WC_Admin_Post_Types::setup_screen() where the method is called via these hooks: (see WC_Admin_Post_Types::__construct())

// Load correct list table classes for current screen.
add_action( 'current_screen', array( $this, 'setup_screen' ) );
add_action( 'check_ajax_referer', array( $this, 'setup_screen' ) );

And in that setup_screen() method, the list table is instantiated like so where the instance is put into a global variable — $wc_list_table:

include_once 'list-tables/class-wc-admin-list-table-orders.php';
$wc_list_table = new WC_Admin_List_Table_Orders();

So you can remove the filter like so:

// Be sure to rename this function..
function my_func() {
    global $wc_list_table;
    if ( $wc_list_table instanceof WC_Admin_List_Table_Orders ) {
        remove_action( 'restrict_manage_posts', array( $wc_list_table, 'restrict_manage_posts' ) );
    }
}
add_action( 'current_screen', 'my_func', 11 );
add_action( 'check_ajax_referer', 'my_func', 11 );

Tried and tested working on WooCommerce 3.6.2.

Leave a Comment