Skip to content

Instantly share code, notes, and snippets.

@Jeff2Ma
Last active August 28, 2022 12:07
Show Gist options
  • 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;
}
?>
@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