HAH, it is always best to book in advance when it comes to the codes. However, I do want to mention that magic can sometimes happen at the last minute.
I was at WDW a few weeks ago. My trip had been planned for almost a year in advance. Then, a few months prior to my trip, I decided to add on another night. I did, and got a discount for that one night. Then, two days before my trip was to begin, I moved my trip up one day earlier. So, less than 24 hours before my vacation was to begin, I called Disney and added on another night. I was able to secure an Annual Pass discount on that one night. So, as you can see, I truly got a last minute discount on a room. Magic does happen, however, it is always best to plan in advance. That way you can assure yourself of some discount magic and not sweat it out.