While some WW1 soldiers may well have tried to avoid being sent to the front by shooting themselves in the foot, I'm fairly sure that the phrase has its origins prior to that period (and, more importantly, refers to an accidental action rather than to a deliberate one).
When a gun is in its holster it's pointing at the owner's foot. To fire quickly, requires that the gun is pulled quickly from the holster as a finger tightens on the trigger ready to fire. If the finger is tightened rather too early the result is that the gun is fired while still pointing at its owner's foot.
Chris