Software Licensing - Custom License Key Formats

EDD License Keys are by default an md5 sum like this:


If you wish to have something else, with  Software Licensing it's as easy as making a function to create consistent unique keys and hooking into a filter called edd_sl_generate_license_key.

License key formats can really be anything you wish, as long as they're unique and consistent. If you want keys in this format:



You can use this function:

// Example shown how to base the MD5 off of the user's email and purchase date
function pw_edd_license_md5_user_and_date( $key, $license_id, $download_id, $payment_id, $cart_index ) {

    $name      = get_user_by( 'email', edd_get_payment_user_email( $payment_id ) );
    $date      = get_post_field( 'post_date', $payment_id );
    $timestamp = strtotime($date);
    $nice_date = date( 'Yndhis', $timestamp );
    $license   = md5( $license_id );
    $key       = $name->user_nicename . '_' . $nice_date . '_' . $license;

    return $key;
add_filter( 'edd_sl_generate_license_key', 'pw_edd_license_md5_user_and_date', 10, 5 );

A simpler function uses only username and license key:

// prepend user's username to license key
function sd_edd_license_username_md5( $key, $license_id, $download_id, $payment_id, $cart_index ) {
    $name      = get_user_by( 'email', edd_get_payment_user_email( $payment_id ) );
    $license   = md5( $license_id );
    $key       = $name->user_nicename . '_' . $license;

    return $key;
add_filter( 'edd_sl_generate_license_key', 'sd_edd_license_username_md5', 10, 5 );

The most important thing to take from this document is that you can use any code that produces consistent unique strings and use those strings as license keys.

Plugin Option

There's also a free plugin which provides a meta box on each Download, allowing you to set a custom format for each Download without having to write code. It's called  EDD License Key Template.  Here's a screenshot of the meta box in the admin area.