• Hello,

    I wanted to include a unique 1 time coupon code (to one of my amazon products) in the welcome e-mail when a new user signs up for a wordpress account on my website.

    The idea I think is to create a database table that stores all these unique coupon codes and just works down the list to assign a new coupon code to the next registered user so that the same coupon code never goes out twice.

    I can manually add/remove more coupons into the table if needed. I think this is the easiest way for me to accomplish this.

    I just don’t know how ??

    Can someone help with this?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    How are you at PHP coding? We can cause an email be sent when nearly anything happens in WP. Maybe the easiest way to send a coupon code to new users is to include it in the “Set your password” email sent to newly registered users. You can modify or replace the email data with the ‘wp_new_user_notification_email’ filter, which passes an array of all email data. You could add the coupon code message to the array element keyed as “message”.

    Your plan to maintain a table of codes is workable, but possibly more fuss than is necessary. What makes the most sense depends mostly on how a coupon would be redeemed. If it’s through a 3rd party app that requires specific codes, then your scheme makes sense. If it’s through your own site, you don’t really need a coupon at all except maybe as part of a desired user experience. The fact a user can log in would be adequate “coupon” validation. You really only need to keep track of which users collected their premium. This can be saved in user meta. You can further control who can collect a premium by any logic you care to code. For example, only new users registered in a certain date range can collect a premium. Or those registered on Tuesdays ?? Any logic at all.

    Thread Starter golfinred

    (@golfinred)

    Hello!

    Yes this coupon code would be redeemed on a third party website and only once. So a different unique code has to be sent to each individual new registered user. As soon as a code is sent off to a new user it has to be deleted or just ignored so the next code down the list can be sent.

    I hope this makes sense.

    Moderator bcworkz

    (@bcworkz)

    OK then, a custom table that is a list of coupon codes is workable. I would include another field for a user ID that is empty by default. I would the hook into the registration email filter I mentioned previously and add in the first coupon code found in the table without a user ID. Then add the new user’s ID into the appropriate field so the code will not be returned in subsequent queries.

    The user ID serves no purpose other than to prevent reuse of the code. The value could just as easily be true or used, but placing the ID adds a bit of audit capability should someone have trouble with their coupon or something.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Coupon Code Sent to user After Registration’ is closed to new replies.