Skip to content

Instantly share code, notes, and snippets.

@joshfeck
Created December 26, 2018 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshfeck/8c32d87377525d2071db4712aa4b4e00 to your computer and use it in GitHub Desktop.
Save joshfeck/8c32d87377525d2071db4712aa4b4e00 to your computer and use it in GitHub Desktop.
Add the event name as a CSS class to the body tag of the EE4 registration page. Useful for custom jQuery and/or CSS for specific events.
<?php
//* Please do NOT include the opening php tag, except of course if you're starting with a blank file
add_filter( 'body_class', 'jf_ee_return_event_name_on_spco' );
function jf_ee_return_event_name_on_spco( $classes ){
// change 'registration-checkout' to match your reg. page slug
if (! is_page( 'registration-checkout' ) ){
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 ) {
$classes[] = sanitize_title($event->name());
}
}
}
}
}
return $classes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment