add_filter('woocommerce_coupon_is_valid', 'check_multi_coupon_code_by_kanha',
10, 3);
function check_multi_coupon_code_by_kanha($valid, $coupon, $discount)
{
if (defined('DOING_AJAX') && DOING_AJAX) {
global $woocommerce;
$vip_coupon = 'ZT127FBB0383';
$sales_coupon_code = ['ZT4227634A00', 'ZTE0599CA9B3'];
//get all applied coupons
$applied_coupons = $woocommerce->cart->get_applied_coupons();
//check vip coupon is applied or not
$is_vip_coupon_applied = in_array(strtolower($vip_coupon), $applied_coupons);
//if vip code applied then check else return as valid
if ($is_vip_coupon_applied) {
//if more than 2 coupon applied then send an error
if (count($applied_coupons) == 2) {
throw new Exception('Sorry! , You can\'t add more than two coupon at once', 109);
return false;
}
$current_coupon = $coupon->code;
$check = in_array(strtolower($current_coupon), array_map('strtolower', $sales_coupon_code));
if (!$check) {
throw new Exception('Sorry! , You can\'t use this coupon with vip coupon', 109);
return false;
}
}
}
return $valid;
}
0 Comments
Post a Comment