Skip to content

Commit

Permalink
Merge pull request #226 from razorpay/magic-checkout-discount
Browse files Browse the repository at this point in the history
disable coupon on discount rule
  • Loading branch information
ChetanGN authored Mar 2, 2022
2 parents 8aa5f7e + 45af465 commit b96f61c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
15 changes: 15 additions & 0 deletions includes/api/coupon-apply.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@ 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', []);
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";
Expand Down
9 changes: 9 additions & 0 deletions includes/api/coupon-get.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ 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', []);
if (!empty($discountOptions)) {
$isCouponEnabled = $discountOptions['disable_coupon_when_rule_applied'];
if ($isCouponEnabled == 'disable_coupon') {
$args = array();
}
}

$coupons = new WP_Query($args);

$couponData['promotions'] = array();
Expand Down

0 comments on commit b96f61c

Please sign in to comment.