Home » WooCommerce: Save “Terms & Conditions” Acceptance @ Checkout

WooCommerce: Save “Terms & Conditions” Acceptance @ Checkout

by Tutor Aspire

When going legal… you need proof. Accepting the “Terms and Conditions” on the checkout is required in order to place an order – but how can you, WooCommerce store admin, “prove” that the Terms and Conditions were actually ticked by the customer?

One of the solutions might be to save such acceptance in the database and print the acceptance on the order admin (and maybe on the customer invoice as well). So, here’s a quick PHP snippet you can simply copy and paste in your child theme’s functions.php file in order to (1) save and (2) print the choice on the Single Order Admin page. Enjoy!

Save Terms & Conditions acceptance upon checkout

PHP Snippet: Save “Terms & Conditions” Customer Acceptance @ WooCommerce Checkout

/**
 * @snippet       Save "Terms and Conditions" @ Checkout - WooCommerce
 * @how-to        Get tutoraspire.com FREE
 * @author        Tutor Aspire
 * @compatible    WooCommerce 6
 * @donate $9     https://www.tutoraspire.com
 */
 
// 1. Save T&C as Order Meta
  
add_action( 'woocommerce_checkout_update_order_meta', 'tutoraspire_save_terms_conditions_acceptance' );
  
function tutoraspire_save_terms_conditions_acceptance( $order_id ) {
   if ( $_POST['terms-field'] ) update_post_meta( $order_id, '_terms_accepted', esc_attr( $_POST['terms-field'] ) );
}
  
// 2. Display T&C @ Single Order Page
  
add_action( 'woocommerce_admin_order_data_after_billing_address', 'tutoraspire_display_terms_conditions_acceptance' );
  
function tutoraspire_display_terms_conditions_acceptance( $order ) {
   if ( get_post_meta( $order->get_id(), '_terms_accepted', true ) == 1 ) {
      echo '

Terms & Conditions: accepted

'; } else echo '

Terms & Conditions: N/A

'; }

You may also like