You have to give the coupon codes to the customer before they purchase the item. When the check out they will be asked to input a coupon code, if they don't have one they leave it blank.
Some people give coupon codes to their twitter/instagram followers, some people put it right in their listing.