The Paris-born striker, who has eight caps for his country, spent three seasons at Hoffenheim and his switch follows Ryan Babel's move to the German side from Liverpool.
"It's a bit difficult to describe myself, but when I'm on the pitch I just give everything for the team I am playing for and the fans who support me," Ba told the West Ham website.
"I like playing football, I like to be on the pitch playing good passes with the other guys and running with the ball, rather than playing in a direct style, so I should be able to fit in well at West Ham.
"I'm really happy that the clubs have reached an agreement. I was eager to join the club and meet my new team-mates. I'd like to thank Hoffenheim for allowing me to join this team."
West Ham face Nottingham Forest in the FA Cup fourth round this Sunday and then face crucial games against Blackpool, Birmingham and West Brom in their next three Premier League fixtures.
This page is best viewed in an up-to-date web browser with style sheets (CSS) enabled. While you will be able to view the content of this page in your current browser, you will not be able to get the full visual experience. Please consider upgrading your browser software or enabling style sheets (CSS) if you are able to do so.