我正在使用WooCommerce Follow Up Emails plugin设计定制订单后发送的自定义电子邮件。
正在订购的产品将显示一些“添加字段”,这些字段将在客户下订单时填充。字段之一是电子邮件地址。
我想将我设计的自定义跟进电子邮件发送到该字段中提供的电子邮件地址,而不是发送给下订单者的电子邮件地址。
我可以使用订单ID(作为元数据分配给它)来获取电子邮件地址,但是我不知道如何覆盖后续电子邮件地址的发送地址。
浏览Follow Up Emails' API时,我可以看到一些挂钩,例如,这些挂钩可以让我通过ID获取电子邮件:
$fue_api->get_email( 2011 )
似乎还有另一个端点可以用来更新电子邮件:
/**
* Update a follow-up email
* @param integer $email_id
* @param array $data
* @return mixed|json string
*/
public function update_email( $email_id, $data = array() ) {
return $this->_make_api_call( 'emails/' . $email_id, $data, 'POST' );
}
但是我不确定如何将收件人的电子邮件地址从变量更改为该电子邮件地址?,因为:
1)收件人的电子邮件仅在下订单后可用
2)我需要先更新电子邮件,然后才能按订单发送
我不知道如何将这两件事链接在一起。
我认为我需要以某种方式挂接到一个控制订单发出后发送电子邮件的事件,获取要修改的电子邮件的ID,然后从订单元数据中将其更改为收件人。 它已添加到队列中。
非常感谢您的帮助!
答案 0 :(得分:0)
在与WooCommerce跟进电子邮件插件战斗之后,我认为最简单的解决方案是:
加入woocommerce新订单;
检查订单是否包含元电子邮件地址;
如果确实发送包含我想要的数据的电子邮件;
缺点是无法从UI进行自定义,但是好处是不必为插件支付99美元即可发送1封电子邮件,甚至他们都不允许您这样做(因为据我所知)。
这是一个示例解决方案:
/**
* CUSTOM EMAIL ON ORDER
*/
add_action( 'woocommerce_payment_complete', 'order_completed' );
function order_completed( $order_id ) {
$variables = array();
$order = wc_get_order( $order_id );
// This goes through the meta data items to add them as variables
foreach ($order->get_items() as $item_id => $item ) {
$item_meta = $item->get_meta('_WCPA_order_meta_data');
foreach ($item_meta as $meta ) {
if (!empty($meta['name'])) {
$variables[$meta['name']] = $meta['value'];
}
}
}
// If the email address meta item is there
// it means we need to send the custom email
if (!empty($variables['custom_addon_email'])) {
$to_email = $variables['custom_addon_email'];
$headers = 'From: Your Name <someone@example.com>' . "\r\n";
$subject = 'This is my custom email test';
$template = 'This is just testing of sending a custom email for: ' . $variables['custom_addon_first_name'] . ' ' . $variables['custom_addon_last_name'] . '. Note:' . $variables['custom_addon_note'];
wp_mail($to_email, $subject, $template, $headers );
}
}
这是一个非常粗糙的例子,但我希望它对其他人有帮助。
['custom_addon_email'], ['custom_addon_first_name'], ['custom_addon_last_name'], ['custom_addon_note']
是添加到产品中的插件字段的名称,它们是我在name=""
属性中为字段指定的名称。
理想情况下,我希望能够使用WooCommerce跟进电子邮件插件来完成此操作,因为它将使自定义电子邮件内容更容易,但是我不知道如何实现。