public static function add_to_qlist()
 {
     global $dvin_qlist_products, $post_id;
     //if form serialized data exists, merge with POST vars
     if (isset($_POST['form_serialize_data'])) {
         parse_str($_POST['form_serialize_data'], $arr);
         $_POST = array_merge($_POST, $arr);
         //if addons extensions active
         if (class_exists('Product_Addon_Cart')) {
             $addons = get_product_addons($_POST['product_id']);
             //initialize the variables
             $addons_result_arr = $arr = array();
             $obj = new Product_Addon_Cart();
             $addons_result_arr = $obj->add_cart_item_data($arr, $_POST['product_id']);
             $_POST['addons'] = $addons_result_arr['addons'];
         }
         //check if it is a simple product
         if (!isset($_POST['variable_id']) && isset($_POST['add-to-cart'])) {
             $_POST['product_id'] = $_POST['add-to-cart'];
         }
     }
     $dvin_wcql_obj = new Dvin_Wcql($_POST);
     //create object
     //add to quotelist
     $ret_val = $dvin_wcql_obj->add();
     if ($ret_val == "true") {
         $_POST['count_refresh'] = isset($_POST['count_refresh']) ? $_POST['count_refresh'] : 'false';
         $_POST['widget_refresh'] = isset($_POST['widget_refresh']) ? $_POST['widget_refresh'] : 'false';
         $data = self::get_refreshed_fragments(array('count_refresh' => $_POST['count_refresh'], 'widget_refresh' => $_POST['widget_refresh']));
         $data['status'] = 'success';
         $data['msg'] = __("Successfully added", "dvinwcql");
     } elseif ($ret_val == "exists") {
         $data = self::get_refreshed_fragments(array('count_refresh' => "false", 'widget_refresh' => "false"));
         $data['status'] = 'exists';
         $data['msg'] = __("Already Exists. Browse Quotelist.", "dvinwcql");
     } elseif (count($dvin_wcql_obj->errors_arr) > 0) {
         $data = self::get_refreshed_fragments(array('count_refresh' => "false", 'widget_refresh' => "false"));
         $data['status'] = 'fail';
         $data['msg'] = $dvin_wcql_obj->errors_arr[0];
     }
     wp_send_json($data);
     exit;
 }
function dvin_qlist_create_order($data)
{
    global $dvin_qlist_products, $dvin_wcql_settings;
    if (class_exists('Product_Addon_Cart')) {
        $addon_cart_obj = new Product_Addon_Cart();
        //create object for addons
    }
    $address = array();
    //stores the billing and shipping info for creating order
    $billing_address = dvin_wcql_map_address($data, '');
    $shipping_address = dvin_wcql_map_address($data, 'ship_');
    $order = wc_create_order();
    foreach ($dvin_qlist_products as $key => $arr) {
        if (!isset($arr['variation_id']) && !isset($arr['product_id'])) {
            continue;
        }
        //simple or variable
        if (isset($arr['variation_id']) && !empty($arr['variation_id'])) {
            $product_obj = wc_get_product($arr['variation_id']);
            if (isset($arr['price'])) {
                $product_obj->set_price($arr['price']);
            }
            $item_id = $order->add_product($product_obj, $arr['quantity'], array('variation' => unserialize($arr['variation_data'])));
        } else {
            $product_obj = wc_get_product($arr['product_id']);
            $item_id = $order->add_product($product_obj, $arr['quantity']);
            //(get_product with id and next is for quantity)
        }
        // Allow plugins to add order item meta
        if (isset($addon_cart_obj) && $addon_cart_obj instanceof Product_Addon_Cart) {
            //to avoid/prevent notices
            $arr['data'] = array();
            $addon_cart_obj->order_item_meta($item_id, $arr);
        }
    }
    //end of foreach
    $order->set_address($billing_address, 'billing');
    $order->set_address($shipping_address, 'shipping');
    $order->calculate_totals();
    //update the customer data
    update_post_meta($order->id, '_customer_user', absint(get_current_user_id()));
    //update the order status to pending
    $order = new WC_Order($order->id);
    $order->update_status('pending');
    return $order->id;
}