You can use has_discount()
function of the cart.. this needs the coupon code as argument.
Use it like this:
if (WC()->cart->has_discount('test1')) {
// cart has coupon test1 applied
}
as suggested by @Anand, you can use WC()->cart->get_coupons()
. This will return all the coupons if there are any in the cart.
However, as I've check woocommerce plugin source code, get_coupons()
is using WP_Query
.
It's really not a big deal if there's no other better way.
Here's a better way. We can access a public variable of the cart applied_coupons
. It contains an array of coupon codes applied to the cart. We can use it like this...
$has_coupons = count(WC()->cart->applied_coupons)>0?true:false;
if($has_coupons) {
// cart has coupons
}