Save terms and conditions agreement on WooCommerce orders 2024

At some point in your business journey, you may encounter a situation where something has gone a little south and the customer is disputing something with their order which is covered by the terms and conditions. While most people probably don’t read terms and conditions when placing an order, the existence of them can help protect the store when a dispute arises. However, a case may arise where the customer also disputed accepting the terms and conditions, and this snippet is designed to solve that problem

Although it’s really not necessary to save the terms and conditions checkbox to the WooCommerce order as it’s impossible to complete checkout without checking the checkbox (if enabled), it can help by providing proof that a customer accepted the terms and conditions when needed. This code snippet doesn’t alter the checkout flow in any way, but will save the checkbox value to the order. It will then display the acceptance below the billing details as well as on the customer order email. Add all PHP code snippets to the functions file of your child theme.

Step 1. Save the terms and conditions checkbox field as order meta. This uses the terms name of the checkbox and stores it as order meta on the order.

/**
 * Snippet: Save terms and conditions agreement on WooCommerce orders 2024
* Author: John Cook
* URL: https://wcsuccessacademy.com/?637
* Tested with WooCommerce 8.8.3
* "Save the terms and conditions checkout checkbox field as the order meta"
*/ add_action( 'woocommerce_checkout_create_order', 'wcsuccess_terms_field_update_order_meta', 10, 2 ); function wcsuccess_terms_field_update_order_meta( $order, $data ) { // Set the correct values from the terms checkbox $value = isset($_POST['terms']) ? '1' : '0'; // Save as custom order meta data $order->update_meta_data( 'terms', $value ); }

Step 2. Display the terms and conditions on the order edit page. The following snippet will place the acceptance below the billing details on the order edit screen

/**
 * Snippet: Save terms and conditions agreement on WooCommerce orders 2024
* Author: John Cook
* URL: https://wcsuccessacademy.com/?637
* Tested with WooCommerce 8.8.3
* "Displaying the terms field value in the order edit page"
*/ add_action( 'woocommerce_admin_order_data_after_billing_address', 'wcsuccess_terms_field_display_admin_order_meta', 10, 1 ); function wcsuccess_terms_field_display_admin_order_meta( $order ){ // Get the custom meta field from the order $accepted_terms = get_post_meta( $order->get_id(), 'terms', true ); // Set the value to readable text. Change the text as necessary // The values are stored as 1 or 0. 1 for yes and 0 for no. $accepted_terms = ($accepted_terms == 1) ? 'Accepted' : 'Not accepted'; // Check that the field is not empty to display the necessary message if( ! empty( $accepted_terms )) echo '<p><strong>'.__('Accepted terms', 'woocommerce').':</strong> ' . $accepted_terms . '</p>'; }

Step 3. Further protect yourself by adding the terms field acceptance to the order email. This serves several purposes. First, they are given written notice that they have accepted the terms and conditions. Second, if the customer contacts you by replying to the order email, they’re actually replying with the proof they accepted the terms and conditions.

/**
 * Snippet: Save terms and conditions agreement on WooCommerce orders 2024
* Author: John Cook
* URL: https://wcsuccessacademy.com/?637
* Tested with WooCommerce 8.8.3
* "Add a custom field (in an order) to the emails"
*/ add_filter( 'woocommerce_email_order_meta_fields', 'terms_woocommerce_email_order_meta_fields', 10, 3 ); function terms_woocommerce_email_order_meta_fields( $fields, $sent_to_admin, $order ) { // Get the order meta for the terms $accepted_terms = get_post_meta( $order->id, 'terms', true ); // Define the text the customer will read for accepted or not accepted $accepted_terms = ($accepted_terms == 1) ? 'Accepted' : 'Not accepted'; // Only display if the terms field is not empty if( ! empty( $accepted_terms )) { $fields['meta_key'] = array( 'label' => __( 'Accepted terms and conditions' ), 'value' => $accepted_terms, ); return $fields; } }

These snippets need to be placed in the functions.php file of your child theme or a code snippets plugin. Please also note that it will only begin to record data from the first order after the snippets have been saved.

See also  How to Fix WooCommerce Out of Stock Variations Appearing on the Product Page 2024

Did this work for you? Please leave a reply if it has helped your store.

0 0 votes
Article Rating

Stay In Touch

Was this post helpful? Why not show your support and buy me a coffee?

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
Scroll to Top
×