Support

Home Forums Event Espresso Premium Custom Registration ID

Custom Registration ID

Posted: December 5, 2022 at 8:58 am

Viewing 3 reply threads


pds-capcog

December 5, 2022 at 8:58 am

I am using the solution provided here and it works great: https://eventespresso.com/topic/custom-registration-id-3/#post-286984

I would like to be able to identify and add the registered Event’s Category or Slug to this custom code as well. So it would generate something like: [YEAR]-[CATEGORY]-001


Tony

  • Support Staff

December 5, 2022 at 2:10 pm

Hi there,

To get the category, you need to know the Event ID and within that code you can get that from the ticket itself:

$event_id = $ticket->get_event_ID();

From there you can use start terms:

$event_categories = get_the_terms($event->ID(), 'espresso_event_categories');
$first_term = array_pop($event_categories);
if ( $first_term instanceof EE_Term ) {
    $category_name = $category->name();
}

Or you use our model system like this:

$event = $ticket->get_related_event();
if ( $event instanceof EE_Event ) {
    $category = $event->first_event_category();
    if ( $category instanceof EE_Term ) {
        $category_name = $category->name();
    }
}

That gives you the category name within $category_name to do whatever you prefer to use it for ๐Ÿ™‚

If you haven’t done so already, I recommend reading the docs on our model system here:

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

Using the models to pull in the data you need makes a lot of takes within EE much easier.


pds-capcog

December 9, 2022 at 7:44 pm

This worked perfectly to get what I needed. Thank you!


Tony

  • Support Staff

December 13, 2022 at 4:43 am

You’re most welcome ๐Ÿ™‚

Viewing 3 reply threads

The support post ‘Custom Registration ID’ 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