Hi Alicia,
Whilst you may not be using it currently, it’s worth noting that you can actually have registrations from multiple events within your current session so your code should accommodate for it.
Here is a quick example of how you can pull details from the current session and add them to the body classes of the checkout page:
function tw_ee_return_event_id_on_spco_body_class( $classes ){
// get out if this isn't the reg checkout page
if ( ! class_exists('EE_Registry') || ! is_page( EE_Registry::instance()->CFG->core->reg_page_id ) ){
return $classes;
}
$events = array();
$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 ) {
$event = $registration->event();
if ( $event instanceof EE_Event ) {
$events[] = 'event-id-' . $event->ID();
}
}
}
}
}
$events = array_unique($events);
return array_merge( $classes, $events );
}
add_filter( 'body_class', 'tw_ee_return_event_id_on_spco_body_class' );