0

I am trying to customise the success message of the Contact Form 7 plugin in WordPress.

I understand that it could be done using javascript, but I don't have this option. That's because I've created a custom coupon code on form submission, by using this - add_action('wpcf7_mail_sent', 'dbo_generate_coupon');.

I need to display that coupon to the user after the form is sent.

I don't want to use an alert. I need to alter the standard "Thank you for your message. It has been sent." response.

I am confident I can retrieve the cookie ok, but the first ( simple? ) step is getting control of the success message. Here I'm out of my depth.

I've tried code like

return apply_filters('wpcf7_messages','dbo_update_form_messages',10,1);

and

add_action('wpcf7_before_send_mail', 'action_wpcf7_mail_sent', 10, 1);
add_action('wpcf7_mail_sent', 'action_wpcf7_mail_sent', 10, 1);

Clearly I need help.

Thanks in advance.

DbO-NZ
  • 1
  • 1

1 Answers1

0

With a little more digging, I found the answer on Stack Overflow

I updated the code from lukeseager under the heading Send the email to a dynamic recipient

This is my working startpoint;

function wpcf7_before_send_mail_function( $contact_form, $abort, $submission ) {

    $dynamic_email = ''; // get your email address...

    $properties = $contact_form->get_properties();
    $properties['messages']['mail_sent_ok'] = 'custom message';
    $contact_form->set_properties($properties);

    return $contact_form;
    
}
add_filter( 'wpcf7_before_send_mail', 'wpcf7_before_send_mail_function', 10, 3 );
DbO-NZ
  • 1
  • 1