Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multicurrency Premium Plugin Support #323

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions includes/api/coupon-apply.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* for coupon related API
*/

require_once __DIR__ . '/../support/multicurrency-premium.php';

function applyCouponOnCart(WP_REST_Request $request)
{
global $woocommerce;
Expand Down Expand Up @@ -165,6 +167,11 @@ function applyCouponOnCart(WP_REST_Request $request)
$promotion["value"] = round($discountAmount ?? 0);
$response["promotion"] = $promotion;

if(is_plugin_active('woocommerce-multicurrency/woocommerce-multicurrency.php')){
$order = wc_get_order($orderId);
$response['promotion']['value'] = currencyConvert($response['promotion']['value'],$order);
}

if ($couponError["failure_reason"] === "") {
$logObj["response"] = $response;
rzpLogInfo(json_encode($logObj));
Expand Down
9 changes: 9 additions & 0 deletions includes/api/shipping-info.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
* @return array|WP_Error|WP_REST_Response
* @throws Exception If failed to add items to cart or no shipping options available for address.
*/

require_once __DIR__ . '/../support/multicurrency-premium.php';

function calculateShipping1cc(WP_REST_Request $request)
{
$params = $request->get_params();
Expand Down Expand Up @@ -63,6 +66,12 @@ function calculateShipping1cc(WP_REST_Request $request)
WC()->cart->empty_cart();
$logObj['response'] = $response;
rzpLogInfo(json_encode($logObj));

if(is_plugin_active('woocommerce-multicurrency/woocommerce-multicurrency.php')){
$order = wc_get_order($orderId);
$response['0']['shipping_fee'] = currencyConvert($response['0']['shipping_fee'],$order);
}

return new WP_REST_Response(array('addresses' => $response), 200);
}

Expand Down
17 changes: 17 additions & 0 deletions includes/support/multicurrency-premium.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

use WOOMC\API;
angbpy marked this conversation as resolved.
Show resolved Hide resolved

function currencyConvert($amountInPaise,$order){
return round(API::convert($amountInPaise,getOrderCurrency($order),"INR"),0);
}

function getOrderCurrency($order)
{
if (version_compare(WOOCOMMERCE_VERSION, '2.7.0', '>='))
{
return $order->get_currency();
}

return $order->get_order_currency();
}