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;
}