Có thể bạn quan tâm
- Thay đổi số lượng khi đặt hàng với woocommerce
- Thêm nút tăng giảm số lượng sản phẩm khi thêm vào giỏ hàng trong woocommerce
- Hiển thị số sản phẩm đã bán trong woocommerce
- Hướng dẫn xóa product, product-category trong đường dẫn của woocommerce
- Xóa bỏ product-category và toàn bộ slug của danh mục cha khỏi đường dẫn của Woocommerce
Code dưới đây sẽ giúp chúng ta thêm field confirm password khi tạo tài khoản mới tại trang checkout của woocommer. Chúng ta chỉ việc thêm đoạn code dưới vào file functions.php trong theme bạn đang sử dụng là được.
Thêm confirm password vào trang checkout
Code cho woocommerce >=3.x Copy đoạn code dưới đây cho vào functions.php của theme đang sử dụng là được
/*Xác nhận mật khẩu khi tạo tài khoản dành cho woocommerce >=3.0*/ // place the following code in your theme's functions.php file // Add a second password field to the checkout page. add_action( 'woocommerce_checkout_init', 'wc_add_confirm_password_checkout', 10, 1 ); function wc_add_confirm_password_checkout( $checkout ) { if ( get_option( 'woocommerce_registration_generate_password' ) == 'no' ) { $fields = $checkout->get_checkout_fields(); $fields['account']['account_password2'] = array( 'type' => 'password', 'label' => __( 'Confirm password', 'woocommerce' ), 'required' => true, 'placeholder' => _x( 'Confirm Password', 'placeholder', 'woocommerce' ) ); $checkout->__set( 'checkout_fields', $fields ); } } // Check the password and confirm password fields match before allow checkout to proceed. add_action( 'woocommerce_after_checkout_validation', 'wc_check_confirm_password_matches_checkout', 10, 2 ); function wc_check_confirm_password_matches_checkout( $posted ) { $checkout = WC()->checkout; if ( ! is_user_logged_in() && ( $checkout->must_create_account || ! empty( $posted['createaccount'] ) ) ) { if ( strcmp( $posted['account_password'], $posted['account_password2'] ) !== 0 ) { wc_add_notice( __( 'Passwords do not match.', 'woocommerce' ), 'error' ); } } }
Code cho woocommerce <3.x
/*Xác nhận mật khẩu khi tạo tài khoản*/ // place the following code in your theme's functions.php file // Add a second password field to the checkout page. add_action( 'woocommerce_checkout_init', 'wc_add_confirm_password_checkout', 10, 1 ); function wc_add_confirm_password_checkout( $checkout ) { if ( get_option( 'woocommerce_registration_generate_password' ) == 'no' ) { $checkout->checkout_fields['account']['account_password2'] = array( 'type' => 'password', 'label' => __( 'Confirm password', 'woocommerce' ), 'required' => true, 'placeholder' => _x( 'Confirm Password', 'placeholder', 'woocommerce' ) ); } } // Check the password and confirm password fields match before allow checkout to proceed. add_action( 'woocommerce_after_checkout_validation', 'wc_check_confirm_password_matches_checkout', 10, 2 ); function wc_check_confirm_password_matches_checkout( $posted ) { $checkout = WC()->checkout; if ( ! is_user_logged_in() && ( $checkout->must_create_account || ! empty( $posted['createaccount'] ) ) ) { if ( strcmp( $posted['account_password'], $posted['account_password2'] ) !== 0 ) { wc_add_notice( __( 'Passwords do not match.', 'woocommerce' ), 'error' ); } } }
Chúc các bạn thành công!
- Bình luận