function clear_cart_and_add_product_redirect_with_checkout()
{
    global $wpdb;
    // if user will buy the course from details page (Live, Consultancy) than remove from Wishlist and add to cart
    if ((isset($_GET['add_product']) && $_GET['add_product'] !== '') || (isset($_GET['add-to-cart']) && $_GET['add-to-cart'] !== '')) {

        $product_id = isset($_GET['add_product']) ? intval($_GET['add_product']) : $_GET['add-to-cart'];
        $courseType = get_post_meta($product_id, 'os_course_type', true);
        $user_id = get_current_user_id();
        if ($user_id !== '' && get_post_type($product_id) == 'lp_course' && ($courseType === 'live' || $courseType === 'consultancy')) {
            $user_wishlist = get_user_meta($user_id, '_lpr_wish_list', true);
            $wishlists = $user_wishlist ? $user_wishlist : array();

            if (!empty($wishlists) && in_array($product_id, $wishlists)) {
                $pos = array_search($product_id, $wishlists);
                unset($wishlists[$pos]);
            }

            if (!empty($wishlists) && count($wishlists) > 0) {
                update_user_meta($user_id, '_lpr_wish_list', $wishlists);
            } else {
                delete_user_meta($user_id, '_lpr_wish_list');
            }
        }
    }

    if (isset($_GET['clear_cart']) && $_GET['clear_cart'] == '1' && isset($_GET['add_product'])) {
        //WC()->cart->empty_cart();
        $product_id = intval($_GET['add_product']);
        // WC()->cart->add_to_cart($product_id);
        if (get_post_type($product_id) == 'lp_course') {
            $wc_product_id = get_post_meta($product_id, '_associated_product_id', true);
            if (isset($_GET['batch'])) {
                $batch_type = get_batch_type_by_id($_GET['batch']);
                $cart_item_data = array(
                    'batch_id' => $_GET['batch']
                );

                if (!$batch_type) {
                    $wc_product_id = $product_id;
                }
            }

            WC()->cart->add_to_cart($wc_product_id, 1, 0, array(), $cart_item_data);
        }
        if (isset($_GET['buynow']) && $_GET['buynow'] == 1) {
            $redirect_url = wc_get_checkout_url();
            wp_safe_redirect(esc_url_raw($redirect_url));
        } else {
            $batch_id = isset($_GET['batch']) ? sanitize_text_field($_GET['batch']) : '';
            $redirect_url = wc_get_checkout_url() . '?add-to-cart=' . $product_id;

            if (!empty($batch_id)) {
                $redirect_url .= '&batch=' . $batch_id;
            }
            wp_safe_redirect(esc_url_raw($redirect_url));
        }
        exit;
    } else if (isset($_GET['add-to-cart']) && $_GET['add-to-cart'] !== '') {
        //WC()->cart->empty_cart();
        $product_id = intval($_GET['add_product']);

        //WC()->cart->add_to_cart($product_id, 1, 0, array());
        $redirect_url = wc_get_checkout_url();
        wp_safe_redirect(esc_url_raw($redirect_url));
        exit;
    } else {
        if (!isset($_GET['_locale'])) {
            $session_handler = WC()->session;
            // Ensure session is initialized
            if (isset($session_handler)) {
                $session_key = $session_handler->get_customer_id();

                $wpdb->delete(
                    $wpdb->prefix . 'woocommerce_sessions',
                    ['session_key' => $session_key],
                    ['%s']
                );
            }
        }
    }
}

in this code when order purchase its store in woocommerce order and lernapress order but in live course batch type purcchae its store only in woocommerce so i want when woocomerce order add after its store in learnpress order create this with hook