Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter askbahar

    (@askbahar)

    Ok, I got the issue. It seems that price was converted twice, first before adding into cart, and then inside cart page.

    I have fixed the problem with a simple hack 🙂

    //We are reversing the price of product to USD in cart page, because the rate is applied again there
    add_action('woocommerce_before_calculate_totals', 'fix_currency_conversion');
    function fix_currency_conversion($cart_object){
                global $WOOCS;
                $cur_currency = $WOOCS->current_currency;
                $currencies = $WOOCS->get_currencies();
                $conversion_rate = $currencies[$WOOCS->current_currency]['rate'];
                if($cur_currency == 'HKD'){
                    foreach ( $cart_object->cart_contents as $cart_item_key => $cart_item ) {
                        $cart_item['data']->price = $cart_item['data']->price / $conversion_rate;
                    }
                }
    }
    Plugin Author RealMag777

    (@realmag777)

    Great! Thank you 😉

    cmahoney83

    (@cmahoney83)

    If I’m using multiple currency options do I need to use this code once for each currency or can i modify this code for each currency?

    Plugin Author RealMag777

    (@realmag777)

    @cmahoney83
    Use it as you want in your functions.php

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Currency conversion is wrong in Cart page’ is closed to new replies.