Title: Add and remove subscribers programmatically
Last modified: August 31, 2016

---

# Add and remove subscribers programmatically

 *  Resolved [MALiberato](https://wordpress.org/support/users/maliberato/)
 * (@maliberato)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/add-and-remove-subscribers-programmatically/)
 * Hi! First of all thank you for the plugin 🙂
    I need to do a tricky thing… I 
   have to send an email every x-days to people who didn’t buy a product (anual 
   subscription). The problem is that they can buy this offline, which means that
   not every purchase is registered in woocommerce. My solution to have everything
   in the same place was creating a custom field for the users that is empty or 
   false (unpayed or payed). I think the easiest way to do this is subscribe everyone
   and create a function where everytime the custom field is updated the user is
   unsubscribed is the field is not empty. Can you help me with this?
 * [https://wordpress.org/plugins/email-subscribers/](https://wordpress.org/plugins/email-subscribers/)

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Plugin Author [storeapps](https://wordpress.org/support/users/storeapps/)
 * (@storeapps)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/add-and-remove-subscribers-programmatically/#post-7225334)
 * [@maliberato](https://wordpress.org/support/users/maliberato/),
 * Using Email Subscribers, you can send an notification immediately when a post
   is published.
 * But if you want to send x-days or on products, you can have a check on [Klawoo](http://klawoo.com/)
   which is our complete Email Marketing solution. Using [Klawoo Connector](https://wordpress.org/plugins/klawoo-connector/)
   you can sync your WooCommerce orders and send notification after any number of
   days.
 *  Thread Starter [MALiberato](https://wordpress.org/support/users/maliberato/)
 * (@maliberato)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/add-and-remove-subscribers-programmatically/#post-7225355)
 * We have online and in person sales, it won’t work. I only need to know how to
   unsubscribe a person in php, I can do the rest.
 *  Plugin Author [storeapps](https://wordpress.org/support/users/storeapps/)
 * (@storeapps)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/add-and-remove-subscribers-programmatically/#post-7225439)
 * [@maliberato](https://wordpress.org/support/users/maliberato/),
 * Go to email-subscribers/classes/ & open es-sendmail.php
    In that file, search
   for the function `es_sendmail`, in that locate this line : `$unsublink = $settings['
   es_c_unsublink'];`
 * There you will find a block of code for creating the unsubscribe link in php.
 *  Thread Starter [MALiberato](https://wordpress.org/support/users/maliberato/)
 * (@maliberato)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/add-and-remove-subscribers-programmatically/#post-7225442)
 * Thank you! I’ll try
 *  Plugin Author [storeapps](https://wordpress.org/support/users/storeapps/)
 * (@storeapps)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/add-and-remove-subscribers-programmatically/#post-7225462)
 * [@maliberato](https://wordpress.org/support/users/maliberato/),
 * You are welcome 🙂
 *  Thread Starter [MALiberato](https://wordpress.org/support/users/maliberato/)
 * (@maliberato)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/add-and-remove-subscribers-programmatically/#post-7225483)
 * I didn’t use that but it’s working… for anyone who want to do the same:
 *     ```
       //hook profile updates
       add_action( 'profile_update', 'my_profile_update', 10, 2 );
   
       //create the function. $user_id is the updated user id
       function my_profile_update( $user_id, $old_user_data ) {
   
           //get the custom field data and verify if it's empty
           $user_info = get_userdata($user_id);
           $custom_field = $user_info->custom_field;
           if (!empty($custom_field)){
   
               //if the custom_field is empty, find user email
               $user_email = $user_info->user_email;
   
                   //connect to DB
                   global $wpdb;
   
                   //delete row where the email exists
                   $wpdb->delete( 'wp_es_emaillist', array( 'es_email_mail' => $user_email ) );
   
           }
   
       }
       ```
   
 * If anyone has a better solution please tell me

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Add and remove subscribers programmatically’ is closed to new replies.

 * ![](https://ps.w.org/email-subscribers/assets/icon-256x256.png?rev=2274172)
 * [Email Subscribers & Newsletters - Email Marketing, Post Notifications & Newsletter Plugin for WordPress](https://wordpress.org/plugins/email-subscribers/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/email-subscribers/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/email-subscribers/)
 * [Active Topics](https://wordpress.org/support/plugin/email-subscribers/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/email-subscribers/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/email-subscribers/reviews/)

 * 6 replies
 * 2 participants
 * Last reply from: [MALiberato](https://wordpress.org/support/users/maliberato/)
 * Last activity: [10 years, 1 month ago](https://wordpress.org/support/topic/add-and-remove-subscribers-programmatically/#post-7225483)
 * Status: resolved