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
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */
 
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' );
    }
}
Share:

Leave a Reply