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.
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 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.
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).
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.
You can change the label text and error message with whatever you see fit.
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!
How can you save the consent, will it appear in the user profile of WP?
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
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 :)
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.
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).
Hey! thanks for your guide, is superb!!
I have added this code in functions.php
/* PRIVACY POLICY -> ADD CHECKBOX */
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' => 'He leído y aceptado la <a href="www.myweb.com/privacy.php" rel="nofollow">política de privacidad</a>',
));
}
add_action('woocommerce_checkout_process', 'privacy_checkbox_error_message');
function privacy_checkbox_error_message() {
if ( ! (int) isset( $_POST['privacy_policy'] ) )
wc_add_notice( __( 'Debes aceptar nuestra política de privacidad.' ), 'error' );
}
As far I know, we can modify the order of validation using hooks. I think that “woocommerce_checkout_process” should be executed before Stripe is fired, but not…. when I click on CHECKOUT, the system validates all woocommerce fields (including accept terms and conditions), but not my new custom field, before it, the system validates the Stripe’s fields.
Do you know how can we change the order / priority of validation of fields? we want to leave the Stripe’s validation at the end.
Thanks in advance for your time
Cheers
Hello! Unfortunately, no, I don’t know. It requires some additional custom coding and, unfortunately, I’m not a web developer. I just use whatever codes I found myself, then share it with you guys.
Thanks for your time!!!
Hey! Awesome post!
I would like to know if I can translate it using some php inside the “label”.
Otherwise I would like to display this checkbox under the registration form (not checkout page). Could you help me?
Thank you very much!
Hello! Thanks!
If you want the label to be in another language, then simply add it another language from the start, after
'label' =>
.As for displaying the checkbox under the registration form, you could try this plugin or search for a custom code on Google. I haven’t written a tutorial for that yet, but it’s on my to-do list :D.
good work. what if i need the snippet in multilanguage. any way to add if language ….
I assume a multilingual plugin can pick that up and translate it.
That’s great. I works.
I’ve added a newsletter checkbox too, according to your code.
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" rel="nofollow">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' );
}
}
add_action( 'woocommerce_review_order_before_submit', 'add_newsletter_checkbox', 10 );
function add_newsletter_checkbox() {
woocommerce_form_field( 'newsletter', array(
'type' => 'checkbox',
'class' => array('form-row newsletter'),
'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' => false,
'label' => 'Keep me occasionally informed about YOURPRODUCT news.',
));
}
Thanks for sharing the code! It will help out others who are looking for the same thing.
Hi, You don’t need any code. Just simply go to Appearance > Customizer > WooCommerce > Checkout and set the page for Terms. Here You have a full description:
https://woocommerce.wordpress.com/2018/05/04/woocommerce-3-4-gdpr-features/
Hello!
Yes, I also mentioned that link and the privacy feature in my post, in the introduction.
But, the default privacy policy feature from WooCommerce doesn’t have a checkbox, as the Terms do. So, some people want to add a Privacy Policy with a checkbox, just like the Terms. That’s what my post offers.
If I’m not mistaken, in some situations, a checkbox is required by the GDPR law as well.
Hi. For some reason no checkbox appears, only the text including the link. What could be the reason for this? Thank you.
Hello! It’s hard to tell without at least inspecting the front-end where the issue occurs.
Hi, thanks fpr ypur response. Would it be possible to take look on my website?
Hi, I could solve the problem. Thank you.
Hello! That’s great! I’m happy you got it fixed.
Hello,
Thanks for the article, wanted to point out that there is a plugin that can help:
https://wordpress.org/plugins/woo-additional-terms/
One more question, how can I add 3 checkboxes with text and link instead of one?
I have to add link to 3 pages from gdpr. Thanks.