Menu Close

WooCommerce: Save “Terms & Conditions” Acceptance @ Checkout

default

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 CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 6
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */
 
// 1. Save T&C as Order Meta
  
add_action( 'woocommerce_checkout_update_order_meta', 'bbloomer_save_terms_conditions_acceptance' );
  
function bbloomer_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', 'bbloomer_display_terms_conditions_acceptance' );
  
function bbloomer_display_terms_conditions_acceptance( $order ) {
   if ( get_post_meta( $order->get_id(), '_terms_accepted', true ) == 1 ) {
      echo '<p><strong>Terms & Conditions: </strong>accepted</p>';
   } else echo '<p><strong>Terms & Conditions: </strong>N/A</p>';
}
View Source
Posted in WooCommerce Tips