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

如何让WooCommerce报表排除账户资金支付订单修正净销售额?

解决WooCommerce报表重复统计Account Funds余额支付订单的问题

确实可以通过WooCommerce提供的过滤器修改净销售额计算逻辑,忽略Account Funds支付网关的订单,避免重复统计。以下是两种可行的实现方案:

方案一:从报表查询层面排除余额支付订单

使用woocommerce_reports_get_order_report_data过滤器,在生成销售报表时直接排除使用Account Funds支付网关的订单:

add_filter( 'woocommerce_reports_get_order_report_data', 'exclude_account_funds_from_sales_reports', 10, 2 );
function exclude_account_funds_from_sales_reports( $report_data, $args ) {
    // 仅对销售类报表生效(比如按日期统计的销售额报表)
    if ( isset( $args['report_type'] ) && $args['report_type'] === 'sales_by_date' ) {
        // 关联支付方式元数据,排除Account Funds网关的订单
        $report_data['join'] .= " LEFT JOIN {$GLOBALS['wpdb']->prefix}postmeta pm ON pm.post_id = orders.ID AND pm.meta_key = '_payment_method'";
        $report_data['where'] .= " AND pm.meta_value != 'account_funds'";
    }
    return $report_data;
}

注意:如果你的Account Funds支付网关ID不是account_funds,可以在WooCommerce后台「设置」→「支付」中查看该网关的ID,替换代码中对应的字符串即可。

方案二:修改订单净金额计算逻辑

通过woocommerce_order_get_net_total过滤器,让使用Account Funds支付的订单净金额统计为0,从而不影响报表的净销售额:

add_filter( 'woocommerce_order_get_net_total', 'zero_out_account_funds_order_net_total', 10, 2 );
function zero_out_account_funds_order_net_total( $net_total, $order ) {
    if ( $order->get_payment_method() === 'account_funds' ) {
        return 0;
    }
    return $net_total;
}

两种方案的区别:

  • 方案一直接从报表的数据库查询中排除目标订单,适合完全不想让余额支付订单出现在销售报表中的场景;
  • 方案二保留订单在报表中,但将其净金额设为0,适合需要展示订单记录但不计入销售额的场景。

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

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.29 20:05:12