在网站上注册后,我想显示一个隐藏的divdiv在同一页面中。但是注册后,该页面将加载并显示同一页面。
这是form-handler.php
public static function process_registration() {
$nonce_value = isset( $_POST['_wpnonce'] ) ? $_POST['_wpnonce'] : '';
$nonce_value = isset( $_POST['woocommerce-register-nonce'] ) ? $_POST['woocommerce-register-nonce'] : $nonce_value;
if ( ! empty( $_POST['register'] ) && wp_verify_nonce( $nonce_value, 'woocommerce-register' ) ) {
$username = 'no' === get_option( 'woocommerce_registration_generate_username' ) ? $_POST['username'] : '';
$password = 'no' === get_option( 'woocommerce_registration_generate_password' ) ? $_POST['password'] : '';
$email = $_POST['email'];
try {
$validation_error = new WP_Error();
$validation_error = apply_filters( 'woocommerce_process_registration_errors', $validation_error, $username, $password, $email );
if ( $validation_error->get_error_code() ) {
throw new Exception( $validation_error->get_error_message() );
}
// Anti-spam trap
if ( ! empty( $_POST['email_2'] ) ) {
throw new Exception( __( 'Anti-spam field was filled in.', 'woocommerce' ) );
}
$new_customer = wc_create_new_customer( sanitize_email( $email ), wc_clean( $username ), $password );
if ( is_wp_error( $new_customer ) ) {
throw new Exception( $new_customer->get_error_message() );
}
if ( apply_filters( 'woocommerce_registration_auth_new_customer', true, $new_customer ) ) {
wc_set_customer_auth_cookie( $new_customer );
}
wp_safe_redirect( apply_filters( 'woocommerce_registration_redirect', wp_get_referer() ? wp_get_referer() : wc_get_page_permalink( 'myaccount' ) ) );
exit;
} catch ( Exception $e ) {
wc_add_notice( '<strong>' . __( 'Error', 'woocommerce' ) . ':</strong> ' . $e->getMessage(), 'error' );
}
}
}
和div
<div class="alert success">
<span class="closebtn">×</span>
<strong>Registration Success!</strong> Check Email.
</div>
这是js代码
jQuery('input.btn.btn-default.size-new-account').click(function() {
jQuery('.alert.success').show();
});
但是问题是,我如何了解注册流程,可以使用条件或其他方式。因此通知将显示验证是否成功,并在加载页面后显示。
处理完您的注册(PHP代码)后,执行以下行
wc_add_notice('Registration successful') ;
然后您不需要新的div