I want to send a reminder email “x” days after an initial email was send.
The admin can choose after how many days they want to send a reminder (after the date of the initial mail).
This amount is stored in this function and returns an integer (for example 14)
public function getAmountDayReminder(): int
{
return get_field('send_reminder_after_amount_day', $this->getId());
}
The date/time of that the initial email was send is stored in this function
public function setWasNotified()
{
update_post_meta($this->getId(), self::META_WAS_NOTIFIED, time());
}
Now I want to write an if statement so that the reminder will be send out “x” days after the date of the initial mail was send.
I guess it will look something like this:
if(!$entry->wasNotified() && !$entry->wasReminded()) {
$remindDate = $entry->setwasNotified() + $this->getAmountDayReminder();
if ($remindDate === //current time) {
$entry->remind();
}
}
This won’t work because I have to covert the output of setwasNotified()
and getAmountDayReminder()
so that I can add them.
Is this a good solution and how would I execute this exactly?
2
Answers
For your code:
I would use the DateTime modify to add getAmountDayReminder() to the time where the first notification has been sent and then compare this to the current time.
Something like that:
Do not forget to store whether you already sent the reminder.
And doing such things in a cron job is probably a good idea.