I’ve been trying to add a kind of security, like a captcha or security question, to the checkout form. I’ve tried it using PHP, add-ons, plugins, but I can’t find anything that works. Do you guys know how I can do this? It’s so that I don’t get a lot of orders from bots. Preferably in code. I tried it using
$number = 2
//other wordpress/woocommerce code
'human' => array(
'label' => __( 'Are you a human?', 'woocommerce' ),
'placeholder' => __( 'What is 1 + 1?', 'woocommerce' ),
'required' => true,
'validate' => $number
),
in woocommerce/includes/class-wc-countries.php
but it wouldn’t work: it showed the form, but I could enter anything, and it would just continue, even if I entered e.g. 324.
You can use Google NoCaptcha Recaptcha for your security purpose
You can generate your own captcha by following the below instructions:
https://developers.google.com/recaptcha/intro
Expanding on my tutorial on customizing the checkout fields we can start with adding and displaying some fields:
This will add the computation check field:
And this displays it on the checkout
I like honeypots, which are fields that humans are meant to keep blank but bots might try to fill. They catch bots but don’t even show to humans and humans don’t have to do anything. Win, win! Because this is a hidden input I was not able to add it via the functions above. Therefore we will add the markup directly the checkout template.
WooCommerce only allows for certain types of validation. Outside of required, city, phone, etc, we must do our own validation with the posted info. By adding an error notice we stop the order from being completed.
You could edit the page the form is on: hide the button until the user enters the captcha correctly, or answers the math question properly:
http://jsfiddle.net/robinvandernoord/pexhLL2g
someone could get the answer too in the console, but only humans know that, right? 😉