在新订单电子邮件通知中显示客户IP地址 [英] Display the customer IP Address in new order email notification

查看:120
本文介绍了在新订单电子邮件通知中显示客户IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建新订单时,woocommerce将向管理员发送电子邮件,我也希望它在电子邮件中发送客户的IP地址.但是我无法正常工作,这是到目前为止我得到的:

When a new order is created, woocommerce will send an email to admin, and I want it to send customer's IP address inside the email as well. But I can't get it work, here is what I got so far:

<?php echo get_post_meta( $order->id, '_customer_ip_address', true ); ?>

此代码位于mytheme/woocommerce/emails/admin-new-order.php

有什么想法吗?

谢谢.

推荐答案

(增加了对WooCommerce 3+版本的兼容性)

更新2::添加了一个条件,以仅显示管理员新订单"通知的地址IP.将未定义的 $email_id 替换为 $email->id;

Update 2: Added a condition to display the address IP only for Admin New orders notification. Replaced undefined $email_id by $email->id;

您可以将任何相关的挂钩用于电子邮件通知,而无需覆盖WooCommerce电子邮件模板.

You can use any related hooks for the emails notifications and you don't need to override the WooCommerce emails templates.

在下面的示例中,将在客户详细信息 using woocommerce_email_customer_details 钩子之前显示客户IP地址:

In the example below, the customer IP address will be displayed just before the customer details, using woocommerce_email_customer_details hook:

add_action('woocommerce_email_customer_details', 'send_customer_ip_adress', 10, 4);
function send_customer_ip_adress($order, $sent_to_admin, $plain_text, $email){

    // Just for admin new order notification
    if( 'new_order' == $email->id ){
        // WC3+ compatibility
        $order_id = method_exists( $order, 'get_id' ) ? $order->get_id() : $order->id;

        echo '<br><p><strong>Customer IP address:</strong> '. get_post_meta( $order_id, '_customer_ip_address', true ).'</p>';
    }
} 

此代码已经过测试,功能齐全.

代码进入您的活动子主题(或主题)的function.php文件中.或在任何插件php文件中.

您也可以改用以下这些钩子:

You can use also instead these hooks:

woocommerce_email_order_details
woocommerce_email_before_order_table
woocommerce_email_after_order_table
woocommerce_email_order_meta

woocommerce_email_order_details
woocommerce_email_before_order_table
woocommerce_email_after_order_table
woocommerce_email_order_meta

这篇关于在新订单电子邮件通知中显示客户IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆