Paypal currency convert upon checking out

I was trying setup a paypal gateway but I was getting an error:

Gateway Disabled: PayPal does not support your store currency

Read More

By default, I have an AED Currency so I’m trying to convert it to USD when checking out to paypal but right now it is not working.
I have this in my theme’s functons.php file:

add_filter( 'woocommerce_currencies', 'add_my_currency' );

function add_my_currency( $currencies ) {
     $currencies['AED'] = __( 'Emirati Dirham', 'woocommerce' );
     return $currencies;
}

add_filter('woocommerce_currency_symbol', 'add_my_currency_symbol', 10, 2);

function add_my_currency_symbol( $currency_symbol, $currency ) {
     switch( $currency ) {
          case 'AED': $currency_symbol = 'AED'; break;
     }
     return $currency_symbol;
}
add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 12;' ), 20 );

add_filter( 'woocommerce_billing_fields', 'wc_billing_fields_state_filter', 10, 1 );

function wc_billing_fields_state_filter( $address_fields ) {
    $address_fields['billing_state']['label'] = 'Emirate';
    $address_fields['billing_state']['placeholder'] = 'Emirate';
    return $address_fields;
}

EDIT: I’ve deactivated the plugin “All Currencies for WooCommerce” and the settings menu is now showing. But PayPal Gateway is still not allowed since AED is not a supported currency. How do I convert it to USD upon paying with PayPal?

The code above doesn’t seem to work

Related posts

1 comment

  1. The code you have adds AED to the list of the currencies “supported” by the PayPal gateway, but it doesn’t perform any conversion to USD. To perform a conversion, you will need a couple of things:

    • A currency conversion function. WooCommerce, by itself, is “single currency” and it doesn’t perform conversions, nor it provides or handles exchange rates. For that, you will need a multi-currency solution.
    • Once you have a multi-currency solution in place, you will have to add the code to invoke the currency conversion to transform AED to USD before the PayPal gateway sends the data to the PayPal servers.
    • Last, but not least, you will have to intercept the payment notification sent by PayPal, so that the cross checks are successful. That is, you will have an order for an amount in AED in your database, and the payment confirmation will send you an amount in USD. You will need a way to prevent such discrepancy from causing the payment validation to fail. Without this step, the orders will be left pending, or on hold, and you will have to “unblock” them manually.

    Depending on the multi-currency solution in use, the exact approach could be slightly different. As the developer of the Currency Switcher for WooCommerce, I solved all of the above for my clients, using the plugins I developed and some custom code.

    You can find the custom code that applies to our plugins in our knowledge base: Is it possible to use the Currency Switcher to allow Users to select a currency, but force payment in base currency, or an arbitrary currency?.

    Whether you decide to use our plugins or not, the code should be a good starting point to implement a solution.

Comments are closed.