From 3ddea932704bea468d3c3a6a414e0f894840b953 Mon Sep 17 00:00:00 2001 From: Anurag Bandyopadhyay Date: Wed, 27 Jul 2022 17:54:14 +0530 Subject: [PATCH] multicurrency premium plugin support --- includes/api/coupon-apply.php | 7 +++++++ includes/api/shipping-info.php | 9 +++++++++ includes/support/multicurrency-premium.php | 17 +++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 includes/support/multicurrency-premium.php diff --git a/includes/api/coupon-apply.php b/includes/api/coupon-apply.php index 039e1cc0..a35bf009 100644 --- a/includes/api/coupon-apply.php +++ b/includes/api/coupon-apply.php @@ -4,6 +4,8 @@ * for coupon related API */ +require_once __DIR__ . '/../support/multicurrency-premium.php'; + function applyCouponOnCart(WP_REST_Request $request) { global $woocommerce; @@ -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)); diff --git a/includes/api/shipping-info.php b/includes/api/shipping-info.php index 61105fe6..9244e22c 100644 --- a/includes/api/shipping-info.php +++ b/includes/api/shipping-info.php @@ -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(); @@ -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); } diff --git a/includes/support/multicurrency-premium.php b/includes/support/multicurrency-premium.php new file mode 100644 index 00000000..7791d584 --- /dev/null +++ b/includes/support/multicurrency-premium.php @@ -0,0 +1,17 @@ +=')) + { + return $order->get_currency(); + } + + return $order->get_order_currency(); +} \ No newline at end of file