Support

Home Forums Event Espresso Premium EVT_ID value of the current event during checkout

EVT_ID value of the current event during checkout

Posted: April 6, 2018 at 10:14 am

Viewing 1 reply thread


bhesketh

April 6, 2018 at 10:14 am

Hi

I’m creating custom registration code for any new registration record using FHEE__Create__regCode__new_reg_code hook. It works fine and I was able to assign a random number to every new registration.

The issue is that I want that number to be unique and before assigning it to a new registration I need to check all other reg_id(s) within the selected event.

To do that I need to know EVT_ID on the stage when reg_id gets generated.

here is my function where I need it:

function ssoc_reg_code($new_reg_code, $registration) {

// here I need to get the value for EVT_ID of the current event
// so I could pull out all existing reg_id(s) for the current event and compare it to a new reg_id

$new_reg_code = “SSOC-” . rand(1000, 9999);
return $new_reg_code;
}
add_filter(‘FHEE__Create__regCode__new_reg_code’,’ssoc_reg_code’, 10, 2);

Thank you for helping!


Josh

  • Support Staff

April 6, 2018 at 12:08 pm

Hi there,

If you check the source where the filter hook is:

$this->reg_code = apply_filters(
 'FHEE__Create__regCode__new_reg_code',
 implode( '-', $this->reg_code ),
 $transaction,
 $ticket
);

You’ll note there are 3 parameters, so if you change your callback function to start like this:

function ssoc_reg_code($new_reg_code, $transaction, $ticket) {

and update the add_filter call to have the correct number of parameters:

add_filter(‘FHEE__Create__regCode__new_reg_code’,’ssoc_reg_code’, 10, 3);

you’ll have access to the $ticket object.

Then you can get the event ID from the $ticket object.

if ( $ticket instanceof EE_Ticket ) {
    $dtt = $ticket->last_datetime();
    if ( $dtt instanceof EE_Datetime ) {
        $event = $dtt->event();
        if ( $event instanceof EE_Event ) {
            $evt_id = $event->ID();
        }
    }
}
Viewing 1 reply thread

The support post ‘EVT_ID value of the current event during checkout’ 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