Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WPForms: add field description in notification HTML and plain text emails
<?php
// HTML Email.
add_filter( 'wpforms_html_field_value', static function ( $field_val, $field, $form_data, $context ) {
if ( $context !== 'email-html' ) {
return $field_val;
}
if ( empty( $form_data['fields'][ $field['id'] ] ) ) {
return $field_val;
}
$field_data = $form_data['fields'][ $field['id'] ];
if ( empty( $field_data['description'] ) ) {
return $field_val;
}
return $field_val . '<p style="padding:5px;background-color:yellow;"><i>' . $field_data['description'] . '</i></p>';
}, 10, 4 );
// Plain text email.
add_filter( 'wpforms_plaintext_field_value', static function ( $field_val, $field, $form_data ) {
if ( empty( $form_data['fields'][ $field['id'] ] ) ) {
return $field_val;
}
$field_data = $form_data['fields'][ $field['id'] ];
if ( empty( $field_data['description'] ) ) {
return $field_val;
}
$field_val = str_replace( [ "\r", "\n" ], '', $field_val );
return $field_val . "\r\n" . $field_data['description'] . "\r\n\r\n";
}, 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.