The Moon doesn't orbit the Sun directly. It orbits the Earth, which in turn orbits the Sun.
The Moon's orbit around the Earth is roughly in the same plane as the Earth's orbit around the Sun. This means that the Moon's orbit around the Earth is also roughly in the same direction as the Earth's orbit around the Sun.