Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Membership 2 PRO
$api = ms_api();
$member = $api->get_current_member();
// Check if current user is in certain membership:
$membership_id = 100; // hardcode the ID.
$membership_id = $api->get_membership_id( 'premium' ); // fetch by membership name.
if ( $member->has_membership( $membership_id ) ) {
echo "You are member of " . $membership_id;
}
// Get the membership of the current user:
$membership = $api->detect_membership();
echo "First membership: " . $membership->name;
// Note: If multiple-memberships is enabled, this will return only the first membership!
// Get all memberships of the current user (multiple memberships)
foreach ( $member->subscriptions as $subscription ) {
// Note: Double check if user has_membership() to filter out expired/pending subscriptions
if ( ! $member->has_membership( $subscription->membership_id ) ) {
continue;
}
$membership = $subscription->get_membership();
echo "<br>Your membership: " . $membership->name;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.