Output a WooCommerce coupon description instead of code

This question comes from Roelof:

Is there a way, in the [WooCommerce] cart, to use the coupon description, not the code?

Sure thing! Outputting the WooCommerce coupon description instead of the code is very do-able. However, it’s not so simple to get the coupon description with current versions of WooCommerce, as you have to know a bit about how coupons are stored (though this is a lot simpler with WooCommerce 3.0+, which is coming soon).

If you want to follow this tutorial, please be sure you know how to add custom code to your site.

First, we need to determine if there’s a way to “hook” into the coupon code output to change it. By default, the coupon output will be Coupon: {code}:

WooCommerce Coupon Label: Default output
Default output

When we dig into WooCommerce a bit, we find where this is output, and see the woocommerce_cart_totals_coupon_label filter is available to let you change the label for applied coupons, giving you the label to change and the coupon itself to refer to.

Even though you have the coupon, for current and past versions of WooCommerce, there’s no “method” or straight-forward way to get the coupon description. You have to know that the coupon is a “custom post” in WordPress, and that the description is the “post excerpt” for the coupon’s post. So getting this is a little convoluted, as you have to use the coupon to get the WordPress post for it, then you can get the excerpt.

We can get the description by doing this when we have the coupon:

$coupon_post = get_post( $coupon->id );
$description = ! empty( $coupon_post->post_excerpt ) ? $coupon_post->post_excerpt : null;

Great, that works for WooCommerce pre-version 2.6. Now what about in the upcoming version 3.0 release? We can do it in a much more direct way:

$description = $coupon->get_description();

Nice, huh? So let’s put this together in a small snippet to (1) account for different WooCommerce versions to (2) get the coupon description, and (3) use this in the coupon label instead of the coupon code. You can view the full snippet here.

Now let’s see what this changes. If there is a coupon description, instead of outputting Coupon: {code}, we’ll output Coupon: {description}:

WooCommerce Coupon Label: WooCommerce coupon description
Description output

If there is no description, this code will just output Coupon instead, without a code or a description.

WooCommerce Coupon Label: no description output
No description

This won’t be a full replacement for hiding coupon fields or codes from customers, but it is handy to give them some more description about a WooCommerce coupon, or details when it’s applied to the cart smile

Hope this helps, Roelof!


  1. It makes a lot of sense to show the coupon description instead of the coupon code. It is now more flexible and convenient to manage woocommerce coupons, especially when there are many.
    Thank you for the snippet. Have an awesome day!

  2. Is there a way to add this function to the email notifications so the coupon description appears in the order emails also?

<em>Hmm, looks like this article is quite old! Its content may be outdated, so comments are now closed.</em>