【问题标题】:Woocommerce Checkout not Working with No CAPTCHA reCAPTCHA for WooCommerce PluginWoocommerce Checkout 无法使用 No CAPTCHA reCAPTCHA for WooCommerce 插件
【发布时间】:2015-11-18 18:02:05
【问题描述】:

当我激活“No CAPTCHA reCAPTCHA for WooCommerce”插件时,当客户检查“创建帐户?”时,在 WooCommerce 的结帐页面上复选框,而不是下订单,它不起作用。页面只是滚动到顶部,没有任何动作。

有什么想法吗?

感谢 费赞

【问题讨论】:

    标签: wordpress plugins captcha checkout


    【解决方案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
    
    
    }
    

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      • 这对我有用。它的作用是防止结帐过程中的错误
      猜你喜欢
      • 2015-02-14
      • 1970-01-01
      • 2017-06-23
      • 2015-03-02
      • 2017-06-11
      • 2015-12-28
      • 2021-10-26
      • 2014-09-17
      • 2021-04-25
      相关资源
      最近更新 更多