• Alicia

    (@adlergraphic)


    Hi!
    Is there any way I cant get de current selected ticket event ID on the ckeckout page?

    I need to difference somehow one event from another on the checkout page.

    Thank you!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi there,

    You could try an action hook like this:

    add_action(
        'AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start',
        function (EE_Checkout $checkout) {
            $transaction = $checkout->transaction;
            if ($transaction instanceof EE_Transaction) {
                $primary_registration = $checkout->transaction->primary_registration()
                if ($primary_registration instanceof EE_Registration) {
                    $ticket_ID = $primary_registration->ticket_ID();
                }
            }
        }
    );
    Plugin Author Tony Warwick

    (@pebblo)

    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' );
    Thread Starter Alicia

    (@adlergraphic)

    Excellent! Thank you for both replies, it worked fine!

    • This reply was modified 4 years, 5 months ago by Alicia.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Get ticket ID on Checkout page’ is closed to new replies.