WordPress + pushplus:评论 / 订单推到微信
效果:有新评论或 WooCommerce 新订单时,微信收到提醒。可用通知插件的 Webhook,或在 WP-Cron / 钩子里 HTTP POST 到
/send。
前置条件
- 一个 pushplus token(官网扫码获取)
- 能安装插件或编辑主题 /
wp-config.php的 WordPress - 订单通知还需要 WooCommerce
配置步骤
方式一:插件 Webhook
- 安装能发 HTTP 请求的通知 / Webhook 插件(或 WooCommerce → Settings → Advanced → Webhooks)。
- 触发事件选「新评论」或「订单状态变化」。
- 插件会 POST 自己的 JSON、且不能改 body 时,URL 填固定文案:
https://www.pushplus.plus/send?token=你的token&title=WordPress通知&content=请打开网站查看评论或订单
- 插件支持自定义 URL、Method、JSON 时,改为:
- URL:
https://www.pushplus.plus/send - Method:
POST - Content-Type:
application/json - Body:
{"token":"你的token","title":"新评论","content":"把插件字段映射到这里","template":"txt"}
WooCommerce 默认 Webhook 报文同样不会自动变成 content,固定文案或自定义 HTTP 二选一。
方式二:WP-Cron / 钩子里调 /send
不装插件时,用 wp_remote_post。token 放进 wp-config.php 常量,不要写进会提交到 git 的主题文件。
wp_remote_post('https://www.pushplus.plus/send', array(
'timeout' => 10,
'headers' => array('Content-Type' => 'application/json'),
'body' => wp_json_encode(array(
'token' => PUSHPLUS_TOKEN,
'title' => 'WordPress 通知',
'content' => $text,
'template' => 'txt',
)),
));
挂到 comment_post、woocommerce_new_order 等钩子,或写一个 WP-Cron 任务定期汇总。$text 不能为空。
验证
curl -X POST "https://www.pushplus.plus/send" \
-H "Content-Type: application/json" \
-d '{"token":"你的token","title":"WordPress 配置测试","content":"token 可用","template":"markdown"}'
返回 JSON 的 code 为 200 后,再发一条测试评论或改一次测试订单状态。
常见问题
评论审核才想推? 钩子里判断 $comment->comment_approved,或只在后台「待审」时调用。
插件测通了但没有订单号? 直连 Webhook 是固定文案。要动态字段必须自定义 JSON 或自己写 wp_remote_post。
站点禁用出站 HTTP? 主机或安全插件可能拦 wp_remote_post。先在服务器上跑上面的 curl。