Check if Coupon Code Exists

In the previous tutorial we already discussed how to check if a specific coupon is applied to cart or to an order. But in this tutorial I will show you a different thing – how to find out programmatically if coupon with a specific code is actually created in WooCommerce admin.

Is there some specific condition for that?

Coupons in WooCommerce admin

In order to check if blackfrd coupon exists we can use just one function wc_get_coupon_id_by_code() and it will be enough.


if( wc_get_coupon_id_by_code( 'blackfrd' ) ) {
	echo 'Yep, the coupon exists.';
} else {
	echo 'Does not exist.';

This function returns a coupon ID in case it exists or 0 if it doesn’t.

Misha Rudrastyh

Misha Rudrastyh

Hey guys and welcome to my website. For more than 10 years I've been doing my best to share with you some superb WordPress guides and tips for free.

Need some developer help? Contact me

Follow me on X