Created
June 4, 2021 14:05
-
-
Save Basilakis/970cd7e0bc986fbf0e6c5d84fc7d16a5 to your computer and use it in GitHub Desktop.
Easy Digital Downloads - Add Handling Fee
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
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