Triley, welcome to FT!
There is a thread here which will give you more info.
Stay at Delta Hotels and save 15% off AC flights
But to answer your question, all you need is one night at a Delta Hotel to get the discount code. It doesn't even have to be on the same trip as the flight. For instance, I have a couple of codes for 15% off from stays in Montreal and Vancouver (which I may end up giving away if I can't find a place to use them). I've already completed my trips and will use the discount in the future. Or you can book your hotel, get the discount code before you stay, and you are good to go as long as you don't cancel your reservation.
In short, the flight and the hotel DO NOT HAVE TO BE ON THE SAME TRIP. And all you need is one night to get the discount code.
Hope that helps.
P.S. Don't forget to check
Delta's Websaver Rates which will get you additional Aeroplan miles.