Direct buses from San Jose to Puerto Viejo leave from Calle Central at the Terminal Gran Caribe and take around 4 1/2 hours. The bus line is called MEPE. If you are planning on traveling on Friday afternoon or Saturday morning, get there early or buy your ticket in advance ( ~$9). See schedule below.
Alternatively, you can catch a bus to Limon and connect with a bus south to Puerto Viejo. Buses to Limon leave every half hour from from the same Terminal Gran Caribe.
The drive to Puerto Viejo from San Jose is easy: head to the coast and turn right! You’ll pass through the chilly heights of Braulio Carrillo National Park, the steamy lowlands of Guapiles, the Caribbean port town of Limon and then follow the palm fringed coastal road south. Alternately, you can take the old road via Cartago and Turrialba reaching the Caribbean town of Siquirres where the highway joins the route to Limón.