Php 在新订单电子邮件通知中显示客户城市

Php 在新订单电子邮件通知中显示客户城市,php,wordpress,woocommerce,orders,email-notifications,Php,Wordpress,Woocommerce,Orders,Email Notifications,创建新订单时,woocommerce将向管理员发送电子邮件,我希望它也在电子邮件中发送客户所在城市的位置 在function.php文件中添加此代码只会显示需要额外步骤才能打开浏览器并搜索IP位置以查找城市的IP: add_action('woocommerce_email_customer_details', 'send_customer_ip_adress', 10, 4); function send_customer_ip_adress($order, $sent_to_admin

创建新订单时,woocommerce将向管理员发送电子邮件,我希望它也在电子邮件中发送客户所在城市的位置

在function.php文件中添加此代码只会显示需要额外步骤才能打开浏览器并搜索IP位置以查找城市的IP:

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 )
    echo '<br><p><strong>Customer IP address:</strong> '. get_post_meta( $order->id, '_customer_ip_address', true ).'</p>';
} 
add_action('woocmerce_email_customer_details','send_customer_ip_address',10,4);
函数send_customer_ip_address($order,$send_to_admin,$plain_text,$email){
//仅用于管理员新订单通知
如果('new_order'=$email->id)
回显“
客户IP地址:”。获取“post”元($order->id,“客户IP地址”,true)。“

”; }
有客户使用假地址下假订单,而这将显示真实的城市位置

那么如何显示客户所在城市


代码来自:

您可以通过以下方式将其添加到客户IP地址,以及他的计费城市:

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

    // Just for admin new order notification
    if( 'new_order' == $email->id ){
        echo '<br>
        <p><strong>'.__('Customer IP address').':</strong> '. get_post_meta( $order->id, '_customer_ip_address', true ).'</p>
        <p><strong>'.__('Customer city').':</strong> '. get_post_meta( $order->get_id(), '_billing_city', true ).'</p>';
    } 
} 
add_action('woocommerce_email_customer_details','send_customer_city',10,4);
函数send_customer_city($order,$send_to_admin,$plain_text,$email){
//仅用于管理员新订单通知
如果('new_order'=$email->id){
回声'
。(“客户IP地址”):”。获取“post”meta($order->id),“客户IP地址”,true)。'

。(客户城市):。获取post元数据($order->get_id(),“账单城市”,true)。

; } }
代码位于活动子主题(或主题)的function.php文件或任何插件文件中

测试和工作