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

将WooCommerce已支付订单从处理状态改为自定义Order Received状态

WooCommerce 修改支付完成后的订单状态为自定义状态

要实现这个需求,需分两步操作:注册自定义订单状态,以及修改支付完成后的状态切换逻辑。以下是完整代码,可添加到主题的functions.php文件或自定义插件中:

1. 注册自定义订单状态

首先在WooCommerce系统中注册名为"Order Received"的自定义状态:

// 注册自定义订单状态
add_action('init', 'register_custom_order_status');
function register_custom_order_status() {
    register_post_status('wc-order-received', array(
        'label'                     => _x('Order Received', 'Order status', 'woocommerce'),
        'public'                    => true,
        'exclude_from_search'       => false,
        'show_in_admin_all_list'    => true,
        'show_in_admin_status_list' => true,
        'label_count'               => _n_noop('Order Received <span class="count">(%s)</span>', 'Order Received <span class="count">(%s)</span>', 'woocommerce')
    ));
}

// 将自定义状态添加到WooCommerce订单状态列表
add_filter('woocommerce_order_states', 'add_custom_order_status_to_list');
function add_custom_order_status_to_list($order_states) {
    $order_states['wc-order-received'] = _x('Order Received', 'Order status', 'woocommerce');
    return $order_states;
}

2. 修改支付完成后的订单状态

通过过滤器拦截支付完成后的状态切换,将默认的processing替换为自定义状态:

// 修改支付完成后的订单状态为自定义状态
add_filter('woocommerce_payment_complete_order_status', 'change_payment_complete_order_status', 10, 2);
function change_payment_complete_order_status($status, $order_id) {
    $order = wc_get_order($order_id);
    // 仅针对已支付且原本会进入processing状态的订单
    if ($order && $order->has_status('pending')) {
        return 'wc-order-received';
    }
    return $status;
}

补充说明

  • 代码中的状态标识wc-order-received可按需修改,但需保证前后代码一致
  • 添加代码后,用户支付完成的订单会自动进入"Order Received"状态,你可在WooCommerce后台订单管理中手动将其切换为"处理中"状态
  • 建议先在测试环境验证代码功能,再部署到生产环境

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.17 19:30:53