【问题标题】:Display order in woocommerce admin list status and user wise在 woocommerce 管理列表状态和用户方面显示订单
【发布时间】:2020-12-04 10:24:00
【问题描述】:

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

我的意思是说如果订单有处理状态,那么该订单应该显示在管理订单列表中,而其他订单不应该显示在该列表中。查看图片了解我需要的更多详细信息..enter image description here

【问题讨论】:

  • 如果您在订单列表上方查看,您可以找到“查看过滤器”。他们已经在做你想做的事了,不是吗?
  • 不..我想务实地完成这项工作..因为在我的项目中会有不同的用户,用户 A 可以看到很少的订单,而用户 B 可以看到很少的订单..所以默认情况下这个列表应该只显示处理状态的订单..
  • 抱歉,我们希望您在问题中提供真实的代码尝试。请注意,StackOverFlow 不是免费的编码服务。
  • 欢迎来到 Stack Overflow!请take the tour(你得到一个徽章!)并通读help center,特别是good question?你最好的选择是做你的研究,search关于SO的相关主题,并试一试。如果您在进行更多研究后卡住并且无法摆脱卡住,请发布您的尝试的Verifiable Example,并具体说明您卡在哪里。人们会很乐意提供帮助。

标签: php wordpress woocommerce status orders


【解决方案1】:

我猜你正在寻找这样的东西?

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

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-21
  • 1970-01-01
  • 1970-01-01
  • 2023-01-25
  • 1970-01-01
  • 2018-08-08
相关资源
最近更新 更多