I've got a lending library system built with Toolset. I have custom post types of Members and Items (books) when a member borrows a book the Item record is updated with a due date and a relationship formed.
I'm looking for some guidance on how to go about the following:
For all Items close to their due date I want to send an email to the Member (email address is help within their post), ideally as a regular job (I'm thinking nightly CRON job) or to have a view that an operator can run then click to send an email to each record.
I realise this is likely to be custom code or another plugin but I'd appreciate any advice from your experiences.
TIA
Hello TIA and thank you for contacting Toolset support.
Honestly, I might need more details about your setup to better advise. But, I still believe there should be a solution without custom code.
For example, your idea about using a view for operators to trigger the email might not need any custom code at all. If you can put the email of the user inside the form(either through a custom field or a generic field), you may trigger an email notification by submitting the form. You can use an edit form that has the email field, and a submit button. Once the form is submitted it will trigger the email notifications that are configured on it.
https://toolset.com/course-lesson/send-notifications-when-someone-submits-the-form/
If the post to edit, using this form, does not include the email address, you will need custom code to get it from a related post. The following article on creating custom placeholder is worth checking https://toolset.com/documentation/programmer-reference/forms/how-to-use-custom-placeholders-in-cred-notifications/
Based on how you are implementing your website, maybe you can use the expiration feature of Toolset forms. Expirations can also trigger notification emails. This is basically relevant if you are storing a "Borrowing" event as a post instead of a custom field. Check this article https://toolset.com/course-lesson/setting-up-automatic-post-expiration/
But, if you want to use CRON jobs, you will definitely need custom code. I can't suggest what to do without knowing more about your use case. But, I can imagine that the code will use WP_Query with some date arguments to get the items that are relevant. Then, it will build and send the email.
- https://developer.wordpress.org/reference/classes/wp_query/
- https://developer.wordpress.org/reference/functions/wp_mail/
Keep in mind that Toolset stores date fields as timestamps.
I hope this helps. Let me know if you have any questions.
Thanks Jamal, that's given me somewhere to start which is exactly what I needed.