There is no direct connection from Alajuela to Machupicchu. However, you can take the bus to San Jose airport, fly to Cuzco, take the taxi to Cusco, take the bus to Ollantaytambo, take the walk to Ollantaytambo, then take the train to Machupicchu.
How to get from Costa Rica to Machupicchu
From Alajuela bus to San Jose airport, fly to Cuzco airport, taxi to Cusco, bus to Ollantaytambo, walk to Ollantaytambo, then train to Machupicchu. 13 h 1 min $538.