One suggestion is to stay in a hotel in the city of Foggia and take the bus to San Giovanni Rotondo. It's about a 45-minute ride from the central bus terminal, which is across the plaza from the train station. There are several nice hotels within a couple of blocks of the plaza and restaurants are within walking distance. Foggia is accessible by train from Bari.
Bus tickets may be purchased at a newsstand inside the train station. They are collected by a conductor on the bus.
A tip: If you take the bus to San Giovanni Rotondo, be sure to tell the driver you want to go to the Padre Pio shrine. Many local residents take the bus to go shopping in the central part of the town, which is not near the shrine. You can easily make the mistake of getting off the bus too soon by following those shoppers. The shrine is the last stop for the bus. Also be sure to check the schedule for return trips to Foggia.