Background
I'm working on a project for a non-profit and they've asked for a user to only be able to ask for mentoring support after completing a course. This makes it easier to set expectations and confirm they understand the code-of-conduct.
My Issue
I've managed to sort out adding a user to a membership when they sign-up using some custom code in my functions.php
// Hook into Gravity Forms User Registration. Runs after user has been registered
add_action( 'gform_user_registered', 'memberpress_membership_account_prep', 10, 4);
// Setup lifetime MemberPress membership
function memberpress_membership_account_prep( $user_id, $feed, $entry ) {
$url = rest_url( 'mp/v1/transactions' );
$headers = [ 'Authorization' => 'AUTHCODEHERE' ];
$data = [
'member' => $user_id,
'amount' => "0.00",
'total' => "0.00",
'membership' => "237", # MemberPress membership ID here
'status' => "complete",
'gateway' => "manual",
'expires_at' => "0000-00-00 00:00:00"
];
$response = wp_remote_post( $url, [
'method' => 'POST',
'headers' => $headers,
'body' => $data
] );
}
But now I'm have trouble. The following snippet can be used when a particular course has been finished.
// Hook into Learndash Course Completion
add_action("learndash_course_completed", function($data $course_id) {
//Called when course is completed
}, 5, 1);
But I can't figure out how to use the data to pass it into the memberpress_membership_account_prep function.
Any help would be very appreciated.
Thanks.
Top comments (1)
This is probably not the main issue, but are you missing a comma between $data and $course_id in the arguments for the
learndash_course_completed
callback?Does
$data
contain the user_id?If so can you just call
memberpress_membership_account_prep()
from within the callback and pass in the user_id?(You may also want to set default values for $feed and $entry since you don't appear to be using them)