Business Bloomer
  • About
  • WooCommerce Blog
  • Online Courses
  • Login
  • 0
  • About
  • WooCommerce Blog
  • Online Courses
  • Login
  • 0

WooCommerce: Add Privacy Policy Consent @ My Account Registration

> Published: May 2018 - Revised: Dec 2020
> Blog Category: WooCommerce Tips
> Blog Tags: GDPR, My Account, Privacy Policy
> Blog Comments: 47 Comments
Tweet

Join 15,000+ WooWeekly subscribers

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        Get CustomizeWoo.com FREE
 * @sourcecode    https://businessbloomer.com/?p=74128
 * @author        Rodolfo Melogli
 * @testedwith    WooCommerce 3.5.1
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

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;
}

Related posts:

  1. WooCommerce: Add Privacy Policy Checkbox @ Checkout
  2. WooCommerce: Add New Tab @ My Account Page
  3. WooCommerce: Hide or Rename a My Account Tab
  4. WooCommerce: How to Merge My Account Tabs
  5. WooCommerce: Add Content Under “Place Order” Button @ Checkout
  6. WooCommerce: Separate Login and Registration Pages
  7. WooCommerce: Allow Users to Edit Processing Orders
  8. WooCommerce: Deny Automatic Login Upon Registration @ My Account
  9. WooCommerce: Rename “My Account” If Logged Out @ Nav Menu
  10. WooCommerce: Add a Custom Download File @ My Account

Where to add this snippet?

You can place PHP snippets at the bottom of your child theme functions.php file (delete "?>" if you have it there). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such files - if you need more guidance, please take a look at my free video tutorial "Where to Place WooCommerce Customization?"

Does this snippet (still) work?

Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7.3.

If you think this code saved you time & money, feel free to join 14,000+ WooCommerce Weekly subscribers for blog post updates or 250+ Business Bloomer supporters for 365 days of WooCommerce benefits. Thank you in advance :)

Need Help with WooCommerce?

Check out these free video tutorials. You can learn how to customize WooCommerce without unnecessary plugins, how to properly configure the WooCommerce plugin settings and even how to master WooCommerce troubleshooting in case of a bug!

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
Category: WooCommerce Tips
Tags: GDPR, My Account, Privacy Policy

Post navigation

Previous post: WooCommerce: Disable Customer Order Email for Free Orders
Next post: WooCommerce: How to Enable Catalog Mode?

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

  1. 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
  2. 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
  3. 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
  4. Misbah
    July 30, 2020

    This one is great!

    Reply
    1. Rodolfo Melogli
      August 18, 2020

      Great!

      Reply
  5. 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
  6. 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
  7. 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
  8. [email protected]
    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
  9. 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
  10. 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
  11. 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
  12. 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
  13. 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
  14. 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
  15. Arno
    June 1, 2018

    Always very useful !

    Reply
    1. Rodolfo Melogli
      June 1, 2018

      Thank you 🙂

      Reply
  16. 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
  17. 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
  18. Nicola Mustone
    May 28, 2018

    Really nice idea! Good job!

    Reply
    1. Rodolfo Melogli
      May 29, 2018

      Thank you so much Nicola! Ciao 🙂

      Reply
  19. 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
  20. 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
  21. 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
  22. 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? Support? Leave your Comment Now!
_____

If you are writing code, please wrap it between shortcodes: [php]code_here[/php]. Failure to complying with this (as well as going off topic, not writing in English, etc.) will result in comment deletion. 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 BloomerArmada to get blog comment reply priority, ask me 1-to-1 WooCommerce questions and enjoy many more perks. Thank you :)

Cancel reply

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

Recent Posts
  • WooCommerce: Switch Shop Columns Responsively
  • WooCommerce: The Need For Custom Order Tables
  • WooCommerce: Get List Of All Customers
  • WooCommerce: How To Enable Stripe Payments
  • WooCommerce: Order Again Button @ My Account > Orders
About Business Bloomer

With 100,000 (and growing) monthly organic sessions, Business Bloomer is the most consistent, most active and most complete WooCommerce development/customization blog.

Of course this website itself uses the WooCommerce plugin, the Storefront theme and runs on a WooCommerce-friendly hosting.

Join 150,000+ Monthly Readers & 14,000+ Subscribers.

Become a Business Bloomer Supporter.

Join BloomerArmada and become an Official Business Bloomer Supporter:
easy-peasy, and lots of perks for you.
See your Benefits →
Popular Searches: Visual Hook Guides - Checkout Page - Cart Page - Single Product Page - Add to Cart - Emails - Shipping - Prices - Hosting
Latest Articles
  • WooCommerce: Switch Shop Columns Responsively
  • WooCommerce: The Need For Custom Order Tables
  • WooCommerce: Get List Of All Customers
  • WooCommerce: How To Enable Stripe Payments
  • WooCommerce: Order Again Button @ My Account > Orders
Latest Comments
  • Rodolfo Melogli on WooCommerce: 10 Crucial Issues That Should Be Fixed Right Now
  • Rodolfo Melogli on WooCommerce: 10 Crucial Issues That Should Be Fixed Right Now
  • Telkom on WooCommerce: 10 Crucial Issues That Should Be Fixed Right Now
  • Tomás Testart on WooCommerce: 10 Crucial Issues That Should Be Fixed Right Now
Find Out More
  • Become a WooCommerce Expert
  • WooCommerce Blog
  • WooCommerce Online Courses
  • WooCommerce Weekly
  • Bloomer Armada
  • Affiliate Program
  • 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:

Email: [email protected]

Twitter: @rmelogli

Hire me by the hour: Get Quote »

VisaMastercardAmexPayPal Acceptance Mark
Business Bloomer © 2011-2022 - Terms of Use - Privacy Policy