• Resolved macsi

    (@macsi)


    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 :

    1. Guests donations : enabled
    2. 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);
    }

    • This topic was modified 10 months ago by macsi.
Viewing 1 replies (of 1 total)
  • Plugin Support Matheus Martins

    (@matheusfd)

    Hi, @macsi.

    Glad you reached out.

    We’ve got a spot where you can ask this question directly to our development team, but the question will need to be more fleshed out there than it is here. I’d recommend passing along the exact code snippet you are attempting to use and what results from that snippet. The more focused the question is, the more likely our development team will be able to step away from their busy schedules to help with this sort of custom code.

    You can reach out to them here:?https://github.com/impress-org/givewp/discussions.

    Feel free to reach out to us if you have any further inquiries or require additional assistance. We’re always happy to help!

Viewing 1 replies (of 1 total)
  • The topic ‘Function to associate wp user account to givewp donor profile’ is closed to new replies.