2
votes

I need to hide orders with a specific status in the WooCommerce admin orders list. (wp-admin/edit.php?post_type=shop_order).

CSS won't work as if the user only shows 20 rows, there might be a page with no results as many orders might have this status.

I tried the following function:

add_action('wc_order_statuses', 'my_statuses');

function my_statuses($order_statuses) {

    unset($order_statuses['wc-my_status']);
    return $order_statuses;
}

...but that made conflict with my function (below) on the Thank you page which no longer changed the order status to my custom status, probably because the function mentioned above removes it.

add_action( 'woocommerce_thankyou', 'woocommerce_thankyou_change_order_status', 10, 1 );
function woocommerce_thankyou_change_order_status( $order_id ){

    if( // my custom code ) {
        $order->update_status( 'my_status' );
      }
}

Is there no easy way to hide orders with my_status from the order list in WooCommerce admin panel?

1
The wc_order_statuses action hook is used to add/remove order status in the dropdown menu @ single order, NOT to hide order status from WooCommerce admin order list and also does not affect the woocommerce_thankyou hook7uc1f3r
Hm, but I tested with this function active / not active not, and it does hide the orders in the admin panel: link with function active - order not showing (correct) but thankyou_hook not changing new orders to my custom status merchdesign link with function not active - order showing in admin list (not correct) but thankyou_hook is changing new orders to my custom status Just did a new test, with making orders with function active/inactive, and it seems to affect it somehow indeedBTB

1 Answers

2
votes

To hide row(s) containing a specific order status, in WooCommerce admin order list. You can use the parse_query action hook.

So you get:

function action_parse_query( $query ) { 
    global $pagenow;
    
    // Your order status to hide, must start with 'wc-'
    $hide_order_status = 'wc-completed';

    // Initialize
    $query_vars = &$query->query_vars;
    
    // Only on WooCommerce admin order list
    if ( $pagenow == 'edit.php' && $query_vars['post_type'] == 'shop_order' ) {
        // Finds whether a variable is an array
        if ( is_array( $query_vars['post_status'] ) ) {  
            // Searches the array for a given value and returns the first corresponding key if successful
            if ( ( $key = array_search( $hide_order_status, $query_vars['post_status'] ) ) !== false ) {
                unset( $query_vars['post_status'][$key] );
            }
        }
    }

}
add_action( 'parse_query', 'action_parse_query', 10, 1 );