Function to associate wp user account to givewp donor profile
-
Hi
Relating to this bug (https://feedback.givewp.com/bug-reports/p/donors-with-account-can-only-donate-again-while-logging-in), I’d like to write a little snippet in order to create a wp user account (for each donation whom donor does not have any wp user account yet) and to associate this wp user account to the Givewp donor profile .
Then, I set the Givewp form options to :
- Guests donations : enabled
- Registration : none
I mmanaged to create a new wp user account after the 1st donation but can’t manage to associate it to my Givewp donor profile.
please, could you help me to do it? I guess my issue is situated in the last function…
Thanks a lot
Gil
add_action('give_insert_payment', 'create_donor_user_and_associate_donation', 10, 2); function create_donor_user_and_associate_donation($payment_id, $payment_data) { $email = give_get_payment_user_email($payment_id); $user = get_user_by('email', $email); // if user doesn't exist, we create him if (!$user) { $random_password = wp_generate_password($length = 12, $include_standard_special_chars = false); $user_id = wp_create_user($email, $random_password, $email); // set the user role to "Donor" $user = new WP_User($user_id); $user->set_role('give_donor'); } else { $user_id = $user->ID; } // Associate the user to the donation give_update_payment_meta($payment_id, '_give_payment_donor_id', $user_id); }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Function to associate wp user account to givewp donor profile’ is closed to new replies.