Sending Email Notifications After User Signup In WordPress, With Delay!

A while back I had a project that needed an email to get sent out to users after a specific action was performed, but it had to be delayed a defined number of days, and as the project was already a custom coded theme, it felt that implementing something custom to solve that problem was the right approach.

In the next example, I will outline how exactly I implemented sending a “continue signup/additional user information” 2 days after the user has officially been registered on the website.

To accomplish the above, we need to use a default user field “user_registered” – this field is generated by default when a user record is created in WordPress, and also we need a meta field to mark a user as “notified” for the current notification.

The process to send out this email is:

  • 1) Get a list of users that we need to send out the notification. (Fetch with SQL Query)
  • 2) Iterate over the returned list of users, and send out the email.

To explain in short what is happening in the above SQL statement:

  • on Line 3: We define the the name of the user meta we are going to use for marking the user as “notified”.
  • on Line 6: we are joining the meta field to the query to exclude notified users.
  • on Line 9 and 10: we target a range of results based on the register date.

Now the existing part, making WordPress send out the emails,

As you can see from the snippet above, its a pretty simple bit of code, but it gets the job done, and prevent duplicate emails getting sent to users.

Leave a Reply

Your email address will not be published. Required fields are marked *