Skip to content

Instantly share code, notes, and snippets.

@joshfeck
Last active December 26, 2018 18:21
Show Gist options
  • Save joshfeck/41ee6fed7fc60400e7db9c1be18f5aed to your computer and use it in GitHub Desktop.
Save joshfeck/41ee6fed7fc60400e7db9c1be18f5aed to your computer and use it in GitHub Desktop.
Add event's category slug to registration checkout page's body class
<?php
//* Please do NOT include the opening php tag, except of course if you're starting with a blank file
// add category slug to registration checkout page's body class
add_filter( 'body_class', 'jf_ee_return_event_tax_term_on_spco' );
function jf_ee_return_event_tax_term_on_spco( $classes ){
// get out if this isn't the reg checkout page
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 ) {
$events[ $event->ID() ] = $event;
$category = $event->first_event_category();
if ( $category instanceof EE_Term ) {
$category_slug = $category->slug();
$classes[] = $category_slug;
}
}
}
}
}
}
return $classes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment