Skip to content

Instantly share code, notes, and snippets.

@iMazed
Created November 30, 2020 05:44
Show Gist options
  • Save iMazed/a6d1c938623ea772a4adbdce88d93c8a to your computer and use it in GitHub Desktop.
Save iMazed/a6d1c938623ea772a4adbdce88d93c8a to your computer and use it in GitHub Desktop.
Update Follow-Ups email on account update
add_action('profile_update', 'wc_fue_update_customers_table_user_profile_update', 10, 2);
function wc_fue_update_customers_table_user_profile_update( $user_id, $old_user_data ) {
// step 1 - get user from user id and email.
$user = get_userdata($user_id);
if ( !$user ) {
return;
}
// step 2 - check if the new email is different from the old email
$new_email = $user->user_email;
$old_email = $old_user_data->user_email;
// bail out if the emails are the same.
if ( $new_email === $old_email ) {
return;
}
// step 3 - get the FUE customer by ID
$customer = FUE_Addon_Woocommerce::get_customer( $user_id, null );
// step 4 - update the FUE customer with the customer from step 4.
if ( $customer ) {
$wpdb = Follow_Up_Emails::instance()->wpdb;
$wpdb->update(
$wpdb->prefix . 'followup_customers',
array( 'email_address' => $new_email),
array( 'id' => $customer->id )
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment