Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WPForms: merge values for 2 fields into a 3rd one
<?php
add_filter( 'wpforms_entry_save_data', static function ( $fields, $entry, $form_data ) {
$value1 = '';
$value2 = '';
// These are field IDs to take data from, and to merge into.
$field1_id = 1;
$field2_id = 2;
$merged_id = 3;
foreach ( $fields as $field ) {
if ( $field['id'] === $field1_id ) {
$value1 = $field['value'];
}
if ( $field['id'] === $field2_id ) {
$value2 = $field['value'];
}
}
$fields[ $merged_id ]['value'] = $value1 . ' - ' . $value2;
return $fields;
}, 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.