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

如何让自定义订单状态In Progress纳入WooCommerce销售报表统计?

Fix: Include Custom "In Progress" Order Status in WooCommerce Sales Reports & Dashboard

Hey there! I get that you've got a working custom "In Progress" order status set up, but it's not being counted in WooCommerce's core sales reports and dashboard widgets. No worries—we just need to hook into a few WooCommerce filters to tell the system to include this status in its calculations.

First, let's recap your existing code for adding the status (I'll fill in the missing bits for completeness), then add the necessary filters:

// Add custom "In Progress" order status (your existing code, completed)
add_action( 'init', 'register_in_progress_order_status' );
function register_in_progress_order_status() {
    register_post_status( 'wc-in-progress', array(
        'label'                     => 'In Progress',
        'public'                    => true,
        'exclude_from_search'       => false,
        'show_in_admin_all_list'    => true,
        'show_in_admin_status_list' => true,
        'label_count'               => _n_noop( 'In Progress <span class="count">(%s)</span>', 'In Progress <span class="count">(%s)</span>' )
    ) );
}

// Add status to WooCommerce order status dropdowns
add_filter( 'wc_order_statuses', 'add_in_progress_to_order_statuses' );
function add_in_progress_to_order_statuses( $order_statuses ) {
    $new_order_statuses = array();
    
    // Insert "In Progress" after "Processing" status (adjust position if needed)
    foreach ( $order_statuses as $key => $status ) {
        $new_order_statuses[ $key ] = $status;
        
        if ( 'wc-processing' === $key ) {
            $new_order_statuses['wc-in-progress'] = 'In Progress';
        }
    }
    
    return $new_order_statuses;
}

// 👇 Critical filters to include "In Progress" in reports & dashboard
// Include status in sales reports
add_filter( 'woocommerce_reports_order_statuses', 'include_in_progress_in_reports' );
function include_in_progress_in_reports( $statuses ) {
    $statuses[] = 'wc-in-progress';
    return $statuses;
}

// Validate status for report calculations
add_filter( 'woocommerce_valid_order_statuses_for_report', 'validate_in_progress_for_reports', 10, 2 );
function validate_in_progress_for_reports( $statuses, $report_type ) {
    // Include for sales/orders/customers reports (adjust if needed for other report types)
    if ( in_array( $report_type, array( 'sales', 'orders', 'customers' ) ) ) {
        $statuses[] = 'wc-in-progress';
    }
    return $statuses;
}

// Include status in dashboard sales widget
add_filter( 'woocommerce_dashboard_status_widget_statuses', 'include_in_progress_in_dashboard' );
function include_in_progress_in_dashboard( $statuses ) {
    $statuses[] = 'wc-in-progress';
    return $statuses;
}

What each part does:

  • The first two functions are your original (completed) code to register the "In Progress" status and add it to order dropdowns.
  • woocommerce_reports_order_statuses: Adds your custom status to the list of statuses WooCommerce considers when generating sales reports.
  • woocommerce_valid_order_statuses_for_report: Ensures the status is recognized as valid for specific report types (we've targeted sales, orders, and customer reports here—tweak the array if you need to include/exclude other report types).
  • woocommerce_dashboard_status_widget_statuses: Makes sure the dashboard's "Total Sales" widget and order status counters include orders marked as "In Progress".

Just drop this code into your theme's functions.php file, or a custom plugin, then refresh your WooCommerce reports and dashboard. Your "In Progress" orders should now be counted in the sales figures!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 07:32:54