【问题标题】:WooCommerce additional email on completed orderWooCommerce 已完成订单的附加电子邮件
【发布时间】:2017-06-07 13:56:52
【问题描述】:

我有一个问题需要社区支持,因为我在网络上找不到任何东西,包括 WooCommerce 支持论坛。

我有一个 WooCommerce 网站,这是一家本地连锁餐厅使用的封闭式电子商务商店。每次商店订购任何东西时,GM 还希望在完成订单时向他发送一封电子邮件,以便他可以阻止订单或批准订单。 GM1负责Store1、Store2和Store3; GM2负责Store4、Store5、Store 6等。

在互联网的帮助下,这就是我目前在 function.php 中所拥有的。功能正常工作并被触发,但所有 3 名 GM 都收到了电子邮件,但理论上,只有一名 GM 应该收到电子邮件。 GM1 用于 Store1 OR Store2 OR Store3;如果 Store4 OR Store5 OR Store6 订单,GM2 应该会收到电子邮件。

如果有人能指出正确的方向或至少让我知道为什么所有三个 if 都会被触发,我真的很感激。

add_filter( 'woocommerce_email_recipient_customer_completed_order', 'your_email_recipient_filter_function', 10, 2);

function your_email_recipient_filter_function($recipient, $object) {
    if( 'Store1@store.com' || 'Store2@store.com' || 'Store3@store.com' == $recipient ){
        $recipient = $recipient .= ', GM1@store.com';
    }

    if( 'Store4@store.com' || 'Store5@store.com' || 'Store6@store.com' == $recipient ){
        $recipient = $recipient .= ', GM2@store.com';
    }

    if( 'Store7@store.com' || 'Store8@store.com' || 'Store9@store.com' == $recipient ){
        $recipient = $recipient .= ', GM3@store.com';
    }

    return $recipient;
}

谢谢。

【问题讨论】:

  • 您是否正在使用任何供应商插件?
  • 查看 PHP 控制结构文档 (php.net/manual/en/control-structures.elseif.php),应该是 ifelseif
  • 不,不使用任何供应商插件。我也试过 if{} elseif{},但结果还是一样。所有 3 位 GM 都收到了电子邮件。

标签: php wordpress woocommerce orders email-notifications


【解决方案1】:

我最终使用了一个如下所示的数组(),它似乎正在工作:

function your_email_recipient_filter_function( $recipient, $order ) {

$Stores1 = array('Store1@store.com', 'Store2@store.com', 'Store3@store.com');
$Stores2 = array('Store4@store.com', 'Store5@store.com', 'Store6@store.com');
$Stores3 = array('Store7@store.com', 'Store8@store.com', 'Store9@store.com');

$StoreEmail =  $order->billing_email;

if ( in_array( $StoreEmail, $Stores1)) {
    $recipient .= ', GM1@store.com';
} elseif ( in_array( $StoreEmail, $Stores2) ) {
    $recipient .= ', GM2@store.com';
} elseif ( in_array( $StoreEmail, $Stores3) ) {
    $recipient .= ', GM2@store.com';
} 
return $recipient;
}
add_filter( 'woocommerce_email_recipient_customer_completed_order', 'your_email_recipient_filter_function', 10, 2);

【讨论】:

    猜你喜欢
    • 2017-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-29
    • 1970-01-01
    相关资源
    最近更新 更多