Skip to content

Instantly share code, notes, and snippets.

@Basilakis
Created June 4, 2021 14:05
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 Basilakis/970cd7e0bc986fbf0e6c5d84fc7d16a5 to your computer and use it in GitHub Desktop.
Save Basilakis/970cd7e0bc986fbf0e6c5d84fc7d16a5 to your computer and use it in GitHub Desktop.
Easy Digital Downloads - Add Handling Fee
function cg_add_handling_fee()
{
$current_user = wp_get_current_user();
if ($current_user !=0) {
$userId = $current_user->ID;
$subscriber = new EDD_Recurring_Subscriber($userId, true);
$subscription = new EDD_Subscription($userId); //subscriber id
//expiration date check
$expiration_date = $subscription->get_expiration();
if (strtotime($expiration_date) > strtotime('-5 day')) {
//check for total payments is less than 5 times
if ($subscription->get_total_payments() < 5) {
EDD()->fees->add_fee('10', 'Handling Fee', 'handling_fee');
}
}
$status = $subscription->get_status();
if (strtolower($status) == 'cancelled') {
EDD()->fees->add_fee('10', 'Handling Fee', 'handling_fee');
}
}
}
add_action( 'init', 'cg_add_handling_fee' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment