/* 
Theme Name: Hello Elementor Child
Theme URI: https://github.com/elementor/hello-theme/
Description: Hello Elementor Child is a child theme of Hello Elementor, created by Elementor team
Author: Elementor Team
Author URI: https://elementor.com/
Template: hello-elementor
Version: 1.0.1
Text Domain: hello-elementor-child
License: GNU General Public License v3 or later.
License URI: https://www.gnu.org/licenses/gpl-3.0.html
Tags: flexible-header, custom-colors, custom-menu, custom-logo, editor-style, featured-images, rtl-language-support, threaded-comments, translation-ready
*/

/*
    Add your custom styles here
*/

// wc form submission

add_action('wp_ajax_submit_custom_form', 'submit_custom_form');
add_action('wp_ajax_nopriv_submit_custom_form', 'submit_custom_form');

function submit_custom_form() {
    if (isset($_POST['form_data'])) {
        // Process and save the form data to create a new WooCommerce-order
        $form_data = $_POST['form_data'];

        // Example - Create a new WooCommerce.order
        $order = wc_create_order();

        // Example - Add product to or.der based on form data
        $product_id = get_product_id_based_on_form_data($form_data);
        $order->add_product(wc_get_product($product_id));

        // Example - Set billing address - customize based on your form data -
        $order->set_address($form_data['billing_address'], 'billing');

        // Example - Set payment method - customize based on your form data - 
        $order->set_payment_method($form_data['payment_method']);

        // Save the or.der
        $order->save();

        echo 'success'; // Return a success message
    } else {
        echo 'error'; // Return an error message
    }

    wp_die(); 
}

function get_product_id_based_on_form_data($form_data) {
    // Implement logic to determine the product ID based on the form data
    // Example - $product_id = get_product_id_for_service($form_data['service1']);
    return $product_id;
}


