function dvin_wcql_mycf7_before_send_mail($WPCF7_ContactForm)
 {
     global $dvin_wcql_settings, $dvin_wcql_obj, $dvin_qlist_products;
     if (!isset($dvin_qlist_products) || empty($dvin_qlist_products)) {
         $dvin_qlist_products = WC()->session->get('$dvin_qlist_products');
     }
     //Get current form
     $wpcf7 = WPCF7_ContactForm::get_current();
     if ($dvin_wcql_settings['contactform7_form_select'] == $WPCF7_ContactForm->id()) {
         //prepare and send email
         $submission = WPCF7_Submission::get_instance();
         $data = $submission->get_posted_data();
         //create order if enabled
         if ($dvin_wcql_settings['create_order'] == 'on') {
             $dvin_wcql_obj->order_id = dvin_qlist_create_order($data);
         }
         //craete order
         // do some replacements in the cf7 email body
         $mail = $wpcf7->prop('mail');
         //find the strings of quotelist, if it is there get the shortcode
         preg_match_all('/(\\[quotelist.*)/', $mail['body'], $matches);
         if (count($matches) > 0) {
             list($total_price, $table) = unserialize(do_shortcode($matches[0][0]));
         }
         // Find/replace the "[quotelist]" and "[orderinfo]"tag as defined in your CF7 email body
         // and add changes name
         $mail['body'] = str_replace(array($matches[0][0], '[orderinfo]'), array($table, $dvin_wcql_obj->get_order_info()), $mail['body']);
         // Save the email body
         $wpcf7->set_properties(array("mail" => $mail));
         $mail2 = $wpcf7->prop('mail_2');
         //get CF7's mail_2 object
         //handle cc mail
         if ($mail2['active']) {
             //if Checkbox checked
             // Find/replace the "[quotelist]" tag as defined in your CF7 email body
             // and add changes name
             //find the strings of quotelist, if it is there get the shortcode
             preg_match_all('/(\\[quotelist.*)/', $mail2['body'], $matches);
             if (count($matches) > 0) {
                 list($total_price, $table) = unserialize(do_shortcode($matches[0][0]));
             }
             $mail2['body'] = str_replace(array($matches[0][0], '[orderinfo]'), array($table, $dvin_wcql_obj->get_order_info()), $mail2['body']);
             $wpcf7->set_properties(array('mail_2' => $mail2));
         }
         $dvin_qlist_products = array();
         WC()->session->set('dvin_qlist_products', array());
         //clear the products from session
     }
     // return current cf7 instance
     return $wpcf7;
 }
 public static function send_request()
 {
     global $dvin_qlist_products;
     $response_arr = array();
     $dvin_wcql_obj = new Dvin_Wcql($_POST);
     //create object
     if (isset($_POST['form_serialize_data'])) {
         parse_str($_POST['form_serialize_data'], $arr);
         $_POST = array_merge($_POST, $arr);
     }
     //update the quantities in session
     foreach ($_POST['qty'] as $key => $qty) {
         $dvin_qlist_products[$key]['quantity'] = (int) $qty;
     }
     WC()->session->set('$dvin_qlist_products', $dvin_qlist_products);
     //validate the form, send back if errors found
     $errors = self::dvin_qlist_validate_form();
     if (count($errors) > 0) {
         $response_arr['status'] = 'error';
         $response_arr['msg'] = join($errors, '<br/>');
         wp_send_json($response_arr);
         exit;
     }
     //get settings to use further
     $dvin_wcql_settings = maybe_unserialize(get_option('dvin_wcql_settings'));
     //create order if enabled
     if (isset($dvin_wcql_settings['create_order']) && $dvin_wcql_settings['create_order'] == 'on') {
         $dvin_wcql_obj->order_id = dvin_qlist_create_order($_POST);
     }
     //now prepare and send email
     $return_arr = self::dvin_qlist_sendreq_func($dvin_wcql_obj);
     if ($return_arr['status'] == "success") {
         if (isset($dvin_wcql_settings['dvin_wcql_redirect_url']) && !empty($dvin_wcql_settings['dvin_wcql_redirect_url'])) {
             $return_arr['status'] = 'redirect';
             $return_arr['redirect_url'] = $dvin_wcql_settings['dvin_wcql_redirect_url'];
             WC()->session->set('dvin_qlist_products', array());
             wp_send_json($return_arr);
             exit;
         } else {
             $return_arr['status'] = 'success';
             WC()->session->set('dvin_qlist_products', array());
             wp_send_json($return_arr);
             exit;
         }
     }
     wp_send_json($return_arr);
     exit;
 }