Last active
June 10, 2020 03:16
-
-
Save ericnicolaas/7971c3a904391a6f6ccb866fd9199eab to your computer and use it in GitHub Desktop.
Apply Gift Aid to renewal donations
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 | |
/** | |
* If the original recurring donation opted in to Gift Aid, apply Gift Aid for | |
* all renewals too. | |
* | |
* @param array $args Array of arguments to create donation. | |
* @return array | |
*/ | |
function ed_charitable_apply_gift_aid_to_renewals( $args ) { | |
// Make sure this is a renewal. | |
if ( ! array_key_exists( 'meta', $args ) || ! array_key_exists( '_renewal_donation', $args['meta'] ) ) { | |
return $args; | |
} | |
// We have already set the Gift Aid. | |
if ( isset( $args['meta']['giftaid'] ) ) { | |
return $args; | |
} | |
// Get the original donation. | |
$original = charitable_get_donation( $args['meta']['_renewal_donation'] ); | |
// Apply Gift Aid to the renewal if it was used on the original. | |
if ( $original->__get( 'giftaid' ) ) { | |
$args['meta']['giftaid'] = (int) $original->__get( 'giftaid' ); | |
} | |
return $args; | |
} | |
add_filter( 'charitable_donation_values', 'ed_charitable_apply_gift_aid_to_renewals' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment