Advertisement
businessdad

EDD Recurring Payments - Set active currency during renewals

May 15th, 2019
950
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.84 KB | None | 0 0
  1. /**
  2.  * Intercepts renewal payments in Easy Digital Downloads, setting the active currency to the one used
  3.  * for the original subscription.
  4.  *
  5.  * HOW TO USE THIS CODE
  6.  * Add the code to the bottom of your theme's functions.php file, and it
  7.  * will run automatically. For more information: https://www.skyverge.com/blog/add-custom-code-to-wordpress/
  8.  *
  9.  * GPL DISCLAIMER
  10.  * Because this code program is free of charge, there is no warranty for it, to the extent permitted by applicable law.
  11.  * Except when otherwise stated in writing the copyright holders and/or other parties provide the program "as is"
  12.  * without warranty of any kind, either expressed or implied, including, but not limited to, the implied warranties of
  13.  * merchantability and fitness for a particular purpose. The entire risk as to the quality and performance of the program
  14.  * is with you. should the program prove defective, you assume the cost of all necessary servicing, repair or correction.
  15.  *
  16.  * Need a consultation, or assistance to customise this code? Find us on Codeable: https://aelia.co/hire_us
  17.  */
  18. add_action('edd_recurring_process_add_renewal_payment', function() {
  19.   if(empty($_POST['sub_id'])) {
  20.     return;
  21.   }
  22.   // Load the subscription
  23.   $subscription = new EDD_Subscription(absint($_POST['sub_id']));
  24.   // Load the payment associated to the subscription
  25.   $subscription_payment = new EDD_Payment($subscription->parent_payment_id);
  26.  
  27.   if(is_objext($subscription_payment)) {
  28.     return;
  29.   }
  30.  
  31.   // Fetch the currency from the original subscription payment
  32.   $subscription_payment_currency = $subscription_payment->currency;
  33.   // Set the active currency to the one from the subscription
  34.   add_filter('edd_aelia_cs_selected_currency', function($selected_currency) use ($subscription_payment_currency) {
  35.     return $subscription_payment_currency;
  36.   }, 20);
  37. }, 0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement