The code in this article is to be considered a customisation. As such, it's outside the scope of our support service. Should you need assistance implementing the code, please feel free to contact us to request a consultation.


In some cases, when a customer chooses Stripe as the payment method to pay for a subscription, he can receive an error message saying "Your order must be completed in <currency>" (where <currency> is a currency code). That message appears due how Easy Digital Downloads and Stripe handle subscriptions. 


Easy Digital Downloads relies on Stripe's native subscription mechanism to handle recurring payments, which doesn't allow a customer to have subscriptions in more than one currency. In other words, if a customer purchased a subscription via Stripe in a currency, he/she will always have to pay for future subscriptions in that currency, when using Stripe.


We reviewed this issue extensively with the EDD Team, and they confirmed that this is the case:


From: Easy Digital Downloads Support

Due to restrictions in Stripe's systems, a customer that purchases a subscription in one currency may only ever purchase subscriptions in that same currency. If a subscription is purchased in USD, all future subscriptions for that customer must also be purchased in USD.


The problem you're encountering here is due to a customer attempting to purchase a subscription in a different currency than their original subscription was purchased in. If we look at the customer account [...] they purchased a subscription in USD. This purchase forever locked (due to Stripe's restrictions) this customer's account into USD. Recently, the customer tried to purchase another subscription, but this time the purchase was not in USD, which failed because Stripe does not support purchasing a subscription in a currency after the account was set up in a different currency.


How to prevent the error message from appearing

Since it's not possible to force Stripe to accept multiple currencies for a subscription, a workaround is to check if a customer purchased a subscription via Stripe in the past and, if that is the case, force the currency to the one used for that purchase. This will ensure that customers will always see the currency used for past Stripe subscriptions, and that will prevent the error message.


We prepared a code snippet that shows how to force the currency, when a customer purchased a subscription via Stripe. To use the code, simply place it in your theme's functions.php. See How to Safely Add Custom Code to WordPress Sites for more information on how to do that.


Example 1 - Force the currency for customers who purchased a subscription via Stripe

/**
 * Returns the currency used to purchase a past subscription via Stripe.
 *
 * @param int user_id
 * @return string|false
 * @author Aelia <support@aelia.co>
 */
function aelia_get_currency_from_stripe_subscription($user_id = null) {
  if(empty($user_id)) {
    $user_id = get_current_user_id();
  }
  
  // Fetch past subscriptions purchased by the user
  $subscriber = new EDD_Recurring_Subscriber($user_id);
  $subscriptions = $subscriber->get_subscriptions();

  if(empty($subscriptions)) {
    return false;
  }

  $stripe_subscription_currency = false;
  foreach($subscriptions as $subscription) {
    // When we find a subscription that was paid via Stripe, we can
    // take the currency from it
    if($subscription->gateway === 'stripe') {
      $stripe_subscription_currency = edd_get_payment_currency_code($subscription->parent_payment_id);
      
      if(!empty($stripe_subscription_currency)) {
        break;
      }
    }
  }
  return $stripe_subscription_currency;
}

/**
 * Checks if a customer purchased a subscription via Stripe in the past. If he
 * did, forces the active currency to the one that was used for such purchase.
 * 
 * @param string currency
 * @return string
 * @author Aelia <support@aelia.co>
 * @link
 */
function aelia_force_currency_for_stripe_subscriptions($currency) {
  // Don't do anything in the following cases
  // - User is not logged in
  // - The edd_recurring() function doesn't exist
  // - There isn't a subscription in the cart
  if(!is_user_logged_in()) {
    return $currency;
  }

  if(!function_exists('edd_recurring')) {
    return $currency;
  }

  if(!edd_recurring()->cart_contains_recurring()) {
    return $currency;
  }

  // If we reach this point, there is a subscription in the cart. We can check
  // if the customer purchased any subscription via Stripe in the past and,
  // if that is the case, we can force the currency to the one used for past
  // purchases
  $stripe_subscription_currency = aelia_get_currency_from_stripe_subscription(get_current_user_id());
  if(!empty($stripe_subscription_currency)) {
    $currency = $stripe_subscription_currency;
  }

  return $currency;
}
add_filter('edd_currency', 'aelia_force_currency_for_stripe_subscriptions', 20);


You can purchase the Currency Switcher for Easy Digital Downloads from our online shop.