When going legal… you need proof. Accepting the “Terms and Conditions” on the checkout is required in order to placer 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" Acceptance Upon Checkout - WooCommerce
 * @how-to        Get CustomizeWoo.com FREE
 * @source        https://businessbloomer.com/?p=74053
 * @author        Rodolfo Melogli
 * @compatible    Woo 3.3.4
 */

// 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'] ) update_post_meta( $order_id, 'terms', esc_attr( $_POST['terms'] ) );
}

// 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', true ) == 'on' ) {
    	echo '<p><strong>Terms & Conditions: </strong>accepted</p>';
	} else echo '<p><strong>Terms & Conditions: </strong>N/A</p>';
}

Share:

Leave a Reply