There are two portions of the United States Flag Code which address your question. They are Sections 8(i) and 8(j) respectively:
(i) The flag should never be used for advertising purposes in any manner whatsoever. It should not be embroidered on such articles as cushions or handkerchiefs and the like, printed or otherwise impressed on paper napkins or boxes or anything that is designed for temporary use and discard. Advertising signs should not be fastened to a staff or halyard from which the flag is flown. (j) No part of the flag should ever be used as a costume or athletic uniform. However, a flag patch may be affixed to the uniform of military personnel, firemen, policemen, and members of patriotic organizations. The flag represents a living country and is itself considered a living thing. Therefore, the lapel flag pin being a replica, should be worn on the left lapel near the heart.
It is appropriate to place the flag on a hat and you are correct, the union should always be to its own right (the viewers' left). Whether the flag is on the left or right side of the cap does not matter. Just like law enforcement and fire agencies around the nation--some place patches on the left shoulder and some on the right, so it's up to you. Thanks.