How to remove the Easy Digital Downloads renewal discount without affecting existing customers

I previously wrote about how to alter the Easy Digital Downloads renewal discount if the license is expired, ie. giving 30% if they renew on time and 20% after that.

But what if you now want to remove the renewal discount entirely for new customers? Most WordPress plugin companies are going in that direction since customers don’t really care too much about the discount if they’re still getting value out of your plugin.

To get rid of the discount without it affecting existing customers just grab the ID of the latest license under Downloads > License, which is in the URL:

/wp-admin/edit.php?post_type=download&page=edd-licenses&view=overview&license=12345

where 12345 is the license ID. Then add the following code to a small functional plugin:

 <?php
/*
Plugin Name: Customize Easy Digital Downloads Renewal Discount
Description: Give normal discount to renew before expiry, only 20% if license has expired, 0% if new customer
Version: 1.0
Author: Brian Hogg
Author URI: https://brianhogg.com
License: GPL2
*/
function edd_ecn_change_discount_after_license_expires( $renewal_discount, $license_id ) {
   if ( ! $license_id || $license_id > 12345 ) {
      return $renewal_discount;
   }
   $license = edd_software_licensing()->get_license( $license_id );
   if ( ! is_object( $license ) ) {
      // This can happen during purchase where the license ID is not yet valid
      return $renewal_discount;
   }
   if ( $license->is_expired() ) {
      $renewal_discount = 20; 
   }
   return $renewal_discount;
}
add_filter( 'edd_sl_renewal_discount_percentage', 'edd_ecn_change_discount_after_license_expires', 10, 2 );

Finally activate the plugin, then change the discount to 0 under Downloads, Settings, Extensions, then Software Licensing.

An alternate (thanks for sending this over Daniel Iser!) is to use the date the license was created rather than the license ID, along with the logic to set the renewal discount based on whether their license has expired or not:

function my_edd_grandfather_renewal_discount( $renewal_discount, $license_id ) {
	if ( ! $license_id ) {
		return $renewal_discount;
	}
	$license = edd_software_licensing()->get_license( $license_id );
	if ( ! is_object( $license ) ) {
		return $renewal_discount;
	}
	if( ! empty( $license->date_created ) && strtotime( $license->date_created ) < strtotime( 'April 1, 2018' ) ) {
		if ( $license->is_expired() ) {
			$renewal_discount = 20;
		} else {
			$renewal_discount = 30;
		}
	}
	return $renewal_discount;
}
add_filter( 'edd_sl_renewal_discount_percentage', 'my_edd_grandfather_renewal_discount', 10, 2 );

Voila, a few minutes of work to increase your revenues by your discount percentage this time next year, without needing to email or affect your existing customers!