Last active
October 7, 2019 02:49
-
-
Save ericnicolaas/699c410aee50fcd1cf6378a86a2e5ca1 to your computer and use it in GitHub Desktop.
Include surplus of one campaign in total of another campaign
This file contains hidden or 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 | |
add_filter( | |
'charitable_campaign_donated_amount', | |
function( $amount, $campaign, $sanitize ) { | |
$new_campaign = 14; | |
$old_campaign = 135; | |
$old_goal = charitable_get_campaign( $old_campaign )->get_goal(); | |
if ( $new_campaign == $campaign->ID ) { | |
// Get the combined total of the old & new campaigns. | |
$amount = charitable_get_table( 'campaign_donations' )->get_campaign_donated_amount( [ $new_campaign, $old_campaign ] ); | |
// Subtract the goal of the old campaign. | |
$amount -= $old_goal; | |
} elseif ( $old_campaign == $campaign->ID ) { | |
$amount = $amount > $old_goal ? $old_goal : $amount; | |
} | |
if ( $sanitize ) { | |
$amount = charitable_sanitize_amount( $amount ); | |
} | |
return $amount; | |
}, | |
10, | |
3 | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment