Skip to content

Instantly share code, notes, and snippets.

@tcdevs
Last active October 10, 2016 13:06
Show Gist options
  • Save tcdevs/d9e68a9b808fea80cacda0d894084267 to your computer and use it in GitHub Desktop.
Save tcdevs/d9e68a9b808fea80cacda0d894084267 to your computer and use it in GitHub Desktop.
Replace form fields by name with uppercase characters - WP Contactform 7
<?PHP add_action( 'wpcf7_before_send_mail', 'wpcf7_add_text_to_mail_body' );
function wpcf7_add_text_to_mail_body($contact_form){
$submission = WPCF7_Submission::get_instance();
if ( $submission ) {
// Get POST data
$posted_data = $submission->get_posted_data();
// get mail property
$mail = $contact_form->prop( 'mail' ); // returns array
// add content to email body
$mail['body'] .= ' - ' . implode(", ", $posted_data);
// Replace exsisting content
$mail['body'] = str_replace('[your-name]', strtoupper($posted_data['your-name']), $mail['body']);
}
// set mail property with changed value(s)
$contact_form->set_properties( array( 'mail' => $mail ) );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment