HI mọi người, mình muốn lấy sự kiện Event Submit send_ok trong Contact Form 7 chuyển sang trang Cảm ơn mỗi khi có người liên hệ thành công. Mình có form liên hệ với Shortcode, giờ mình muốn mỗi khi khách hàng liên hệ đặt hàng thành công, form sẽ di chuyển sang 1 trang mình đang xây dựng sẵn có page tên là : /dat-hang-thanh-cong/ Bạn nào biết giúp mình với, cảm ơn Mã: [contact-form-7 id="549" title="Đặt hàng Popup"]
Về sự kiện on_send_ok bạn xem ở link sau nhé, contactform7 đã nói khá rõ ở đây. https://contactform7.com/2017/06/07/on-sent-ok-is-deprecated/ Còn bạn muốn nó redirect qua trang cảm ơn như bạn cần thì bạn thêm code sau vào tập tin function.php của themes như sau: Mã: add_action( 'wp_footer', 'mycustom_wp_footer' ); function mycustom_wp_footer() { ?> <script type="text/javascript"> document.addEventListener( 'wpcf7mailsent', function( event ) { if ( '549' == event.detail.contactFormId ) { window.location.href = '/dat-hang-thanh-cong/'; } }, false ); </script> <?php } Với 549 là ID của form liên hệ [contact-form-7 id="549" title="ĐH"]
Ngoài ra có thêm sự kiện tại function.php khi gửi email như sau: PHP: add_action( 'wpcf7_mail_sent', 'your_wpcf7_mail_sent_function' );function your_wpcf7_mail_sent_function( $contact_form ) { $form_id = $contact_form->id(); $submission = WPCF7_Submission::get_instance(); $posted_data = $submission->get_posted_data(); if ( 336 == $form_id ) { if ($posted_data['contact-title'] != '') { $post_title = $posted_data['contact-title']; } else { $post_title = 'Câu hỏi từ '.$posted_data['contact-name']; } // Add new faq $new_post = array( 'post_title' => $post_title, 'post_type' => 'faq', 'post_staus' => 'draft', 'meta_input' => array( 'name' => $posted_data['contact-name'], 'phone' => $posted_data['contact-phone'], 'email' => $posted_data['contact-mail'], 'question' => $posted_data['contact-content'], ) ); wp_insert_post( $new_post ); //nếu đúng thì bắt đầu tạo bài viết }}