Home » WooCommerce: Add Privacy Policy Checkbox @ Checkout

WooCommerce: Add Privacy Policy Checkbox @ Checkout

by adminkys

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 tutoraspire.com FREE
 * @author        Tutor Aspire
 * @compatible    WooCommerce 3.6.3
 * @donate $9     https://www.tutoraspire.com
 */
 
add_action( 'woocommerce_review_order_before_submit', 'tutoraspire_add_checkout_privacy_policy', 9 );
   
function tutoraspire_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',
)); 
  
}
  
// Show notice if customer does not tick
   
add_action( 'woocommerce_checkout_process', 'tutoraspire_not_approved_privacy' );
  
function tutoraspire_not_approved_privacy() {
    if ( ! (int) isset( $_POST['privacy_policy'] ) ) {
        wc_add_notice( __( 'Please acknowledge the Privacy Policy' ), 'error' );
    }
}

You may also like