50% OFF Limited time deal!

Convert entries form to subscribers after submitting new from in Contact Form 7

Updated on Aug 14, 2021

Sometimes you’d like to store your contact’s data in the WP-SMS newsletter, so here is a simple function that helps you to do that.


/**
 * @param WPCF7_ContactForm $WPCF7_ContactForm
 */
function addNumberToSubscriberList($WPCF7_ContactForm)
{
    $name   = isset($_POST['your-name']) ? sanitize_text_field($_POST['your-name']) : "";
    $mobile = isset($_POST['your-mobile']) ? sanitize_text_field($_POST['your-mobile']) : "";

    if ($name and $mobile) {
        \WP_SMS\Newsletter::addSubscriber($name, $mobile, 'group-id', '1');
    }
}
add_action('wpcf7_before_send_mail', 'addNumberToSubscriberList');