# Phone Number Field at EDD Checkout

> Adds a phone number field to the Easy Digital Downloads checkout, saves it with the order, shows it on the order screen and provides a {checkout_phone} email tag.

- Type: PHP
- Runs: Run everywhere
- Category: [Easy Digital Downloads](https://wpide.com/library/category/edd/)
- Requires: Easy Digital Downloads
- Tags: edd, checkout, fields, phone
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/edd-checkout-phone-field/

## Code

```php
$wpide_edd_phone_required = true; // Require a phone number.

add_action( 'edd_purchase_form_user_info_fields', function () use ( $wpide_edd_phone_required ) {
    ?>
    <p id="edd-phone-wrap">
        <label class="edd-label" for="edd-phone"><?php echo esc_html( 'Phone number' ); ?><?php echo $wpide_edd_phone_required ? ' <span class="edd-required-indicator">*</span>' : ''; ?></label>
        <input class="edd-input" type="tel" name="edd_phone" id="edd-phone" autocomplete="tel" <?php echo $wpide_edd_phone_required ? 'required' : ''; ?>>
    </p>
    <?php
} );

if ( $wpide_edd_phone_required ) {
    add_filter( 'edd_purchase_form_required_fields', function ( $fields ) {
        $fields['edd_phone'] = array(
            'error_id'      => 'invalid_phone',
            'error_message' => 'Please enter your phone number.',
        );

        return $fields;
    } );
}

add_action( 'edd_built_order', function ( $order_id ) {
    // phpcs:ignore WordPress.Security.NonceVerification -- EDD verifies the purchase form nonce.
    $phone = isset( $_POST['edd_phone'] ) ? sanitize_text_field( wp_unslash( $_POST['edd_phone'] ) ) : '';

    if ( '' !== $phone && function_exists( 'edd_add_order_meta' ) ) {
        edd_add_order_meta( $order_id, 'wpide_phone', $phone, true );
    }
} );

add_action( 'edd_view_order_details_billing_after', function ( $order_id ) {
    $phone = function_exists( 'edd_get_order_meta' ) ? edd_get_order_meta( $order_id, 'wpide_phone', true ) : '';

    if ( $phone ) {
        printf( '<div class="edd-order-phone" style="padding:12px"><strong>%1$s</strong> <a href="tel:%2$s">%3$s</a></div>', esc_html( 'Phone:' ), esc_attr( preg_replace( '/[^\d+]/', '', $phone ) ), esc_html( $phone ) );
    }
} );

add_action( 'edd_add_email_tags', function () {
    edd_add_email_tag( 'checkout_phone', 'The phone number entered at checkout', function ( $order_id ) {
        return esc_html( (string) edd_get_order_meta( $order_id, 'wpide_phone', true ) );
    }, 'Phone' );
} );
```

## Notes

Set $wpide_edd_phone_required to false to make the field optional, and use {checkout_phone} in Downloads > Emails templates.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Phone Number Field at EDD Checkout" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
