Adding extra fields to Woocommerce checkout and applying them to the email

How to add extra fields to the Woocommerce Checkout page and have those values get sent in the order email.

This expands on a tutorial here.

We will be adding two extra checkout fields, “Student’s Name” and “Teacher’s” Name, both text inputs. First we create the fields, then save them. We will also show them in the order in the dashboard as well as send the info through the new order email.

The first function creates the field. Put all of these in your theme’s functions file.

Next we process the fields when we submit and check to see if they’re required. In this case, we will require them:

Next we save the values, if not empty, to the orders meta:

This function will display the values on the order edit page in the backend under orders:

 

Lastly we can send the values out through the email. There are a number of emails to choose from. We will choose the on located here: Dashboard > Woocommerce > Settings > Emails (tab) > New Order. At the bottom of this page, you can see the html email template. Open thatĀ up and place the following in that file.

 

Leave a Reply

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

36 − 28 =