As mentioned, you can only buy it in-person while on property.
We've bought it upon entering the parks, but you can also do it at any time during your trip at Guest Services (We usually do it at MK City Hall or Epcot). In January we waited a day or two to buy.