Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sarancartrabbit/fcf045a147df392f475345740ad5112f to your computer and use it in GitHub Desktop.
Save sarancartrabbit/fcf045a147df392f475345740ad5112f to your computer and use it in GitHub Desktop.
Woo Discount Rules: Remove the coupon customize and applied message
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