Forked from ThomasLeCoz/ld_woosubs_course_access.php
Created
February 24, 2020 13:12
-
-
Save dmasotti/dca12045b7bb6f1861e2f560374469d7 to your computer and use it in GitHub Desktop.
Functions to give or remove access to LearnDash courses
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment