Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-mw committed Jun 9, 2023
1 parent 5eb9c33 commit 890e983
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/MicroweberPackages/Checkout/CheckoutManager.php
Expand Up @@ -408,10 +408,10 @@ public function checkout($data)
$posted_fields[$value] = $data[$value];
}
}

$canUseCoupons = $this->app->option_manager->get('enable_coupons', 'shop') == 1;

// Discount details save
if ($coupon_code) {
if ($canUseCoupons and $coupon_code) {
$place_order['promo_code'] = $coupon_code;
$place_order['coupon_id'] = $coupon_id;
$place_order['discount_type'] = $discount_type;
Expand Down
2 changes: 1 addition & 1 deletion userfiles/modules/shop/coupons/admin.php
Expand Up @@ -84,7 +84,7 @@ function reload_coupon_after_save() {
if ($coupon_get_count > 0) {
?>
<label class="form-check form-check-single form-switch ps-0 mb-4" style="width: unset;">
<input type="checkbox" name="enable_coupons" class="mw_option_field form-check-input" id="enable_coupons" data-option-group="shop" data-value-checked="y" data-value-unchecked="n" <?php if (get_option('enable_coupons', 'shop') == 1): ?>checked<?php endif; ?> />
<input type="checkbox" name="enable_coupons" class="mw_option_field form-check-input" id="enable_coupons" data-option-group="shop" data-value-checked="1" data-value-unchecked="0" <?php if (get_option('enable_coupons', 'shop') == 1): ?>checked<?php endif; ?> />
&nbsp; <?php _e('Enable'); ?>
</label>
<?php
Expand Down
5 changes: 5 additions & 0 deletions userfiles/modules/shop/coupons/functions.php
Expand Up @@ -21,6 +21,11 @@ function coupon_apply($params = array())
$coupon_code = $params['coupon_code'];
$coupon_code = xss_clean($coupon_code);

if (get_option('enable_coupons', 'shop') == 0){
$json['error_message'] = _e('The coupon code usage is disabled.', true);
return $json;
}

$coupon = coupon_get_by_code($coupon_code);
if (empty($coupon)) {
$json['error_message'] = _e('The coupon code is not valid.', true);
Expand Down

0 comments on commit 890e983

Please sign in to comment.