Support

Home Forums Event Espresso Premium EE4: Not seeing any "Event Datetimes" or event ticket info in the $data object

EE4: Not seeing any "Event Datetimes" or event ticket info in the $data object

Posted: June 28, 2019 at 9:45 am

Viewing 15 reply threads


mbeede@tracom.com

June 28, 2019 at 9:45 am

Greetings – When we setup events in EE for training we also setup multiple dates and times for the training using the “Event Datetimes” section. SO the user goes to the event page, chooses the datetime of interest, and proceeds to the registration page. Then they fill out the registration page fields and select the Submit button.

In the back-end PHP the registration field data shows up in the $data object, but not any of the “Event Datetime” or event ticket information (name, desc, etc.) – so I can’t tell what specific datetime was chosen for the event. I need to get at this data somehow. Can you help me out?

Here is what is in the $data object upon the Submit:

[28-Jun-2019 14:52:21 UTC] $data Array
(
[default_hidden_inputs] => Array
(
[action] => process_reg_step
[next_step] => finalize_registration
[e_reg_url_link] =>
[revisit] =>
[consent_box] => Array
(
[consent] => Array
(
[0] => consent
)
)
)

[1-9b2d0cc33250a445bb98613a6816e0cc] => Array
(
[personal-information-1553793652] => Array
(
[fname] => First
[lname] => Last
[email] => test@test.com
[11] => Company
[12] => Position
[phone] => 303-111-2222
)
[address-information-1553793652] => Array
(
[country] => US
[address] =>
[address2] =>
[city] =>
[state] =>
[zip] =>
)
[cert-purchase-kit] => Array
(
[13] => Array
(
[0] => Check here to confirm that you have purchased the Administration Kit from TRACOM required in advance of this training session
)

)
[additional_attendee_reg_info] => 1
[primary_registrant] => 1-9b2d0cc33250a445bb98613a6816e0cc
)
)


mbeede@tracom.com

June 28, 2019 at 9:46 am

If you want to see this in action go here:
https://tracomevents.wpengine.com/sessions/cert-virt-social-style


Josh

  • Support Staff

June 28, 2019 at 10:14 am

Hi,

I’m not sure where/how you’re getting the $data object. It looks like it could be the registration form object, which does not include ticket or datetime data.

What you could do is start with the EE_Checkout object and from there get the EE_Registration object, which can access the EE_Ticket object, which can access the EE_Datetime objects.

e.g.

$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 ) {
    $ticket = $registration->ticket();
    if ( $ticket instanceof EE_Ticket ) {
     $datetimes = $ticket->datetimes();
    }
   }
  }
 }
}


mbeede@tracom.com

June 28, 2019 at 10:21 am

Josh – Yes, the $data is the registration form object. Thanks for working up the sample code – MUCH appreciated.

One more question: If I wanted to access say the first name element in $data how do I do this? I’ve tried these and they don’t work…

$firstname = $data[fname];
$firstname = $data[“1-9b2d0cc33250a445bb98613a6816e0cc”][“personal-information-1553793652”][“fname”];

Thanks again!


Josh

  • Support Staff

June 28, 2019 at 10:34 am

I’m not sure. May I ask how exactly are you getting the $data object?


mbeede@tracom.com

June 28, 2019 at 10:46 am

Sure – A while back you showed me that I could extend the Submit registration functionality by tying into an AHEE action like this:

function my_custom_submit_action( $spco, $data)
{
  // Call ZOOM REST API method to add this registrant to the desired meeting
  $response = registerMeetingParticipant($data);
}
add_action('AHEE__EE_Single_Page_Checkout__process_attendee_information__end','my_custom_submit_action', 10, 2);

So the $data object looks like the registration form object based on what is inside of it. Printing that $data object is what I listed at the top of this post – it’s an ugly object. I’m not sure how to access the different data elements of it like “fname” and “lname” for example.

Does this help?

  • This reply was modified 5 years, 3 months ago by Josh. Reason: fix code formatting


mbeede@tracom.com

June 28, 2019 at 11:02 am

Josh – Going back to your code example when I run it the $datetimes object contains an array of ALL the datetimes for that event. I only care about the datetime that was actually selected by the user. How can I determine that?

Thanks so much for all of you help!!!


Josh

  • Support Staff

June 28, 2019 at 11:16 am

when I run it the $datetimes object contains an array of ALL the datetimes for that event.

It should only return datetimes for that specific ticket, it doesn’t query the event. Are you sure the ticket is assigned to only one datetime?


Tony

  • Support Staff

June 28, 2019 at 11:48 am

On that hook $data is all of the validated data EE was passed, you likely don’t actually need to use it and should use our models to pull the details from the EE_Registration or EE_Transaction objects (like Josh did). The reason I say you don’t need it is in your example:

$firstname = $data[fname];
$firstname = $data[“1-9b2d0cc33250a445bb98613a6816e0cc”][“personal-information-1553793652”][“fname”];

That’s not going to be the same on the next registration, meaning it’s not going work for what you need.

When we setup events in EE for training we also setup multiple dates and times for the training using the “Event Datetimes” section. SO the user goes to the event page, chooses the datetime of interest, and proceeds to the registration page. Then they fill out the registration page fields and select the Submit button.

To step back from this a second, with EE users do NOT select datetimes, they select tickets (which are assigned to datetimes).

I get that you are naming your ticket the same as the datetime etc, but its an important distinction, because:

In the back-end PHP the registration field data shows up in the $data object, but not any of the “Event Datetime” or event ticket information (name, desc, etc.) – so I can’t tell what specific datetime was chosen for the event. I need to get at this data somehow. Can you help me out?

They didn’t select a datetime, they selected a ticket, yes it’s linked to a datetime but they selected a ticket and it’s the ticket you need to work with to get back to the datetime.

Can you pull the datetime(s) the ticket they selected from their ticket/registration? Sure you can and the code Josh gave you above should do just that BUT tickets can also be assigned to multiple datetimes which may cause problems.

So, starting from the beginning for what you want to do, have you confirmed that the ticket the user selected above is assigned to ONLY one specific DateTime?
(Edit the event, click on the cog icon next to the ticket in question and check which datetimes it’s assigned to)

Was it on the event you included above? If so, which specific ticket did they select on that? We can investigate a little more from there.


mbeede@tracom.com

June 28, 2019 at 12:11 pm

THANK YOU for the information above – that was helpful. I did have a few tickets that had multiple Datetimes assigned to them – my bad, sorry.

I am now simplifying this: I am just going to work with the tickets. So to each TICKET for an event I am adding to the ticket description a meeting number, e.g. 123-456-789. So using Josh’s code I can get the TICKET that was selected. So $ticket is an EE_Ticket object. I want to get the description for that ticket. How do I get that?

I thought it would be something like $ticket.description() but I get a “PHP Fatal error: Uncaught Error: Call to undefined function description()” when I do that.

The EE_Ticket class has that function defined as public:

***************
/**
* Gets description
*
* @return string
* @throws \EE_Error
*/
public function description()
{
return $this->get(‘TKT_description’);
}
***************

Thanks guys! – Mark


mbeede@tracom.com

June 28, 2019 at 12:17 pm

Nevermind – I figured that one out. It is $ticket->description(). (I am still learning PHP nuances, coming from a deep Java background 🙂

This issue can be closed now.
THANKS AGAIN for all your help!
Have a great day!


Josh

  • Support Staff

June 28, 2019 at 12:18 pm

Should be $ticket->description(); to use that method.


mbeede@tracom.com

June 28, 2019 at 1:33 pm

I spoke too soon -> I checked the EE_Checkout object, the EE_Transaction object, the EE_Registration object, and the EE_Ticket object and none of them contain the form input from the Registration page. Only the $data object that is a parameter in my called function below contains it.

But this is a very confusing object to me – I can’t figure out how to get the individual form input elements like “fname” “lname” “email” etc. The $data object contents are listed at the very top of this posting. How can I get at the individual form elements using PHP code?

function my_custom_submit_action( $spco, $data) // $data has the form input
{
// Call ZOOM REST API method to add this registrant to the desired meeting
$response = registerMeetingParticipant($data);
}
add_action(‘AHEE__EE_Single_Page_Checkout__process_attendee_information__end’,’my_custom_submit_action’, 10, 2);

Thanks – Mark


Tony

  • Support Staff

June 28, 2019 at 1:38 pm

Forget about $data, it’s causing you more confusion than you need.

There’s a huge number of hooks in EE (~900 action hook, frefixed with AHEE__ and ~1600 Filter hooks prefixed with FHEE__) thats not including the WP core hooks which also apply. So if you had another hook that just passed an EE_Registration object for example in $registration and nothing else, $data wouldn’t even be part of the equation. Use the models, they can be used everywhere to get pretty much whatever you would need once you know how to use them.

EE_Registration will be linked to an EE_Attendee, you can get that with:

$attendee = $registration->attendee();

Check its an instanceof EE_Attendee:

if($attendee instanceof EE_Attendee) {
    echo $attendee->fname();
}

Please take a look over the model documentation as it goes through all of this:

https://github.com/eventespresso/event-espresso-core/tree/master/docs/G–Model-System


mbeede@tracom.com

June 28, 2019 at 1:57 pm

Tony – I will look that over shortly. Quick question: My registration page has several custom fields of input as well as the normal default fields. Will the custom field input also be available somewhere in the EE_Attendee object? That’s why I thought I had to use the $data object, because it contains everything.

Mark


Josh

  • Support Staff

June 28, 2019 at 2:08 pm

The answers to custom questions are available from EE_Answer, which is related to the EE_Registration object. There are methods that can be used too.

e.g. all answers:

if($registration instanceof EE_Registration) {
    $answers = $registration->answers();
}

or for an answer to a specific question with ID 20:

if($registration instanceof EE_Registration) {
    $answer = $registration->answer_value_to_question(20);
}
Viewing 15 reply threads

The support post ‘EE4: Not seeing any "Event Datetimes" or event ticket info in the $data object’ 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