Support

Home Forums Event Espresso Premium Custom Meta Data on profile

Custom Meta Data on profile

Posted: June 26, 2019 at 2:09 am

Viewing 36 reply threads


rossib94

June 26, 2019 at 2:09 am

Hi,

Two things:

1. We are trying to get todays events and then get the registrant data for each event i.e First/Last name and the custom registration fields. This needs to be custom so we are looking to use the classes which I have got a start with but want to see if there’s a better way as it isn’t finding the first and last names (probably using the wrong class).

2. We have custom meta fields on the user so wondering if there’s a hook we can use so upon registering (when the account is created) can we save the registration custom fields (etc) to the user account.

Thanks in advance for your help.


Tony

  • Support Staff

June 26, 2019 at 3:44 am

Hi there,

1. We are trying to get todays events and then get the registrant data for each event i.e First/Last name and the custom registration fields. This needs to be custom so we are looking to use the classes which I have got a start with but want to see if there’s a better way as it isn’t finding the first and last names (probably using the wrong class).

Can you post the code you currently have so we can take a look?

We can’t write custom code for you but we can help point you in the right direction.

2. We have custom meta fields on the user so wondering if there’s a hook we can use so upon registering (when the account is created) can we save the registration custom fields (etc) to the user account.

When registering onto an event and the account is created by EE you mean?

If so then you’re using the WP User integration add-on to create/update the user accounts? If so take a look in: \eea-user-intergration\EED_WP_Users_SPCO.module.php at the process_wpuser_for_attendee method.

It has 2 hooks:

AHEE__EED_WP_Users_SPCO__process_wpuser_for_attendee__user_user_created

and

AHEE__EED_WP_Users_SPCO__process_wpuser_for_attendee__user_user_updated

both are passed the user account and the current registration.


rossib94

June 26, 2019 at 4:26 am

Hi Tony,

Thanks for this it is a great help.

1. The code is https://pastebin.com/VtJGg5tF if it helps we are trying to create a custom CSV export to break the export in to sections for each event to list the attendees to that event with the relevant data, they want it a bit more custom to just removing irrelevant fields screenshot here: http://prntscr.com/o6vcsr

2. That’s perfect looks like it will do the trick, when I get round to that part I will let you know how it goes.

Thanks


Tony

  • Support Staff

June 26, 2019 at 5:19 am

For #1 EE offers event specific registration exports already:

Event Espresso -> Events -> {hover over event name} -> Registrations

That lists all of the registrations for that specific event.

All of the CSV fields are passed through a filter, meaning you can use that filter to add additional columns or remove columns. So in short, if all you are looking to do is create a CSV that looks like the above, you can do that using the FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array filter without having to build out a completely custom solution.

I’m assuming based on your reply that you’ve already seen similar uses of that filter (or one similar) top remove/re-order the fileds but you can completely change the CSV output using that if needed.

I’m guessing some of those fields are based on user meta rather than all from the registration form?


rossib94

June 26, 2019 at 5:23 am

Thanks Tony, the problem with it is they want to section out each event. So if you look at the screenshot the CSV will be like that but for each event on one csv printout with necessary headings.

So it would be:

Event Heading (etc)
Attendees..

(spacing to get it to a new page)

Event Heading (etc)
Attendees..

(spacing to get it to a new page)

etc..

Does that make sense can send full CSV if it would help?

I was going to do it this way but because of the layout of the CSV I thought it might be worth doing it custom?

Thanks


Tony

  • Support Staff

June 26, 2019 at 7:41 am

Thanks Tony, the problem with it is they want to section out each event. So if you look at the screenshot the CSV will be like that but for each event on one csv printout with necessary headings.

Ah, right, ok that’s not really clear in the screenshot but I understand now.

Have you done that before with a CSV? Some of what you have in the image can’t be saved in CSV, for example, the merged fields for the header, I don’t think you can save that in the field, the header sure, but not the formatting to merge the fields.

What issue do you have with your current code?

Right now you’re overwriting the save value in the $values array with the name of the attendee, so it will essentially also contain a single value and that the First Name of the last registration’s attendee.


rossib94

June 26, 2019 at 7:54 am

No can’t really use the styling but plain text in that format would be fine. I suppose I would do something like Event Name, Date Time & Instructor and just have it as one field/cell.

It isn’t printing the fname as it says it doesn’t exist in the class?

How would I get the custom registration fields from that also?

Thanks


Tony

  • Support Staff

June 26, 2019 at 8:21 am

It isn’t printing the fname as it says it doesn’t exist in the class?

What’s the exact error you are getting?

I’m guessing PHP Fatal error: Uncaught Error: Call to a member function fname() on null and if so, you’re getting that error as you have registrations that are incomplete (meaning they have no EE contact assigned to them).

You’ll need to either check you have a valid EE_Attendee object for each registration first, or exclude those registrations from the query which you can do with:

'Transaction.STS_ID' => array(
	'NOT IN',
	array(
		EEM_Transaction::failed_status_code,
	),
)

Add that to the where conditions for the EEM_Registrations call.

How would I get the custom registration fields from that also?

I’d recommend you take a look at how EE constructs the default registration csv rows in:

\event-espresso-core-reg\core\libraries\batch\JobHandlers\RegistrationsReport.php::get_csv_data_for()

The code there will guide you through on how to pull all of the information you need.


rossib94

June 26, 2019 at 8:38 am

Thanks Tony I will take a look in the get_csv_data_for function I tried adding your code and got:

Fatal error: Uncaught EE_Error: You passed Transaction.STS_ID as a query parameter to EEM_Registration, which is illegal!

But If I re-work it with the get_csv_data_for function might have better luck.

Thanks


Tony

  • Support Staff

June 26, 2019 at 8:47 am

The above error means your not passing my code in the where conditions but as a query parameter.

The above means you have something like this:

$registrations = EEM_Registration::instance()->get_all(
    array(
        array(
	    'EVT_ID' => array( '=', $event_id ),
	),
        'Transaction.STS_ID' => array(
	    'NOT IN',
	    array(
                EEM_Transaction::failed_status_code,
            ),
        ),
    )
);

You need something like this:

$registrations = EEM_Registration::instance()->get_all(
    array(
        array(
            'EVT_ID' => array( '=', $event_id ),
            'Transaction.STS_ID' => array(
                'NOT IN',
                array(
                    EEM_Transaction::failed_status_code,
                ),
            ),
        )
    )
);


rossib94

June 26, 2019 at 9:49 am

Sounds about right thanks tony I will let you know how I get on.


Tony

  • Support Staff

June 26, 2019 at 10:08 am

You’re most welcome.


rossib94

June 27, 2019 at 3:04 am

Hi Tony,

Sorry another question, is there a way to show the amount of attendees on the checkout page i.e if they sign up to multiple attendees for an event or if they have 2 different events with 1 attendee for each?

I have seen you can do it based on event but assume theres a different way to get this displayed on the checkout page?

Thanks


Tony

  • Support Staff

June 27, 2019 at 8:42 am

My apologies but I’m not sure I follow.

In EE there’s a 1 to 1 relationship between tickets and registrations, each ticket creates a registration within EE and the checkout page shows a breakdown of all of your registrations already so I guess I don’t understand your question.

Can you add a screenshot showing what it is you want to do?

https://eventespresso.com/wiki/troubleshooting-checklist/#screenshots


rossib94

June 27, 2019 at 1:29 pm

Sorry so on the checkout page I want to show the users attendees (saved as meta data) and then allow then to copy that data over to one of the attendee forms.

If you look at the screenshot you will notice my drop down, I want to say copy attendee data to either Attendee 1 or 2 etc.

http://prntscr.com/o7lpee

Thanks


rossib94

June 27, 2019 at 1:35 pm

Sorry dont worry Tony now I am looking at it, it was easy to find!

$total_tickets = EE_Registry::instance()->CART->all_ticket_quantity_count();


rossib94

June 27, 2019 at 5:25 pm

Hi Tony,

I have hit a little snag, we are using Multi event registrations so is there a possible way to add all attendee data to 1 user account?

I think this hook ‘AHEE__EED_WP_Users_SPCO__process_wpuser_for_attendee__user_user_created’ just allows it for the standard EE4 setup is that correct?

Thanks,


rossib94

June 30, 2019 at 3:57 pm

Hi Tony,

OK so managed to look in to the CSV export more, looking at get_csv_data_for it looks like its what I need as I can just filter out the columns I don’t need for each event however I can’t seem to connect to the CLASS I am obviously missing something assuming I need to include the namespace of some sort?

If not is there a quicker way than having to replicate what this function does would it be as easy as copying the function and changing where it references $this to the correct class?

Thanks again and sorry for the questions!


Tony

  • Support Staff

July 1, 2019 at 8:34 am

I have hit a little snag, we are using Multi event registrations so is there a possible way to add all attendee data to 1 user account?

May I ask how that would work? If you have attendee 1 linked to profile one, what would you do with attendee 2’s details?

I think this hook ‘AHEE__EED_WP_Users_SPCO__process_wpuser_for_attendee__user_user_created’ just allows it for the standard EE4 setup is that correct?

Can you define the ‘standard EE4 setup’ in this situation? That hook is fired when a user account is created, you can link the registration data from all registrations to that account using the same hook if needed so I’m not sure what you mean.

The more context you can provide on what you’re trying to do at each step, the better/more specific we can be with our answers for your use case.

OK so managed to look in to the CSV export more, looking at get_csv_data_for it looks like its what I need as I can just filter out the columns I don’t need for each event however I can’t seem to connect to the CLASS I am obviously missing something assuming I need to include the namespace of some sort?

I’m not sure what you mean by ‘connect to the CLASS’? Do you mean how you use the class?

It’s used as part of a batch process, so you’d also need your own batch method if you want to do it using the class as is if I’m not mistaken, but either way it’s not something we can walk you through on the forums.

If not is there a quicker way than having to replicate what this function does would it be as easy as copying the function and changing where it references $this to the correct class?

Well, no not really, other than building out your own custom version from scratch.

There is the \event-espresso-core-reg\core\db_classes\EE_Export.class.php class we used before the batch method was introduced, although usage of that class is discouraged as it’s now been deprecated and will eventually be removed from core.


rossib94

July 1, 2019 at 9:48 am

Thanks Tony.

May I ask how that would work? If you have attendee 1 linked to profile one, what would you do with attendee 2’s details?

What I am trying to do is create 1 user account but save all the attendees data to my custom meta field (array). I think how the EE login plugin works is it create 1 account for the primary attendee?

I’m not sure what you mean by ‘connect to the CLASS’? Do you mean how you use the class?

It’s used as part of a batch process, so you’d also need your own batch method if you want to do it using the class as is if I’m not mistaken, but either way it’s not something we can walk you through on the forums.

I want to use the get_csv_data_for function, what is the best way to use it? I am trying to loop through each event and get the data for that event for example:

foreach ($events as $event)
get_csv_data_for( $event->ID, (other args here));
endforeach;

I can then create my own CSV output like I shown you earlier in the thread.

Thanks again for your help.


Tony

  • Support Staff

July 2, 2019 at 3:54 am

lockquote>What I am trying to do is create 1 user account but save all the attendees data to my custom meta field (array). I think how the EE login plugin works is it create 1 account for the primary attendee?

AHEE__EED_WP_Users_SPCO__process_wpuser_for_attendee__user_user_created is only fired when a user account is created, meaning they didn’t have one in the first place, so do you only want the code to run in that situation?

If you have an EE_Registration object (which the above hooks does) you can call the get_all_other_registrations_in_group() method on that registration object to pull all of of the other registrations in the group, then loop over them and stored them in meta.

I want to use the get_csv_data_for function, what is the best way to use it? I am trying to loop through each event and get the data for that event for example:

foreach ($events as $event)
get_csv_data_for( $event->ID, (other args here));
endforeach;

In that case, you would be better copying the function and editing the suit.


rossib94

July 2, 2019 at 7:23 am

Hi Tony,

Ah perfect I wanted it to run on update too so assume it should be the same just use the AHEE__EED_WP_Users_SPCO__process_wpuser_for_attendee__user_user_updated hook?

OK perfect I thought that might be the case and I should be able to use the classes within get_csv_data_for() function or am I better off creating a total custom query?

Thanks


Tony

  • Support Staff

July 2, 2019 at 7:28 am

Ah perfect I wanted it to run on update too so assume it should be the same just use the AHEE__EED_WP_Users_SPCO__process_wpuser_for_attendee__user_user_updated hook?

Yeah, you can use both hooks.

OK perfect I thought that might be the case and I should be able to use the classes within get_csv_data_for() function or am I better off creating a total custom query?

Sure, you should be able to use the classes used within that method but I haven’t stepped through the code to confirm.


rossib94

July 2, 2019 at 7:55 am

OK I will try today, thanks again Tony for your great help.


rossib94

July 2, 2019 at 3:45 pm

Hi Tony,

So it turned out to be problematic so going to create my own batch job as probably the best way to use the event espresso classes etc.

I have followed this and copied the RegistrationsReport (just for testing) but I can seem to find where I can put this code:

$job_starter_url = EE_Admin_Page::add_query_args_and_nonce(
				array(
					'page' => 'espresso_support',
					'action' => 'batch_file_create',
					'job_handler' => urlencode( 'EventEspressoBatchRequest\JobHandlers\AttendeesReport' ),
					'redirect_url' => urlencode( $this->_req_data[ 'return_url' ] ),
				));
echo "<a href='" . $job_starter_url . "'>Start Job!</a>";

I have got it to print out on my custom admin page but it doesn’t like $this (obviously) I have got my custom batch and put it in /libraries/batch/JobHandlers/ do I have to declare the above in my custom file somewhere?

Sorry to be a right pain!

Thanks


rossib94

July 2, 2019 at 4:49 pm

Sorry Tony,

Ignore the above, I am sure there’s an easier way I can achieve this I think there has been some confusion on what I am trying to achieve.

So I am trying to create a CSV as you know, these are the steps I am assuming I need to take:

1. Get all todays events
2. Get attendees for those events
3. Display attendee data (fname, lname and other custom feilds in the registration)

Could you let me know which modals I may need and any examples of using them please as I think I am getting confused with the Attendees modal and the Registrations modal, sorry I am not familiar with the way EE works so it’s all new to me!

Thanks again for your support


Tony

  • Support Staff

July 3, 2019 at 2:50 am

Ignore the above, I am sure there’s an easier way I can achieve this I think there has been some confusion on what I am trying to achieve.

I don’t think there is any confusion on what you’re trying to do, you essentially want an event registration report for multiple events in a single CSV (with separators etc), right?

However, what you are trying to do is not as ‘easy’ as it seems. Is it massively complex? No. But it’s not something your just going to be able to plug in one of EE’s functions into and loop over without customization or following through with how EE batches work.

Could you let me know which modals I may need and any examples of using them please as I think I am getting confused with the Attendees modal and the Registrations modal, sorry I am not familiar with the way EE works so it’s all new to me!

Have you checked the documentation on how the models work?

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

The functions I mentioned above already show you how to use the models to get all of the information you need, so if you don’t follow that then me giving you more examples isn’t really going to help if you don’t understand the model system.

Also, without stepping through and essentially doing this for you to work out everything you need (which we can’t do as we don’t support custom development) I can’t give you more specifics.


rossib94

July 3, 2019 at 3:44 am

Hi Tony,

Thanks for this, totally understand I will get my head around these Models then the get_csv_data looks like quite a lot of queries but I will see what I can do.

Thanks


rossib94

July 3, 2019 at 5:04 pm

Hi Tony,

Your going to be sick of me soon, sorry!

I am still getting the fname is null on my query although there is a contact assigned and I am getting the Attendee object also.

foreach ( $events as $event ) {
  $event_id = $event->ID();

  $registrations = EEM_Registration::instance()->get_all(
      array(
          array(
              'EVT_ID' => array( '=', $event_id ),
              'REG_date' => array( 'BETWEEN', array( strtotime('2019-07-03 00:00:00'), strtotime('2019-07-03 23:59:59')) ),
              'Transaction.STS_ID' => array(
                  'NOT IN',
                  array(
                      EEM_Transaction::failed_status_code,
                  ),
              ),
          )
      )
  );
// var_dump( $registrations );
  foreach( $registrations as $registration ) {
      $attendee = $registration->attendee();
      $values[]['First Name'] = $attendee->fname();
  }

}

object(EE_Attendee) object shows if I var_dump $attendee so can’t see why it still thinks its null as I can see fname in the object.

Thanks again…


Tony

  • Support Staff

July 4, 2019 at 3:53 am

Are you sure the EE_Attendee object that you’re seeing above is in the same iteration of your loop?

If you know you have an EE_Attendee object then you won’t be getting an error like:

PHP Fatal error: Uncaught Error: Call to a member function fname() on null

On that iteration of the loop.

What you can do is build out your $values array better so you know which registration it’s failing on, for example:

foreach( $registrations as $registration ) {
    $value[$registration->ID()];
    $attendee = $registration->attendee();
    if($attendee instanceof EE_Attendee) {
        $values[$registration->ID()]['First Name'] = $attendee->fname();
    }
}

That will change your $values array to index by registration ID and any index that doesn’t have a name assigned to it above, didn’t have an EE_Attendee object meaning you can then start investigating why that is on using the Registration ID (the array index).

Get into the habit of checking you have an instance of something before you try to use one of its methods, it’ll prevent the fatal errors your getting, it doesn’t fix the problem (as the problem is the registration doesn’t have an attendee) but stops the fatal and allows you to trace it back from there.


rossib94

July 4, 2019 at 8:33 am

Thanks Tony, it wasn’t getting the attendees I was expecting seems 1 is missing the attendee class is there a better way to get the correct event datetime object I thought using REG_date but doesn’t seem to be getting the right attendees will look in to it again.


Tony

  • Support Staff

July 4, 2019 at 2:38 pm

Your not getting a DateTime object in the code above so I’m not sure?

If you mean the code to pull registrations created between certain dates, ie:

'REG_date' => array( 'BETWEEN', array( strtotime('2019-07-03 00:00:00'), strtotime('2019-07-03 23:59:59')) )

then no, the above is the correct way to do it, although you’ll obviously want that to be more dynamic. However, that is different from your original request as that’s essentially pulling a daily request of registrations…. so you want registration made on the day of the event?

Or to pul it in the context of that code, you want all of the registrations created between 2019-07-03 00:00:00 & 2019-07-03 23:59:59? Note registrations linked to events on that date, but registrations actually made/created between those times?

If you want all of the registrations for a specific event, you don’t need to set REG_date, you just pull the registrations for that date passing the EVT_ID as you did before.


rossib94

July 4, 2019 at 5:53 pm

Hi Tony,

Your right that’s obviously not going to work, sorry a lot of late nights working on this!

How would I get the correct registrations for the Event Date time?

Can I use $event->datetimes and query the same dates as I do events?

How do you query the registration object with date time?

Sorry again for all my questions,

thanks


rossib94

July 4, 2019 at 5:56 pm

Just a breakdown of what I am doing:

1. Getting Events for today
2. Get the correct event Date Time
3. Get attendees for that Date Time

Thanks


Tony

  • Support Staff

July 5, 2019 at 3:07 am

How would I get the correct registrations for the Event Date time?

Within the registration row of the DB there is no DateTime ID (DTT_ID) specified as a registration is linked to a ticket and the ticket is linked to a datetime. So you need to pull the registration based on the info you have and link them together when you pass that to the model.

So you have a Ticket, linked to a datetime and want the DTT_ID of the datetime, in other words you need to JOIN the datetime table to the registration table based on the ID of the datetime linked to the ticket, sounds tough, but the models make it easy, which is why I keep pointing you the models.

In the where conditions for the EEM_Registration query you can add:

'Ticket.Datetime.DTT_ID' => $DTT_ID

A little easier to read it backwards, in English ‘Where the DTT_ID of the DateTime linked to the Ticket for the registration (because it’s on the registration model) is…’

How you get the $DTT_ID depends on the rest of this reply and I’ll leave that to you.

Can I use $event->datetimes and query the same dates as I do events?

Events don’t have dates set on them, they have datetimes assigned to them which have dates, so whatever you are doing to pull the events by date, is actually using the datetimes… so yes you can use the same dates.

You can pull the datetimes from an event using the above method yes and datetimes() accepts query params passed to is, meaning you can specify the DTT_EVT_start and or DTT_EVT_end, or just pull the datetimes ordered, or many other different ways using the models.

We have an example here:

https://github.com/eventespresso/event-espresso-core/blob/master/docs/G–Model-System/model-querying.md#querying-datetime-fields

How do you query the registration object with date time?

Isn’t this the same as your first question? If not my apologies, but if that’s the case I’ll need more info.

Just a breakdown of what I am doing:

1. Getting Events for today
2. Get the correct event Date Time
3. Get attendees for that Date Time

Thanks

Can you define the ‘correct’ DateTime within an event?
I’m guessing it’s a single datetime based on the current date?

I’m assuming you don’t have a page displaying the registrations which can be filtered (like EE does) beforehand so the user can’t select a specific datetime to export.


rossib94

July 5, 2019 at 7:00 am

Hi Tony,

This sounds perfect, so if I use datetimes() to get the closest one to the date specified I can then use ‘Ticket.Datetime.DTT_ID’ => $DTT_ID in the registrations object to pull the correct attendees?

Thanks


Tony

  • Support Staff

July 5, 2019 at 8:55 am

Almost, you’ll use the EEM_Registration model to pull the registrations for that DateTime using the above.

From there you can get the attendees.

Viewing 36 reply threads

The support post ‘Custom Meta Data on profile’ 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