Created
January 23, 2020 14:06
-
-
Save slaFFik/d43ba58e19ade4d76ded3b0e34082472 to your computer and use it in GitHub Desktop.
WPForms: merge values for 2 fields into a 3rd one
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); |
Yes, you can check the $form_data['id']
to be the value you need.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi
this is very helpful, since the field ID is not unique in wpforms is there a way to validate the filter with form ID ?