Created
October 17, 2025 14:20
-
-
Save xlplugins/65db57a8961a3f404762b2ff993278e9 to your computer and use it in GitHub Desktop.
Fetch Upsell Transaction IDs by Parent Order
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $order_id = 44534535; | |
| $wfocu_session_ids = WFOCU_Core()->track->query_results( array( | |
| 'data' => array( | |
| 'id' => array( | |
| 'type' => 'col', | |
| 'function' => '', | |
| 'name' => 'session_id', | |
| ), | |
| ), | |
| 'where' => array( | |
| array( | |
| 'key' => 'events.order_id', | |
| 'value' => $order_id, | |
| 'operator' => '=', | |
| ), | |
| ), | |
| 'query_type' => 'get_results', | |
| 'session_table' => true, | |
| 'nocache' => true, | |
| ) ); | |
| $wfocu_session_id = ''; | |
| if ( is_array( $wfocu_session_ids ) && count( $wfocu_session_ids ) > 0 ) { | |
| $wfocu_session_ids = end( $wfocu_session_ids ); | |
| if ( isset( $wfocu_session_ids->session_id ) ) { | |
| $wfocu_session_id = $wfocu_session_ids->session_id; | |
| } | |
| } | |
| $eventsdb = WFOCU_Core()->track->query_results( array( | |
| 'where' => array( | |
| array( | |
| 'key' => 'events.sess_id', | |
| 'value' => $wfocu_session_id, | |
| 'operator' => '=', | |
| ), | |
| ), | |
| 'query_type' => 'get_results', | |
| 'order_by' => 'events.timestamp', | |
| 'order' => 'ASC', | |
| 'nocache' => true, | |
| ) ); | |
| $event_ids = wc_list_pluck( $eventsdb, 'id' ); | |
| $events_meta = WFOCU_Core()->track->get_meta( $event_ids ); | |
| $transactions = array(); | |
| $events = []; | |
| foreach ( is_array( $events_meta ) ? $events_meta : array() as $key => $meta ) { | |
| if ( ! isset( $events[ $meta['event_id'] ] ) ) { | |
| $events[ $meta['event_id'] ] = []; | |
| } | |
| $events[ $meta['event_id'] ][ $meta['meta_key'] ] = $meta['meta_value']; | |
| } | |
| // $events have all the accepted upsell events including paypal transaction IDS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment