make order notes field required

How to make order notes field required?

Do you want to make order notes field required and show an error if order notes box is empty in WooCommerce?

You can either use plugin or a simple code snippet to make it work. Let’s have a look on both of these methods.

Code Snippet

It’s quite simple you can  add the snippet below and in your themes functions.php file or use code snippets plugin.

add_action('woocommerce_after_checkout_validation', 'my_custom_checkout_field_process');

  function my_custom_checkout_field_process() {
            // Check if set, if its not set add an error.
            if ( ! $_POST['order_comments'] )
                wc_add_notice( __( 'Please add delivery instructions' ), 'error' );
        }

If you want to change the error message, Please see line number 6 in the code snippet and change the text Please add delivery instructions to whatever you would like to.

Using Plugin

Check out Field Editor for WooCommerce plugin provides an easy way to customise (add, edit, delete and change display order) your fields displayed on WooCommerce checkout page.

This plugin requires WooCommerce to be installed, activated, and configured.

Once you activate the plugin go to contact for tab from Wordpress Admin Menu, On the right side of all fields you will see button labelled “Edit”.

make order notes field required

Just click the button, A popup window will open to edit the fields settings. From here you can simply tick required box and save it.

make order notes field required field settings.

And you are done, Now order notes will be a required field and customers will see an error if they don’t fill out this field.

Have any question? Don’t forget to leave a comment below

Leave a Reply

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