// Account creation within checkout must not consume its verified CAPTCHA twice. add_action( 'wp_loaded', 'tala_wrap_checkout_registration_captcha', 100 ); function tala_checkout_registration_captcha_verified( $validator ) { if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) || ! WOOCOMMERCE_CHECKOUT || ! wp_doing_ajax() || 'POST' !== ( $_SERVER['REQUEST_METHOD'] ?? '' ) || 'checkout' !== ( $_GET['wc-ajax'] ?? '' ) || 'recaptcha_v3' !== get_option( 'wc_blacklist_manager_premium_captcha_selected', 'none' ) ) { return false; } $token = $_POST['g-recaptcha-response'] ?? ''; if ( ! is_string( $token ) || '' === trim( $token ) ) { return false; } // Read only the vendor's successful, request-local cache; never session history. try { $read = Closure::bind( function ( $key ) { return isset( $this->request_validation_cache ) && is_array( $this->request_validation_cache ) && true === ( $this->request_validation_cache[ $key ] ?? false ); }, $validator, 'WC_Blacklist_Manager_Premium_Captcha_Base' ); return $read && $read( hash( 'sha256', 'recaptcha_v3|checkout|' . trim( $token ) ) ); } catch ( Throwable $error ) { return false; } } function tala_wrap_checkout_registration_captcha() { global $wp_filter; if ( ! class_exists( 'WC_Blacklist_Manager_Premium_Checkout_Captcha' ) || ! class_exists( 'WC_Blacklist_Manager_Premium_Captcha_Base' ) || empty( $wp_filter['woocommerce_registration_errors']->callbacks ) ) { return; } foreach ( $wp_filter['woocommerce_registration_errors']->callbacks as $priority => $callbacks ) { foreach ( $callbacks as $entry ) { $callback = $entry['function']; if ( ! is_array( $callback ) || ! isset( $callback[0], $callback[1] ) || ! $callback[0] instanceof WC_Blacklist_Manager_Premium_Checkout_Captcha || 'validate_captcha_woocommerce_register' !== $callback[1] ) { continue; } remove_filter( 'woocommerce_registration_errors', $callback, $priority ); add_filter( 'woocommerce_registration_errors', function ( $errors, $username, $email ) use ( $callback ) { if ( tala_checkout_registration_captcha_verified( $callback[0] ) ) { tala_record_checkout_captcha_diagnostic( 'checkout_registration_captcha_reused' ); return $errors; } return call_user_func( $callback, $errors, $username, $email ); }, $priority, 3 ); } } }