Posted on

WooCommerce: Save “Terms & Conditions” User Acceptance @ Checkout

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        Watch tutorial @ https://businessbloomer.com/?p=19055
 * @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>';
}

Where to add this code?

You can place PHP snippets at the bottom of your child theme functions.php file (before "?>" if you have it). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such delicate files - if you need more guidance, please take a look at my free WooCommerce Customization video tutorial.

Does this snippet still work?

Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7.

If you think this code saved you time & money, please join other Business Bloomer supporters and avail of 365 days of WooCommerce benefits. Thank you in advance ๐Ÿ™‚

Need Help with WooCommerce?

Check out these free videos, tutorials and tips!

  • how-to-edit-woocommerce-with-php-snippets
  • woocommerce-hooks-add_action-list-visual
  • woocommerce-customize-single-product-page-PHP
  • woocommerce-customize-shop-page-PHP
  • woocommerce-advanced-customization
  • how-to-edit-woocommerce-cart
  • woocommerce-customize-checkout-page-PHP
  • woocommerce-email-customization
  • woocommerce-conditional-logic

Rodolfo Melogli

Author, WooCommerce expert, WordCamp speaker and Internet marketer, Rodolfo Melogli has worked as a WooCommerce freelancer since 2011. He helps entrepreneurs and developers overcome their WooCommerce nightmares ๐Ÿ™‚ Rodolfo is the organiser of WordCamp Dublin, the Dublin WooCommerce Meetup, the Dublin Ecommerce Meetup and the Dublin WordPress Meetup. He enjoys interacting with people, travelling and chasing tennis & soccer balls. Of course, he loves pizza too.

17 thoughts on “WooCommerce: Save “Terms & Conditions” User Acceptance @ Checkout

  1. This is really a great code, but it is not to get GDPR complaint (in my opinion). Since you pay for a service, you will give your data under the contractual or legal basis. I am not an expert about it, but I have read a lot about GDPR over the last week so I wanted to share my opinion. This is however very good to confirm that customers are not minor!
    Anwyhow, I do loooove all the work you’re sharing with use!!!

    1. Yes Raluca, I totally agree ๐Ÿ™‚ Thank you!

  2. Hi Rodolfo,

    Great site, I love the snippets and tutorials. For this one there is an error in the code which cause the error ‘id was called incorrectly. order properties should not be accessed directly’ cause by part 2:

    Your Snippet

    function bbloomer_display_terms_conditions_acceptance( $order ) {
        if ( get_post_meta( $order->id, 'terms', true ) == 'on' ) {
            echo '<p><strong>Terms & Conditions: </strong>accepted</p>';
        } else echo '<p><strong>Terms & Conditions: </strong>N/A</p>';
    }
    

    The following correction $order->get_id() will solve the error.

    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>';
    }
    
    1. Chris, excellent stuff! Thank you ๐Ÿ™‚

  3. Since the checkout can’t be completed without checking the terms (which is the default behaviour of WooCommerce if a terms page is set) this shouldn’t be needed for GDPR compliance.

    1. Yep, I agree Sven, thanks for that ๐Ÿ™‚ This might apply to specific businesses that need proof however, but for different reasons than GDPR.

  4. Did it!! Thanks for this snippet, Rodolfo, it worked perfectly ๐Ÿ˜€
    In my case it’s a good idea since parents need to share some of their children info.

    1. Now that I’m reading the GDPR article you wrote I realized that maybe it would be interesting to do the same with the acceptance of privacy policy (since it need to be in the checkout page), would it be possible to know what changes should I make to this code??

      Thanks again!!

    2. Excellent Monica ๐Ÿ™‚ You can simply duplicate the snippet and change it slightly to target the privacy policy input field “name” and that should save as well. Have fun!

  5. Thankyou Rodolfo!

  6. Great job !!!
    I alreay follow your steps for GDPR in order to make my shop ยซย legalย ยป.
    Keep the good work ๐Ÿ˜‰

    1. Great! Thanks for your feedback Stan ๐Ÿ™‚

  7. Hi Rodolfo, another great post!! thank you!! do you think we can put that line in the order confirmation email? can you suggest the code snippet?

    thank you
    Angelo

    1. Hello Angelo, thanks a million for your comment! This tutorial might help: https://businessbloomer.com/woocommerce-add-extra-content-order-email/

  8. Hi Rodolfo,

    isn’t the fact that T&C is required field enough of the proof? How can somebody not agree to a required checkbox? Is this really necessary?

    Best regards.

    1. Canagon, thanks so much for your comment! In my view, the T&C acceptance should also be printed in the customer email as well, so that both parties are aware of that. This is not required for all businesses, but some might need this extra care ๐Ÿ™‚

Questions? Feedback? Support? Leave your Comment Now!
If you're writing code, please wrap it between: [php] code_here [/php]

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