Docs Advanced Shipment Tracking Pro (AST PRO) PayPal Tracking Sync for FunnelKit Upsell Orders

PayPal Tracking Sync for FunnelKit Upsell Orders

When a customer accepts a FunnelKit one-click upsell, FunnelKit creates additional PayPal transactions linked to the original order. By default, AST PRO syncs tracking only to the primary PayPal transaction. This snippet extends the sync to cover all FunnelKit upsell transaction IDs on the same order.

This is a manual code snippet — it must be added to your child theme’s functions.php or a site-specific plugin. Requires FunnelKit (WFOCU) to be installed and active. Tested against FunnelKit 2.x; verify against your version before deploying to production.

How it works

The ast_paypal_child_transaction_ids filter lets you add extra PayPal transaction IDs to the sync. The snippet queries FunnelKit’s tracking tables for all transaction IDs associated with the order’s upsell sessions, merges them with the primary ID, and returns the deduplicated list to AST PRO.

Filter reference

ParameterTypeDescription
$idsarrayTransaction IDs already queued for sync. Merge your additional IDs into this array and return it.
$order_idintThe WooCommerce order ID.

Code snippet

add_filter( 'ast_paypal_child_transaction_ids', function( $ids, $order_id ) {

    $fk_ids = get_all_fk_transaction_ids( $order_id );

    if ( ! empty( $fk_ids ) ) {
        $ids = array_merge( $ids, $fk_ids );
    }

    return array_unique( $ids );

}, 10, 2 );

if ( ! function_exists( 'get_all_fk_transaction_ids' ) ) {
    /**
     * Get all FunnelKit upsell PayPal transaction IDs for an order.
     *
     * @param int $order_id WooCommerce order ID.
     * @return array Array of PayPal transaction ID strings.
     */
    function get_all_fk_transaction_ids( $order_id ) {
        $transaction_ids = [];

        if ( ! class_exists( 'WFOCU_Core' ) || ! method_exists( WFOCU_Core()->track, 'query_results' ) ) {
            return $transaction_ids;
        }

        // Get sessions linked to this order
        $sessions = WFOCU_Core()->track->query_results( [
            'data' => [
                'id' => [
                    'type'     => 'col',
                    'function' => '',
                    'name'     => 'session_id',
                ],
            ],
            'where' => [
                [
                    'key'      => 'events.order_id',
                    'value'    => $order_id,
                    'operator' => '=',
                ],
            ],
            'query_type'    => 'get_results',
            'session_table' => true,
            'nocache'       => true,
        ] );

        if ( empty( $sessions ) ) {
            return $transaction_ids;
        }

        foreach ( $sessions as $session ) {
            $sess_id = $session->session_id ?? '';

            if ( ! $sess_id ) {
                continue;
            }

            $events_db = WFOCU_Core()->track->query_results( [
                'where' => [
                    [
                        'key'      => 'events.sess_id',
                        'value'    => $sess_id,
                        'operator' => '=',
                    ],
                ],
                'query_type' => 'get_results',
                'order_by'   => 'events.timestamp',
                'order'      => 'ASC',
                'nocache'    => true,
            ] );

            if ( empty( $events_db ) ) {
                continue;
            }

            $event_ids   = wc_list_pluck( $events_db, 'id' );
            $events_meta = WFOCU_Core()->track->get_meta( $event_ids );

            foreach ( $events_meta as $meta ) {
                if ( isset( $meta['meta_key'], $meta['meta_value'] ) && '_transaction_id' === $meta['meta_key'] ) {
                    $transaction_ids[] = $meta['meta_value'];
                }
            }
        }

        return array_unique( $transaction_ids );
    }
}

Related: PayPal Tracking settings