Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 = 'email@kamtoposlat'; //address that will receive this email
- $subject = 'Uživatel upravil své údaje';
- $curr_user = wp_get_current_user();
- $user_id = $curr_user->ID;
- $curr_username = $curr_user->data->user_login;
- $body .= '<table>';
- $body .= '<tr><td><strong>Účet</strong></td></tr>';
- $body .= '<tr><td>Uživatel: </td><td>' . $curr_username . '</td></tr>';
- $body .= '<tr><td colspan="2"> </td></tr>';
- $body .= '<tr><td colspan="2"><strong>Fakturační údaje</strong></td></tr>';
- $body .= '<tr><td>Křestní jméno: </td><td>' . get_user_meta( $user_id, 'billing_first_name', true ). '</td></tr>';
- $body .= '<tr><td>Příjmení: </td><td>' . get_user_meta( $user_id, 'billing_last_name', true ) . '</td></tr>';
- $body .= '<tr><td>Společnost: </td><td>' . get_user_meta( $user_id, 'billing_company', true ) . '</td></tr>';
- $body .= '<tr><td>Ulice a č.p.: </td><td>' . get_user_meta( $user_id, 'billing_address_1', true ) . '</td></tr>';
- $body .= '<tr><td>Město: </td><td>' . get_user_meta( $user_id, 'billing_city', true ) . '</td></tr>';
- $body .= '<tr><td>PSČ: </td><td>' . get_user_meta( $user_id, 'billing_postcode', true ) . '</td></tr>';
- $body .= '<tr><td>Země: </td><td>' . get_user_meta( $user_id, 'billing_country', true ) . '</td></tr>';
- $body .= '<tr><td>Telefon: </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"> </td></tr>';
- $body .= '<tr><td colspan="2"><strong>Doručovací údaje</strong></td></tr>';
- $body .= '<tr><td>Křestní jméno: </td><td>' . get_user_meta( $user_id, 'shipping_first_name', true ). '</td></tr>';
- $body .= '<tr><td>Příjmení: </td><td>' . get_user_meta( $user_id, 'shipping_last_name', true ) . '</td></tr>';
- $body .= '<tr><td>Společnost: </td><td>' . get_user_meta( $user_id, 'shipping_company', true ) . '</td></tr>';
- $body .= '<tr><td>Ulice a č.p.: </td><td>' . get_user_meta( $user_id, 'shipping_address_1', true ) . '</td></tr>';
- $body .= '<tr><td>Město: </td><td>' . get_user_meta( $user_id, 'shipping_city', true ) . '</td></tr>';
- $body .= '<tr><td>PSČ: </td><td>' . get_user_meta( $user_id, 'shipping_postcode', true ) . '</td></tr>';
- $body .= '<tr><td>Země: </td><td>' . get_user_meta( $user_id, 'shipping_country', 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();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement