If the user Woocommerce changes his data, a mail to the administrator receives a email about these changes.
I need to show in this letter the custom fields that I created in the ACF. (In ACF created a questionnaire and put it into a /edit-account)
Here is the complete code, based on - Send notification email when customer changes address WooCommerce
if( !class_exists('WooCommerceNotifyChanges') ){
class WooCommerceNotifyChanges{
function __construct(){
// customer saves main account data
add_action('woocommerce_save_account_details', array( $this, 'woocommerce_send_notification' ));
}
function woocommerce_send_notification(){
$body = '';
$to = '[email protected]'; //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>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>Phone: </td><td>' . get_field('user_phone') . '</td></tr>';
$body .= '<tr><td>Age: </td><td>' . get_field('user_age') . '</td></tr>';
$body .= '</table>';
//set content type as HTML
$headers = array('Content-Type: text/html; charset=UTF-8;');
}
} new WooCommerceNotifyChanges();
}
Unfortunately, the custom field is not displayed. All fields in my account have been filled in, I received a email about changing the user's data. But custom fields are not shown in the email.
I tried the option:
$body .= '<tr><td>Phone: </td><td>' . get_field('user_phone', 'user_1') . '</td></tr>';
$body .= '<tr><td>Phone: </td><td>' . get_field('user_phone', $user_id) . '</td></tr>';
I will be happy with your help.