Advertisement
Fany_VanDaal

Email že uživatel změnil adresu v účtu

Dec 28th, 2021
1,268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.59 KB | None | 0 0
  1. if( !class_exists('WooCommerceNotifyChanges') ){
  2.  
  3. class WooCommerceNotifyChanges{
  4.  
  5.     function __construct(){
  6.         // customer saves main account data
  7.         add_action('woocommerce_save_account_details', array( $this, 'woocommerce_send_notification' ));
  8.  
  9.         // customer saves billing or shipping data
  10.         add_action('woocommerce_customer_save_address', array( $this, 'woocommerce_send_notification' ));
  11.     }
  12.  
  13.     function woocommerce_send_notification(){
  14.         $body       = '';
  15.         $to         = 'email@kamtoposlat';    //address that will receive this email
  16.         $subject    = 'Uživatel upravil své údaje';
  17.  
  18.         $curr_user      = wp_get_current_user();
  19.         $user_id        = $curr_user->ID;
  20.         $curr_username  = $curr_user->data->user_login;
  21.  
  22.         $body .= '<table>';
  23.         $body .= '<tr><td><strong>Účet</strong></td></tr>';
  24.         $body .= '<tr><td>Uživatel: </td><td>' . $curr_username                                         . '</td></tr>';
  25.         $body .= '<tr><td colspan="2">&nbsp;</td></tr>';
  26.         $body .= '<tr><td colspan="2"><strong>Fakturační údaje</strong></td></tr>';
  27.         $body .= '<tr><td>Křestní jméno: </td><td>' . get_user_meta( $user_id, 'billing_first_name', true ). '</td></tr>';
  28.         $body .= '<tr><td>Příjmení: </td><td>' . get_user_meta( $user_id, 'billing_last_name', true )  . '</td></tr>';
  29.         $body .= '<tr><td>Společnost: </td><td>' . get_user_meta( $user_id, 'billing_company', true )      . '</td></tr>';
  30.         $body .= '<tr><td>Ulice a č.p.: </td><td>' . get_user_meta( $user_id, 'billing_address_1', true )  . '</td></tr>';
  31.         $body .= '<tr><td>Město: </td><td>' . get_user_meta( $user_id, 'billing_city', true )            . '</td></tr>';
  32.         $body .= '<tr><td>PSČ: </td><td>' . get_user_meta( $user_id, 'billing_postcode', true )   . '</td></tr>';
  33.         $body .= '<tr><td>Země: </td><td>' . get_user_meta( $user_id, 'billing_country', true )      . '</td></tr>';
  34.         $body .= '<tr><td>Telefon: </td><td>' . get_user_meta( $user_id, 'billing_phone', true )          . '</td></tr>';
  35.         $body .= '<tr><td>Email: </td><td>' . get_user_meta( $user_id, 'billing_email', true )          . '</td></tr>';
  36.         $body .= '<tr><td colspan="2">&nbsp;</td></tr>';
  37.         $body .= '<tr><td colspan="2"><strong>Doručovací údaje</strong></td></tr>';
  38.         $body .= '<tr><td>Křestní jméno: </td><td>' . get_user_meta( $user_id, 'shipping_first_name', true ). '</td></tr>';
  39.         $body .= '<tr><td>Příjmení: </td><td>' . get_user_meta( $user_id, 'shipping_last_name', true ) . '</td></tr>';
  40.         $body .= '<tr><td>Společnost: </td><td>' . get_user_meta( $user_id, 'shipping_company', true )     . '</td></tr>';
  41.         $body .= '<tr><td>Ulice a č.p.: </td><td>' . get_user_meta( $user_id, 'shipping_address_1', true ) . '</td></tr>';
  42.         $body .= '<tr><td>Město: </td><td>' . get_user_meta( $user_id, 'shipping_city', true )           . '</td></tr>';
  43.         $body .= '<tr><td>PSČ: </td><td>' . get_user_meta( $user_id, 'shipping_postcode', true )  . '</td></tr>';
  44.         $body .= '<tr><td>Země: </td><td>' . get_user_meta( $user_id, 'shipping_country', true )     . '</td></tr>';
  45.         $body .= '</table>';    
  46.  
  47.         //set content type as HTML
  48.         $headers = array('Content-Type: text/html; charset=UTF-8;');
  49.  
  50.         //send email
  51.         if( wp_mail( $to, $subject, $body, $headers ) ){
  52.             //echo 'email sent';
  53.         }else{
  54.             //echo 'email NOT sent';                
  55.         }
  56.         //exit();
  57.     }
  58. }
  59. new WooCommerceNotifyChanges();
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement