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

如何在WooCommerce中过滤John Smith虚假订单并优化统计数据?

处理WooCommerce中Google John Smith机器人虚假订单方案

一、自动过滤虚假订单并移入回收站(不发送通知)

Google的John Smith机器人会创建无法完成的虚假订单,直接拦截会影响产品列表验证,可通过WooCommerce钩子实现自动处理:

将以下代码添加到主题的functions.php文件,或使用自定义代码插件(如Code Snippets)避免主题更新丢失:

add_action('woocommerce_new_order', 'handle_john_smith_google_bot_orders', 10, 1);
function handle_john_smith_google_bot_orders($order_id) {
    $order = wc_get_order($order_id);
    if (!$order) return;

    // 匹配机器人使用的账单姓名
    if ($order->get_billing_first_name() === 'John' && $order->get_billing_last_name() === 'Smith') {
        // 禁用所有新订单及状态变更通知
        remove_action('woocommerce_new_order_notification', array(WC()->mailer(), 'send_transactional_email'));
        remove_action('woocommerce_order_status_pending_to_processing_notification', array(WC()->mailer(), 'send_transactional_email'));
        remove_action('woocommerce_order_status_pending_to_completed_notification', array(WC()->mailer(), 'send_transactional_email'));
        remove_action('woocommerce_order_status_pending_to_on-hold_notification', array(WC()->mailer(), 'send_transactional_email'));

        // 将订单移入回收站
        wp_trash_post($order_id);
    }
}

这段代码会在新订单创建时检查账单姓名,若为John Smith则禁用通知并直接移至回收站,完全不影响Google的验证流程。

二、修正转化率、弃购率等统计数据

虚假订单会干扰店铺统计,可通过以下方式排除:

1. 修正WooCommerce内置报表

添加以下代码,让内置报表自动排除John Smith的订单及回收站订单:

add_filter('woocommerce_reports_order_query', 'exclude_john_smith_orders_from_reports', 10, 2);
function exclude_john_smith_orders_from_reports($query_args, $report_type) {
    // 移除回收站订单状态
    $query_args['post_status'] = array_diff($query_args['post_status'], array('trash'));
    
    // 添加条件排除John Smith的订单
    $query_args['meta_query'][] = array(
        'relation' => 'AND',
        array(
            'key'     => '_billing_first_name',
            'value'   => 'John',
            'compare' => '!='
        ),
        array(
            'key'     => '_billing_last_name',
            'value'   => 'Smith',
            'compare' => '!='
        )
    );
    return $query_args;
}

2. 第三方统计工具过滤

如果使用Google Analytics等工具,可在后台设置过滤规则:

  • 排除交易中账单姓名为John Smith的记录
  • 或通过用户代理(UA)识别Google机器人流量并排除(需提前确认该机器人的UA特征)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.06 03:50:22