How to Add WooCommerce Accept Terms and Conditions Checkbox On Registration Form

WooCommerce Accept Terms and Conditions Checkbox On Registration Form

Are you looking for a simple and easy way to add Terms and Conditions on the registration page?

In today’s post, we will share a custom code we made specifically for adding Terms and Conditions to this page.

If you have some coding experience, you will not have a hard time implementing this solution. However, we will try to explain each step in detail.

It is worth mentioning that a terms and conditions document is very important in any online store.

This document contains a set of rules and guidelines that users must agree with when registering as a member of your store.

In addition, payment gateways like Authorize.net require that you post terms and conditions documents on your website.

It is important to note that WooCommerce has a built-in option for adding this feature on the checkout page. This means that we need a custom solution to add it to the registration page. This is why we created this tutorial to help you out.

WooCommerce Accept Terms and Conditions Checkbox On Registration Form

By the end of this post, you will be able to edit the registration page by adding Accept Terms and Conditions on the registration page.

To achieve this, we will edit some of WooCommerce’s core files. This is why it is essential to install or create a child theme. It will ensure that the changes you make are not lost during an update.

With that in mind, let us get right into it.

Steps to Add Accept Terms and Conditions Checkbox On the Registration Form

Here are the simple steps you need to follow:

  1. Log into your WordPress site and access the dashboard as the admin user
  2. Create a terms and conditions document by navigating to Pages > Add New. Add your document to this page, and remember to add all the relevant rules and regulations. You can check for templates online to make your work easier.Add terms and conditions page
  3. Save and publish the Terms and Conditions page.
  4. To enable that page in Appearance > Customize > WooCommerce > Checkout.
  5. In the Terms and Conditions page list, select the Terms and Conditions page you just created.set the terms and conditions page
  6. Remember to save your changes.
  7. The next step is to add the following code in the functions.php file to add the term and conditions check box on the registration form:
// Add term and conditions check box on the registration form
add_action( 'woocommerce_register_form', 'njengah_terms_and_conditions_to_registration', 20 );
function njengah_terms_and_conditions_to_registration() {
if ( wc_get_page_id( 'terms' ) > 0 && is_account_page() ) {
?>
<p class="form-row terms wc-terms-and-conditions">
<label class="woocommerce-form__label woocommerce-form__label-for-checkbox checkbox">
<input type="checkbox" class="woocommerce-form__input woocommerce-form__input-checkbox input-checkbox" name="terms" <?php checked( apply_filters( 'woocommerce_terms_is_checked_default', isset( $_POST['terms'] ) ), true ); ?> id="terms" /> <span><?php printf( __( 'I&rsquo;ve read and accept the <a href="%s" target="_blank" class="woocommerce-terms-and-conditions-link">terms &amp; conditions</a>', 'woocommerce' ), esc_url( wc_get_page_permalink( 'terms' ) ) ); ?></span> <span class="required">*</span>
</label>
<input type="hidden" name="terms-field" value="1" />
</p>
<?php
}
}
// Validate required term and conditions check box
add_action( 'woocommerce_register_post', 'terms_and_conditions_validation', 20, 3 );
function terms_and_conditions_validation( $username, $email, $validation_errors ) {
if ( ! isset( $_POST['terms'] ) )
$validation_errors->add( 'terms_error', __( 'Terms and condition are not checked!', 'woocommerce' ) );
return $validation_errors;
}

  1. This is the outcome:terms
  2. If you want to allow it only on the Registration page use one of the following:

 

add_filter( 'woocommerce_checkout_show_terms', '__return_false' );

Conclusion

In summary, you have seen how it is easy to add the accept terms and conditions checkbox on the registration form. We have also shared a snippet to display it only on the registration page.

However, you should be very careful when editing the functions file. If you make a mistake, a critical error will be displayed on your site.

We hope that this tutorial helped you to find the solution you were looking for.

Similar Articles