my customer want to add re-capcha of google in checkout of Woocommerce login form.

my code was check json connect with google OK. But form not check validate when submit. (show correct value from google but not effect with form)
how to fix code to validate re-capcha when submit with this form

my code:

function xrvel_login_recaptcha_open_url($url) {
if (function_exists('curl_init') && function_exists('curl_setopt') && function_exists('curl_exec')) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 60);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    $response = curl_exec($ch);
    curl_close($ch);
} else {
    $response = file_get_contents($url);
}
    return trim($response);
}
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
        if(isset($_POST['g-recaptcha-response'])){
        $captcha = $_POST['g-recaptcha-response'];
        $parameters = array(
        'secret' => '6LcN6BwUAAAAAH3x3dryOl2lm92Xvgr7tTnPEUPX',
        'response' => $captcha,
        'remoteip' => $_SERVER['REMOTE_ADDR'],
        );

        $url = 'https://www.google.com/recaptcha/api/siteverify?' . http_build_query($parameters);
        $response = xrvel_login_recaptcha_open_url($url);
        $json_response = json_decode($response, true);
        if (isset($json_response['success']) && true !== $json_response['success']) {
            echo 'Not successfulllll';
            return;
        }else{
            echo 'OK';
        }
    } /*end is set*/
} /*end submit*/

Read more here: how to add re-capcha to login form in checkout woocommerce


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: