2015-08-25 43 views

回答

1

插件只是写入保护Woocommerce注册和登录,不结帐流程。

为了保护结帐过程中,我调整和registration.php这样

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 


} 
1

添加到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'); 
+0

这为我工作。它所做的是防止结帐过程中的错误 – nicogaldo