Custom Checkout Fields

Adding custom fields to the checkout form is easy to do with just a couple of functions. The code below will allow you to add two additional fields, one for Phone and one for Company.

Note: we now have an official extension that allows you to create custom checkout fields and arrange them however you like. View Checkout Fields Manager extension.

The code below adds a Phone Number field to the checkout form.


Enter your phone number so we can get in touch with you.

'invalid_phone', 'error_message' => 'Please enter a valid Phone number' ); return $required_fields; } add_filter( 'edd_purchase_form_required_fields', 'sumobi_edd_required_checkout_fields' ); /** * Set error if phone number field is empty * You can do additional error checking here if required */ function sumobi_edd_validate_checkout_fields( $valid_data, $data ) { if ( empty( $data['edd_phone'] ) ) { edd_set_error( 'invalid_phone', 'Please enter your phone number.' ); } } add_action( 'edd_checkout_error_checks', 'sumobi_edd_validate_checkout_fields', 10, 2 ); /** * Store the custom field data into EDD's payment meta */ function sumobi_edd_store_custom_fields( $payment_meta ) { if ( 0 !== did_action('edd_pre_process_purchase') ) { $payment_meta['phone'] = isset( $_POST['edd_phone'] ) ? sanitize_text_field( $_POST['edd_phone'] ) : ''; } return $payment_meta; } add_filter( 'edd_payment_meta', 'sumobi_edd_store_custom_fields'); /** * Add the phone number to the "View Order Details" page */ function sumobi_edd_view_order_details( $payment_meta, $user_info ) { $phone = isset( $payment_meta['phone'] ) ? $payment_meta['phone'] : 'none'; ?>

The checkout form will then look similar to this:

And then when looking at the transaction under Downloads Payment History you'll see a meta box similar to this:

This code is simply meant as an example and can be tweaked however you wish to add even more fields.
To add this code example to your site, we recommend using  Pluginception to create a new custom plugin, and paste the code into the new plugin.