From 6329413402a5d51e3be6886b945858802121bd22 Mon Sep 17 00:00:00 2001 From: poojarazor Date: Wed, 23 Feb 2022 15:42:33 +0530 Subject: [PATCH 1/4] disable coupon on discount rule --- includes/api/coupon-get.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/includes/api/coupon-get.php b/includes/api/coupon-get.php index cbcd8d27..824a3cd2 100755 --- a/includes/api/coupon-get.php +++ b/includes/api/coupon-get.php @@ -67,6 +67,14 @@ function getCouponList($request) 'posts_per_page' => -1, // By default WP_Query will return only 10 posts, to avoid that we need to pass -1 ); + //check woo-discount-rule plugin disabling the coupons + $discountOptions = get_option( 'woo-discount-config-v2', array()); + $isCouponEnabled = $discountOptions['disable_coupon_when_rule_applied']; + if ($isCouponEnabled == 'disable_coupon') + { + $args = array(); + } + $coupons = new WP_Query($args); $couponData['promotions'] = array(); From 5150ca4ea17ef93177e8ede223608c06b9a9d66a Mon Sep 17 00:00:00 2001 From: poojarazor Date: Wed, 2 Mar 2022 10:34:40 +0530 Subject: [PATCH 2/4] change in apply coupon --- includes/api/coupon-apply.php | 18 ++++++++++++++++++ includes/api/coupon-get.php | 10 +++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/includes/api/coupon-apply.php b/includes/api/coupon-apply.php index d96ed85a..912c18eb 100644 --- a/includes/api/coupon-apply.php +++ b/includes/api/coupon-apply.php @@ -59,6 +59,24 @@ function applyCouponOnCart(WP_REST_Request $request) return new WP_REST_Response($response, 400); } + //check woo-discount-rule plugin disabling the coupons + $discountOptions = get_option( 'woo-discount-config-v2', array()); + if (!empty($discountOptions)) + { + $isCouponEnabled = $discountOptions['disable_coupon_when_rule_applied']; + if ($isCouponEnabled == 'disable_coupon') + { + $response["failure_reason"] = "Coupon feature disabled"; + $response["failure_code"] = "INVALID_COUPON"; + $logObj["response"] = $response; + + rzpLogError(json_encode($logObj)); + + return new WP_REST_Response($response, 400); + } + } + + if (empty($coupon->get_email_restrictions()) === false) { if ($email == "") { $response["failure_reason"] = "User email is required"; diff --git a/includes/api/coupon-get.php b/includes/api/coupon-get.php index 824a3cd2..77e38adf 100755 --- a/includes/api/coupon-get.php +++ b/includes/api/coupon-get.php @@ -69,11 +69,15 @@ function getCouponList($request) //check woo-discount-rule plugin disabling the coupons $discountOptions = get_option( 'woo-discount-config-v2', array()); - $isCouponEnabled = $discountOptions['disable_coupon_when_rule_applied']; - if ($isCouponEnabled == 'disable_coupon') + if (!empty($discountOptions)) { - $args = array(); + $isCouponEnabled = $discountOptions['disable_coupon_when_rule_applied']; + if ($isCouponEnabled == 'disable_coupon') + { + $args = array(); + } } + $coupons = new WP_Query($args); From bbd0b593b1af5ba44eb1ba670873466fe1dd5cec Mon Sep 17 00:00:00 2001 From: poojarazor Date: Wed, 2 Mar 2022 10:45:56 +0530 Subject: [PATCH 3/4] change in array format --- includes/api/coupon-apply.php | 2 +- includes/api/coupon-get.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/api/coupon-apply.php b/includes/api/coupon-apply.php index 912c18eb..e3a8567e 100644 --- a/includes/api/coupon-apply.php +++ b/includes/api/coupon-apply.php @@ -60,7 +60,7 @@ function applyCouponOnCart(WP_REST_Request $request) } //check woo-discount-rule plugin disabling the coupons - $discountOptions = get_option( 'woo-discount-config-v2', array()); + $discountOptions = get_option( 'woo-discount-config-v2', []); if (!empty($discountOptions)) { $isCouponEnabled = $discountOptions['disable_coupon_when_rule_applied']; diff --git a/includes/api/coupon-get.php b/includes/api/coupon-get.php index 77e38adf..b395a89b 100755 --- a/includes/api/coupon-get.php +++ b/includes/api/coupon-get.php @@ -68,7 +68,7 @@ function getCouponList($request) ); //check woo-discount-rule plugin disabling the coupons - $discountOptions = get_option( 'woo-discount-config-v2', array()); + $discountOptions = get_option( 'woo-discount-config-v2', []); if (!empty($discountOptions)) { $isCouponEnabled = $discountOptions['disable_coupon_when_rule_applied']; From 45af465048f4a992a8ed1e4a346e3a718892f37e Mon Sep 17 00:00:00 2001 From: ChetanGN Date: Wed, 2 Mar 2022 10:51:51 +0530 Subject: [PATCH 4/4] Code beautify --- includes/api/coupon-apply.php | 15 ++++++--------- includes/api/coupon-get.php | 11 ++++------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/includes/api/coupon-apply.php b/includes/api/coupon-apply.php index e3a8567e..1ea29dae 100644 --- a/includes/api/coupon-apply.php +++ b/includes/api/coupon-apply.php @@ -60,22 +60,19 @@ function applyCouponOnCart(WP_REST_Request $request) } //check woo-discount-rule plugin disabling the coupons - $discountOptions = get_option( 'woo-discount-config-v2', []); - if (!empty($discountOptions)) - { + $discountOptions = get_option('woo-discount-config-v2', []); + if (!empty($discountOptions)) { $isCouponEnabled = $discountOptions['disable_coupon_when_rule_applied']; - if ($isCouponEnabled == 'disable_coupon') - { - $response["failure_reason"] = "Coupon feature disabled"; - $response["failure_code"] = "INVALID_COUPON"; - $logObj["response"] = $response; + if ($isCouponEnabled == 'disable_coupon') { + $response["failure_reason"] = "Coupon feature disabled"; + $response["failure_code"] = "INVALID_COUPON"; + $logObj["response"] = $response; rzpLogError(json_encode($logObj)); return new WP_REST_Response($response, 400); } } - if (empty($coupon->get_email_restrictions()) === false) { if ($email == "") { diff --git a/includes/api/coupon-get.php b/includes/api/coupon-get.php index b395a89b..4c240d06 100755 --- a/includes/api/coupon-get.php +++ b/includes/api/coupon-get.php @@ -68,16 +68,13 @@ function getCouponList($request) ); //check woo-discount-rule plugin disabling the coupons - $discountOptions = get_option( 'woo-discount-config-v2', []); - if (!empty($discountOptions)) - { + $discountOptions = get_option('woo-discount-config-v2', []); + if (!empty($discountOptions)) { $isCouponEnabled = $discountOptions['disable_coupon_when_rule_applied']; - if ($isCouponEnabled == 'disable_coupon') - { - $args = array(); + if ($isCouponEnabled == 'disable_coupon') { + $args = array(); } } - $coupons = new WP_Query($args);