显示woocommerce管理员列表状态和用户明智的顺序

问题描述

在woocommerce的管理端订单列表中,我想按状态显示订单。

我的意思是说,如果订单具有处理状态,则该订单应显示在管理订单列表中,而其他订单则不应显示在该列表中。查看图片以获取更多详细信息。enter image description here

解决方法

我想您正在寻找类似的东西吗?

/**
 * 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 );
} );

贷方转到https://wordpress.org/support/topic/order-status-visibility-by-role/(Kingfisher64)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...