gpt4 book ai didi

php - 在 woocommerce 中过滤货币并将其从 usd 转换为 inr for ccavenue

转载 作者:可可西里 更新时间:2023-10-31 23:46:10 25 4
gpt4 key购买 nike

我在我的 wordpress 网站上使用 ccavenue 支付网关。
插件网址是 https://wordpress.org/plugins/ccavenue-payment-gateway-woocommerce/
但我有一个问题,我的基础货币是印度卢比,而 ccavenue 只接受印度卢比付款,所以当用户将货币切换为美元时,ccavenue 将 40 美元作为 inr40。
我想先转换货币,然后再转到 ccavenue 页面。
相同的代码片段是。

 public function generate_ccavenue_form($order_id){

global $woocommerce;
$order = new WC_Order($order_id);
$redirect_url = ($this -> redirect_page_id=="" || $this -> redirect_page_id==0)?get_site_url() . "/":get_permalink($this -> redirect_page_id);
//For wooCoomerce 2.0

$redirect_url = add_query_arg( 'wc-api', get_class( $this ), $redirect_url );
$order_id = $order_id.'_'.date("ymds");
$checksum = $this -> getCheckSum($this -> merchant_id, $order->order_total, $order_id, $redirect_url, $this -> working_key);


$ccavenue_args = array(
'Merchant_Id' => $this -> merchant_id,

'Amount' => $order->order_total,
'Order_Id' => $order_id,
'Redirect_Url' => $redirect_url,
'Checksum' => $checksum,
'currency_code' => get_woocommerce_currency(),

'billing_cust_name' => $order -> billing_first_name .' '. $order -> billing_last_name,
'billing_cust_address' => $order -> billing_address_1,
'billing_cust_country' => $order -> billing_country,
'billing_cust_state' => $order -> billing_state,
'billing_cust_city' => $order -> billing_city,
'billing_zip' => $order -> shipping_postcode,
'billing_cust_tel' => $order -> billing_phone,
'billing_cust_email' => $order -> billing_email,
'delivery_cust_name' => $order -> shipping_first_name .' '. $order -> shipping_last_name,
'delivery_cust_address' => $order -> shipping_address_1,
'delivery_cust_country' => $order -> shipping_country,
'delivery_cust_state' => $order -> shipping_state,
'delivery_cust_tel' => $order -> shipping_phone,
'delivery_cust_notes' => '',
'Merchant_Param' => '',
'billing_zip_code' => $order -> billing_postcode,
'delivery_cust_city' => $order -> shipping_city,
'delivery_zip_code' => $order -> shipping_postcode
);

$ccavenue_args_array = array();
foreach($ccavenue_args as $key => $value){
$ccavenue_args_array[] = "<input type='hidden' name='$key' value='$value'/>";
}

我想我必须为此在 function.php 中添加一个过滤器 Hook 。但我无法为此制作和添加过滤器。

最佳答案

您可以使用 Google API 进行货币换算。

您必须在 woocommcerce 中放置一些自定义函数来实时转换您的货币,因为 CCavenue 不支持 INR,因此您必须先转换为美元,然后将此可变金额发送到 CCavenue 表单。

将以下代码添加到 functions.php 中,并执行您想要的适当操作。

<?php
$from_currency = 'USD';
$to_currency = 'INR';
$amount = 1;
$results = converCurrency($from_currency,$to_currency,$amount);
$regularExpression = '#\<span class=bld\>(.+?)\<\/span\>#s';
preg_match($regularExpression, $results, $finalData);
echo $finalData[0];

function converCurrency($from,$to,$amount){
$url = "http://www.google.com/finance/converter?a=$amount&from=$from&to=$to";
$request = curl_init();
$timeOut = 0;
curl_setopt ($request, CURLOPT_URL, $url);
curl_setopt ($request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($request, CURLOPT_USERAGENT,"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
curl_setopt ($request, CURLOPT_CONNECTTIMEOUT, $timeOut);
$response = curl_exec($request);
curl_close($request);
return $response;
}
?>

关于php - 在 woocommerce 中过滤货币并将其从 usd 转换为 inr for ccavenue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35716053/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com