Forked from Jeff2Ma/Support PayPal GateWay in woocommerce.php
Last active
May 6, 2021 09:27
-
-
Save jkiss/456f992b4acd2de31d1b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, just a contribution to your code: You might consider adding this
$paypal_args['currency_code'] = 'USD'; // change to USD
Full code below.
`add_filter('woocommerce_paypal_args', 'convert_to_usd');