|
| 1 | +<?xml version="1.0" encoding="UTF-8"?> |
| 2 | +<!-- This is a code snippets export file generated by the Code Snippets WordPress plugin. --> |
| 3 | +<!-- https://wordpress.org/plugins/code-snippets --> |
| 4 | +<!-- To import these snippets a WordPress site follow these steps: --> |
| 5 | +<!-- 1. Log in to that site as an administrator. --> |
| 6 | +<!-- 2. Install the Code Snippets plugin using the directions provided at the above link. --> |
| 7 | +<!-- 3. Go to 'Tools: Import' in the WordPress admin panel. --> |
| 8 | +<!-- 4. Click on the "Code Snippets" importer in the list --> |
| 9 | +<!-- 5. Upload this file using the form provided on that page. --> |
| 10 | +<!-- 6. Code Snippets will then import all of the snippets and associated information contained in this file into your site. --> |
| 11 | +<!-- 7. You will then have to visit the 'Snippets: All Snippets' admin menu and activate desired snippets. --> |
| 12 | +<!-- generator="Code Snippets/2.8.6" created="2017-06-14 16:11" --> |
| 13 | +<snippets> |
| 14 | + <snippet scope="2"> |
| 15 | + <name>WooCommerce Confirm Password</name> |
| 16 | + <desc></desc> |
| 17 | + <tags>woocommerce</tags> |
| 18 | + <code>// Add a second password field to the checkout page. |
| 19 | +add_action( 'woocommerce_checkout_init', 'wc_add_confirm_password_checkout', 10, 1 ); |
| 20 | +function wc_add_confirm_password_checkout( $checkout ) { |
| 21 | + if ( get_option( 'woocommerce_registration_generate_password' ) == 'no' ) { |
| 22 | + $checkout->checkout_fields['account']['account_password2'] = array( |
| 23 | + 'type' => 'password', |
| 24 | + 'label' => __( 'Confirm password', 'woocommerce' ), |
| 25 | + 'required' => true, |
| 26 | + 'placeholder' => _x( 'Confirm Password', 'placeholder', 'woocommerce' ) |
| 27 | + ); |
| 28 | + } |
| 29 | +} |
| 30 | +// Check the password and confirm password fields match before allow checkout to proceed. |
| 31 | +add_action( 'woocommerce_after_checkout_validation', 'wc_check_confirm_password_matches_checkout', 10, 2 ); |
| 32 | +function wc_check_confirm_password_matches_checkout( $posted ) { |
| 33 | + $checkout = WC()->checkout; |
| 34 | + if ( ! is_user_logged_in() && ( $checkout->must_create_account || ! empty( $posted['createaccount'] ) ) ) { |
| 35 | + if ( strcmp( $posted['account_password'], $posted['account_password2'] ) !== 0 ) { |
| 36 | + wc_add_notice( __( 'Passwords do not match.', 'woocommerce' ), 'error' ); |
| 37 | + } |
| 38 | + } |
| 39 | +}</code> |
| 40 | + </snippet> |
| 41 | +</snippets> |
0 commit comments