继续讨论来自 使用 Zapier 自动发送 Discourse 邀请邮件:
在实现目标的过程中,我发现了这个主题。这很棒,但 Zapier 毕竟不是免费的,
所以我创建了这两个代码,希望它们对某人有用。请将它们放入您的主题 functions.php 文件中。
如果您也有类似的有用代码,请告诉我
我想更多地了解 Discourse API,以及仅通过编码免费将它们与 WordPress 连接的方法 ^^!
在用户提交评论后(待审核状态)发送 Discourse 邀请
function invite_forum_from_comment($comment_ID) {
$comment = get_comment($comment_ID);
$comment_email = get_comment_author_email($comment);
$maybe_notify = ('0' == $comment->comment_approved);
if ($maybe_notify) {
// 邀请用户
wp_remote_post('https://forum.yourdomain.com/invites', array(
'method' => 'POST',
'headers' => array(
'Content-Type' => 'multipart/form-data',
'Api-key' => 'yourapikey',
'Api-Username' => 'yourusername'
),
'body' => array(
'email' => $comment_email,
'custom_message' => '感谢您的评论,在等待审核期间,为什么不加入我们的论坛呢?!'
)
));
}
}
add_action('comment_post', 'invite_forum_from_comment');
在用户完成 WooCommerce 订单后邀请其加入 Discourse
function invite_forum_from_order($order_id) {
// 获取所有订单数据
$order = new WC_Order($order_id);
// 从订单中获取用户邮箱
$order_email = $order->billing_email;
// 邀请用户
wp_remote_post('https://forum.yourdomain.com/invites', array(
'method' => 'POST',
'headers' => array(
'Content-Type' => 'multipart/form-data',
'Api-key' => 'yourapikey',
'Api-Username' => 'yourusername'
),
'body' => array(
'email' => $order_email,
'custom_message' => '感谢您的订单,何必浪费时间等待,直接加入我们的论坛吧!'
)
));
}
// 将此新创建的函数添加到感谢页面
add_action('woocommerce_thankyou', 'invite_forum_from_order', 10, 1);

