How to Add a Privacy Policy Checkbox in WooCoommerce Checkout

>How to Add a Privacy Policy Checkbox in WooCoommerce Checkout
  • checkout cart checkobox

You’ve probably already read that one of the GDPR requirements is to add a consent / privacy policy checkbox to all your forms that gather personal data, including your WooCommerce checkout page.

At this point, by default, WooCommerce only allows you to add a Terms & Conditions checkbox on the checkout page.

And yes, I’m aware that they’ll implement some GDPR features in the 3.4 version, but it will still be a little different from what I’m about to show you.

In WooCommerce 3.4, a privacy policy snippet will be added in the checkout page, not a checkbox, as you can see below.

woocommerce policy snippet

While this might be enough to comply with the GDPR requirements, some of you might want to go further, to be extra safe, and add another checkbox, in order for the users to check, if they agree with your privacy policy.

How to add a privacy policy checkbox in the WooCoommerce checkout page

To add a privacy policy checkbox in the WooCommerce checkout page, you’ll need to add some code in your theme’s functions.php file.

To do that, first you’ll need to know how to access and edit your WordPress files.

The functions.php file is usually found in /public_html/wp-content/themes/YOURTHEMENAME-child/functions.php. This is for your primary domain.

If you want to edit the file of an add-on domain that’s found on the same hosting account, you’ll most likely have to go here: /public_html/YOURDOMAIN.COM/wp-content/themes/YOURTHEMENAME-child/functions.php.

This might differ from web host to web host.

I recommend backing up the functions.php file or the whole website before making any changes, and I also recommend having a child theme in place.

Once you’ve opened the functions.php file for editing, add the below code at the very bottom, or right before ?> (if there’s any).

add_action( 'woocommerce_review_order_before_submit', 'add_privacy_checkbox', 9 );
function add_privacy_checkbox() {
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="https://YOURDOMAIN.com/privacy-policy">Privacy Policy</a>',
));
}
add_action( 'woocommerce_checkout_process', 'privacy_checkbox_error_message' );
function privacy_checkbox_error_message() {
if ( ! (int) isset( $_POST['privacy_policy'] ) ) {
wc_add_notice( __( 'You have to agree to our privacy policy in order to proceed' ), 'error' );
}
}

Don’t forget to add your actual domain name for the privacy policy page.

Save the file and that’s it!

A privacy policy checkbox should appear in your WooCommerce checkout page.

woocommerce privacy policy checkbox

You can change the label text and error message with whatever you see fit.

You might also want to read:

That’s a wrap

Hope you found the post useful and comprehensive!

If you have any questions or thoughts, drop a comment, contact us or message us on Facebook.

You can also follow us on Twitter and subscribe to our YouTube channel.

If you want to start your own WordPress blog, or need a website for your business, our WordPress services are at your disposal! We also provide WordPress support and maintenance!

You can also purchase a ready-made WordPress website with hosting and support included!

By |2018-07-25T20:25:03+00:00May 19th, 2018|Customization, Plugins|5 Comments

5 Comments

  1. Ben May 25, 2018 at 10:03 AM - Reply

    How can you save the consent, will it appear in the user profile of WP?

    • ThemeSkills May 25, 2018 at 6:50 PM - Reply

      Hello! I don’t know, to be honest, especially if it’s custom. You could drop a question here – https://wordpress.org/support/plugin/woocommerce

    • John June 15, 2018 at 5:37 PM - Reply

      I reckon that, because it’s a required field, getting past this page implies consent. So the fact that order details are saved to your database mean the user has accepted your privacy policy. Unless you intend to use this data for anything other than processing this order I believe this should be enough.

      If you are worried about offering the option to let users withdraw their consent, I don’t think it is even possible when the order is already processed. You cannot undo the processing and you may by law be required to keep this data (for instance Dutch administration requires me to keep the invoice I sent for 7 years).

      The only case where I think it might be an issue is if the order is not completely processed and remains on pending. But in that case you can just remove this order (or change the personal data to some fake info in order to keep your stats). I’m not a lawyer though 🙂

      • Eemeli July 23, 2018 at 5:50 PM - Reply

        John, maybe he wants to get a consent to do marketing. According to the GDPR you need that on the checkout page if you want to send your newsletter to the customer. That needs be optional, so the customer will not refuse to order just because you force him to register on the mailing list. Also you need to prove this consent later, so it has to be stored like he wrote.

  2. John June 15, 2018 at 5:15 PM - Reply

    Thanks for this! I’m using this instead of the built in functionality because this code allows me to link to my existing privacy policy and terms of service (which are outside my wordpress root).

Leave A Comment

Subscribe
SIGN ME UP

All Aboard!

Get WordPress guides and tutorials right in your inbox once per week, plus some cool   offers from time to time!
close-link