Support

Home Forums Event Espresso Premium EE4 – User Buys Ticket ID, Gets Assigned Specific Paid Membership Pro Level

EE4 – User Buys Ticket ID, Gets Assigned Specific Paid Membership Pro Level

Posted: May 22, 2017 at 5:46 pm


afermtools

May 22, 2017 at 5:46 pm

Hello,

We’re trying to set up an event such that when the user buys a particular ticket and doesn’t already have a Paid Memberships Pro level, they get assigned to our ‘Guest’ membership level.

I think I’ve come a long way today on figuring out the code to make it work, but we’re clearly not all the way there – it’s not working…

Here’s my code – obviously I don’t expect you all to know how to get the PMPro code to work, but I think the issues I’m encountering are actually either calling something wrong on EE4 or with WP Core.

function pmpro_assign_guest_level_on_ticket_purch($user_id) {
	
	$get_registration = get_EE4_registration($registration, $additional_details);
	//Check if the user has no existing membership level already, and if they bought the relevant ticket
	if (pmpro_hasMembershipLevel('0') && $get_registration[0]==78) {
		// If so, give them the "Guest - ERM 2017 Summit Ticket" Membership level
		pmpro_changeMembershipLevel(12, $user_id);
	}
}

	// Get the ticket that was purchased 
function get_EE4_registration($registration, $additional_details ) {
	if ( $registration instanceof EE_Registration ) {
		$ticket_ID = $registration->ticket_ID();
		$event = $registration->event();
		$attendee = $registration->attendee();
		$reg_obj = array( $ticket_ID , $event, $attendee );
		
		return $reg_obj;
	}
}

/* When the User Registration is updated, assign them the Guest Level  */
add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notification', 'pmpro_assign_guest_level_on_ticket_purch' , 10, 2 ); 

Any help would be appreciated. I’m also going to post this on the PMPro side and will share the forum link here as soon as I do.

Thanks.


afermtools

May 22, 2017 at 5:53 pm

Here’s the link to the Paid Memberships Pro ticket I just submitted.

https://www.paidmembershipspro.com/forums/topic/user-buys-event-espresso-ticket-id-gets-assigned-pmrro-level/

Thanks.


Josh

  • Support Staff

May 22, 2017 at 6:39 pm

Hi there,

I checked over your code and I’m afraid that
get_EE4_registration() is not a function or a method that Event Espresso 4 defines anywhere. Also, Ticket_ID() is not a method of the EE_Registration class. Where are you getting these methods from?

Anyhow, I can share some code with you that will help you get the registration object and you can use the kint debugging tool to see which methods are available on the registration object. Example code follows:

$checkout = EE_Registry::instance()->SSN->checkout();
if ( $checkout instanceof EE_Checkout ) {
 $transaction = $checkout->transaction;
 if ( $transaction instanceof EE_Transaction ) {
  foreach ( $transaction->registrations() as $registration ) {
   if ( $registration instanceof EE_Registration ) {
    if ( function_exists('d') ) {
     d($registration);
    }
   }
  }
 }
}

Please be sure to install the Kint debugging plugin!


afermtools

May 23, 2017 at 1:31 pm

The “get” function I used is my own function declaration. Methods used I got from here:

http://code.eventespresso.com/class-EE_Registration.html

Anyway, thanks for the help. I’m going to see if we can get this working.


Tony

  • Support Staff

May 24, 2017 at 6:02 am

There’s a lot of problems with the code you’ve posted, is some missing?

The main problem is there is no AHEE__EE_Registration_Processor__trigger_registration_update_notification hook within EE.

There is AHEE__EE_Registration_Processor__trigger_registration_update_notifications
(Note the s on the end)

So currently your code isn’t even running as its using the wrong hook.

There is no $registraton variable but you’re passing it to your own get_EE4_registration() function?

$additional_details doesn’t exist but you’re passing it to your own get_EE4_registration() function?

pmpro_assign_guest_level_on_ticket_purch() is being passed $user_id but that’s not what the hook your attempting to use passes to the functions.

AHEE__EE_Registration_Processor__trigger_registration_update_notifications passes a $registraion and $additional_details variable which I think is what you are trying to use in the above but your not using the hook correctly if that’s the case.


afermtools

May 31, 2017 at 3:50 pm

For the moment, per budget and project scope considerations, we’ve agreed with the client that we’re going to manually assign PMPro membership when the user purchases an event ticket. So we may come back to trying to get this to work later, but turning our attention to other items to check off the list.

Points taken and thanks for your help on this. If needed, I’ll open another ticket when necessary.

The support post ‘EE4 – User Buys Ticket ID, Gets Assigned Specific Paid Membership Pro Level’ 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.

Support forum for Event Espresso 3 and Event Espresso 4.
Documentation for EE3 and EE4
Documentation for Event Espresso 3

Documentation for Event Espresso 4

Status: closed

Updated by  afermtools 2 years, 7 months ago ago

Topic Tags

Notifications

This topic is:
pending
Do NOT follow this link or you will be banned from the site!