Work Exceptionally Well! Plus an Extra Touch
-
Hi there, I just want to add that it would be useful if you could include this too. ^^ I tested it on my website and it worked like a charm. I didn’t test it for PayPal subscriptions, but for PMPro and Stripe, it works 100%.
If someone needs it, you need to insert it into delete-me/inc/delete_user.php after line 123 and before the // Delete user (line comment.) Please make a back-up first.. 🙂
// Assuming you have the subscription ID stored somewhere in your code or user data $subscription_id = get_user_meta($this->user_ID, 'stripe_subscription_id', true); // Check and delete Paid Memberships Pro membership if (function_exists('pmpro_getMembershipLevelForUser') && function_exists('pmpro_changeMembershipLevel')) { $membership_level = pmpro_getMembershipLevelForUser($this->user_ID); if (!empty($membership_level)) { pmpro_changeMembershipLevel(false, $this->user_ID, 'inactive'); // Change to 'expired' if you want to expire the membership immediately } } // Check and cancel the Stripe subscription if (!empty($subscription_id)) { // Cancel the Stripe subscription at the end of the billing period try { $stripe->subscriptions->update($subscription_id, ['cancel_at_period_end' => false]); } catch (\Stripe\Exception\ApiErrorException $e) { // Handle any errors that occur during the Stripe API call // You might want to log the error or take appropriate action error_log('Stripe API Error: ' . $e->getMessage()); } } // Cancel the PayPal subscription $paypal_subscription_id = get_user_meta($this->user_ID, 'paypal_subscription_id', true); if (!empty($paypal_subscription_id)) { try { $subscription = \PayPal\Api\Subscription::get($paypal_subscription_id, $paypal); $subscription->cancel([], $paypal); } catch (\PayPal\Exception\PayPalConnectionException $e) { error_log('PayPal API Error: ' . $e->getMessage()); } }
p.s. PLEASE, keep this plugin alive. Much appreciated!
- The topic ‘Work Exceptionally Well! Plus an Extra Touch’ is closed to new replies.