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

如何将WordPress WooCommerce站点推送通知集成到Flutter电商应用

WooCommerce 对接 Flutter 电商App自定义推送通知解决方案

实现思路

现有公开推送插件仅适配文章发布触发场景,你可以通过「自定义WooCommerce钩子触发推送+ Flutter端集成推送服务」的方式实现需求,无需依赖第三方推送插件。

服务端(WordPress + WooCommerce 侧)操作步骤

  • 选择一个推送通道服务,在WordPress侧集成对应服务的服务端SDK,国内可选个推、极光推送,海外可选FCM
  • 绑定用户标识:用户在Flutter端登录时,将当前设备的推送token和用户ID同步上传到WordPress侧存储,关联对应用户账号
  • 通过WooCommerce原生钩子触发对应推送:
    1. 用户下单触发:使用woocommerce_new_order钩子,触发时拉取当前订单所属用户的推送token,组装下单成功通知内容调用推送接口发送
    2. 订单状态更新触发:使用woocommerce_order_status_changed钩子,触发时获取更新后的订单状态,组装对应状态通知内容发送给对应用户
    3. 新增优惠券触发:使用woocommerce_new_coupon钩子,触发时如果是全量发放优惠券,可以批量拉取所有有效用户的推送token群发通知,如果是定向发放优惠券,仅发送给指定用户群体

Flutter 端操作步骤

  • 集成对应推送通道的Flutter SDK,完成设备通知权限申请、推送token获取逻辑
  • 处理推送点击事件:用户点击通知时,根据推送携带的参数(比如订单ID、优惠券ID)跳转到App内对应的订单详情页、优惠券领取页

核心代码示例(服务端钩子部分)

// 用户下单推送示例
add_action( 'woocommerce_new_order', 'custom_push_on_new_order', 10, 1 );
function custom_push_on_new_order( $order_id ) {
    $order = wc_get_order( $order_id );
    $user_id = $order->get_user_id();
    // 从你的存储表中获取对应用户的推送token
    $push_token = get_user_meta( $user_id, 'custom_user_push_token', true );
    if ( !$push_token ) return;
    $notification_content = '您的订单#' . $order_id . '已提交成功,我们会尽快为您发货';
    // 调用你选择的推送服务的发送接口
    custom_send_push_request( $push_token, '订单提交成功', $notification_content, [
        'type' => 'order_detail',
        'order_id' => $order_id
    ] );
}

// 订单状态更新推送示例
add_action( 'woocommerce_order_status_changed', 'custom_push_on_order_status_change', 10, 3 );
function custom_push_on_order_status_change( $order_id, $old_status, $new_status ) {
    $order = wc_get_order( $order_id );
    $user_id = $order->get_user_id();
    $push_token = get_user_meta( $user_id, 'custom_user_push_token', true );
    if ( !$push_token ) return;
    $status_map = [
        'processing' => '已付款待发货',
        'completed' => '已发货',
        'cancelled' => '已取消'
    ];
    $notification_content = '您的订单#' . $order_id . '状态已更新为:' . $status_map[$new_status] ?? $new_status;
    custom_send_push_request( $push_token, '订单状态更新', $notification_content, [
        'type' => 'order_detail',
        'order_id' => $order_id
    ] );
}

// 新增优惠券推送示例
add_action( 'woocommerce_new_coupon', 'custom_push_on_new_coupon', 10, 1 );
function custom_push_on_new_coupon( $coupon_id ) {
    $coupon = new WC_Coupon( $coupon_id );
    // 如果是全量优惠券,拉取所有有效用户的推送token批量发送
    // 此处省略批量拉取token逻辑
    $notification_content = '新的优惠券已上线:' . $coupon->get_code() . ',立减' . $coupon->get_amount() . '元,快去领取使用吧';
    custom_send_push_request( $all_user_tokens, '新优惠券上线', $notification_content, [
        'type' => 'coupon_list'
    ] );
}

注意事项

  • 推送内容支持自定义拼接,你可以根据业务需要调整通知文案和携带的跳转参数
  • 推送发送逻辑建议加入异步队列处理,避免阻塞WooCommerce原有订单、优惠券的生成流程

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.03 01:48:03