简体   繁体   English

Woocommerce将新订单通知发送到不同的电子邮件(基于运送国家)

[英]Woocommerce new order notification to different email based on shipping country

Been pulling my hair out over this for a few days now. 几天以来一直在拉我的头发。 The scenario is that 1 store has 2 locations so based on the shipping country selected at checkout the new order notification needs to go to the relevant email address. 场景是1家商店有2个地点,因此根据结帐时选择的运送国家/地区,新订单通知需要转到相关的电子邮件地址。

I got this to work....partially. 我让它工作了。。。部分地。

During testing phase I used "direct bank transfer" payment method for the sake of getting the order completed. 在测试阶段,为了完成订单,我使用了“直接银行转帐”付款方式。 The below code works great with that payment method but as i discovered later when an order gets placed through paypal it no longer works. 以下代码适用于该付款方式,但是正如我后来发现通过Paypal下订单时,它不再起作用。

Futhermore, if you change the product to virtual then it works with paypal, but as soon as you add 此外,如果您将产品更改为虚拟产品,则该产品可与Paypal一起使用,但是一旦添加

add_filter( 'woocommerce_cart_needs_shipping', '__return_true' );

to bring back the shipping options then it stops working again. 恢复运输选项,然后它将再次停止工作。

Here is my code so far 到目前为止,这是我的代码

    global $woocommerce;
if (strtolower($woocommerce->customer->get_shipping_country()) === 'us') {
$this->send( 'shopone@gmail.com', $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
} else {
$this->send( 'shoptwo@gmail.com', $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
};

Hopefully someone can spot something obvious that I am missing, thanks in advance! 希望有人能发现我显然缺少的东西,在此先感谢!

UPDATE: Zapier works but has some limitations, I would still like to find a solution to this that doesnt require a third party app. 更新:Zapier可以工作但是有一些限制,我仍然想找到一个不需要第三方应用程序的解决方案。

Found the solution. 找到了解决方案。

For anyone with the same problem in future, in class-wc-email-new-order.php replace 对于以后遇到相同问题的任何人,请在class-wc-email-new-order.php中替换

$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );

with

if ($this->object->shipping_country === 'US') {
$this->send( 'shopeone@gmail.com', $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
} else { 
$this->send( 'shoptwo@email.com', $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
}

The problem was using the $woocommerce global to grab the value from the customer when you should be grabbing the value from the order itself. 问题在于,当您应该从订单本身中获取价值时,使用$ woocommerce全局功能从客户那里获取价值。

If you want to create a conditional based on a different checkout field you can find the list in class-wc-api-orders.php 如果要基于其他结帐字段创建条件,则可以在class-wc-api-orders.php中找到列表

Just replace 只需更换

 $order->shipping_country

With

$this->object->shipping_country

There is an alternative way to accomplish this using a site called Zapier . 使用名为Zapier的站点可以完成此操作。 It allows you to link up multiple APIs, one of which is WooCommerce. 它允许您链接多个API,其中之一是WooCommerce。 All you would need to do is create a trigger that would send an email to shopone@gmail.com if the Shipping Country was US, and shoptwo@gmail.com if it wasn't, regardless of payment method. 您需要做的就是创建一个触发器,该触发器将在发件国家/地区为美国时将电子邮件发送到shopone@gmail.com,如果不是,则将电子邮件发送到shoptwo@gmail.com,而不管付款方式如何。

This works better than any other option that I have seen, thanks! 这比我见过的任何其他选项都更好,谢谢! I changed the shipping_country for billing_state . 我将shipping_country更改为billing_state

Is it possible to add more than two variants? 是否可以添加两个以上的变体? Let say something like: 像这样说:

    if ($this->object->billing_state === 'SC') {
    $this->send( 
        'sc@gmail.com', 
        $this->get_subject(),     
        $this->get_content(), 
        $this->get_headers(), 
        $this->get_attachments()
    ); 
}

    if ($this->object->billing_state === 'RS') {
        $this->send( 
            'rs@gmail.com', 
            $this->get_subject(),
            $this->get_content(), 
            $this->get_headers(), 
            $this->get_attachments() 
        );
    } 

if ($this->object->billing_state === 'PR') {
        $this->send( 
            'pr@gmail.com', 
            $this->get_subject(),
            $this->get_content(), 
            $this->get_headers(), 
            $this->get_attachments() 
        );
    } 


    else { 
        $this->send( 
            'else@gmail.com',
            $this->get_subject(), 
            $this->get_content(), 
            $this->get_headers(), 
            $this->get_attachments() 
        );
    }

I tried applying the code to allow for conditional emails based on a custom checkout field - select with two values. 我尝试应用该代码以允许基于自定义结帐字段的条件电子邮件-使用两个值进行选择。 As described and no emails went out. 如前所述,没有电子邮件出去。

if ($this->object->billing_divisions === 'sprinkler') {
  $this->send( 'shopeone@gmail.com', $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
} else { 
  $this->send( 'shoptwo@mail.com', $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
}

I edited the php file again to add back the replaced code. 我再次编辑了php文件,以添加回替换的代码。 Otherwise new order emails are not triggered for admin. 否则,不会为管理员触发新订单的电子邮件。

if ( $this->is_enabled() && $this->get_recipient() ) {

I've been racking my brain trying to get conditional emails working based on a custom checkout field selection. 我一直在绞尽脑汁,试图根据自定义结帐字段选择来使条件电子邮件正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 基于 Woocommerce 新订单通知的配送方式 ID 的电子邮件收件人 - Email recipients based on Shipping method Id for Woocommerce new order notification 在 WooCommerce 新订单 email 通知中添加运输 state - Add shipping state to subject in WooCommerce new order email notification 根据送货方式 ID 在 WooCommerce 新订单电子邮件通知中隐藏送货地址 - Hide shipping address in WooCommerce new order email notification depending on shipping method id 在不同的收件人上有条件的自定义新订单Woocommerce电子邮件通知 - Conditional custom New Order Woocommerce email notification on different recippients 基于 Woocommerce 中的运输方式的不同电子邮件标题 - Different email heading based on shipping methods in Woocommerce 根据 Woocommerce 中的发货项目,向客户的新订单电子邮件添加回复电子邮件 - Add a reply email to customer new order email, based on shipping item in Woocommerce WooCommerce 中新订单电子邮件通知的自定义主题 - Custom subject for New Order Email notification in WooCommerce 在 WooCommerce 的新订单电子邮件中的项目下添加运输类别? - Add shipping class under items in New Order email in WooCommerce? WooCommerce 根据运送国家/地区更改电子邮件收件人 - WooCommerce Change Email Recipient Depending on Shipping Country Woocommerce 基于地理位置的发货通知 - Woocommerce Shipping notification based on Geolocation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM