Skip to content

Instantly share code, notes, and snippets.

@ericnicolaas
Last active October 7, 2019 02:49
Show Gist options
  • Save ericnicolaas/699c410aee50fcd1cf6378a86a2e5ca1 to your computer and use it in GitHub Desktop.
Save ericnicolaas/699c410aee50fcd1cf6378a86a2e5ca1 to your computer and use it in GitHub Desktop.
Include surplus of one campaign in total of another campaign
<?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