I modified the default Wordpress registration page to include a role and also payment fields. I am adding a Gold Member feature the my website, which requires payment.
I'd like it that after this user makes a payment and it is approved, he gets redirected back to the home page. I'm using the registration_errors filter to achieve this. This is not working, the user is instead redirected back to the wp-login page with a successful message on top.
Additionally, the wp_update_user function is not working either; the user is added to the db with the default role - Subscriber. How do I pass the user_id in here? Or, should I do this in another place.
function process_payment($errors, $sanitized_user_login, $user_email) {
if ( $errors->get_error_code() ) return $errors;
global $tran;
if($tran->Process()) {
$approved = $tran->authcode;
add_filter('registration_redirect', 'gold_login_redirect');
wp_update_user( array ('ID' => $user_id, 'role' => 'gold_member') ) ;
} else {
$errors->add( 'fidelipay_response', __('<strong>Declined</strong>:'. $tran->result . '<br/>' . $tran->error . '<br/>' . $tran->cvv2_result . '<br/>' ,'mysite.com') );
if($tran->curlerror) {
$errors->add( 'fidelipay_response', __('<strong>Reason</strong>:' . $tran->curlerror, 'mysite.com'));
return $errors;
}
return $errors;
}
return $errors;
}
add_filter('registration_errors', 'process_payment', 10, 3);
function gold_login_redirect() {
return home_url('?role=gold_member');
}