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 GDPR My Account Privacy Policy

WooCommerce: Add Privacy Policy Consent @ My Account Registration

Last Revised: Dec 2020

STAY UPDATED

Here’s a snippet regarding the “My Account” registration form and, once again, GDPR. If you get any website traffic from EU, you will need users to give you Privacy Policy consent – including when they register a new account on your WooCommerce website.

So, how do we display a checkbox on the My Account page, at the bottom of the registration form?

WooCommerce: add Privacy Policy consent to the My Account registration form

PHP Snippet: Add Privacy Policy Checkbox @ WooCommerce My Account Registration Form


/**
 * @snippet       Add Privacy Policy Checkbox @ WooCommerce My Account Registration Form
 * @how-to        businessbloomer.com/woocommerce-customization
 * @sourcecode    https://businessbloomer.com/?p=74128
 * @author        Rodolfo Melogli, Business Bloomer
 * @testedwith    WooCommerce 3.5.1
 * @community     https://businessbloomer.com/club/
 */

add_action( 'woocommerce_register_form', 'bbloomer_add_registration_privacy_policy', 11 );
  
function bbloomer_add_registration_privacy_policy() {

woocommerce_form_field( 'privacy_policy_reg', array(
	'type'          => 'checkbox',
	'class'         => array('form-row privacy'),
	'label_class'	=> array('woocommerce-form__label woocommerce-form__label-for-checkbox checkbox'),
	'input_class'	=> array('woocommerce-form__input woocommerce-form__input-checkbox input-checkbox'),
	'required'      => true,
	'label'         => 'I\'ve read and accept the <a href="/privacy-policy">Privacy Policy</a>',
));
 
}
 
// Show error if user does not tick
  
add_filter( 'woocommerce_registration_errors', 'bbloomer_validate_privacy_registration', 10, 3 );
 
function bbloomer_validate_privacy_registration( $errors, $username, $email ) {
if ( ! is_checkout() ) {
    if ( ! (int) isset( $_POST['privacy_policy_reg'] ) ) {
        $errors->add( 'privacy_policy_reg_error', __( 'Privacy Policy consent is required!', 'woocommerce' ) );
    }
}
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: Add Privacy Policy Checkbox @ Checkout
    Here’s a snippet regarding the checkout page. If you’ve been affected by GDPR, you will know you now need users to give you Privacy Policy…
  • 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…

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

49 thoughts on “WooCommerce: Add Privacy Policy Consent @ My Account Registration”

  1. Jacek
    May 7, 2024

    Hello,
    Any tip how to fix it for block editor?

    Reply
    1. Rodolfo Melogli
      May 15, 2024

      Not possible, sorry.

      Reply
  2. Vincenzo
    March 23, 2022

    Thank you Rodolfo for information πŸ˜‰

    There is a way to save this user action by “database list”? To tracking user and acceptance of the conditions, like into contact form for GPDR.

    Thank you,

    Vincenzo

    Reply
    1. Rodolfo Melogli
      March 25, 2022

      Ciao Vincenzo, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

      Reply
  3. Dave
    October 4, 2020

    I found help on Stackoverflow how to add the HTML5 require attribute to the tag. You need to add this:

    function filter_woocommerce_form_field_checkbox( $field, $key, $args, $value ) {
        // Based on key
        if ( $key == 'privacy_policy_reg' ) {
            $field = str_replace( '&lt;input&#039;, &#039;&lt;input required&#039;, $field );
        }
        
        return $field;
    }
    add_filter( &#039;woocommerce_form_field_checkbox&#039;, &#039;filter_woocommerce_form_field_checkbox&#039;, 10, 4 );
    
    Reply
    1. Rodolfo Melogli
      October 16, 2020

      Nice, but does it actually validate and stop the registration?

      Reply
  4. Andrei
    August 10, 2020

    Hello. Does it work with code snippets plugin? Because I just tried it like that and the check box or text don’t show up on the checkout page. Thank you.

    Reply
    1. Rodolfo Melogli
      August 18, 2020

      Yes – tried with a different theme also?

      Reply
  5. Misbah
    July 30, 2020

    This one is great!

    Reply
    1. Rodolfo Melogli
      August 18, 2020

      Great!

      Reply
  6. Jorge
    June 2, 2020

    Hi Rodolfo!
    I need to add a checkbox below or beside the create account checkbox in the finish buy page of woocommerce.
    it has to be: “I accept the register privacy policy” checkbox, neccessary clickable for craete account, you know.
    Important: this checkbox has to be different to the two checkboxes below the “finish buy button” ( terms and conditions and privacy policy)
    Thank you very much.

    Reply
    1. Rodolfo Melogli
      June 2, 2020

      Hola Jorge, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

      Reply
  7. Alfonso
    February 7, 2020

    Hi Rodolfo,
    excellent post like everyone in your blog.
    Is it possible to save consent in the profile of the user who registered on the website?

    Reply
    1. Rodolfo Melogli
      February 14, 2020

      Thank you! Yes, use something similar to https://businessbloomer.com/woocommerce-save-terms-conditions-user-acceptance-checkout/

      Reply
  8. JoΓ£o Ferreira
    February 7, 2020

    Hello Rodolfo,

    I installed the hook on functions.php, but just text is showing. The checkbox don’t show, can you help?

    Thanks in advance

    Reply
    1. Rodolfo Melogli
      February 14, 2020

      Did you use the exact snippet?

      Reply
      1. JoΓ£o Ferreira
        June 12, 2020

        Hello Rodolfo,

        Yes! I’m using this exact snippet

        Reply
        1. Rodolfo Melogli
          June 15, 2020

          Disable all plugins but Woo and switch theme, test again πŸ™‚

          Reply
  9. mfreixa@exonmedia.es
    January 29, 2020

    Hey1

    First of all thank you for this code. I’ve been using it for a long time but now is giving me some little problems.

    When I register an user trough the register form and then you click the “user icon” to login or register in the top-right of the website) when the user doesn’t check the checkbox it just redirects the user to the home page but is not displaying any error… so sometimes can be confusing for some users to understand that the have not registered.

    Reply
    1. Rodolfo Melogli
      February 4, 2020

      Hi there, thanks for your comment! If you temporarily disable all plugins but Woo and switch theme, does the snippet work?

      Reply
  10. Hal
    August 30, 2019

    Hi, thank you for this example.
    There is some bug in woocommerce I think, that prevents the woocom native privacy checkbox from displaying in checkout page in some scenarios. So I tried to use your code, only hooking on to woocommerce_after_checkout_billing_form instead of woocommerce_register_form. So the checkbox displays, but I still get the error msg
    ‘Please acknowledge the Privacy Policy’
    What should be the name of the checkbox input to make woocommerce reckognize it?

    Reply
    1. Rodolfo Melogli
      September 6, 2019

      Hello Hal, try with https://businessbloomer.com/woocommerce-additional-acceptance-checkbox-checkout/

      Reply
  11. khalid.oliveroute
    March 18, 2019

    Its not working for me my changes are getting reverted with php. And if i try style.css in my child theme it shows 69 errors should i try style.css?

    Reply
    1. Rodolfo Melogli
      March 28, 2019

      Hey Khalid, what error are you getting? This goes in functions.php

      Reply
  12. Roberto
    January 9, 2019

    It works perfectly! Could you add the possibility to save the check on the database?

    Reply
    1. Rodolfo Melogli
      January 10, 2019

      Hey Roberto, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

      Reply
  13. Mirta
    December 10, 2018

    Hi Rodolfo.
    Can you help me to add a second checkbox that links another additional Privacy Page?
    What is the best way please? I see that duplicate is not the best way and my site go to error 500.

    Thanks.
    Mirta

    Reply
    1. Rodolfo Melogli
      December 11, 2018

      Hi Mirta, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ~R

      Reply
  14. RadosΕ‚aw Pachowicz
    July 2, 2018

    Hi! Great stuff, thanks! It would be awesome if you could show how to add an optional checkbox to registration page, and how to display the status of it on user profile pages (backend/frontend).

    Reply
    1. Rodolfo Melogli
      July 4, 2018

      Hey Radoslaw, thanks for your comment! Here you go: https://businessbloomer.com/woocommerce-add-privacy-policy-consent-my-account-registration

      Reply
  15. Bill
    June 4, 2018

    Hello,

    great snippet and it works great on the My Account page.

    I can see though that this causes an issue when a user will try to register to the site via the checkout page ,
    as the checkbox to opt in for the Privacy Policy is not appearing there and “Privacy Policy consent is required!” is showing – thus preventing the user from placing an order!

    Any workarounds here?

    Would it better if just added a text as done here? > https://businessbloomer.com/woocommerce-add-content-under-place-order-button-checkout/

    Thank you!

    ___
    WP 4.9.5 – WC 3.2.6

    Reply
    1. Rodolfo Melogli
      June 6, 2018

      Hey Bill, thanks for that, good point πŸ™‚ I added:

      if ( ! is_checkout() ) {
      

      … to both parts of the snippet. Can you test again please?

      Reply
  16. Arno
    June 1, 2018

    Always very useful !

    Reply
    1. Rodolfo Melogli
      June 1, 2018

      Thank you πŸ™‚

      Reply
  17. Sam
    May 30, 2018

    Could we make it so they have to tick that box each time they log in too? That way it’ll capture all the current members too.

    Reply
    1. Rodolfo Melogli
      June 1, 2018

      Hello Sam, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

      Reply
  18. Sean
    May 29, 2018

    Hi Rodolfo

    I tried this and it seems to be working now! However the codes I copied & pasted disappeared from the child theme function.php, is this normal?

    Reply
    1. Rodolfo Melogli
      June 1, 2018

      Cool Sean πŸ™‚ No, it’s not normal… what happened?

      Reply
  19. Nicola Mustone
    May 28, 2018

    Really nice idea! Good job!

    Reply
    1. Rodolfo Melogli
      May 29, 2018

      Thank you so much Nicola! Ciao πŸ™‚

      Reply
  20. Gary
    May 26, 2018

    Works perfectly Rodolfo. Thank you. Really great website resource btw. Just discovered you and I like what I read.

    Reply
    1. Rodolfo Melogli
      May 28, 2018

      Brilliant πŸ™‚

      Reply
  21. Guillermo
    May 25, 2018

    Many thanks for this. It is working great on some of my pages BUT on others it shows correctly but no errors are shown if I don’t tick the checkbox or even if I do not enter an email. What could this be??

    Reply
    1. Guillermo
      May 25, 2018

      Ok I figured it out. It was the Advanced noCaptcha & invisible Captcha Plugin messing about.

      Just a couple of questions:
      1. If I wanted to add a second checkbox (I am over 13 years of age, etccc) can I just duplicate de module
      2. Is the consent recorded anywhere?

      Again, many thanks.

      Reply
      1. Rodolfo Melogli
        May 28, 2018

        Excellent πŸ™‚ Yes, you can add as many checkboxes as you like. To save them, take a look at https://businessbloomer.com/woocommerce-save-terms-conditions-user-acceptance-checkout/

        Reply
  22. Fabrizio
    May 25, 2018

    Hi Rodolfo,
    thanks for the new amazing snippet. I only would like to know if there’s a way to output the “I’ve read and accept the Privacy Policy” label also in other language. I have a multilanguage website with polylang plugin.
    Thanks again for your availability.

    Reply
    1. Rodolfo Melogli
      May 28, 2018

      Hey Fabrizio, thanks for your comment! In order to make a string translatable you have to wrap it in a __() function: https://codex.wordpress.org/I18n_for_WordPress_Developers#Translatable_strings – hope this helps πŸ™‚

      Reply
  23. Angelo
    May 25, 2018

    works perfectly!!!!! thank you!!!!! another master piece from you!!!! grazie!!!

    Reply
    1. Rodolfo Melogli
      May 25, 2018

      Excellent πŸ™‚

      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: How to Stop Spam Orders on Free Products
  • WooCommerce: How to Configure Product and Order Sync
  • WooCommerce: “Beautify” Item Meta in Order Emails
  • WooCommerce: Per-Product Checkout Fees / Tariffs
  • WooCommerce: Auto-Cancel Orders After 3 Failed Payments

Latest Comments

  1. Eduard on WooCommerce Add To: Cc: Bcc: Email Recipients Mini-Plugin
  2. Rodolfo Melogli on WooCommerce: Remove “Payments” From WordPress Sidebar Admin Menu
  3. Rodolfo Melogli on WooCommerce: Remove “Payments” From WordPress Sidebar Admin Menu

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