Giới thiệu
Gini Webseo là công ty thiết kế web chuyên nghiệp có trụ sở chính tại Hải Phòng. Gini cung cấp giải pháp phát triển doanh nghiệp, thiết kế website chuẩn SEO, hiện đại phù hợp với thị trường cũng như bộ nhận diện thương hiệu độc quyền.
Tình trạng spam tài khoản, hay khách hàng không nghiêm túc trong việc tạo tài khoản để spam đơn hàng. Mình khuyến khích các bạn thêm một field nhập nữa là “Nhập lại mật khẩu”.
Khá là đơn giản, bạn chỉ cần việc copy các đoạn sau đây vào file function.php là được. Ở đây có 2 trường hợp, mình sẽ tách ra làm 2 giúp các bạn dễ hiểu.
<?php // ----- Kiểm tra password ở trang đăng ký Woocommerce function registration_errors_validation($reg_errors, $sanitized_user_login, $user_email) { global $woocommerce; extract( $_POST ); if ( strcmp( $password, $password2 ) !== 0 ) { return new WP_Error( 'registration-error', __( 'Mật khẩu không trùng nhau.', 'woocommerce' ) ); } return $reg_errors; } add_filter('woocommerce_registration_errors', 'registration_errors_validation', 10,3); // ----- Thêm field Nhập lại mật khẩu ở trang đăng ký Woocommerce function wc_register_form_password_repeat() { ?> <p class="form-row form-row-wide"> <label for="reg_password2"><?php _e( 'Nhập lại mật khẩu', 'woocommerce' ); ?> <span class="required">*</span></label> <input type="password" class="input-text" name="password2" id="reg_password2" value="<?php if ( ! empty( $_POST['password2'] ) ) echo esc_attr( $_POST['password2'] ); ?>" /> </p> <?php } add_action( 'woocommerce_register_form', 'wc_register_form_password_repeat' );
// ----- Kiểm tra password ở trang thanh toán Woocommerce function lit_woocommerce_confirm_password_validation( $posted ) { $checkout = WC()->checkout; if ( ! is_user_logged_in() && ( $checkout->must_create_account || ! empty( $posted['createaccount'] ) ) ) { if ( strcmp( $posted['account_password'], $posted['account_confirm_password'] ) !== 0 ) { wc_add_notice( __( 'Mật khẩu không trùng nhau.', 'woocommerce' ), 'error' ); } } } add_action( 'woocommerce_after_checkout_validation', 'lit_woocommerce_confirm_password_validation', 10, 2 ); // ----- Thêm field Nhập lại mật khẩu ở trang thanh toán Woocommerce function lit_woocommerce_confirm_password_checkout( $checkout ) { if ( get_option( 'woocommerce_registration_generate_password' ) == 'no' ) { $fields = $checkout->get_checkout_fields(); $fields['account']['account_confirm_password'] = array( 'type' => 'password', 'label' => __( 'Nhập lại mật khẩu', 'woocommerce' ), 'required' => true, 'placeholder' => _x( 'Nhập lại mật khẩu', 'placeholder', 'woocommerce' ) ); $checkout->__set( 'checkout_fields', $fields ); } } add_action( 'woocommerce_checkout_init', 'lit_woocommerce_confirm_password_checkout', 10, 1 );
Đây là kết quả, có gì không hiểu hay không được, bạn hãy bình luận ở dưới nhé!
Tin tức liên quan
Hãy để Gini Webseo tư vấn cho bạn
không biết comfirm password
Không rõ bạn có khó khăn gì nói rõ chút hơn được không