问题
when i active 'No CAPTCHA reCAPTCHA for WooCommerce' plugin, so on checkout page of WooCommerce when customer checked the 'Create an account?' check-box and than Place Order, it does not work. the page just scroll on to the top and nothing action.
any idea?
Reagrds Faizan
回答1:
The plugin is just written to protect the Woocommerce Registration and Login, not the Checkout Process.
In order to protect the Checkout Process, I tweaked registration.php like this
class WC_Ncr_Registration_Captcha extends WC_Ncr_No_Captcha_Recaptcha {
/** Initialize actions and filters */
public static function initialize() {
// initialize if login is activated
if ( isset( self::$plugin_options['captcha_wc_registration'] ) || self::$plugin_options['captcha_wc_registration'] == 'yes' ) {
// adds the captcha to the registration form
add_action( 'register_form', array( __CLASS__, 'display_captcha' ) );
}
//added the following lines to the plugin
add_action('woocommerce_after_checkout_billing_form', array( __CLASS__, 'display_captcha' ));
add_action('woocommerce_checkout_process', array(
__CLASS__,
'validate_captcha_wc_checkout'
), 10, 3 );
//added the previous lines to the plugin
}
/**
* Verify the captcha answer
*
* @param $validation_errors
* @param $username
* @param $email
*
* @return WP_Error
*/
public static function validate_captcha_wc_registration( $validation_errors, $username, $email ) {
if ( ! isset( $_POST['g-recaptcha-response'] ) || ! self::captcha_wc_verification() ) {
$validation_errors = new WP_Error( 'failed_verification', self::$error_message );
}
return $validation_errors;
}
//added the following lines to the plugin
public static function validate_captcha_wc_checkout( $validation_errors, $username, $email ) {
if ( ! isset( $_POST['g-recaptcha-response'] ) || ! self::captcha_wc_verification() ) {
wc_add_notice(__( 'Please verify you are not a robot.' ), 'error' );
}
}
//added the previous lines to the plugin
}
回答2:
Add to functions.php
function my_woocommerce_before_checkout_process() {
remove_filter( 'woocommerce_registration_errors', array('WC_Ncr_Registration_Captcha', 'validate_captcha_wc_registration'), 10 );
}
add_action('woocommerce_before_checkout_process', 'my_woocommerce_before_checkout_process');
来源:https://stackoverflow.com/questions/32197121/woocommerce-checkout-not-working-with-no-captcha-recaptcha-for-woocommerce-plugi