-1

I need to convert currency from PEN to USD for the Paypal plugin in Woocommerce.

My code below works for converting the price but not the shipping costs:

add_filter('woocommerce_paypal_args', 'convert_bgn_to_eur');
function convert_bgn_to_eur($paypal_args){
    if ( $paypal_args['currency_code'] == 'PEN'){
        $convert_rate = 3.3; //set the converting rate
        $paypal_args['currency_code'] = 'USD'; //change Pen to USD
        $i = 1;

        while (isset($paypal_args['amount_' . $i])) {
            $paypal_args['amount_' . $i] = round( $paypal_args['amount_' . $i] / $convert_rate, 2);
            ++$i;
        }

    }
return $paypal_args;
}

How do I also convert the shipping costs of the product?

Anand Choudhary
  • 566
  • 4
  • 16

2 Answers2

1

Thanks! i find more solutions! for tax and discount

add_filter('woocommerce_paypal_args', 'convert_bgn_to_eur');
function convert_bgn_to_eur($paypal_args){
    if ( $paypal_args['currency_code'] == 'PEN'){
        $convert_rate = 3.200; //set the converting rate
        $paypal_args['currency_code'] = 'USD'; //change Pen to USD
        $i = 1;

        while (isset($paypal_args['amount_' . $i])) {
            $paypal_args['amount_' . $i] = round( $paypal_args['amount_' . $i] / $convert_rate, 2);
            ++$i;
        }

                if (isset($paypal_args['tax_cart'])) {
            $paypal_args['tax_cart'] = round($paypal_args['tax_cart'] / $convert_rate, 2);
        }

        if (isset($paypal_args['shipping_1'])) {
            $paypal_args['shipping_1'] = round($paypal_args['shipping_1'] / $convert_rate, 2);
        }

        if ( $paypal_args['discount_amount_cart'] > 0 ) {
$paypal_args['discount_amount_cart'] = round( $paypal_args['discount_amount_cart'] / $convert_rate, 2);
}

    }
return $paypal_args;
}
0

Simply go to WooCommerce Settings, and under Currency options you'll see an option to change the currency.

WooCommerce Currency Options

Sheedo
  • 524
  • 5
  • 13