我需要在Woocommerce的Paypal插件中将货币从PEN转换为USD。
我的代码适用于转换价格而非运费:
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;
}
如何转换产品的运费?
答案 0 :(得分:1)
谢谢!我找到更多解决方案!税收和折扣
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;
}
答案 1 :(得分:0)