복붙노트

[WORDPRESS] 고객이 변경할 때 알림 전자 메일을 보내고 있습니다

WORDPRESS

고객이 변경할 때 알림 전자 메일을 보내고 있습니다

해결법


  1. 1.몇 주 전에 나는 거의 모든 정확한 목적을 위해 내 고객 중 하나에 대해 간단한 플러그인을 썼습니다. 이렇게하면 고객이 변경 / 업데이트 할 때마다 전자 메일 알림을 보냅니다.

    몇 주 전에 나는 거의 모든 정확한 목적을 위해 내 고객 중 하나에 대해 간단한 플러그인을 썼습니다. 이렇게하면 고객이 변경 / 업데이트 할 때마다 전자 메일 알림을 보냅니다.

    내 코드를 조회하고 거기에서 필요로하지 않는 것을 편집 / 제거하십시오.

     if( !class_exists('WooCommerceNotifyChanges') ){
    
    class WooCommerceNotifyChanges{
    
        function __construct(){
            // customer saves main account data
            add_action('woocommerce_save_account_details', array( $this, 'woocommerce_send_notification' ));
    
            // customer saves billing or shipping data
            add_action('woocommerce_customer_save_address', array( $this, 'woocommerce_send_notification' ));
        }
    
        function woocommerce_send_notification(){
            $body       = '';
            $to         = 'recipient@gmail.com';    //address that will receive this email
            $subject    = 'One of your customers has updated their information.';
    
            $curr_user      = wp_get_current_user();
            $user_id        = $curr_user->ID;
            $curr_username  = $curr_user->data->user_login;
    
            $body .= '<table>';
            $body .= '<tr><td><strong>Account</strong></td></tr>';
            $body .= '<tr><td>Username: </td><td>' . $curr_username                                         . '</td></tr>';
            $body .= '<tr><td colspan="2">&nbsp;</td></tr>';
            $body .= '<tr><td colspan="2"><strong>Billing</strong></td></tr>';
            $body .= '<tr><td>First name: </td><td>' . get_user_meta( $user_id, 'billing_first_name', true ). '</td></tr>';
            $body .= '<tr><td>Last name: </td><td>' . get_user_meta( $user_id, 'billing_last_name', true )  . '</td></tr>';
            $body .= '<tr><td>Company: </td><td>' . get_user_meta( $user_id, 'billing_company', true )      . '</td></tr>';
            $body .= '<tr><td>Address 1: </td><td>' . get_user_meta( $user_id, 'billing_address_1', true )  . '</td></tr>';
            $body .= '<tr><td>Address 2: </td><td>' . get_user_meta( $user_id, 'billing_address_2', true )  . '</td></tr>';
            $body .= '<tr><td>City: </td><td>' . get_user_meta( $user_id, 'billing_city', true )            . '</td></tr>';
            $body .= '<tr><td>Post code: </td><td>' . get_user_meta( $user_id, 'billing_postcode', true )   . '</td></tr>';
            $body .= '<tr><td>Country: </td><td>' . get_user_meta( $user_id, 'billing_country', true )      . '</td></tr>';
            $body .= '<tr><td>State: </td><td>' . get_user_meta( $user_id, 'billing_state', true )          . '</td></tr>';
            $body .= '<tr><td>Phone: </td><td>' . get_user_meta( $user_id, 'billing_phone', true )          . '</td></tr>';
            $body .= '<tr><td>Email: </td><td>' . get_user_meta( $user_id, 'billing_email', true )          . '</td></tr>';
            $body .= '<tr><td colspan="2">&nbsp;</td></tr>';
            $body .= '<tr><td colspan="2"><strong>Shipping</strong></td></tr>';
            $body .= '<tr><td>First name: </td><td>' . get_user_meta( $user_id, 'shipping_first_name', true ). '</td></tr>';
            $body .= '<tr><td>Last name: </td><td>' . get_user_meta( $user_id, 'shipping_last_name', true ) . '</td></tr>';
            $body .= '<tr><td>Company: </td><td>' . get_user_meta( $user_id, 'shipping_company', true )     . '</td></tr>';
            $body .= '<tr><td>Address 1: </td><td>' . get_user_meta( $user_id, 'shipping_address_1', true ) . '</td></tr>';
            $body .= '<tr><td>Address 2: </td><td>' . get_user_meta( $user_id, 'shipping_address_2', true ) . '</td></tr>';
            $body .= '<tr><td>City: </td><td>' . get_user_meta( $user_id, 'shipping_city', true )           . '</td></tr>';
            $body .= '<tr><td>Post code: </td><td>' . get_user_meta( $user_id, 'shipping_postcode', true )  . '</td></tr>';
            $body .= '<tr><td>Country: </td><td>' . get_user_meta( $user_id, 'shipping_country', true )     . '</td></tr>';
            $body .= '<tr><td>State: </td><td>' . get_user_meta( $user_id, 'shipping_state', true )         . '</td></tr>';
            $body .= '</table>';    
    
            //set content type as HTML
            $headers = array('Content-Type: text/html; charset=UTF-8;');
    
            //send email
            if( wp_mail( $to, $subject, $body, $headers ) ){
                //echo 'email sent';
            }else{
                //echo 'email NOT sent';                
            }
            //exit();
        }
    }
    new WooCommerceNotifyChanges(); 
    } 
    
  2. from https://stackoverflow.com/questions/31270846/send-notification-email-when-customer-changes-address-woocommerce by cc-by-sa and MIT license