How To Add A Checkbox To Woocommerce Checkout Page

In this tutorial I’m going to show you how to add a checkbox to the woocommerce checkout page. By default, Woocommerce comes with the ability to add a checkbox confirming that you agree to the terms and conditions. But what if you need something else to be confirmed before the buyer commits to the payment? Such as confirming they have selected the correct size variations or understand that there is a manufacturing or handling time.

While I personally don’t use checkboxes, mainly because I feel that they present a barrier to completing a purchase, I also understand there are circumstances and situations where they will be needed.

/*
* Snippet Add A Checkbox To Woocommerce Checkout Page
* how-to Read at https://wcsuccessacademy.com/?p=368
* source code https://wcsuccessacademy.com/?p=368
* author John Cook
* tested with WooCommerce 3.3.3
*/

add_action('woocommerce_review_order_before_submit', 'add_my_checkout_tickbox', 9);
 
function add_my_checkout_tickbox() {
 //you can change the message here just ensure that the formatting is maintained
echo '<p class="form-row terms"> <input type="checkbox" class="input-checkbox" name="deliverycheck" id="deliverycheck" /> <label for="deliverycheck" class="checkbox">Please confirm you understand there is a 10 day handling time on this order prior to dispatch</label> </p>';
}
 
// tick the box to acknowledge handling time response if not checked
 
add_action('woocommerce_checkout_process', 'not_ticked_box');
 
function not_ticked_box() {
    if ( ! (int) isset( $_POST['deliverycheck'] ) ) {
// You can edit the message below between the two ' ' for when there is an error eg box not ticked
        wc_add_notice( __( 'Please acknowledge the handling time' ), 'error' );
    }
}

This is how it should look

Where to place the code

Place the code for how to add a checkbox to the Woocommerce checkout page in the theme functions.php file of your child theme, or a functions plugin. Add the code to the end of the file before the closing ?> (if your file has it).

Let me know if it works

Did this work for you? Please let me know in the comments if the code snippet works for you.

Written by John Cook
I've been using WordPress for over 6 years and Woocommerce for over 4 years. In that time I have explored the depths of customizations and helped many online retailers grow and expand their business using the Woocommerce selling platform. My aim here is to help enable Woo users around the globe get even more out of their e-commerce platform of choice.