Search code examples
phpwordpresswoocommercestatusorders

Display order in woocommerce admin list status and user wise


In woocommerce in order list in admin side I want to display orders by status.

I mean to say if order has processing status then and then that order should display in admin order list and other orders should not display in that list. Check image for more details what I need..enter image description here


Solution

  • I guess you are looking for something like this?

    /**
     * Limit statuses dropdown for custom user role.
     *
     * @param array $statuses
     * @see wc_get_order_statuses()
     */
    add_filter( 'wc_order_statuses', function( $statuses ) {
        # Custom user role (registered elsewhere).
        $custom_user_role = 'administrator';
        
        # Status(es) of orders to show to custom user role.
        $limit_to_order_statuses = array(
            'wc-processing' => 1,
            'wc-on-hold' => 1,
        );
        
        # Make sure we're editing right query.
        # If not, then nothing to change ("return early").
        if (
            !function_exists( 'get_current_screen' )
            ||  'shop_order' !== get_current_screen()->post_type
            || 'woocommerce' !== get_current_screen()->parent_base
        )
            return $statuses;
        
        # Check if user has the specified custom user role.
        # If they don't, then nothing to change ("return early").
        if ( !in_array( $custom_user_role, wp_get_current_user()->roles ) )
            return $statuses;
        
        return array_intersect_key( $statuses, $limit_to_order_statuses );
    } );
    

    Credit goes to https://wordpress.org/support/topic/order-status-visibility-by-role/ (Kingfisher64)