The 25-year-old will stay on loan with the Hammers until the end of the season.
Sunderland, Everton, Fulham and West Brom were also interested in the highly-rated striker.
Ba was set to join Stoke earlier this month, but the move collapsed after the striker failed a medical.