Skip to content

Commit b59d5af

Browse files
authored
WooCommerce Password Strength Add
1 parent 43c9f75 commit b59d5af

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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.&#13;
19+
add_action( 'woocommerce_checkout_init', 'wc_add_confirm_password_checkout', 10, 1 );&#13;
20+
function wc_add_confirm_password_checkout( $checkout ) {&#13;
21+
if ( get_option( 'woocommerce_registration_generate_password' ) == 'no' ) {&#13;
22+
$checkout-&gt;checkout_fields['account']['account_password2'] = array(&#13;
23+
'type' =&gt; 'password',&#13;
24+
'label' =&gt; __( 'Confirm password', 'woocommerce' ),&#13;
25+
'required' =&gt; true,&#13;
26+
'placeholder' =&gt; _x( 'Confirm Password', 'placeholder', 'woocommerce' )&#13;
27+
);&#13;
28+
}&#13;
29+
}&#13;
30+
// Check the password and confirm password fields match before allow checkout to proceed.&#13;
31+
add_action( 'woocommerce_after_checkout_validation', 'wc_check_confirm_password_matches_checkout', 10, 2 );&#13;
32+
function wc_check_confirm_password_matches_checkout( $posted ) {&#13;
33+
$checkout = WC()-&gt;checkout;&#13;
34+
if ( ! is_user_logged_in() &amp;&amp; ( $checkout-&gt;must_create_account || ! empty( $posted['createaccount'] ) ) ) {&#13;
35+
if ( strcmp( $posted['account_password'], $posted['account_password2'] ) !== 0 ) {&#13;
36+
wc_add_notice( __( 'Passwords do not match.', 'woocommerce' ), 'error' );&#13;
37+
}&#13;
38+
}&#13;
39+
}</code>
40+
</snippet>
41+
</snippets>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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 Remove Password Strength</name>
16+
<desc></desc>
17+
<tags>woocommerce</tags>
18+
<code>function wc_ninja_remove_password_strength() {&#13;
19+
if ( wp_script_is( 'wc-password-strength-meter', 'enqueued' ) ) {&#13;
20+
wp_dequeue_script( 'wc-password-strength-meter' );&#13;
21+
}&#13;
22+
}&#13;
23+
add_action( 'wp_print_scripts', 'wc_ninja_remove_password_strength', 100 );</code>
24+
</snippet>
25+
</snippets>

0 commit comments

Comments
 (0)