Skip to content

Instantly share code, notes, and snippets.

@andrewlimaza
Last active April 22, 2024 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save andrewlimaza/c3893542d44cdaf5aa766fcce2857063 to your computer and use it in GitHub Desktop.
Save andrewlimaza/c3893542d44cdaf5aa766fcce2857063 to your computer and use it in GitHub Desktop.
Sell PMPro Series through AddOn Packages
<?php
/**
* Adds the AddOn Package post meta to 'Series' post type.
* Give access if they purchased "Series" parent container.
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function add_pmpro_series_to_AP( $types ) {
$types[] = 'pmpro_series';
return $types;
}
add_filter( 'pmproap_supported_post_types', 'add_pmpro_series_to_AP', 10, 1 );
function pmpro_give_access_to_users_for_series( $hasaccess, $mypost, $myuser, $post_membership_levels) {
$post_id = $mypost->ID;
$is_in_series = get_post_meta( $post_id, '_post_series', 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_in_series) ) {
return $hasaccess;
}
if ( in_array( $is_in_series[0], $ap_posts ) ) {
$hasaccess = true;
}
return $hasaccess;
}
add_filter('pmpro_has_membership_access_filter', 'pmpro_give_access_to_users_for_series', 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment