• Resolved schmago

    (@schmago)


    Hi,

    I am restricting order status depending of the user roles.
    For regular order page, I have used the following snippet :

    add_filter('wc_order_statuses', 'filter_order_statuses', 100 );
    function filter_order_statuses( $statuses ) {
        global $pagenow, $typenow;
    
        if( in_array( $pagenow, array('post.php', 'post-new.php') )
        && 'shop_order' === $typenow && user_roles_allowed_orders() ) {
            $allowed_statusses = array('wc-on-hold', 'wc-processing');
    
            foreach ($statuses as $key => $option ) {
                if( ! in_array( $key, $allowed_statusses ) ){
                    unset($statuses[$key]);
                }
            }
        }
        return $statuses;
    }

    Is it possible to apply something similar to the Phone Orders page?
    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author algol.plus

    (@algolplus)

    hi

    please, use this hook to adjust visible statuses.

    add_filter( 'wpo_order_status_list_statuses', function ($statuses) {
    return $statuses;
    });

    WARNING – we don’t use status as key in this array.

    Thread Starter schmago

    (@schmago)

    if you don’t use status as key in array like this
    unset( $statuses['wc-processing'] );

    I am not sure how I am supposed to remove unwanted status.

    Plugin Author algol.plus

    (@algolplus)

    please, submit ticket to https://algolplus.freshdesk.com/
    and we’ll provide modified version tomorrow

    Plugin Author algol.plus

    (@algolplus)

    for whom having same problem.
    please, adapt following code .

    use $data[“value”] to check , and array_values​() is required too.

    add_filter( 'wpo_order_status_list_statuses', function ($statuses) {
        $allowed_statusses = array('wc-on-hold', 'wc-processing');
    
        foreach ($statuses as $key => $data ) {
            if(  !in_array( $data["value"], $allowed_statusses ) ){
                    unset($statuses[$key]);
            }
        }
        return array_values($statuses);
    });
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Restriction on Order status’ is closed to new replies.