Created
November 30, 2020 05:44
-
-
Save iMazed/a6d1c938623ea772a4adbdce88d93c8a to your computer and use it in GitHub Desktop.
Update Follow-Ups email on account update
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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