I have a multi language site in this site we're using a lot of WPC7, when users send us and email from our website they receive a confirmation.
This confirmation we designed in html so it looks better. We now have support of 3 languages and we're planning to have even more. Designing and maintaining each of this HTML mail templates has become really hard.
I have successfully saved the HTML Template into a shortcode, but now i can't use the user input data into that template.
This is what i have:
add_filter( 'wpcf7_form_elements', 'mycustom_wpcf7_form_elements' );
function mycustom_wpcf7_form_elements( $form ) {
$form = do_shortcode( $form );
return $form;
}
add_filter( 'wpcf7_special_mail_tags', 'special_mail_shortcodes', 10, 3 );
function special_mail_shortcodes( $output, $name, $html ) {
if ( 'email-response-user' == $name )
$output = do_shortcode( '[email-response-user]' );
return $output;
}
function email_response_user( $cf7 ) {
return '<html><body><table>Hi [your-name] this is my template.</table></body></html>';
}
add_shortcode( 'email-response-user', 'email_response_user' );
Now i only put [email-response-user] where the second mail content is and when i hit send email i receive it, the problem as i mention before i get "[your-name]" instead of the user name.
I tried to this:
function email_saved_values( $cf7 ) {
try {
if (!isset($cf7->posted_data) && class_exists('WPCF7_Submission')) {
$submission = WPCF7_Submission::get_instance();
if ($submission) {
$data = array();
$data['FormularioReservaciones'] = $cf7->title();
$data['posted_data'] = $submission->get_posted_data();
$test = $data['posted_data']['your-name'];
}
}
} catch (Exception $ex) {
print $ex;
}
return true;
}
add_action( 'wpcf7_before_send_mail', 'email_saved_values');
// and then
function email_response_user( $cf7 ) {
return '<html><body><table>Hi ' . $test . ' this is my template.</table></body></html>';
}
add_shortcode( 'email-response-user', 'email_response_user' );
But didn't work.
Reigel Gallarde answers:
you should use do_shortcode in here.. to run the shortcode inside...
function email_response_user( $cf7 ) {
return do_shortcode('<html><body><table>Hi [your-name] this is my template.</table></body></html>');
}
add_shortcode( 'email-response-user', 'email_response_user' );
Alvaro Rosado comments:
Hi thanks for the answer. I'll attach how i got the email. I did as you suggested but it did not worked.