You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何仅在筛选处理中订单时显示后台订单列表批量操作?

仅在处理状态订单列表显示批量操作的实现方案

完全可行,你可以通过判断当前订单列表的筛选状态,结合WooCommerce的钩子来实现需求。以下是具体代码:

add_filter( 'bulk_actions-edit-shop_order', 'custom_restrict_bulk_actions_to_processing_orders' );
function custom_restrict_bulk_actions_to_processing_orders( $actions ) {
    // 仅在订单列表页面执行逻辑
    if ( ! isset( $_GET['post_type'] ) || $_GET['post_type'] !== 'shop_order' ) {
        return $actions;
    }

    // 获取当前筛选的订单状态
    $current_status = isset( $_GET['post_status'] ) ? $_GET['post_status'] : '';

    // 若当前不是处理状态(wc-processing),移除所有批量操作
    if ( $current_status !== 'wc-processing' ) {
        return array();
    }

    // 处理状态下保留原有批量操作
    return $actions;
}

代码说明:

  • 借助bulk_actions-edit-shop_order钩子修改订单列表的批量操作选项
  • 先验证当前页面是否为订单列表,避免影响后台其他页面功能
  • 通过$_GET['post_status']获取用户当前筛选的订单状态
  • 仅当筛选状态为wc-processing时保留批量操作,其他状态下清空操作列表

将上述代码添加到你的主题functions.php文件或自定义插件中即可生效。

内容的提问来源于stack exchange,提问作者David

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 14:08:11