Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jkiss/456f992b4acd2de31d1b to your computer and use it in GitHub Desktop.
Save jkiss/456f992b4acd2de31d1b to your computer and use it in GitHub Desktop.
<?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;
}
?>
@mrkapable007
Copy link

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');

function convert_to_usd($paypal_args){  
  if ( $paypal_args['currency_code'] == 'AED'){  
      $convert_rate = 3.67; // set the converting rate here
      $paypal_args['currency_code'] = 'USD'; // change 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;  
}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment