Add a new required checkbox for privacy before order

If you need a new checkbox after the term & conditions on WooCommerce orders you can easily do this by adding the following code:

add_action( 'woocommerce_review_order_before_submit', 'dex_add_checkout_privacy_policy', 9 );
function dex_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 checkboxship checkbox'),
            'input_class' => array('woocommerce-form__input woocommerce-form__input-checkbox input-checkbox'),
            'required' => true,
            'label' => 'Text for the checkbox--this needs to be changed',
        ));
}

add_action( 'woocommerce_checkout_process', 'dex_not_approved_privacy' );

function dex_not_approved_privacy() {
    if ( ! (int) isset( $_POST['privacy_policy'] ) ) {
        wc_add_notice( __( 'Please acknowledge the terms and conditions' ), 'error' );
    }
}

One thought on “Add a new required checkbox for privacy before order

Leave a Reply

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