(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