Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dwanjuki/00e574e8868c5a329706e2e35c82f703 to your computer and use it in GitHub Desktop.
Save dwanjuki/00e574e8868c5a329706e2e35c82f703 to your computer and use it in GitHub Desktop.
Sell PMPro Courses through AddOn Packages
<?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