Support

Home Forums Event Espresso Premium Pending Payments for logged in user

Pending Payments for logged in user

Posted: March 11, 2019 at 7:05 am


Antenna Digital

March 11, 2019 at 7:05 am

My client wants to prevent a user from registering for an event if they have pending payments for another event (they take payment by check as well as cc)

I think my best bet is to add a snippet in my version of the content-espresso_events-tickets.php file. I have determined where I want to do that…I can just surround the line <?php espresso_ticket_selector( $post ); ?> with an ‘if user has payment outstanding’ statement. So far so good.

I have searched the forum for ways to get if the current user has pending payments but so far have not found anything that seems like what I need.

I tried to figure it out from the models docs but have not been successful.

Can you help me get this figured out?


Josh

  • Support Staff

March 11, 2019 at 12:13 pm

You’ll first need to make sure there’s a logged in user:

if ( is_user_logged_in() ) {
  // initialize
  $user_regs = array();
  // more code here
}

then get the current user’s user ID, and you could use:
https://codex.wordpress.org/Function_Reference/wp_get_current_user
$user = wp_get_current_user();
Then you could get the attendee ID from the user ID:
$att_id = get_user_option( 'EE_Attendee_ID', $user->ID );

then get the EE_Contact record:
$contact = EEM_Attendee::instance()->get_one_by_ID( $att_id );

then get the registrations:

if ( $contact instanceof EE_Attendee ) {
      $regs = $contact->get_many_related( 'Registration' );
     // loop here
}

then loop through the registrations to get registration statuses:

foreach ( $regs as $reg ){
      $user_regs[] = $reg->get( 'STS_ID' );
}

then check for pending payments:

if( in_array( 'RPP', $user_regs ) ) {
 echo 'message to show if they have a pending payment registration';
} else {
 // code to display ticket selector
}


Antenna Digital

March 11, 2019 at 2:34 pm

Thanks Josh. That works perfectly. And in the last bit I just added a link to a page where I use the [ESPRESSO_MY_EVENTS template=simple_list_table ] shortcode.

I appreciate your help.

The support post ‘Pending Payments for logged in user’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso