• Hello !
    I created a date field with WP-member and I need to send an e-mail 11 months and 1 year after this date for each user.
    I really need help on how to do it.
    Thank you for your response.
    Have a nice day !

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Chad Butler

    (@cbutlerjr)

    That really has more to do with knowing how to handle WP scheduled events than it does the plugin.

    Certainly, if you want to manage the email content in the plugin, you can use wpmem_add_custom_email() to do that (see: https://rocketgeek.com/plugins/wp-members/docs/api-functions/wpmem_add_custom_email/).

    So what you’d do is create a scheduled event to run daily. In the function triggered by your event, you’d check the value of your custom field and if it is X from the date, then use wp_mail() to send your custom email.

    The trickiest part is probably the date handling to see if you need to send the message or not. All custom fields (wp_usermeta) are stored as strings but you’ll need to handle it as a date. There isn’t an internal function in WP for doing that, so to get your users who are at the time period you need from the date, you’ll need to do that with a direct SQL query. You may need to tweak things but I think you could that with something like:

    "SELECT user_id, meta_value
    FROM wp_usermeta
    WHERE 
        meta_key = 'whatever_your_date_field_meta_key_is' 
    AND
        CURDATE() = DATE_SUB( STR_TO_DATE( meta_value, '%Y-%m-%d' ), INTERVAL 11 months)"

    That would get you an array of user IDs who are due to receive your email, so then you’d loop through the result and send your custom email.

    Thread Starter leonardgry

    (@leonardgry)

    Thank you very much for your response, it works !
    I have one last question, if I use shortcode in this new email (such as [username]) how can i do for make it works ?
    Thank again for your help.

    Plugin Author Chad Butler

    (@cbutlerjr)

    The email shortcodes used in the plugin only work if you’re using the plugin’s email function to send the message. When you send directly through wp_mail() then those wouldn’t be parsed.

    To use the plugin’s function is a little more complicated and I don’t presently have any specific and freely available examples. But the function is wpmem_email_to_user() (https://rocketgeek.com/plugins/wp-members/docs/api-functions/wpmem_email_to_user/)

    Otherwise, you could use a PHP function like str_replace() on your email body content to replace any shortcodes with content before the message is sent through wp_mail()

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Send automate e-mail WP-member field’ is closed to new replies.