Reserve Your Free Seat for Our Next WooCommerce Class! Search
Business Bloomer
  • Business Bloomer Club
  • WooCommerce Plugins
  • WooCommerce Tips
  • Log In
  • 0
  • Business Bloomer Club
  • WooCommerce Plugins
  • WooCommerce Tips
  • Log In
  • Search
  • Contact
  • Cart
WooCommerce Code Snippets Customer Registration My Account Spam

WooCommerce: My Account Registration Anti-Spam Honeypot

Last Revised: Aug 2023

STAY UPDATED

Here’s my personal attempt to fight against the WooCommerce My Account Page registration spam, without installing yet another captcha plugin.

I’m pretty sure this solution is not perfect, because spam bots are very “smart”, but it can help prevent most fake registrations.

The way I built it, is by adding a custom input field to the My Account Register form with an empty value. Hidden via CSS, this is not visible to the user – but it is visible to spam bots, which will try to post a value. The trick here is the validation check; an error will be generated if the input has a value, and therefore should prevent most fake registration to go through.

Take a look at the code, test it, and enjoy!

PHP Snippet: (Try to) Prevent Fake Spam Registrations @ My Account Page

/**
 * @snippet       Custom Captcha @ WooCommerce My Account Registration
 * @how-to        businessbloomer.com/woocommerce-customization
 * @author        Rodolfo Melogli, Business Bloomer
 * @compatible    WooCommerce 8
 * @community     https://businessbloomer.com/club/
 */

add_action( 'woocommerce_register_form', 'bbloomer_register_form_honeypot', 9999 );

function bbloomer_register_form_honeypot() {
    echo '<p style="opacity: 0; position: absolute; top: 0; left: 0; height: 0; width: 0; z-index: -1;"><input type="text" name="bb_reg_hp" value="" tabindex="-1" autocomplete="off"></p>';
}

add_filter( 'woocommerce_registration_errors', 'bbloomer_register_form_honeypot_check', 9999, 3 );

function bbloomer_register_form_honeypot_check( $errors, $username, $email ) {
    if ( isset( $_POST['bb_reg_hp'] ) && ! empty( $_POST['bb_reg_hp'] ) ) {
        $errors->add( 'registration-error-invalid-honeypot', 'Sorry, our system flagged this registration attempt as non-human.' );
    }
    return $errors;
}

Where to add custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

  • WooCommerce: Separate Login, Registration, My Account Pages
    There are times when you need to send logged out customers to a Login page and unregistered customers to a standalone Register page. As you…
  • WooCommerce: Add New Tab @ My Account Page
    One of the features of Business Bloomer Club is the provision of Premium WooCommerce Q&A Support to supporters who enroll. So, how to add an…
  • WooCommerce: How To Make A Website GDPR Compliant? (12 Steps)
    Ok, we all know that the EU General Data Protection Regulation (GDPR) will come into force on the 25th May 2018. So the main question…
  • WooCommerce Visual Hook Guide: My Account Pages
    Hey WooCustomizers, the Visual Hook Guide is back 🙂 In this episode, I’ve created a visual HTML hook guide for the WooCommerce Account Pages (there…
  • WooCommerce: Add First & Last Name to My Account Register Form
    Here’s yet another useful PHP snippet – and a mini-plugin alternative with super simple settings – that adds the Billing First Name and Billing Last…

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

8 thoughts on “WooCommerce: My Account Registration Anti-Spam Honeypot”

  1. Rudy
    March 19, 2024

    Added this to my functions.php a while a go. Still got thousands of spammers / fake registrations. So it doesn’t seem to work. Any update on this?

    Reply
    1. Rodolfo Melogli
      April 18, 2024

      I guess it could be that bots have gotten smarter lately and can bypass this. In my tests I had 0 spam, so it could also be that your website is a spam target and mine was not

      Reply
  2. Dragos Stancu
    October 4, 2023

    Hi,

    Thanks for your article.

    I added it to our code and it didn’t seem to work.
    I used a different action hook instead:

    function wooc_validate_extra_register_fields($username, $email, $validation_errors) {
        if (isset($_POST['website']) && !empty($_POST['website'])) {
            $validation_errors->add('registration_error_invalid_honeypot', 'Sorry, our system flagged this registration attempt as non-human.');
        }
        if (isset($_POST['billing_first_name']) && empty($_POST['billing_first_name'])) {
            $validation_errors->add('billing_first_name_error', __('<strong>Error</strong>: First name is required!', 'woocommerce'));
        }
        if (isset($_POST['billing_last_name']) && empty($_POST['billing_last_name'])) {
            $validation_errors->add('billing_last_name_error', __('<strong>Error</strong>: Last name is required!.', 'woocommerce'));
        }
        return $validation_errors;
    }
    add_action('woocommerce_register_post', 'wooc_validate_extra_register_fields', 10, 3);
    
    Reply
    1. Rodolfo Melogli
      October 14, 2023

      Thanks for sharing!

      Reply
      1. Julie Zinck
        January 7, 2024

        It’s strange, when I create an account, the password visibility eye doesn’t appear.

        Reply
        1. Rodolfo Melogli
          January 23, 2024

          Strange – can you try with the Storefront theme maybe?

          Reply
          1. Guillaume
            June 3, 2024

            Hello,

            Thank you for sharing this useful piece of code. By any chance, would you have the same functionality but for WooCommerce reviews?

            Best regards.

            Reply
            1. Rodolfo Melogli
              June 12, 2024

              I don’t, but it’s only a matter of changing the hook

              Reply
Questions? Feedback? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining the Business Bloomer Club to get quick WooCommerce support. Thank you!

Cancel reply

Your email address will not be published. Required fields are marked *


Search WooCommerce Tips

Popular Searches: Visual Hook Guides - Checkout Page - Cart Page - Single Product Page - Add to Cart - Emails - Shipping - Prices - Hosting

Recent Articles

  • WooCommerce: Redirect Empty Paginated Category Pages (404)
  • WooCommerce: Complete Button @ Order Admin
  • WooCommerce: Allow Guest Checkout For Existing Customers
  • WooCommerce: Simplify Free Checkout
  • WooCommerce: Inject Ad After the nth Product @ Shop Page

Latest Comments

  1. Rodolfo Melogli on WooCommerce: Prevent Duplicate Orders
  2. Rodolfo Melogli on WooCommerce: Remove “Get the app” Ad @ Admin Order Emails
  3. Rodolfo Melogli on WooCommerce: Failed Orders Monitor & Temporary Lockdown

Find Out More

  • Become a WooCommerce Expert
  • Business Bloomer Club
  • WooCommerce Blog
  • WooCommerce Weekly
  • Contact

Contact Info

Ciao! I'm Rodolfo Melogli, an Italian Civil Engineer who has turned into an international WooCommerce expert. You can contact me here:

Twitter: @rmelogli

Get in touch: Contact Page

Business Bloomer © 2011-2025 - VAT IT02722220817 - Terms of Use - Privacy Policy

Cart reminder?

x