Support » Plugin: Registrations for the Events Calendar - Event Registration Plugin » Limit RSVP/Registration Per User for Event Category

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author roundupwp

    (@roundupwp)

    Hey Tara,

    I think I can come up with something that will work using this hook:
    https://roundupwp.com/codex/filter-rtec_event_meta/

    Are you comfortable with PHP? I can provide a PHP snippet you can add to your theme’s functions.php file if so.

    Do you happen to know the category ID or slug for the category? This can be found when using the “Event Categories” menu page.

    Thanks,

    Craig

    I would be interested in using this code snippet as well. My company has season tickets to the Washington Nationals, and we make the tickets available for request to our employees. We have had a problem with them not adhering to the one-person-one-ticket rule, so if this code can handle that it would be great.

    I am comfortable with PHP and I can find the category slug with no problem.

    Plugin Author roundupwp

    (@roundupwp)

    Hey Kevin A,

    Sorry I missed your response here! I’ll put something together tomorrow for you.

    – Craig

    Plugin Author roundupwp

    (@roundupwp)

    Hello again Kevin,

    This ended up being more complex than I thought but I have something that should work!

    function ru_one_per_category( $event_meta ) {
        if ( is_admin() ) {
            return $event_meta;
        }
    
    	if ( is_user_logged_in() ) {
            $tax = 'tribe_events_cat';
    	    $terms = get_the_terms( $event_meta['post_id'], $tax );
    	    if ( empty( $terms ) ) {
    	        return $event_meta;
            }
    		$post_type = defined('Tribe__Events__Main::POSTTYPE') ? Tribe__Events__Main::POSTTYPE : 'tribe_events';
    		$args = array(
    			'post_type'      => $post_type,
    			'post_status'    => 'publish',
    			'posts_per_page' => 50,
    			'order'          => 'ASC'
    		);
    
    		$ids = array();
    	    foreach( $terms as $term ) {
    		    $ids[] = $term->term_id;
    
            }
    
    		$args['tax_query'] = array(
    			array(
    				'taxonomy' => $tax,
    				'field'    => 'id',
    				'terms'    => $ids
    			)
    		);
    		$posts = tribe_get_events( $args );
    		
    		$event_ids = array();
    		foreach ( $posts as $post ) {
    			$event_ids[] = $post->ID;
            }
    
    		$rtec = RTEC();
    		foreach ( $event_ids as $event_id ) {
    			$args = array(
    				'fields' => array( 'id' ),
    				'where' => array(
    					array( 'event_id', $event_id, '=', 'int' ),
    					array( 'user_id', get_current_user_id(), '=', 'int' )
    				),
    				'order_by' => 'registration_date'
    			);
    
    			$registrations = $rtec->db_frontend->retrieve_entries( $args, true );
    
    			if ( isset( $registrations[0] ) ) {
    				$event_meta['registrations_disabled'] = true;
                }
    		}
    
    	}
    
    	return $event_meta;
    }
    add_filter( 'rtec_event_meta', 'ru_one_per_category' );

    If you can follow the code works by getting the event categories that the event in question has. Then getting all events that have that same category. The IDs of these events are collected. Then finally the registration database is searched to see if there are any entries that match the user that is logged in. Registration is disabled if one is found.

    Let me know if you have questions!

    – Craig

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Limit RSVP/Registration Per User for Event Category’ is closed to new replies.