Woocommerce-需要根据邮政编码将电子邮件发送到特定地址 [英] Woocommerce - Need to send email to specific address based on zip code

查看:315
本文介绍了Woocommerce-需要根据邮政编码将电子邮件发送到特定地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,在woocommerce中,您可以选择在WooCommerce->设置"->电子邮件"->新订单"中输入多个电子邮件地址(以逗号分隔),以将完成的订单发送给谁.但是我需要一种方法,可以根据订购产品的客户的邮政编码仅发送给这些收件人中的一个.或完全覆盖woocommerce的处理方式.

Basically, in woocommerce you have the option to input multiple email addresses (separated by commas) of who to send the completed order to, in WooCommerce -> Settings -> Emails -> New order. But I need a way to send to only one of these recipients based on the zip code of the customer who is ordering the product. Or completely overwrite woocommerce's way of handling this.

我如何绑定到负责此功能的功能,以便发送给正确的收件人?基本上,是否为此定义了一个钩子,或者是否存在类似这样的插件,或者我是否必须编辑核心WooCommerce文件?如果需要对核心文件进行编辑,有人可以向我指出需要编辑哪些文件的正确方向吗?

How can I tie into the function responsible for this, in order to send to the correct recipient? Basically, is there a hook defined for this, or does a plugin exist for something like this, or will I have to edit core WooCommerce files? If edits are needed to core files, can someone point me in the right direction as to which files will need edits?

推荐答案

每封电子邮件都有一个过滤器,可让您调整该电子邮件的收件人.过滤器名称实质上是woocommerce_email_recipient_{$email_id}.

Each email has a filter that allows you to adjust the recipients of that email. The filter name is essentially woocommerce_email_recipient_{$email_id}.

因此,以下内容将过滤"new_order"电子邮件的收件人"地址.

So the following would filter the "to" addresses for the "new_order" email.

add_filter( 'new_order' , 'so_26429482_add_recipient', 20, 2 );
function so_26429482_add_recipient( $email, $order ) {
    $additional_email = "somebody@somewhere.net";
    if( $order->shipping_postcode == "90210" ){
        $email = explode( ',', $email );
        array_push( $email, $additional_email );
    }
    return $email;
}

我不确定100%是否符合条件逻辑,但我认为应该检查运输邮政编码,然后再发送至其他电子邮件地址.

I'm not 100% certain on the conditional logic, but I think that should check the shipping zip code and subsequently send to the additional email address.

这篇关于Woocommerce-需要根据邮政编码将电子邮件发送到特定地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆