Forked from andrewlimaza/sell-series-addon-packages.php
Last active
January 24, 2025 10:27
-
-
Save kimwhite/8dba5409381115d253d69c471d1f9d31 to your computer and use it in GitHub Desktop.
Sell PMPro Course as AddOn Packages
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
<?php | |
/** | |
* Adds the AddOn Package post meta to 'Courses' 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[] = 'courses'; | |
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