Add Google reCAPTCHA to WooCommerce Signup

That’s all I need “Add Google reCAPTCHA to WooCommerce Signup Form”. There are ton of plugins out there can satisfy this simple requirement. However they have more than what I need. So I googled the minimum requirement to reach the goal and try it out. Let’s check below and share if you find it helpful.

Google reCAPTCHA

Get Google reCAPTCHA Keys

Basically you need

  1. Site Key
  2. Secret Key

You can get the keys as well as learn more about Google reCAPTCHA at https://www.google.com/recaptcha/intro/index.html

Make it happens

Simply put below script into your WordPress theme’s functions.php

Final thoughts

You can replace woocommerce_register_form by register_form and woocommerce_register_post by register_post if you don’t use WooCommerce. Further customization can be found as below

There are many reasons for using WooCommerce and here are mine: E-Commerce readiness, prevent user from accessing backend.

Notify Admin On WooCommerce User Registration

As web site admin, I am so happy when receiving this kind of email, user registration notification. By default, WordPress will send web site admin notification email upon user registration. However I received none since I’ve used WooCommerce Custom Fields on REGISTER form. The web site didn’t notify admin (me) on user registration.

Notify Admin On WooCommerce User Registration

If we are using WooCommerce, user registration will done through process_registration action in WooCommerce. At that time, WordPress never send email notification to admin about new user. It only sends notification email for new orders. So to sort this out, we are going to call wp_new_user_notification WordPress notification function during new user registration by WooCommerce via woocommerce_created_customer hook.

function admin_email_on_registration( $customer_id) {
wp_new_user_notification( $customer_id );
}
add_action(‘woocommerce_created_customer’, ‘admin_email_on_registration’, 10 , 1);

Credit: http://sarathlal.com/send-admin-notification-on-woocommerce-user-registration/

Remove WooCommerce Password Strength Meter

One friend of mine signed up for new account. Actually, I invited him to signup for an account using “REGISTER” form that I created in this post so that we could test it one more time. He complained that I couldn’t change his password because the web site thinks his password is so weak (even it isn’t he thought). I googled and found the reason. It’s due to new feature introduced in WooCommerce 2.5: password strength meter. By default, user needs to use strong password for security purpose.

Remove WooCommerce Password Strength Meter

My very first user has priority so I need to remove it so that he can change his password. I added this function in my plugin.

function wc_ninja_remove_password_strength() {
if ( wp_script_is( ‘wc-password-strength-meter’, ‘enqueued’ ) ) {
wp_dequeue_script( ‘wc-password-strength-meter’ );
}
}
add_action( ‘wp_print_scripts’, ‘wc_ninja_remove_password_strength’, 100 );

Credit: https://nicola.blog/2016/01/27/remove-the-password-strength-meter-on-the-checkout-page/

WooCommerce Registration Custom Fields

There are many reasons for using WooCommerce. Here are mine E-Commerce readiness, prevent user from accessing backend. The second one convinced me significantly. I know there are plugins doing same job. Please share your own reasons if you are using WooCommerce on your WordPress site or blog.

This is how WooCommerce My Account looks by default

WooCommerce Default

And what we want: couple of custom fields added into the form: First Name, Last Name, Phone, Company, Subscribe to our newsletter and terms & privacy policy

WooCommerce Signup Custom Fields

Here are couple of steps that I am going to cover:

  1. Create plugin folder structure
  2. Adding custom fields on frontend
  3. Validate these custom fields
  4. Save custom fields data to database
  5. Redirect all logins to WooCommerce “My Account”
  6. Notify user about registration status

Ready? Let’s get started

Create plugin folder structure

If you like, you can put all these snippets below to function.php of active theme. However I would strongly recommend you to put it to a WordPress Plugin so that you can reuse, share and maintain it with ease.

I name my plugin as “woocommerce-registration-custom-fields” so I create folder with same name and inside it. I also create couple of sub folders (follows WordPress Plugin best practice).

  • admin
  • includes
  • languages
  • public

In this article, I only use root folder (i.e. woocommerce-registration-custom-fields) and “includes”. In root folder, I create “woocommerce-registration-custom-fields.php” and it looks like this

Adding custom fields on front-end

Validate these custom fields

Save custom fields data to database

Redirect all logins to WooCommerce “My Account”

Wrapping up

Here’s what you accomplished in this tutorial:

  1. Create plugin folder structure
  2. Adding custom fields on frontend
  3. Validate these custom fields
  4. Save custom fields data to database
  5. Redirect all logins to WooCommerce “My Account”
  6. Notify user about registration status

If you need everything at once, you can download ready-to-use plugin on github. Leave a comment or feedback right below.