1
votes

I use the "Advanced Custom Fields" and "ACF for WooCommerce" plugins. I created several custom fields and placed them on the "edit-account" page.

If the user changes the personal information on this page, I need to receive an email with the values ​​of these custom fields.

For this, I downloaded the test plugin, which was written by @helgatheviking - WooCommerce trigger custom email via AJAX

I have the output code for these fields, for example:

get_field( 'user_phone', "user_{$user_id}" );

How can I correctly place this code in the plugin so that the data of these custom fields come to the administrator?

How can I combine the "Email Trigger" button with the custom fields so that the field data is stored in the database and simultaneously sent to the administrator?

I will be glad of your help!

1

1 Answers

0
votes

You can use the profile_update hook and create a custom function to email the custom field data. Something along these lines should work. Note the formatting of the $user_id variable within the get_field() function.

function my_custom_function( $user_id ) {

    $phone = get_field( 'user_phone', 'user_'.$user_id );

    // Get the rest of your field values, format them together however you want, then use wp_mail() to send the email

}
add_action( 'profile_update', 'my_custom_function');