awesomemotive / edd-library

EDD Code Snippet Library
http://library.easydigitaldownloads.com/
141 stars 42 forks source link

Disable renewals/extensions for a specific Download #150

Closed mihaijoldis closed 3 years ago

mihaijoldis commented 3 years ago

A customer asked how he can do that and @ashleyfae got this wipped up pretty quick and it works correctly on my test site.

function ag_edd_sl_can_renew( $can_renew, $license_id ) {
    // Bail if they already can't renew.
    if ( ! $can_renew ) {
        return $can_renew;
    }
    $license = edd_software_licensing()->get_license( $license_id );
    if ( ! $license ) {
        return $can_renew;
    }
    $download_id_not_allowed = 123; // Change this
    if ( $license->download_id == $download_id_not_allowed ) {
        $can_renew = false;
    }
    return $can_renew;
}
add_filter( 'edd_sl_can_extend_license', 'ag_edd_sl_can_renew', 10, 2 );
add_filter( 'edd_sl_can_renew_license', 'ag_edd_sl_can_renew', 10, 2 );