Home / Admin / Remove Multiple Fields From {all_fields} in Notifications
Duplicate Snippet

Embed Snippet on Your Site

Remove Multiple Fields From {all_fields} in Notifications

This code snippet removes multiple fields from your email notifications while still using the {all_fields} smart tag.

<10
Code Preview
php
<?php
/**
 * Remove Specific Fields from Notifications
 *
 * @link https://wpforms.com/developers/how-to-remove-specific-fields-from-notifications
 */
add_action('wpforms_loaded', function() {
    add_filter('wpforms_entry_email_data', function ($fields, $entry, $form_data) {
        // Bail early if form ID is not equal to 1000
        if ((int)$form_data['id'] !== 1000) {
            return $fields;
        }
 
        // Unset fields from notifications with field IDs #3, #4, and #5
        $fields_to_unset = [3, 4, 5];
        foreach ($fields_to_unset as $field_id) {
            if (isset($fields[$field_id])) {
                unset($fields[$field_id]);
            }
        }
 
        return $fields;
    }, 11, 3);
});

Comments

Add a Comment