Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

how to add recaptcha to woocommerce register php

// Add field into the registration form

    function nada_woocommerce_edit_registration_form() {
            ?>
            <p id="recaptcha" class="g-recaptcha" data-sitekey="##your-google-captcha-key##"></p>
            <?php
        }
        add_action( 'woocommerce_register_form', 'nada_woocommerce_edit_registration_form', 15 );

    /**
     * Validate Woocommerce Registration form fields
     */

    function nada_validate_extra_register_fields( $errors, $username, $email ) {
        if ( empty( $_POST['g-recaptcha-response'] ) ) {
                $errors->add( 'captcha-error', wp_kses_post( '<strong>Error</strong>: Captcha is missing.', 'nada' ) );
        }
        return $errors;
    }
    add_filter( 'woocommerce_registration_errors', 'nada_validate_extra_register_fields', 10, 3 );
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #add #recaptcha #woocommerce #register #php
ADD COMMENT
Topic
Name
5+7 =