Storing WooCommerce Terms and Conditions in the Database

Terms and conditions for woocommerce

Storing WooCommerce Terms and Conditions in the Database

WooCommerce provides a nice feature that force your customers to accept your terms and conditions if you define the corresponding page within WooCommerce settings. If your customers don’t check the “terms and conditions”, they can’t proceed the order. This is nice and easy to setup.

Setup the Terms & Conditions Page

Just a quick reminder on how to set this up. First of all, create a new page, call it “Terms” (or what you want!), add your content, then go to WooCommerce > Settings > Pages. Then choose the page you just created in the corresponding dropdown select and save settings.

Setup terms and conditions page for woocommerce
Setup terms and conditions page for Woocommerce

And here is what your customers will see on the checkout page:

Accept terms and conditions

Nice but…

That’s pretty neat right? But what happens when one your customer has a litigation with you? Can you prove that your customer accepted your terms and conditions? The answer is not that simple. You can still say that it’s impossible to purchase on your site without accepting your terms and conditions, but legally, it is not enough.

The solution, is to add a snippet to your site that will store the “terms and conditions” field value within the database, and in that case you can prove that terms and conditions were accepted, order by order.

Simply add this code to the functions.php file within your theme folder:

add_action( 'woocommerce_checkout_update_order_meta', 'skyeye_save_terms_conditions_acceptance' );
function skyeye_save_terms_conditions_acceptance( $order_id ) {
if ( $_POST['terms'] ) update_post_meta( $order_id, 'terms', esc_attr( $_POST['terms'] ) );
add_action( 'woocommerce_admin_order_data_after_billing_address', 'skyeye_display_terms_conditions_acceptance' );
function skyeye_display_terms_conditions_acceptance( $order ) {
if ( get_post_meta( $order->get_id(), 'terms', true ) == 'on' ) {
echo '<p><strong>Terms & Conditions: </strong>Accepted by customer</p>';
} else echo '<p><strong>Terms & Conditions: </strong>N/A</p>';

This code will store the field value within the database, and will also print this information on the “edit order” page:

Terms accepted by customer
Terms accepted by customer


Was this post helpful?

Leave your thought here

Your email address will not be published.