From e8bd204fcce5bfb4d51917aa6769ddee9bbaa243 Mon Sep 17 00:00:00 2001 From: ChetanGN Date: Thu, 2 Jun 2022 17:30:36 +0530 Subject: [PATCH 1/2] Fixed dual shipping fee label on wc order details page --- woo-razorpay.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/woo-razorpay.php b/woo-razorpay.php index 71aa7361..de8682a1 100644 --- a/woo-razorpay.php +++ b/woo-razorpay.php @@ -1429,6 +1429,9 @@ public function update1ccOrderWC(& $order, $wcOrderId, $razorpayPaymentId) //Apply coupon to woo-order if (empty($couponKey) === false) { + // Remove the same coupon, if already being added to order. + $order->remove_coupon($couponKey); + //TODO: Convert all razorpay amount in paise to rupees $discount_total = $razorpayData['promotions'][0]['value']/100; @@ -1452,6 +1455,18 @@ public function update1ccOrderWC(& $order, $wcOrderId, $razorpayPaymentId) //Apply shipping charges to woo-order if(isset($razorpayData['shipping_fee']) === true) { + + //To remove by default shipping method added on order. + $existingItems = (array) $order->get_items('shipping'); + rzpLogInfo("Shipping details updated for orderId: $wcOrderId is".json_encode($existingItems)); + + if (sizeof($existingItems) != 0) { + // Loop through shipping items + foreach ($existingItems as $existingItemId) { + $order->remove_item($existingItemId); + } + } + // Get a new instance of the WC_Order_Item_Shipping Object $item = new WC_Order_Item_Shipping(); From 381426ae6db811755076ddbbabfda3572f3f14eb Mon Sep 17 00:00:00 2001 From: ChetanGN Date: Thu, 2 Jun 2022 17:34:59 +0530 Subject: [PATCH 2/2] Bug fix for undefined variable --- includes/api/shipping-info.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/includes/api/shipping-info.php b/includes/api/shipping-info.php index 8ef33c87..c4b7ca4d 100644 --- a/includes/api/shipping-info.php +++ b/includes/api/shipping-info.php @@ -278,13 +278,13 @@ function getCodShippingInfo1cc($instanceId, $methodId, $orderId, $address) $availablePaymentMethods = WC()->payment_gateways->payment_gateways(); + $minCODAmount1cc = !empty(get_option('woocommerce_razorpay_settings')['1cc_min_COD_slab_amount']) ? get_option('woocommerce_razorpay_settings')['1cc_min_COD_slab_amount'] : 0; + $maxCODAmount1cc = !empty(get_option('woocommerce_razorpay_settings')['1cc_max_COD_slab_amount']) ? get_option('woocommerce_razorpay_settings')['1cc_max_COD_slab_amount'] : 0; + if (!isset($availablePaymentMethods['cod']) || 'no' == $availablePaymentMethods['cod']->enabled || !(($minCODAmount1cc <= $amount) && ($maxCODAmount1cc <= $amount))) { return false; } - $minCODAmount1cc = !empty(get_option('woocommerce_razorpay_settings')['1cc_min_COD_slab_amount']) ? get_option('woocommerce_razorpay_settings')['1cc_min_COD_slab_amount'] : 0; - $maxCODAmount1cc = !empty(get_option('woocommerce_razorpay_settings')['1cc_max_COD_slab_amount']) ? get_option('woocommerce_razorpay_settings')['1cc_max_COD_slab_amount'] : 0; - $order = wc_get_order($orderId); $amount = floatval($order->get_total()); @@ -431,6 +431,7 @@ function smartCodRestriction($addresses, $order) $postals = explode(',', trim($restriction['restrict_postals'])); $postals = array_map('trim', $postals); $customerZipcode = $addresses['zipcode']; + $flag = 0; foreach ($postals as $p) { if (!$p) {