Add custom checkout fields to Easy Digital Downloads

If you use Easy Digital Downloads for your e-commerce store, you are probably a fan of his minimal and straightforward checkout like I am. At the same time, I have to say it is not rare I need to implement custom checkout fields to collect additional information from users.

Of course, you can use the official extension (Checkout Fields Manager) to implement them, which is very good and flexible. But sometimes you may prefer to code them yourself if you don’t want to add backend interfaces or to keep more control over your code.

EDD custom checkout fields

EDD is a nicely coded plugin, and you have all the hooks needed to load, validate and process the custom checkout fields. I actually use a functionality plugin, which takes care of:

Displaying the fields on the checkout form – hooking edd_purchase_form_user_info_fields()

Validating the fields – hooking edd_purchase_form_required_fields()

Showing error messages – hooking edd_checkout_error_checks()

Saving the fields in the backend – hooking edd_payment_meta()

Displaying the fields on payment backend page – hooking edd_payment_personal_details_list()

The plugin is open sourced on GitHub, and you’ll find in the code the parts to change to add your own custom fields (documented in a clear way, hopefully).

It also takes care of prefixing the fields automatically, so you just need to input the keys, labels, and descriptions. There is no definition for the priority/order for the fields in checkout, so they are shown just in the same order of the array containing the data.

It is a great and lightweight alternative to Checkout Fields Manager, especially useful if you do not need complex fields like radio buttons or multi-select.

Join the Conversation

5 Comments

  1. Hi Francesco,
    Nice to meet mate.
    Australian based Digital Strategist now, but 20 years ago I did a CompSci degree. Visual basic and java type stuff 🙂

    I moonlight at my tender age of 48 as a Digital Marketer/ WP Designer. Age-ism is real my friend 🙂

    So for a client I love your code to extend EDD checkout fields.
    For me my .php has always been rusty and kind skipped it in my career.
    So I am wondering if you might help a little.
    I can customise your code to add extra fields, however for my client, they ideally need a drop down list of say 8 items to choose from. I assume your {empty} validation code would still work across such a list.
    But I am keen to know how best to code such a list into your code snippets.

    I know this seems basic, but to avoid more pain, i thought I would ask the great Francesco for his wise advice or example.

    Very best,

    Mark

  2. Hello Francesco

    Thanks for this guide, and I have a question if you can help me figure out a solution for it,

    I have 4 digitals product on my website, two of them require my customer to fill some extra infos like: server IP address + SSH port + root username and password.

    How can I add those fild on the checkout to only two products ? is there a way to it like you did with this guide ?

  3. Hey, thanks for this. So helpful.

    Just a heads up — under where you say “Validating the fields – hooking edd_purchase_form_required_fields(),” the code does not match. In fact, it is duplicated from the next (correct) code box.

    Another thought, running the function hooked to “edd_purchase_form_user_info_fields” on a foreach() with text inputs doesn’t allow for other type of form fields, such as selects or whatnot. Efficient, but not necessarily always realistic.

Leave a comment

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