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

时间:2017-11-16 17:29:57

标签: 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, $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>';
} 

有客户使用虚假地址下订单,而这会显示真实的城市位置。

那么如何显示客户城市?

代码来自:Display the customer IP Address in new order email notification

1 个答案:

答案 0 :(得分:1)

您可以通过以下方式添加到客户的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>';
    } 
} 

代码放在活动子主题(或主题)的function.php文件中,或者放在任何插件文件中。

经过测试和工作

相关问题