Forked from kimwhite/sell-courses-addon-packages.php
Last active
June 6, 2024 07:43
-
-
Save dwanjuki/00e574e8868c5a329706e2e35c82f703 to your computer and use it in GitHub Desktop.
Sell PMPro Courses through AddOn Packages
This file contains 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
<?php | |
/** | |
* Adds the AddOn Package post meta to 'pmpro_course' post type. | |
* Give access if they purchased "Courses" parent container. | |
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function add_pmpro_courses_to_AP( $types ) { | |
$types[] = 'pmpro_course'; | |
return $types; | |
} | |
add_filter( 'pmproap_supported_post_types', 'add_pmpro_courses_to_AP', 10, 1 ); | |
function pmpro_give_access_to_users_for_course( $hasaccess, $mypost, $myuser, $post_membership_levels) { | |
$post_id = $mypost->ID; | |
$is_course = get_post_meta( $post_id, '_post_courses', true ); | |
$ap_posts = get_user_meta( $myuser->ID, '_pmproap_posts', true ); | |
// Bail if nothing is found and return current access. | |
if ( empty( $ap_posts) || empty( $is_course) ) { | |
return $hasaccess; | |
} | |
if ( in_array( $is_course[0], $ap_posts ) ) { | |
$hasaccess = true; | |
} | |
return $hasaccess; | |
} | |
add_filter('pmpro_has_membership_access_filter', 'pmpro_give_access_to_users_for_course', 10, 4 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment