Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save verygoodplugins/c10bf9a5b856ec319ffc402763cc37ff to your computer and use it in GitHub Desktop.
Save verygoodplugins/c10bf9a5b856ec319ffc402763cc37ff to your computer and use it in GitHub Desktop.
Easy Digital Downloads grandfathered renewal discounts, with support for upgrades and reactivations
<?php
/**
* Sets renewal discount to 30% for any customer that purchased before January
* 1, 2021.
*
* @param int $renewal_discount The renewal discount.
* @param int $license_id The license ID.
* @return int The renewal discount amount.
*/
function wpf_edd_grandfather_renewal_discount( $renewal_discount, $license_id ) {
// During an upgrade or reactivation of an expired license, for some reason
// $license_id is 0.
if ( empty( $license_id ) ) {
$cart_items = edd_get_cart_contents();
if ( ! empty( $cart_items ) && ! empty( $cart_items[0]['options']['license_id'] ) ) {
$license_id = $cart_items[0]['options']['license_id'];
}
}
$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( 'January 1, 2021' ) ) {
$renewal_discount = 30;
}
return $renewal_discount;
}
add_filter( 'edd_sl_renewal_discount_percentage', 'wpf_edd_grandfather_renewal_discount', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment