• Hi – wondering if there’s a way to restrict ticket types to Members based on PMPro membership levels, rather than just being logged in or not. For example, there could be expired or past members who can still log in but not access any member-only functions, and they should not be able to view the “members-only” tickets.

    Thank you!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Add the following code snippet so that you can use Paid Memberships Pro to restrict events to particular membership levels:

    add_filter( 'pmpro_restrictable_post_types', function( $post_types ) {
        if ( is_plugin_active( 'events-manager/events-manager.php' ) && !in_array( 'event', $post_types ) ) {
            $post_types[] = 'event';
        }
        return $post_types;
    });

    You can use the Code Snippets plugin to add this code snippet.

    Optionally, you can add a category for members only events and then create a page with the [events_list category=”membersonly”] shortcode and restrict that page to members only.

    • This reply was modified 11 months, 3 weeks ago by joneiseman.
    • This reply was modified 11 months, 3 weeks ago by joneiseman.
    Thread Starter tnightingale

    (@tnightingale)

    Hi – thanks but that’s not at all what I was asking. I can already hide or show events based on membership levels using the PMPro events add-on. (We don’t need to do that – events are for members and non-members.) I was asking about tickets. Please re-read my original question.

    We have lower priced tickets for members. I want only actual members to see the member tickets (not anyone who is logged in). This would be related to the settings for individual tickets, where they can be restricted to “everyone”, “members”, or “guests”. But “members” is not checking for membership levels.

    Hope that is clearer.

    I should have read your post more carefully before answering.

    The choices for ticket availability right now are for “Everyone”, “Logged in Users”, or “Guests”. If you choose “Logged in Users” you can restrict it to specific roles. I suggest you assign a role to your members (say the role is called “member”) then you could restrict the tickets just to users with the “member” role.

    You can use the Members plugin to create the new “member” role.

    To maintain the “member” role correctly you could use the following code snippet:

    add_action('pmpro_after_change_membership_level', function($level_id, $user_id, $old_level) {
        if ($user_id == 0)
            return;
        $user = get_userdata($user_id);
        if ($level_id && $level_id > 0 && (empty($old_level ||  $old_level == 0))) {
            $user->add_role('member');
        }
        else if (!empty($old_level) && $old_level > 0) {
            $user->remove_role('member');
        }
    }, 10, 3);

    To add the code snippet you can use the “Code Snippets” plugin.

    To assign the “member” role to all your current members you could use the following code snippet (set this to run only once in the Code Snippets plugin).

    $users = get_users();
    foreach ($users as $user) {
        $level = pmpro_getMembershipLevelForUser($user->ID);
        if ($level !== null && $level > 0) {
            $user->add_role('member');
        }
    }
    • This reply was modified 11 months, 3 weeks ago by joneiseman.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Restrict booking tickets by PMPro membership?’ is closed to new replies.