我需要一些帮助来完成此操作,我的woocommerce使用的是AED,并且我想使用Paypal,我已经成功添加了以下代码,但是当我测试购买时出现“内部错误”,这是我所需要的代码已经在结帐页面上使用了内部服务器错误。
我添加了步骤1和步骤2的代码
*Step 1 Code to add AED currency symbol in WooCommerce:*/
add_filter( 'woocommerce_paypal_supported_currencies', 'add_aed_paypal_valid_currency' );
function add_aed_paypal_valid_currency( $currencies ) {
array_push ( $currencies , 'AED' );
return $currencies;
}
/*Step 2 – Code to change 'AED' currency to ‘USD’ before checking out with Paypal through WooCommerce:*/
add_filter('woocommerce_paypal_args', 'convert_aed_to_usd', 11 );
function get_currency($from, $to){
$from = "USD";
$to = "AED";
// create curl resource
$ch = curl_init();
// set url
curl_setopt($ch, CURLOPT_URL, "https://free.currencyconverterapi.com/api/v5/convert?q={$from}_{$to}&compact=ultra");
//return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// $output contains the output string
$output = curl_exec($ch);
// close curl resource to free up system resources
curl_close($ch);
$data = explode(':', $output);
$data = explode(" ", $data[1]);
$amnt = round($data[0], 2);
return $amnt;
}
function convert_aed_to_usd($paypal_args){
if ( $paypal_args['currency_code'] == 'AED'){
$convert_rate = get_currency(); //Set converting rate
$paypal_args['currency_code'] = 'USD'; //change AED to USD
$i = 1;
while (isset($paypal_args['amount_' . $i])) {
$paypal_args['amount_' . $i] = round( $paypal_args['amount_' . $i] / $convert_rate, 2);
++$i;
}
if ( $paypal_args['shipping_1'] > 0 ) {
$paypal_args['shipping_1'] = round( $paypal_args['shipping_1'] / $convert_rate, 2);
}
if ( $paypal_args['discount_amount_cart'] > 0 ) {
$paypal_args['discount_amount_cart'] = round( $paypal_args['discount_amount_cart'] / $convert_rate, 2);
}
if ( $paypal_args['tax_cart'] > 0 ) {
$paypal_args['tax_cart'] = round( $paypal_args['tax_cart'] / $convert_rate, 2);
}
}
return $paypal_args;
}
点击结帐完成付款时出现的错误是“内部错误”,有人可以帮助您成功完成此操作吗?