This guide outlines the process of integrating Elementor forms with an SMS newsletter subscription system. By following these steps, you can automatically add user-submitted form entries to your SMS newsletter subscriber list using the provided code snippet. This integration enhances your website’s functionality by seamlessly capturing user data and extending your reach through SMS newsletters.
Prerequisites:
- A WordPress website with Elementor Pro installed.
- An active SMS newsletter subscription service, such as WP SMS.
Integration Steps:
Step 1: Accessing Your WordPress Dashboard
Log in to your WordPress admin dashboard.
Step 2: Open the Theme’s functions.php File
Navigate to Appearance in the sidebar and select Theme Editor. Then, locate and open the functions.php file for your active theme.
Step 3: Adding the Integration Code
Copy and paste the following code snippet at the end of your theme’s functions.php file:
// save entry form to db one user submitted form on elementor form
function subscribe_form_entry_to_sms_newsletter($record, $handler)
{
$form_name = $record->get_form_settings('form_name');
// Replace MY_FORM_NAME with the name you gave your form
if ('MY_FORM_NAME' !== $form_name) {
return;
}
$raw_fields = $record->get('fields');
$fields = [];
foreach ($raw_fields as $id => $field) {
$fields[$id] = $field['value'];
}
// Subscribe to SMS Newsletter
\WP_SMS\Newsletter::addSubscriber($fields['first_name'], $fields['mobile_number']); // Replace with your own fields
}
add_action('elementor_pro/forms/new_record', 'subscribe_form_entry_to_sms_newsletter', 10, 2);
Step 4: Adjusting Form Name and Fields
Replace 'MY_FORM_NAME'
with the actual name of the Elementor form you want to integrate. Additionally, ensure that the fields you’re capturing (first_name and mobile_number in this example) match the fields in your form.
Step 5: Save Changes
Click the Update File button to save your changes to the functions.php file.
Step 6: Test the Integration
Create a submission on the designated Elementor form to verify that the integration is working as expected. The user’s first name and mobile number should now be automatically added to your SMS newsletter subscriber list.
You can also use one of our newest add-ons called WP SMS Elementor Form