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        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 3.6.3
 * @community     https://businessbloomer.com/club/
 */
 
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 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: Cart and Checkout on the Same Page
    This is your ultimate guide – complete with shortcodes, snippets and workarounds – to completely skip the Cart page and have both cart table and checkout form on the same (Checkout) page. But first… why’d you want to do this? Well, if you sell high ticket products (i.e. on average, you sell no more than […]
  • WooCommerce: Disable Payment Method If Product Category @ Cart
    Today we take a look at the WooCommerce Checkout and specifically at how to disable a payment gateway (e.g. PayPal) if a specific product category is in the Cart. There are two tasks to code in this case: (1) based on all the products in the Cart, calculate the list of product categories in the […]
  • WooCommerce: Redirect to Custom Thank you Page
    How can you redirect customers to a beautifully looking, custom, thank you page? Thankfully you can add some PHP code to your functions.php or install a simple plugin and define a redirect to a custom WordPress page (as opposed to the default order-received endpoint). This is a great way for you to add specific up-sells, […]
  • WooCommerce: Disable Payment Gateway by Country
    You might want to disable PayPal for non-local customers or enable a specific gateway for only one country… Either way, this is a very common requirement for all of those who trade internationally. Here’s a simple snippet you can further customize to achieve your objective. Simply pick the payment gateway “slug” you want to disable/enable […]
  • WooCommerce: Disable Payment Gateway for Specific User Role
    You may want to disable payment gateways depending on the logged in user role. For example, you may want to disable PayPal for user role “subscriber” or enable a specific gateway for user role “customer”. All you need is to paste the following code in your functions.php or to install a super simple plugin. Enjoy!

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

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

  1. Hello,
    Is it still works with new Woocomemrce?
    Thanks for answer

    1. Hey Jacek, what error are you getting?

  2. Hi,
    I want to display another checkbox after the Privacy Policy one. Can you please guide me on how I can add the second one? Thank you.

    1. Hello Mark, 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!

  3. Thank you. This post was a great help. One question: the size of the text next to the checkbox is bigger than of the text to the pre-installed “CTG” checkbox. Could you please show me how to fix the font size? Thanks!

    1. Hi Carmen you probably need to reuse the same CSS classes, or apply some custom CSS

  4. Hi! Thanks for all your snippets 🙂 They are great! Have one question regarding this one. Is it possible to show checkbox on checkout field when user selects “New Account” checkbox? That would help a lot

    1. Hi Lukas, 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!

  5. Hello,

    i need a checkbox snippet for the product review. I use the Woodmart Theme. Any idea ?

    1. Hi Andrej, 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!

  6. It’s not working for my site. And found no issue.

    1. Even if you disable all plugins but Woo and switch theme temporarily?

  7. Hi, how can I show privacy inline on click, like terms?

    1. Hi Radu, 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!

  8. Why would you type cast isset() to int when that function returns to boolean already.

    1. Sure, feel free to remove it

      1. Hello I would like to place this checkbox above name field, how can I do it?

        1. Hi Andrea, 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!

  9. Hi I think this will do exactly what I need.
    Just one question when the user ticks the box and submits the order will the confirmation be shown in the order details in the admin backend?

    Thanks

  10. Hi,

    This snippet brake the website.

    WordPress 5.4.1
    Storefront 2.5.7

    1. What error did you get? Works for me

  11. Hey Rodolfo,

    snippet is still working. Thanks very much for the code!!!

    Regards

    1. Awesome!

  12. I hope this comment will find an answer, if now, it am doomed. :))
    I used you script and its working perfect.
    However, i want to add a condition.
    I want to display privacy policy only to products that are in Category: Pre-Orders. (in the checkout)
    can you help a brother in need out ?

    Thanks
    Alex

    1. Hi Alex, 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!

  13. Hi! Great snippet! One question: Currently when a user clicks on the privacy policy this directs them to this page, and therefore away from the checkout page. Would it be possible to make it so the link opens the privacy policy page in another tab?

    Thanks in advance 🙂

    1. Hi Mikael, 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!

  14. It’s 2020 and your code still works perfectly. I just found it, thank you so much for sharing!

    1. Brilliant!

  15. Hi. It works and works great.
    I changed the text a bit and aiming for SMS/Email marketing acceptance so I did it as an optional field (not required).
    My question is how can I view on the back-end who clicked and who accept this – so that I know that I can send them newsletters and such…
    Thanks

  16. Hiya this was working perfectly but now has stopped. When I’ve tried to read the snippet I’m getting an error for the
    function bbloomer_add_checkout_privacy_policy() {

    Line, it’s saying

    syntax error, unexpected ‘add_checkout_privacy_policy’ (T_STRING)

    What has changed that would cause this to stop working suddenly?

    Thanks 🙂

    1. Hi Elly! Did you forget “bbloomer_” in front of the function name? It should read “bbloomer_add_checkout_privacy_policy”

  17. Hi Rudolfo,

    How can I see in the backend that people have agreed to this? I have deleted required! People do not necessarily have to accept it. I hope to get an answer from you.

    Sincerely,
    Jeffrey

    1. Hello Jeffrey, 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!

  18. It works great with the latest versions of WordPress and WooCommerce. Thanks!

    I’d like to know if it’s possible to change the order in which this error appears. Say you have a checkout form with name, email, phone and this privacy policy.
    If I don’t fill none of the fields I’ll get 4 errors, and this last one will be on top of the list. Is there a way to push it to the end?

    Thanks again!

    1. Hi Antonio, 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!

  19. Works!!!!THANKS

    1. Great!

  20. Hi Rodolfo,
    your code was totally helpful once I deal with website!
    But now, based on your solution, I want to add the next checkbox for sms marketing consent.
    Do you think is it possible to update your script and use it for two checkboxes – one for privacy policy and the second one for sms marketing consent?

    1. Hi Bart, 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!

  21. Hey ! Ciao Rodolfo,
    Could you please tell me, is there a way to make this Privacy Policy checkbox at checkout optional rather than required?
    Many thanks
    Andrea

    1. Hello Andrea, yes, just remove the validation bit

  22. hi rodolfo, i would like to add multilanguage, because my shop is also in IT and DE, can you give me some advice where to put

    $currentlang = get_bloginfo('language');
    if($currentlang=="it-IT") { ?&gt;
    		italiano
    
    		tedesco
    		&lt;?php } else
    
    1. Hello Hannes, thanks so much for your comment! Yes, this is possible – 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

    2. i was ably to change the code by myself, thank you
      i tested it on woocommerce 3.5.3 and it still work – does it work also on woocommerce 3.6 ?

      1. Yes it should 🙂

  23. Hi, Great snippet, Thanks
    1. I’m trying to get it checked by default, how can I achieve that?
    2. Can I remove the error? meaning it would not be required?
    Thank you

    1. Hey David, thanks for your comment! If this is for GDPR purposes, checking the checkbox by default is not acceptable 🙂 And yes, you can remove the error bit if you like

  24. Hey

    Thanks for your time to write this tip!! I have a question. It works fine, but in my case, first WC fields are validated, then credit card and finally, the new checkbox of Privacy. I wonder if it’s possible to change the validation order to:

    1. Woocommerce fields
    2. New checkbox of Privacy
    3. Credit Card fields

    Thanks again,
    Cheers

    1. Hello Kure, 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. I saw your post on adding to database: https://businessbloomer.com/woocommerce-save-terms-conditions-user-acceptance-checkout/

    Could you provide details on how to make that work with this custom privacy policy checkbox vs. terms?

    1. Hello Ryan, 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

  26. Hi Rodolfo,

    Just letting you know people are still finding this article and using the code. Works like a charm. Very helpful. Thanks!

    Ciao!
    Guido

    1. Excellent! Grazie Guido 🙂

  27. Thanks for the jump start. You could also add this to the ‘woocommerce_checkout_terms_and_conditions’ action hook instead, with some nice result.

    1. Brilliant, thanks for the tip 🙂

  28. Hello Rodolfo,

    thanks for your useful snippet!

    WC 3.4.0 added registration / checkout privacy policy text, but, as far as I could understand, it’s an implicit consent, without any, separate, mandatory checkbox.

    Your snippet, instead, allows explicit consent, but it does not store any information in the database, it’s only front-end input (same as WC Checkout Terms), is it right?

    As far as I could understand it’s not enough, you must get verifiable consent from users; in other terms, it’s mandatory that you keep records and that you’re able to demonstrate that the user has given consent, how and when.

    Do you suggest hooking in

    woocommerce_checkout_update_user_meta

    to add a user meta with

    privacy_consent = 1

    and

    privacy_consent_date = time()

    ?
    And then to hide privacy checkbox for this user if he has already accepted previously?
    Otherwise, if you have to require consent for each new order is better to save consent as order meta in

    woocommerce_checkout_update_order_meta

    .

    Thanks,
    Davide

    1. Hello Davide, thanks so much for your comment! Yes, you can totally “save” the acceptance with something similar to this: https://businessbloomer.com/woocommerce-save-terms-conditions-user-acceptance-checkout/ – also your suggestion for the update order meta is a good idea, but if you want to assign tat to the user instead maybe you should update the user_meta 🙂 Hope this helps!

    2. Hello Rodolfo,
      exactly what I meant, I had not seen this other your snippet, great!

      However, talking with lawyers it emerged that the consent checkbox should be enough during registration (with proof of consent).
      Once the Privacy Policy has been accepted, it is not necessary to ask to accept it for every order (unless the Privacy Policy has been modified, but in that case you would send a notification to those who already accepted, as many others do by email or banner on the website).
      Then, on Checkout the implicit sentence introduced in WC 3.4 may be enough.
      Clearly, if you allow the checkout also for guests, the checkbox is also useful during checkout, so it depends on how the store is configured 😉

      Anyway, thanks again for your resources!
      Best,
      Davide

      1. Excellent, grazie Davide 🙂

  29. Hi there!
    Is it possible to have 2 checkboxes instead of just one?
    thanks! 🙂

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

    2. Sorry i realy need help with checkbox on cart page, i would like to ad checkbox before the button proceed to checkout, and i did it, but when i dont mark it, its till follow the form and takes me to next page. Could u look on it ?

      
      add_action( 'woocommerce_after_cart_table', 'bbloomer_add_checkout_privacy_policy', 11 );
         
      function bbloomer_add_checkout_privacy_policy() {
        
      woocommerce_form_field( 'privacy_policy', array(
          'type'          =&gt; 'checkbox',
          'class'         =&gt; array('form-row privacy'),
          'label_class'   =&gt; array('woocommerce-form__label woocommerce-form__label-for-checkbox checkbox'),
          'input_class'   =&gt; array('woocommerce-form__input woocommerce-form__input-checkbox input-checkbox'),
          'required'      =&gt; true,
          'label'         =&gt; 'I\'ve read and accept the <a href="/privacy-policy" rel="nofollow">Privacy Policy</a>',
      )); 
        
      }
        
      // Show notice if customer does not tick
         
      add_action( 'woocommerce_after_cart_table', 'bbloomer_not_approved_privacy' );
        
      function bbloomer_not_approved_privacy() {
          if ( ! (int) isset( $_POST['privacy_policy'] ) ) {
              wc_add_notice( __( 'Please acknowledge the Privacy Policy' ), 'error' );
          }
      
      }
      
      
      1. Sorry, can’t help here 🙂

  30. Hi,

    Is it possible that the snippet does not work with Woocommerce 3.4.0. and WordPress version 4.9.6?

    Thanks!

    Best regards,
    Freckles

    1. Hey Freckles – it should work 🙂 Try with another theme and no other plugins than Woo and see if it works!

  31. Hello,
    I tried your snippet and it works in part. If I click on CONTINUE ON PAYPAL without having flagged the box, the site redirects me to Paypal without giving an error.

    1. Hey Valeria 🙂 Is that PayPal express?

  32. Works perfectly! Many thanks!

  33. Hi,
    i placed php code in functions.php and checkbox is showing, but even if i check that i agree with privacy policy, i get a message “Please acknowledge the Privacy Policy”.
    Also, checkbox is showing next to the terms and conditions checkbox, how should i move it to the next row?
    Tnx

    1. Hey Ljupka, did you change the snippet at all? Because this version works like a charm. For the other issue, you will need to add some custom CSS. Hope this helps 🙂

  34. 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?

  35. 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.

  36. 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

  37. 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

  38. 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?

  39. 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 🙂

  40. 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) 🙂

  41. 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 🙂

  42. 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 🙂

  43. So far so good!

  44. 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 🙂

  45. 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]

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

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

  46. 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!

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

  47. 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.

  48. 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

  49. 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 🙁

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

  50. 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        Get CustomizeWoo.com FREE
     * @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

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

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

      1. 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!

    5. 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.

  51. 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 🙂

  52. Thank you! Works great!

  53. 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

  54. 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!

  55. 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:)

  56. 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 🙂

  57. 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

  58. 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

  59. 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?

  60. Thank you very much!

    1. You’re welcome Michael 🙂

  61. 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

  62. 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

  63. 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

  64. 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

  65. 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 🙂

  66. 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/

      1. 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

        1. Excellent, let me know 🙂

  67. 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 🙂

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

  68. 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! 🙂

  69. 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: https://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? 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!

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