Last active
August 28, 2021 10:47
-
-
Save verygoodplugins/c10bf9a5b856ec319ffc402763cc37ff to your computer and use it in GitHub Desktop.
Easy Digital Downloads grandfathered renewal discounts, with support for upgrades and reactivations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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