From abaaf455582e385ad455dd3db1145697a2d2c2f2 Mon Sep 17 00:00:00 2001 From: ChetanGN Date: Tue, 10 May 2022 11:57:49 +0530 Subject: [PATCH] Fixed auto apply coupon for smart coupon plugin --- includes/api/coupon-apply.php | 3 ++- includes/api/order.php | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/includes/api/coupon-apply.php b/includes/api/coupon-apply.php index 419fb9aa..039e1cc0 100644 --- a/includes/api/coupon-apply.php +++ b/includes/api/coupon-apply.php @@ -122,10 +122,11 @@ function applyCouponOnCart(WP_REST_Request $request) // to clear any residual notices $temp = wc_print_notices(true); - WC()->cart->remove_coupon($couponCode); WC()->cart->empty_cart(); $cart1cc = create1ccCart($orderId); + + WC()->cart->remove_coupon($couponCode); if ($cart1cc) { $applyCoupon = WC()->cart->add_discount($couponCode); diff --git a/includes/api/order.php b/includes/api/order.php index 78b4005c..595d7baa 100644 --- a/includes/api/order.php +++ b/includes/api/order.php @@ -113,6 +113,10 @@ function createWcOrder(WP_REST_Request $request) updateOrderStatus($orderId, 'draft'); } else { $orderId = $woocommerce->session->get(RZP_1CC_CART_HASH . $cartHash); + + //To get the applied coupon details from cart object. + $coupons = WC()->cart->get_coupons(); + $couponCode = !empty($coupons)? array_key_first($coupons): null; } }