Home / Admin / Approving User Account After Completed PayPal Payment
Duplicate Snippet

Embed Snippet on Your Site

Approving User Account After Completed PayPal Payment

This snippet conditionally approves a user's account after they've completed their payment through the PayPal gateway.

<10
Code Preview
php
<?php
/**
 * Approve user after PayPal payment status is Complete
 *
 * @link https://wpforms.com/developers/how-to-approve-a-user-after-a-paypal-payment/
 */
 
function wpf_dev_activate_user_after_paypal_complete( $fields, $form_data, $payment_id, $data ){
     
    // Add the field ID for the user's account email
    $email_field = 3;
 
    // Stop editing
    $user = get_user_by( 'email', $form_data[ $email_field ][ 'value' ] );
     
    delete_user_meta( $user->ID, 'wpforms-activate' );
    delete_user_meta( $user->ID, 'wpforms-pending' );
    delete_user_meta( $user->ID, 'wpforms-confirmation' );
 
    // Check if we need to assign new role.
    $role = get_user_meta( $user->ID, 'wpforms-role', true );
 
    if ( $role ) {
 
        wp_update_user(
            [
                'ID'   => $user->ID,
                'role' => $role,
            ]
        );
        delete_user_meta( $user->ID, 'wpforms-role' );
    }
 
    wpforms_user_registration()->get( 'email_notifications' )->after_activation( $user->ID );
 
}
 
add_action( 'wpforms_paypal_standard_process_complete', 'wpf_activate_user_after_paypal_complete', 10, 4 );

Comments

Add a Comment