Posted on

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 consent. Or, you might need customer to acknowledge special shipping requirements for example.

So, how do we display an additional tick box on the Checkout page (together with the existing T&C checkbox)?

Add a privacy policy acceptance checkbox @ WooCommerce Checkout

PHP Snippet: Add Privacy Policy Acceptance Checkbox @ WooCommerce Checkout


/**
 * @snippet       Add privacy policy tick box at checkout
 * @how-to        Watch tutorial @ https://businessbloomer.com/?p=19055
 * @sourcecode    https://businessbloomer.com/?p=19854
 * @author        Rodolfo Melogli
 * @testedwith    WooCommerce 3.3.4
 */

add_action( 'woocommerce_review_order_before_submit', 'bbloomer_add_checkout_privacy_policy', 9 );
  
function bbloomer_add_checkout_privacy_policy() {
 
woocommerce_form_field( 'privacy_policy', 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 notice if customer does not tick
  
add_action( 'woocommerce_checkout_process', 'bbloomer_not_approved_privacy' );
 
function bbloomer_not_approved_privacy() {
    if ( ! (int) isset( $_POST['privacy_policy'] ) ) {
        wc_add_notice( __( 'Please acknowledge the Privacy Policy' ), 'error' );
    }
}

Where to add this code?

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

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.

If you think this code saved you time & money, please join other Business Bloomer supporters and avail of 365 days of WooCommerce benefits. Thank you in advance 🙂

Need Help with WooCommerce?

Check out these free videos, tutorials and tips!

  • how-to-edit-woocommerce-with-php-snippets
  • woocommerce-hooks-add_action-list-visual
  • woocommerce-customize-single-product-page-PHP
  • woocommerce-customize-shop-page-PHP
  • woocommerce-advanced-customization
  • how-to-edit-woocommerce-cart
  • woocommerce-customize-checkout-page-PHP
  • woocommerce-email-customization
  • woocommerce-conditional-logic

Rodolfo Melogli

Author, WooCommerce expert, WordCamp speaker and Internet marketer, Rodolfo Melogli has worked as a WooCommerce freelancer since 2011. He helps entrepreneurs and developers overcome their WooCommerce nightmares 🙂 Rodolfo is the organiser of WordCamp Dublin, the Dublin WooCommerce Meetup, the Dublin Ecommerce Meetup and the Dublin WordPress Meetup. He enjoys interacting with people, travelling and chasing tennis & soccer balls. Of course, he loves pizza too.

97 thoughts on “WooCommerce: Add Privacy Policy Checkbox @ Checkout

  1. Hi! I´ve been trying to add this to the My account Register form and failed hopelessly. Have you a similar snippet for the My Account Registration please?

  2. Hi, I have a siteweb in double languages, how I can insert the Privacy Policy Acceptance Checkbox @ WooCommerce Checkout” in due languages?
    If I add this code in the functions.php file in Italian, how I can translate in english?
    For the transaltion I use wpml.
    Thank you for your support.

  3. Hi, thanks so much for this!!!

    How to set to open the Policy in a new tab or IDEALLY inline (in a box under/over the text) like the T&C set default in WooCommerce?

    1. Hey Ivelina, 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

  4. Any chance of getting the webpage to open in a popup, the same as the standard woocommerce T’s and C’s?

    1. Hey Charles, 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

  5. Hi I paste the code but I can’t see the check-box in the CHECKOUT PAGE.
    But if I try to procede with the CHECKOUT it show me the error “Please acknowledge the Privacy Policy”.
    How can I see the check-box?

    Cioa, ho provato a copiare il codice ma, una volta nel carrello in fase di checkout, mi compare solo il box per il check dei termini e condizioni e non quello della privacy policy.
    Se però provo a procedere con l’ordine mi compare l’errore “Devi accettare la Privacy Policy”.
    Quindi sembra funzionare ma io non lo vedo (e quindi non posso fare il check per accettare privacy policy e completare l’acquisto)
    Come faccio a rendere visibile il check-box?

    Grazie,

    Samuele

    1. Hey Samuele, thanks for your comment! It must be a CSS problem maybe?

  6. Hi thanks for this, I have stripe as a payment option which brings up a pop up box to enter card details after the checkout button is clicked.

    So at the moment they don’t have to tick the option they can checkout without checking the box. Any ideas how to fix this?

    1. Hey Stephen, thanks for your comment! That’s the “Stripe modal” I guess. You can disable it via the settings and have people enter their card details on the WooCommerce checkout. In this way they also need to accept the Privacy. Hope this helps 🙂

  7. Tutto perfetto, solo un dubbio: il checkbox per la privacy, se non ho capito male, non dovrebbe essere flaggato obbligatoriamente dall’utente. Ovvero, l’utente dovrebbe avere la facoltà di scelta se accettare o meno la privacy, soprattutto qualora ci fossero finalità di marketing. E’ corretto?

    1. Hello Laura, thanks for your comment! I think you’re right, however if this is a WooCommerce order you need to collect personal data in order to create the order, invoice, etc. It’s my understanding that WooCommerce customers must accept the Privacy Policy (but I might be wrong) 🙂

  8. Ive copy and pasted this into my style.css but all the rows have a red x by the line. What am I doing wrong. Im a novice lol

    1. Hey Zee, thanks for your comment! This goes in your child theme’s functions.php 🙂

  9. By the way – I am not sure how to make the string “not bold” i.e. – regular text.

    Your suggestion will be appreciated -)

    1. Hey Alex, you’ll need to add some custom CSS to target the “woocommerce-form__label” class 🙂

  10. So far so good!

  11. Works perfectly! But how do i force the checkbox to be below the terms and conditions checkbox? It currently positions itself to the right and slightly lower (strangely enough) of the terms and conditions checkbox.

    1. Hey Fhilip, thanks for your comment! You’ll need a CSS fix in that case, sorry but I cannot help from here 🙂

  12. I’ve added the checkbox successfully. Link to privacy policy works fine. I check the box and the form does not submit. It returns the error as if i had forgotten to check the box.

    1. Hey Michael, thanks for your comment! I just tested again and I get no error. What PHP version are you on?

    2. Guess it would be helpful if I remembered to follow up on my question. PHP 7.0. Still getting the error. This is a development site, so no SSL yet.

    3. [php]
      // ADD PRIVACY POLICY CHECKBOX TO CHECKOUT

      function add_checkout_privacy_policy() {

      woocommerce_form_field( ‘privacy_policy’, 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 privacy policy‘,
      ));

      }
      add_action( ‘woocommerce_review_order_before_submit’, ‘add_checkout_privacy_policy’, 9 );

      // Show notice if customer does not tick

      function not_accepted_privacy() {
      if ( ! (int) isset( $_POST[‘privacycheck’] ) ) {
      wc_add_notice( __( ‘Please accept our privacy policy’ ), ‘error’ );
      }
      }
      add_action( ‘woocommerce_checkout_process’, ‘not_accepted_privacy’ );
      [/PHP]

    4. Well 🙂 Make sure the “$_POST[‘privacycheck’]” matches the name of the input, which in your case is ‘privacy_policy’. The error is there!

    5. Story of my life. It’s usually something incredibly obvious that I’m staring right at but don’t see. ;o) Thank you.

  13. I figured it out. This works well enough for me.

    .privacy {
    text-align: right;
    }

    Sorry to bother you.

    1. Excellent Paul 🙂

    2. Where exactly did you add this bit? I am trying to align the text, for the same reasons, but anywhere I have tried to add

      .privacy {
      text-align: right;
      }

      it tells me that there is an error.

      Any advice would be immensely appreciated!

    3. Hey Andrea, PHP goes in functions.php and CSS in style.css 🙂

  14. Another great tool. Thanks.
    Unfortunately, my “I’ve read and approve Terms and Conditions” is right justified but the “I’ve read and approve Privacy Policy” is left justified.
    Is there any easy fix?
    Thanks again.

  15. Hi Rodolfo,
    is it possible to have a double opt-in for the privacy acceptance where the user can choose if agree or not?
    And then, is there a way to put a text into the woocommerce email that inform the admin and the user about the choice made?

    Thank you for this perfect tip! 🙂

    1. Hey Simone, 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

  16. Thanks for this code!

    The notice is appearing as an ‘invalid label’ for me – a red dotted line appears under the ‘required’ asterisk and the text goes red. I noticed it is using the invalid label CSS because of this. Can you help?

    Andy

    1. Hey Andy, thanks for your comment 🙂 I’ve revised the snippet now, try using the latest version!

    2. Hi Rodolfo

      Thanks so much for your quick reply. I have added the latest snippet and am still getting the same error unfortunately 🙁

    3. Hey Andy! Are you on PHP 7? Another user had problems with PHP 5.6 🙂

  17. Hi Rolf.

    Great site – your blog and visual guides are a go-to resource for me – regularly!

    I’ve made great use of your GPDR guide and ended up on this page from there. I have added a “I’ve read and accept the privacy policy ” after the Terms and Conditions on the checkout page. I tested it in FireFox and Edge on my Windows PC and on my Windows phone. I’ve had many successful orders but have had two customers in the last two days saying that they have ticked both boxes but still get a “You must accept our Privacy Policy.” message so can’t checkout and pay. I quizzed the last and he said he was using IE on a PC. I have a version of IE and all is okay for me.

    I’ve modified the code a little from yours but is 99% much the same – the addition of the word privacy all over, a link to the privacy policy in a new window and a class to get the red *.

    /**
     * @snippet       Add extra tick box at checkout (for privacy policy)
     * @how-to        Watch tutorial @ https://businessbloomer.com/?p=19055
     * @sourcecode    https://businessbloomer.com/?p=19854
     * @author        Rodolfo Melogli
     * @testedwith    WooCommerce 3.2.6
     * Modified by JF e.g. red star!
     */
     
    add_action( 'woocommerce_review_order_before_submit', 'bbloomer_add_privacy_checkout_tickbox', 9 );
      
    function bbloomer_add_privacy_checkout_tickbox() {
     
    ?>
     
    <p class="form-row terms">
    <input type="checkbox" class="input-checkbox" name="privacycheck" id="privacycheck">
    <label for="privacycheck" class="checkbox">I've read and accept the <a href="MY URL REMOVED/privacy-policy/" target ="_blank">privacy policy</a></label>
    <span class="required">*</span>
    </p>
     
     
    <?php
     
    }
     
    // Show notice if customer does not tick privacy policy (on checkout page)
      
    add_action( 'woocommerce_checkout_process', 'bbloomer_not_approved_privacy' );
     
    function bbloomer_not_approved_privacy() {
        if ( ! (int) isset( $_POST['privacycheck'] ) ) {
            wc_add_notice( __( 'You must accept our Privacy Policy.' ), 'error' );
        }
    }
    

    Any ideas on what’s causing the problem please?

    Thanks very much,

    James

    1. Hey James, thanks for your comment 🙂 I’ve revised the snippet now, try using the latest version!

    2. Hi Rolf,

      Thanks for the swift fix.

      James

    3. Hi Rolf,

      Just heard from a customer who encountered the problem before the fix and is still getting the “You must accept our Privacy Policy” message when it is ticked so he can’t pay.

      He has tried with his iPhone running Safari and his desktop running IE7. I don’t know if he cleared his cache??

      I’ve got calls out with two others who had the same problem to see if it is fixed for them.

      Thanks,

      James

    4. Hey James, thanks for that! I just tested again and I get no error. What PHP version are you on?

    5. Morning. I’m running PHP version 5.6. Thanks, James

    6. That could be the reason 🙂 You should consider moving to PHP 7, it should be pretty easy via your hosting. Always test this on staging/clone environment before changing PHP version. Let me know!

    7. Thanks for the PHP update suggestion. I did this and put a note at the bottom of the checkout (using one of your visual guides!) to get in touch if you experienced the problem. I’ve had some orders placed successfully since and no-one one has reported it :-). I’ll take the note off in a couple of days.

  18. Thank you for this great guide!

    Do you know why the tickbox is not aligned with the text? I’ve simply copied and pasted the code.

    https://www.dropbox.com/s/3xmqik8eg94flgp/Checkbox%20PP.JPG?dl=0

    1. Thanks for your comment Bogdan! It could be simple HTML problem due to your custom HTML / theme CSS. Try starting the < label > tag before the < input > tag for example, play with those a little 🙂

  19. Thank you! Works great!

  20. Hi there.
    What a piece of code. Thanks!
    I was just wondering if the same checkbox could be move to every Woo product that we sell (appear on single product page just before add to cart button). For example, checkbox would appear on the single page of product A asking the user to acknowledge that they are buying product A, and would appear on single page of product B asking the user to acknowledge that they are buying product B etc.
    Is that possible?

    1. Hey Coach, 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

  21. I get the error:

    Your PHP code changes were rolled back due to an error on line 52 of file wp-content/themes/generatepress-child/functions.php. Please fix and try saving again.

    syntax error, unexpected ‘?’

    That’s point to the “?>” that’s on it’s own line – any ideas?

    1. Ouch, I think my editor stripped all the HTML tags – try again with the updated snippet please 🙂 Thanks for your patience!

  22. It looks like the error prompt isn’t working on new version on woocommerce. Is this any way to fix this? Cheers

    1. James, thanks so much for your comment! I just retested on Woo 3.2.6 and the error correctly displays when you click on “Pay” on the checkout and the field is not set:)

  23. This was really helpful. I have a coupon that requires acknowledgement, so I moved the tickbox into the woocommerce-checkout-review-order-table area and made it conditional when a certain coupon(s) is selected. Your code saved me a lot of work getting the order to fail when the box is not ticked.

    1. Brilliant, thanks for your comment Phil 🙂

  24. Thanks! Very good job but i have one problem… I have 2 languages in my site… The content of the text should change according to the type of language chosen. Could You help me?

    1. Ciao Simo, 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

  25. The code works perfectly for me, but I have encountered another issue, maybe I could get some help?

    I need this checkbox to become “not required” when something is written into textarea field. So for example, if it is not ticked and the textarea field is empty – it should still be required (it is by default), but if it is not ticked and the textarea field has at least one letter/symbol – the unticked checkbox should allow user to proceed. Is this possible?

    1. Hey Mantas, 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

  26. This doesn’t actually block the purchase if the checkbox is not checked though. How do you take the user back to the checkout page with the notice and require them to check the box?

    1. Hey Dima, thanks for your comment! Well, in the second part of the snippet it shows a notice that the checkbox has not been ticked. Is this not working?

  27. Thank you very much!

    1. You’re welcome Michael 🙂

  28. Where does it show if the customer who ordered checked the box or not? I am using it like “Add a free upgrade to your purchase” but I need to know if they actually check the box or not.

    1. Hello Wes, thanks for your comment! This snippet doesn’t behave like you want – in this case if the checkbox is not checked an error appears and checkout won’t be processed. You will need to customize the snippet to make it function in the way you need. Unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  29. Hi Rodolfo,

    You make some great custom extentions for woocommerce, thanks for that!
    I was wondering if it’s possible to change this one in a way that it functions as a newsletter subscription checkbox.

    Could you help me with that?

    1. Hey Sjoerd, thanks so much for your comment! Yes, this is possible and will depend on your Newsletter provider – unfortunately this is custom work and I cannot provide a complementary solution here on the blog. Thanks a lot for your understanding! ~R

  30. Hi Rodolfo,

    Great snippet!

    It it possible to only show the checkbox with paid products and hide it for free products?

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

  31. Hello,

    this code works fine, but I need two checkboxes on my order page. I pasted twice this code by renaming the function name, and id of the input, but the second checkbox in not displeyed, byt the error massage for it appears. Could You help me?

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

  32. […] código original de: https://businessbloomer.com/woocommerce-additional-acceptance-checkbox-checkout/ […]

  33. Very helpful, thanks! I would like to add this to a Registration page (for when someone creates an account) instead of the checkout page. What modifications would I make to your code so that it appears on the registration page?

    1. Hello Emily, thanks for your comment! This is a little custom so I can’t help here in the comments for free I’m afraid. All I can say is that you should look into the “WooCommerce” registration PHP template and find the right “hook”, then use this instead of the checkout one I used. hope this helps a little 🙂

  34. Hi thanks for the code, looks exactly what we are after, only one question can this be added to a child theme as I am guessing that every time woo-commerce updates this will be overwritten, or do I copy the checkout php into a sub folder so not to be overwritten, we have had issues in the past with the later method where the code can get out of date with the core.

    1. Hello Alan, thanks for your comment! Positive – this code definitely goes in your child theme’s functions.php file. I strongly recommend not to override/duplicate WooCommerce templates – if you need more guidance, please take a look at this video tutorial: https://businessbloomer.com/woocommerce-customization-hangout/

    2. Thanks very much for your speady feedback, I thought as much but just wanted to clarify, I will modify and test tomorrow but it looks a fantastic expansion well done.
      Alan

    3. Excellent, let me know 🙂

  35. Great snippet! Thank you very much for this.

    Do you think it is possible to use it in the Cart page instead of the Chekcout page?

    1. Thank you Susan 🙂 Yes, I’m sure it is possible, with a few modifications of course. You’ll need to change the “hook” (cart instead of checkout) and also – I believe – disable the “Proceed to Checkout” button unless the terms have been accepted. Happy coding 🙂

    2. Thanks a lot for your help Rodolfo!!!

    3. You’re welcome 🙂

  36. Thank you for this.

    I was recently informed that having additional tick boxes can possibly save your *** in a legal battle.

    Again: Much appreciated.

    1. Thank you Steven, very true! 🙂

  37. […] WooCommerce: Additional Acceptance Checkbox @ Checkout […]

  38. I will definitely be using this, thank you! Can this also be applied to specific products? Particularly back-ordered products?

    1. Awesome Sharon, thanks for your comment. The answer to your question is definitely yes! You can basically loop through the cart to see if there are products, and for each product see if they are backorders. I can’t develop the snippet now, but these two resources will help you:

      1) Loop through the cart and return true/false if some condition is met: http://isabelcastillo.com/woocommerce-check-shipping-class
      2) Function is_on_backorder, which return true/false if product is on backorder: https://docs.woothemes.com/wc-apidocs/source-class-WC_Product.html#638-646

      Hope this helps 🙂

    1. You’re welcome Jan! Thanks for your comment 🙂

Questions? Feedback? Support? Leave your Comment Now!
If you're writing code, please wrap it between: [php] code_here [/php]

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