is_registration_context() ) { return false; } return ! AgeOnce_API::is_verified( true, self::get_required_age() ); } /** * @param string[] $classes Body classes. * @return string[] */ public function registration_body_class( $classes ) { if ( $this->registration_submit_locked() ) { $classes[] = 'ageonce-registration-requires-verification'; } return $classes; } /** * Enqueue styles always on registration when feature is on; JS only while locked. */ public function enqueue_assets() { if ( ! self::is_feature_enabled() || ! $this->is_registration_context() ) { return; } $version = defined( 'AGEONCE_VERIFICATION_VERSION' ) ? AGEONCE_VERIFICATION_VERSION : '1.0.0'; $base = defined( 'AGEONCE_VERIFICATION_PLUGIN_FILE' ) ? AGEONCE_VERIFICATION_PLUGIN_FILE : dirname( __DIR__ ) . '/ageonce-verification.php'; wp_enqueue_style( 'ageonce-checkout-age-gate', plugins_url( 'assets/css/checkout-age-gate.css', $base ), array(), $version ); wp_enqueue_style( 'ageonce-registration-age-gate', plugins_url( 'assets/css/registration-age-gate.css', $base ), array( 'ageonce-checkout-age-gate' ), $version ); wp_enqueue_style( 'dashicons' ); if ( ! $this->registration_submit_locked() ) { return; } wp_enqueue_script( 'ageonce-registration-age-gate', plugins_url( 'assets/js/registration-age-gate.js', $base ), array( 'jquery' ), $version, true ); wp_localize_script( 'ageonce-registration-age-gate', 'ageonceRegistration', array( 'disableButtonTitle' => __( 'Please verify your age above', 'age-verification-with-ageonce' ), ) ); } /** * Render age gate (or verified notice) inside the WooCommerce register form. */ public function render_age_gate_area() { if ( ! self::is_feature_enabled() ) { return; } $required_age = self::get_required_age(); $is_verified = AgeOnce_API::is_verified( true, $required_age ); if ( $is_verified ) { ?>
add( 'ageonce_registration_unverified', __( 'Please verify your age before creating a store account.', 'age-verification-with-ageonce' ) ); } return $validation_error; } /** * Persist verification outcome on the new customer when session is verified. * * @param int $customer_id New user ID. */ public function save_user_verification_meta( $customer_id ) { $customer_id = absint( $customer_id ); if ( $customer_id <= 0 ) { return; } if ( ! AgeOnce_API::is_verified( true, self::get_required_age() ) ) { return; } update_user_meta( $customer_id, '_ageonce_status', 'verified' ); $tx_id = ( function_exists( 'WC' ) && WC()->session ) ? WC()->session->get( 'ageonce_transaction_id' ) : null; if ( $tx_id ) { update_user_meta( $customer_id, '_ageonce_transaction_id', sanitize_text_field( (string) $tx_id ) ); } $verified_at = ( function_exists( 'WC' ) && WC()->session ) ? WC()->session->get( 'ageonce_timestamp' ) : null; if ( ! $verified_at ) { $verified_at = current_time( 'mysql' ); } update_user_meta( $customer_id, '_ageonce_timestamp', sanitize_text_field( (string) $verified_at ) ); update_user_meta( $customer_id, '_ageonce_required_age', self::get_required_age() ); } }