Created
March 13, 2024 06:10
-
-
Save sarancartrabbit/fcf045a147df392f475345740ad5112f to your computer and use it in GitHub Desktop.
Woo Discount Rules: Remove the coupon customize and applied message
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action('woocommerce_before_cart', function(){ | |
if(class_exists('\Wdr\App\Router') && class_exists('\Wdr\App\Controllers\DiscountCalculator') && class_exists('\Wdr\App\Helpers\Woocommerce')){ | |
$manage_discount = \Wdr\App\Router::$manage_discount; | |
$applied_rules = \Wdr\App\Controllers\DiscountCalculator::$applied_rules; | |
foreach ($applied_rules as $rule) { | |
if($rule->rule->exclusive == 1){ | |
$applied_coupons = \Wdr\App\Helpers\Woocommerce::getAppliedCoupons(); | |
$exclude_coupons = ['shipfree']; //You can add the coupons here (with comma separate) | |
foreach ($applied_coupons as $applied_coupon) { | |
if (in_array($applied_coupon,$exclude_coupons)) { | |
$manage_discount->removeAppliedCoupon($applied_coupon); | |
} | |
} | |
break; | |
} | |
} | |
} | |
}); | |
add_filter('woocommerce_coupon_message', function ($message, $msg_code, $coupon) { | |
$awdr_coupons = ['shipfree']; //You can add the coupons here (with comma separate) | |
if(in_array($coupon->get_code(), $awdr_coupons)){ | |
$message = ''; | |
} | |
return $message; | |
}, 10, 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment