# "How Did You Hear About Us?" Checkout Field

> Adds a dropdown to the classic checkout asking customers how they found your store, saves the answer with the order and shows it on the order screen.

- Type: PHP
- Runs: Run everywhere
- Category: [WooCommerce](https://wpide.com/library/category/woocommerce/)
- Requires: WooCommerce
- Tags: woocommerce, checkout, fields, marketing
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/woo-checkout-referral-source/

## Code

```php
$wpide_referral_options = array(
    ''        => 'Choose an option',
    'search'  => 'Search engine',
    'social'  => 'Social media',
    'friend'  => 'Friend or family',
    'ad'      => 'Advertisement',
    'other'   => 'Other',
);

add_action( 'woocommerce_after_order_notes', function ( $checkout ) use ( $wpide_referral_options ) {
    woocommerce_form_field( 'wpide_referral_source', array(
        'type'     => 'select',
        'label'    => 'How did you hear about us?',
        'required' => false,
        'class'    => array( 'form-row-wide' ),
        'options'  => $wpide_referral_options,
    ), $checkout ? $checkout->get_value( 'wpide_referral_source' ) : '' );
} );

add_action( 'woocommerce_checkout_create_order', function ( $order ) use ( $wpide_referral_options ) {
    $value = isset( $_POST['wpide_referral_source'] ) ? sanitize_key( wp_unslash( $_POST['wpide_referral_source'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification

    if ( '' !== $value && isset( $wpide_referral_options[ $value ] ) ) {
        $order->update_meta_data( '_wpide_referral_source', $wpide_referral_options[ $value ] );
    }
} );

add_action( 'woocommerce_admin_order_data_after_billing_address', function ( $order ) {
    $source = $order->get_meta( '_wpide_referral_source' );

    if ( $source ) {
        echo '<p><strong>Heard about us via:</strong> ' . esc_html( $source ) . '</p>';
    }
} );
```

## Notes

Edit $options to change the choices. Answers are stored in the order meta key _wpide_referral_source.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find ""How Did You Hear About Us?" Checkout Field" 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/
