gpt4 book ai didi

php - 基于 WooCommerce 中付款方式 ID 的其他电子邮件收件人

转载 作者:行者123 更新时间:2023-12-04 08:48:44 24 4
gpt4 key购买 nike

我正在尝试根据 WooCommerce“新订单”电子邮件通知上的付款方式 ID 添加其他电子邮件收件人。
这是我的代码:

function at_conditional_admin_email_recipient($recipient, $order){
// if( ! is_a($order, 'WC_Order') ) return $recipient;

if ( get_post_meta($order->id, '_payment_method', true) == 'my_custom_gateway_id' ) {
$recipient .= ', xx1@xx.com';
} else {
$recipient .= ', xx2@xx.com';
}
return $recipient;


};
add_filter( 'woocommerce_email_recipient_new_order', 'at_conditional_admin_email_recipient', 10, 2 );
但是钩子(Hook)似乎没有触发我的功能。可能是什么原因?

最佳答案

自 Woocommerce 3 以来,您的代码已过时,请尝试以下操作:

add_filter( 'woocommerce_email_recipient_new_order', 'payment_id_based_new_order_email_recipient', 10, 2 );
function payment_id_based_new_order_email_recipient( $recipient, $order ){
// Avoiding backend displayed error in Woocommerce email settings (mandatory)
if( ! is_a($order, 'WC_Order') )
return $recipient;

// Here below set in the array the desired payment Ids
$targeted_payment_ids = array('bacs');

if ( in_array( $order->get_payment_method(), $targeted_payment_ids ) ) {
$recipient .= ', manager1@gmail.com';
} else {
$recipient .= ', manager2@gmail.com';
}
return $recipient;
}
代码在您的事件子主题(或事件主题)的functions.php 文件中。它应该有效。

Also sometimes the problem can be related to a wrong payment method Id string in your code (so try first for example with WooCommerce "cod" or "bacs" payment methods ids, to see if the code works).

关于php - 基于 WooCommerce 中付款方式 ID 的其他电子邮件收件人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64179508/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com