Skip to content

Instantly share code, notes, and snippets.

@ericnicolaas
Last active June 10, 2020 03:16
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 ericnicolaas/7971c3a904391a6f6ccb866fd9199eab to your computer and use it in GitHub Desktop.
Save ericnicolaas/7971c3a904391a6f6ccb866fd9199eab to your computer and use it in GitHub Desktop.
Apply Gift Aid to renewal donations
<?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