How to save terms and conditions acceptance in WooCommerce

woo expert

If you want to comply as much as possible with privacy regulations, such as the GDPR for example, it doesn’t hurt to make sure that you keep track of whether the customers of your online store have accepted the terms and conditions of your e-commerce, in case there are later complaints.

The following code accomplishes this doubly:

  1. Stores the acceptance of the terms and conditions in the database, in the metadata of each order.
  2. It shows in the administrative details of the order if the customer accepted the terms and conditions.
/* Save and show acceptance of terms and conditions */
// 1. We save the acceptance in the meta data of the order.
add_action( 'woocommerce_checkout_update_order_meta', 'wphelp_save_tos_acceptance' );
function wphelp_save_tos_acceptance( $order_id ) {
if ( $_POST['terms'] ) update_post_meta( $order_id, 'terms', esc_attr( $_POST['terms'] ) );
}
// 2. We show the acceptance in the order edition
add_action( 'woocommerce_admin_order_data_after_billing_address', 'wphelp_show_tos_acceptance' );
function wphelp_show_tos_acceptance( $order ) {
if ( get_post_meta( $order->get_id(), 'terms', true ) == 'on' ) {
echo '<p><strong>Terms and conditions: </strong>Accepted</p>';
} else echo '<p><strong>Terms and conditions: </strong>N/D</p>';
}Code language: PHP (php)

This code must be added to your plugin or function file, as I explain in this simple guide…

How and where to paste PHP, JS, CSS codes and functions you find around in WordPress

Once you have implemented the code in your installation the acceptance of the terms and conditions will be saved with the metadata of the order and will be displayed in the order management.

How useful was this post?

Click on a smiley to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

As you found this post useful...

Follow us on social media!

About The Author

Leave a Comment

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

Scroll to Top
Skip to content