Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Support PayPal GateWay in woocommerce【让woocommerce中文网关支持paypal并自动转换人民币美元转换】
<?php
//woocommerce中文网关支持paypal
// details at http://devework.com/support-paypal-gateway-in-woocommerce.html
//本函数解决的问题:贝宝不支持你的商铺货币。Gateway Disabled: PayPal does not support your store's currency.
add_filter( 'woocommerce_paypal_supported_currencies', 'enable_custom_currency' );
function enable_custom_currency($currency_array) {
$currency_array[] = 'CNY';
return $currency_array;
}
//美元人民币转,汇率自己定义
//thanks http://www.solagirl.net/woocommerce-paypal-rmb.html
add_filter('woocommerce_paypal_args', 'convert_rmb_to_usd');
function convert_rmb_to_usd($paypal_args){
if ( $paypal_args['currency_code'] == 'CNY'){
$convert_rate = 6.2; //Set converting rate
$count = 1;
while( isset($paypal_args['amount_' . $count]) ){
$paypal_args['amount_' . $count] = round( $paypal_args['amount_' . $count] / $convert_rate, 2);
$count++;
}
}
return $paypal_args;
}
?>
@yifenglv46

This comment has been minimized.

Copy link

@yifenglv46 yifenglv46 commented Jul 4, 2017

谢谢,就是用优惠卷的时候 金额 还是 用之前的!
不知道为什么

@teaguexiao

This comment has been minimized.

Copy link

@teaguexiao teaguexiao commented Dec 14, 2018

固定6.2的汇率不知道能否改成动态的呢?

@wordpress219

This comment has been minimized.

Copy link

@wordpress219 wordpress219 commented Sep 22, 2019

固定6.2的汇率不知道能否改成动态的呢?

理论上来说可以,但你要调用获取汇率的API,这个国内没公司资质不太好申请吧,可以申请国外的接口。

@xjqx05

This comment has been minimized.

Copy link

@xjqx05 xjqx05 commented May 17, 2020

不明白这个代码要粘贴到哪里?是 function.php 里面吗,因为没有发现 woocommerce.php 这个文件

@xjqx05

This comment has been minimized.

Copy link

@xjqx05 xjqx05 commented May 17, 2020

了解了!是 function.php里,而且这两个删掉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.