Support

Home Forums Event Espresso Premium Auto-registering for additional events

Auto-registering for additional events

Posted: September 27, 2021 at 10:58 am


bhhsflpg

September 27, 2021 at 10:58 am

Hi,

We have an 8-class series which is taught throughout the year. It cycles continuously, and is taught in a manner so it doesn’t matter which class the agent takes first. One person may start on class 1 and end with class 8 four weeks later, another may start on class 5 and end on class 4 four weeks later.

Because of that setup, each class has been setup as an individual event on our calendar. They all contain a portion of the same title (Ex – “BHU โ€“ Class #1” or “BHU โ€“ Class #2” that can be searched for, and all have the same category as well.

Our goal is to have the students register for their first class – their start date, and then to have the system automatically register them for the following 7 classes based on their chosen start date.

I’m using Zapier for many of our automations, but hesitate to use an “Add New Row” zap for MySQL due to the multiple tables involved, and the need for sequential row numbers in most of those tables.

Do you have any suggestions for a better way to “find” the right 7 follow-up classes and then automate registering the student for them?

Thanks,
Stephanie


Tony

  • Support Staff

September 29, 2021 at 3:25 am

Hi Stephanie,

I really don’t recommend you do this through Zapier to add rows manually, there’s a bunch of updates and relationships you need to set up for registrations in the database.

There are hooks throughout EE for use cases like these so our recommended method would be to use one of those with our model system:

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

So you could hook into when a ticket is added to the cart and add additional registrations for the other events at that point. I’ve put together a simple example of doing the above using one of the hooks available in the checkout process here:

https://gist.github.com/Pebblo/42a6755ac618e2f3b88c6b945c08ff53

That snippet uses the current ticket in the cart to pull the event, then finds out the category for that event and pulls the ‘next’ (base on datetime start date) 3 events from that category and adds the first ticket it finds from each of those events to the cart.

Note that the above snippet is not an official feature of Event Espresso and should be considered untested. It is intended as a guide to creating your own version and won’t work for all use cases as is. I recommend you add a check within that function for it to only apply to the specific category you are intending this to be used on as right now it does the same for all events.


bhhsflpg

October 11, 2021 at 10:08 am

Hi Tony,

Thanks for the guidance. I’m in no way a programmer. How do I add the the filter to that code I need to add to the custom plugin? I’d want it to occur for only registrations involving category ID 61.

In looking at what you’ve provided in other areas, am I just tacking something like this on?


foreach( $event_categories as $cat ) {
if ($cat->term_id != 70) { // exclude this category only!
$event_category_ids[] = $cat->term_id;
}


Tony

  • Support Staff

October 11, 2021 at 10:51 am

If you only want it to happen on a specific category then where the snippet has this:

if(
    $category instanceof EE_Term
    && $datetime instanceof EE_Datetime
) {

You can change it to something like this:

if(
    $category instanceof EE_Term
    && $category->ID() == 61
    && $datetime instanceof EE_Datetime
) {

That should then only apply to the category with ID 61


bhhsflpg

October 11, 2021 at 11:19 am

Hi Tony,

I added that code, but it doesn’t seem to be pulling the correct classes.

Ex – I started a registration for Class # 2 on 10/13/21. It should have added class 3 on 10/19, class 4 on 10/20, class 5 on 10/26, class 6 on 10/27, class 7 on 11/2, class 8 on 11/3, and class 1 on 11/9.

Instead, it added these:
** REMOVED **


Tony

  • Support Staff

October 11, 2021 at 1:14 pm

Can you recheck that screenshot?

I think that might be the wrong screen.


bhhsflpg

October 11, 2021 at 1:24 pm

Whoops, sorry! Here you go: https://www.dropbox.com/s/zm79o2iz02lfehm/Screen%20Shot%202021-10-11%20at%203.23.30%20PM.png?dl=0


Tony

  • Support Staff

October 11, 2021 at 2:39 pm

Hmm, strange.

That could be from the Event query ordering by ID by default, try adding this line:

https://gist.github.com/Pebblo/42a6755ac618e2f3b88c6b945c08ff53#file-tw_ee_add_additional_regs_to_cart-php-L29

Your line numbers will be slightly different due to the change above, but find that same location and add the above, any better?


bhhsflpg

October 11, 2021 at 2:43 pm

That seems to have worked, thanks so much for all your help Tony!


Tony

  • Support Staff

October 11, 2021 at 2:56 pm

You’re most welcome, I’m glad that worked.

I’ve removed your screenshot from above just because its not related to anything here ๐Ÿ™‚

Any further issues just let me know.

You must be logged in to reply to this support post. Sign In or Register for an Account

Event Espresso