3

新しい注文が作成されると、woocommerce は管理者に電子メールを送信します。電子メール内に顧客の IP アドレスも送信する必要があります。しかし、私はそれを機能させることができません。これが私がこれまでに得たものです:

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

このコードが入りますmytheme/woocommerce/emails/admin-new-order.php

何か案は?

ありがとう。

4

1 に答える 1

6

(WooCommerce バージョン 3 以降の互換性を追加)

更新 2:管理者の新規注文通知にのみアドレス IP を表示する条件を追加しました。未定義$email_idを置き換え$email->id;

メール通知に関連する任意のフックを使用でき、WooCommerce メール テンプレートを上書きする必要はありません。

以下の例では、顧客の詳細の直前に顧客の IP アドレスが表示されますusing woocommerce_email_customer_details

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 ファイルでも。

代わりにこれらのフックを使用することもできます:

woocommerce_email_order_details
woocommerce_email_before_order_table
woocommerce_email_after_order_table
woocommerce_email_order_meta

于 2016-12-13T04:07:44.763 に答える