PayPal Tracking Sync for FunnelKit Upsell Orders

This enhancement extends AST PRO’s PayPal Tracking integration to fully support orders generated through FunnelKit Upsell (One-Click Upsell). When a customer accepts an upsell, FunnelKit may create additional PayPal Transaction IDs that are separate from the main order’s payment.
By default, AST PRO only syncs tracking to the primary PayPal Transaction ID.
With this integration, AST PRO automatically detects all FunnelKit child/upsell PayPal transaction IDs linked to the order and syncs tracking information to every associated PayPal transaction — main + upsells.  This ensures customers and PayPal receive complete tracking updates across multi-payment upsell funnels, with no extra configuration required.

/**
 * FunnelKit / Upsell child transaction ID integration for AST PRO.
 */
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' ) ) {
	/**
	 * Fallback: Get child transaction ID for FunnelKit / Upsell orders.
	 *
	 * @param int $order_id WooCommerce Order ID.
	 * @return string Child transaction ID or empty string.
	 */
	function get_all_fk_transaction_ids( $order_id ) {
		$transaction_ids = [];
	
		if ( class_exists( 'WFOCU_Core' ) && method_exists( WFOCU_Core()->track, 'query_results' ) ) {
	
			// 1. 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 [];
			}
	
			// Loop each session and extract 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 );
	}
}

$129.00

Billed annually

Buy Now