Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Functions to give or remove access to LearnDash courses
// Remove Access to the course linked to the subscription key
function remove_course_access( $user_id, $subscription_key ) {
// Get the course ID related to the subscription
$subscription = WC_Subscriptions_Manager::get_subscription( $subscription_key );
$courses_id = get_post_meta($subscription['product_id'], '_related_course', true);
// Update access to the courses
if ($courses_id && is_array($courses_id)) {
foreach ($courses_id as $course_id) {
ld_update_course_access($user_id, $course_id, $remove = true);
}
}
}
// Give Access to the course linked to the subscription key
function give_course_access( $user_id, $subscription_key ) {
// Get the course ID related to the subscription
$subscription = WC_Subscriptions_Manager::get_subscription( $subscription_key );
$courses_id = get_post_meta($subscription['product_id'], '_related_course', true);
// Update access to the courses
if ($courses_id && is_array($courses_id)) {
foreach ($courses_id as $course_id) {
ld_update_course_access($user_id, $course_id, $remove = false);
}
}
}
@ZeeshanAslam123

This comment has been minimized.

Copy link

@ZeeshanAslam123 ZeeshanAslam123 commented Sep 21, 2020

how to get only course id

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment