Skip to content

Instantly share code, notes, and snippets.

@Jeff2Ma
Last active August 28, 2022 12:07
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save Jeff2Ma/91f148fc301a8ae0851b to your computer and use it in GitHub Desktop.
Save Jeff2Ma/91f148fc301a8ae0851b to your computer and use it in GitHub Desktop.
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;
}
?>
@teaguexiao
Copy link

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

@brotherjie-win
Copy link

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

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

@xjqx05
Copy link

xjqx05 commented May 17, 2020

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

@xjqx05
Copy link

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