I use in a CMS wordpress website form (Contact Form 7) for recording the patients. The need arose to after clicking the button to sign in before sending email has printed some coupon with the user-entered data in a pre-prepared template.
How to implement it? Please help.
screen http://pastenow.ru/2EQF9
What i get from your question is
So before sending mail, you need to show which data is sending. for this, you can use the hook
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 ) {
$posted_data = $submission->get_posted_data();
print_r($posted_data)
}
}
Related
I have an automation tool inside woocommerce that i want to use to send all emails like new order/processing etc. I do not want to send woo emails from the inbuilt functionality. So i turned off the new order email in woocommerce setting.
In my automation I have added below code:
add_action( 'email_callback', 'email_callback' );
function email_callback( $args ) {
$email_new_order = WC()->mailer()->get_emails()['WC_Email_New_Order'];
$email_new_order->trigger( $args['order_id'] );
}
But this seems to trigger only if i enable new order email from woo -email-setting but that leads to send double email.
Can anyone suggest what can be done. I do not want to send duplicate email ???
WC_Email_New_Order email is triggered both by the WooCommerce email system and by your custom code. To avoid sending duplicate emails, you need to modify your custom code.
add_action( 'email_callback', 'email_callback' );
function email_callback( $args ) {
// Check if the New Order email is enabled in WooCommerce settings
$new_order_email_enabled = get_option( 'woocommerce_new_order_email_enabled' );
if ( $new_order_email_enabled == 'yes' ) {
return;
}
$email_new_order = WC()->mailer()->get_emails()['WC_Email_New_Order'];
$email_new_order->trigger( $args['order_id'] );
}
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.
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 );
I have written the following codes:
// define the wpcf7_mail_sent callback
function action_wpcf7_mail_sent( $contact_form ) {
$temp1246 = get_post_meta( 1246, $key = 'ID', TRUE);
$temp1246 = intval($temp1246) + 1;
update_post_meta( 1246, 'ID', $temp1246 );
};
// add the action
add_action( 'wpcf7_mail_sent', 'action_wpcf7_mail_sent', 10, 1 );
What the code does is that it will increment a page's custom value by 1 every time a contact form is submitted. But the problem I have now is that I only want a specific contact form to trigger this code when it is sent, not all the contact forms (I have a few contact forms in the site powered by CF7).
May I know how can I adjust the codes above so that it is only triggered when the contact form (id = '1000') was sent for example?
Appreciate if anyone can assist, thank you!
Just found a solution that I can use the ID properties to find out which contact form I use:
if($contact_form -> id() == 1000){
}
I've created a form with contact form 7, and I need to send two e-mails, one with all the data that I pick up from the form, another one with a "thank you" message and other important information, these informations are statics, all the same for every user that clicks in the submit button.
So my problem is this email, CF7 can send only one type of mail to multiple users, but not two differents mail to two differents users. The second mail needs to use the [your-mail] (the mail that the users write in the form).
I've discovered the on_sent_ok function that allows me to open a page or something else after the submit, but I have no idea how to send this different mail.
It's been a while from your request, but I write here my solution for future needs.
You can reach the goal by following 2 steps:
A) handle the sent mail Contact Form 7 event.
function your_wpcf7_mail_sent_function( $contact_form ) {
$title = $contact_form->title;
$submission = WPCF7_Submission::get_instance();
if ($submission && "New hospital" == $title) {
$posted_data = $submission->get_posted_data();
//$posted_data is an associative array that contains all the form input values,
//so you can use it to proceed with B step
}
}
add_action( 'wpcf7_mail_sent', 'wpcf7_mail_sent_event_triggered' );
If you're not sure on where place this code my suggestion is to add it at the beginning of your theme's function.php file.
B) send a custom mail using wp_mail API.
If you take a look at the docs you'll find that the API is quite easy to understand.
$to = 'sendto#example.com';
$subject = 'The subject';
$body = 'The email body content';
$headers = array('Content-Type: text/html; charset=UTF-8');
wp_mail( $to, $subject, $body, $headers );
Obviously you can customize the body message using or not the $posted_data values according to your needs.
I've one form built with ninja forms, and I use ajax to send it.
I need to check if the email introduced already exists in database (user_email), and if it exists properly, I send the form properly, but if it doesn't exist, the form isn't submitted, and I need to give the user the message like "email does not exist".
The form is a survey to be completed by a registered user, who gives us a feedback about our services, but the survey is located in a page where the user can send its opinion without needed to be logged.
I'm investigating, and at the moment I have:
function example_disable_saving_subs( $save, $form_id ) {
global $ninja_forms_processing;
$form_id = $ninja_forms_processing->get_form_ID();
$email = ninja_forms_get_field_by_id( 18 );
//cuestionario feedback profesor sobre creación de un curso
if($form_id == 3){
if( !email_exists( $email )) {
$save = false;
$ninja_forms_processing->add_error('email_no_existe', 'El email no existe');
}
}
return $save;
}
add_filter( 'ninja_forms_save_submission', 'example_disable_saving_subs', 2, 10 );
But I pick up the field $email without value introduced...In addition, I don't know the way to give the user the message "email does not exists".
As you see, I chose the filter ninja_forms_save_submission. Maybe this is not the correct filter.
I hope your valious help.
Thanks in advance, Daniel
thanks for your help #Renato , I give you +1 :)
It's true that I can do it through the way you tell me, but I don't want to break the api of WordPress, that is, the way this cms uses javascript, php, etc etc...So, I wanted to do this through the API of ninja forms, which is the plugin I use for build this survey.
Finally, I solved it...it was my mistake, because I didn't use the correct filter...Investigating few more, there's another filter much more appropiate: ninja_forms_pre_process
Here is the code:
function add_change_ninja_forms_landing_page(){
add_action( 'ninja_forms_pre_process', 'handle_custom_ninja_forms' );
}
add_action( 'init', 'add_change_ninja_forms_landing_page' );
function handle_custom_ninja_forms(){
global $ninja_forms_processing;
$form_id = $ninja_forms_processing->get_form_ID();
//if it's my form of survey
if( $form_id == 3 ){
$email = $ninja_forms_processing->get_field_value( 18 ); //pick up the value of the email field
//use the native function of wordpress to check if there's a user with this email
//is anyone has this email, it does not exist
if( !email_exists( $email )) {
$ninja_forms_processing->add_error('email_no_existe', 'El email indicado no está registrado en nuestra base de datos'); //add_error stop the form and gives the error message
}
}
}
With the code above everything works fine! :)
Thanks!
Daniel,
I am not familiar with ninja_forms, but thinking of javascript, you can encapsulate your code to verify if users exists into an url and then, when making the ajax call, use it to verify...
If you can't change the ajax request, you can validate the field on it's blur event and disable the submit button untill it's marked as "successfull"
For you to create PHP files, and yet, use all Wordpress power and functionalities, you can simply include this file on the beggining of the file that will be called
require(wp-blog-header.php)