Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ThomasLeCoz
Created February 15, 2015 13:22
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ThomasLeCoz/0838a71e3bb339aadd8b to your computer and use it in GitHub Desktop.
Save ThomasLeCoz/0838a71e3bb339aadd8b to your computer and use it in GitHub Desktop.
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
Copy link

how to get only course id

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