/* 
Theme Name: Knee Replacement Indore
Theme URI: https://github.com/elementor/hello-theme-child/
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: 2.0.0
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 */

add_action('metform_after_form_submit', 'send_metform_data_to_webhook', 10, 2);

function send_metform_data_to_webhook($entry, $form_id) {
    $webhook_url = 'https://connect.pabbly.com/workflow/sendwebhookdata/IjU3NjYwNTY0MDYzMjA0M2M1MjY5NTUzNjUxM2Ei_pc';

    $payload = [
        'form_id' => $form_id,
        'submission' => $entry
    ];

    $response = wp_remote_post($webhook_url, [
        'method'    => 'POST',
        'headers'   => ['Content-Type' => 'application/json'],
        'body'      => wp_json_encode($payload),
        'data_format' => 'body'
    ]);

    if (is_wp_error($response)) {
        error_log('Webhook failed: ' . $response->get_error_message());
    } else {
        error_log('Webhook sent successfully');
    }
}

