Search code examples
wordpresspaypalcurrency

Best way to implement unsupported paypal currency into woocommerce


I'm making a webshop and I'm using woocommerce. The problem is following:

My customer wants to sell only in Croatia, for now which means I have to display price in Kunas (HRK)...

I have PayPal gateway for woocommerce, and I have implemented Croatian Kuna into woocommerce system by using following code (I'm only posting this to make full description):

<?php
// Add currency / symbol
add_filter( 'woocommerce_currencies', 'add_rand_currency' );
add_filter( 'woocommerce_currency_symbol', 'add_rand_currency_symbol' );

function add_rand_currency( $currencies ) {
    $currencies['HRK'] = __( 'Croatian Kuna (kn)', 'woothemes' );
    return $currencies;
}

function add_rand_currency_symbol( $symbol ) {
    $currency = get_option( 'woocommerce_currency' );
    switch( $currency ) {
        case 'HRK': $symbol = 'kn'; break;
    }
    return $symbol;
}
?>

If I select Croatian Kuna for my currency from administration, PayPal gateway says currency is not supported. Ok, so I understand I can't send customers order in Kunas but I can do that in Euros for example.

So here's my Idea, and I'd like to hear what you think about it.

I'll make my default currency Euros (which means I'll have to enter product prices in euros), and on the front end I'll get all prices (that are nicely wrapped with .price css class) with jQuery and recalculate them to from Euro to Kuna (just visually), while woocommerce will send on checkout all products to pay pal in Euros.

Just to add, I'm running on deadline and this is only problem left to solve, so this is the main reason why I'm doing it with JavaScript. I'll probably use yahoo api for currency conversion, if there's something better let me know.


Solution

  • Some time ago I made a tutorial about this topic in my blog. It deals with

    1. How to add new currency;
    2. Currency symbol;
    3. Allow Paypal with your new currency and transform amounts into a Paypal supported currency before Paypal payments.

    http://devseon.com/en/wordpress-tutorials/woocommerce-add-a-paypal-unsupported-currency/

    Please check it out. I guess that for the current problem you need only part 3 of my tutorial. But George was right that in order to allow Paypal with the new currency you have to edit the is_valid_for_use() function in a plugin file: wp-content/plugins/woocommerce/classes/gateways/paypal/class-wc-paypal.php to be exact. The currency transformation before payment filter is described in my blog.