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.
function addNumberToSubscriberList($fields, $entry, $form_data, $entry_id)
{
// Optional, you can limit to specific forms. Below, we restrict output to form #5.
if (absint($form_data['id']) !== 5) {
return;
}
$name = $entry['fields'][1]; // #1 is the field ID
$mobile = $entry['fields'][2]; // #2 is the field ID
$groupId = 2; // determine what group should add the number to that, you can get it from the form as well.
if ($name and $mobile) {
\WP_SMS\Newsletter::addSubscriber($name, $mobile, $groupId, '1');
}
}
add_action('wpforms_process_complete', 'addNumberToSubscriberList', 10, 4);