我正在尝试在新订单时设置电子邮件地址.我将新电子邮件存储在wp_postmeta中.
使用woocommerce_email_headers时如何获得$order_id?
我需要让order_id与get_post_meta()函数一起使用它.
这是我的代码:
function techie_custom_wooemail_headers( $headers, $object) {
$email = get_post_meta( $order_id, '_approver_email', true );
// Replace the emails below to your desire email
$emails = array('eee@hotmail.com', $email);
switch($object) {
case 'new_order':
$headers .= 'Bcc: ' . implode(',', $emails) . "\r\n";
break;
case 'customer_processing_order':
$headers .= 'Bcc: ' . implode(',', $emails) . "\r\n";
break;
case 'customer_completed_order':
case 'customer_invoice':
$headers .= 'Bcc: ' . implode(',', $emails) . "\r\n";
break;
default:
}
return $headers;
}
add_filter( 'woocommerce_email_headers', 'techie_custom_wooemail_headers', 10, 2);
我如何取回数据?
谢谢.
解决方法:
Updated: Added compatibility with Woocommerce version 3+
我做了一些测试试图从$order对象输出原始数据但没有成功.经过一些其他测试,我现在得到了正确的订单ID.我已经使用下面的代码进行测试.用您自己的电子邮件替换$your_email的值.然后,您将收到标题名称中包含订单ID的电子邮件:
function testing_hook_headers( $headers, $id, $order ) {
// The order ID | Compatibility with WC version +3
$order_id = method_exists( $order, 'get_id' ) ? $order->get_id() : $order->id;
$your_email = '<name@email.com>';
$headers = "To: Order Num $order_id $your_email";
return $headers;
}
add_filter( 'woocommerce_email_headers', 'testing_hook_headers', 10, 3);
所以这是你的代码:
function techie_custom_wooemail_headers( $headers, $email_id, $order ) {
// The order ID | Compatibility with WC version +3
$order_id = method_exists( $order, 'get_id' ) ? $order->get_id() : $order->id;
$email = get_post_meta( $order_id, '_approver_email', true );
// Replace the emails below to your desire email
$emails = array('eee@hotmail.com', $email);
switch( $email_id ) {
case 'new_order':
$headers .= 'Bcc: ' . implode(',', $emails) . "\r\n";
break;
case 'customer_processing_order':
$headers .= 'Bcc: ' . implode(',', $emails) . "\r\n";
break;
case 'customer_completed_order':
case 'customer_invoice':
$headers .= 'Bcc: ' . implode(',', $emails) . "\r\n";
break;
default:
}
return $headers;
}
add_filter( 'woocommerce_email_headers', 'techie_custom_wooemail_headers', 10, 3);
我没有测试你的代码,因为它是特别的,但你有正确的方式来获得订单ID.
原文地址:https://codeday.me/bug/20190927/1825016.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。