Skip to content

Instantly share code, notes, and snippets.

@paulgoodchild
Last active February 6, 2023 10:56
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save paulgoodchild/e15774a5307d8f65416234b4ac61203c to your computer and use it in GitHub Desktop.
Easy Digital Downloads: Prevent license expiration notices being sent for licenses linked to refunded payments
<?php declare( strict_types=1 );
/**
* Easy Digital Downloads will send license expiration notices for any licenses, even if they
* have been refunded. This is not ideal.
*
* This filter will prevent such notices being sent if any payments associated with this
* license have been refunded.
*
* This may not be applicable in cases where you EDD store supports multiple products in
* the same payment/purchase. There's no way to know whether a (partial-)refund applies
* to any particular product.
*
* However, we test the license status for it being "disabled", as any fully refunded
* purchase normally sets associated licenses to be disabled.
*
* The filter also honours any pre-existing filters by only continuing with processing if
* the flag to send the email is true.
*/
add_filter( 'edd_sl_send_scheduled_reminder_for_license', function ( $ifSendEmail, $license_id ) {
if ( $ifSendEmail ) {
$lic = edd_software_licensing()->get_license( $license_id );
if ( $lic instanceof \EDD_SL_License && $lic->status == 'disabled' ) {
foreach ( $lic->payment_ids as $paymentID ) {
$p = edd_get_payment( $paymentID );
if ( $p instanceof \EDD_Payment && $p->status === 'refunded' ) {
$ifSendEmail = false;
break;
}
}
}
}
return $ifSendEmail;
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment