php – 如何在woocommerce_email_headers钩子中获取订单ID
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php – 如何在woocommerce_email_headers钩子中获取订单ID,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2305字,纯文字阅读大概需要4分钟。
内容图文
我正在尝试在新订单时设置电子邮件地址.我将新电子邮件存储在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.
内容总结
以上是互联网集市为您收集整理的php – 如何在woocommerce_email_headers钩子中获取订单ID全部内容,希望文章能够帮你解决php – 如何在woocommerce_email_headers钩子中获取订单ID所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。