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 id="deliverycheck" class="input-checkbox" name="deliverycheck" type="checkbox" /> <label class="checkbox" for="deliverycheck">';
  _e('Please confirm you understand there is a 10 day handling time on this order prior to dispatch', 'textdomain');
  echo '</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.

5 3 votes
Article Rating

Stay In Touch

Was this post helpful? Why not show your support and buy me a coffee?

Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Nathalie
Nathalie
April 8, 2021 11:38 pm

Thanks!!

1
0
Would love your thoughts, please comment.x
()
x
Scroll to Top