Make WooCommerce Coupons more user friendly by telling people what they are getting in your own words

September 15, 2015 | Ecommerce, PHP, Plugins, Time Savers, Tutorials, WooCommerce, Wordpress | 1 comment

WooCommerce is, as the WordPress community agrees, a behemoth of fabulous functionality and extensibility. It’s what I wish all plugins were like in terms of their cross compatibility and ease of use. I had an interesting issue yesterday which involved the coupon system. There are plugins which allow the coupons to do more and provide more functionality (like Smart Coupons for instance) but what WooCommerce seems to do from a user perspective is inherently the same.

You are invited to add a coupon to the purchase both in the shopping cart and at checkout. Normally it’s the checkout where I tend to actually see the coupon box and then start Googling to find one to get a few quid off. On adding a coupon you are told ‘Coupon added successfully’ but you aren’t told what you’re getting until the bottom of the page when it translates as a discount (maybe).

In my situation I actually had a zero value coupon that entitled the user to a ‘free gift’ which is added as part of the packing process manually. The user never knows what they are getting unless they saw the description wherever they got the coupon from.

I decided to change that an write a short snippet of code that can be added to your theme functions.php file or a custom plugin which will augment the ‘Coupon added successfully’ message to include the description of the coupon which you can enter when setting the coupon up in the first place. This means that you can tune the text to be user friendly. My code appends the message onto the default text but it can just as easily override the default text and replace it entirely.

Use the following code:

add_filter('woocommerce_coupon_message', 'sb_woocommerce_coupon_message', 10, 3);

function sb_woocommerce_coupon_message($msg, $msg_code, $coupon_obj) {
     if ($msg_code == WC_Coupon::WC_COUPON_SUCCESS) {
          if ( $post = get_post( $coupon_obj->id ) ) {
                    if ( !empty( $post->post_excerpt ) ) {
                         $msg .= ' ' . $post->post_excerpt;
     return $msg;

What this then gets you in visual terms is the following on your checkout page:

Screen Shot 2015-09-15 at 09.54.24

In addition to this if you wish for the message to be persistent then you could also show the coupon description in the ‘Cart Totals’ block at the bottom of the cart and checkout pages. The following code achieves this for you:

add_filter('woocommerce_cart_totals_coupon_label', 'sb_woocommerce_cart_totals_coupon_label', 10, 3);

function sb_woocommerce_cart_totals_coupon_label($coupon_text, $coupon) {
     if ( $post = get_post( $coupon->id ) ) {
               if ( !empty( $post->post_excerpt ) ) {
                    $coupon_text .= '
' . $post->post_excerpt . '';
     return $coupon_text;

It then, in turn, gives this result:

Screen Shot 2015-09-15 at 10.01.13

On adding both of these code snippet you can then be sure that the user will be well informed as to what the coupon ‘deal’ is and what they are getting for their effort. As with any code like this it falls back gracefully and doesn’t add any additional code if no coupon description is present.

A Donate Button!

1 Comment

  1. Debby

    I was looking for this, thanks!
    Do you know how I can add this code to checkout and e-mail as well?

    add_filter(‘woocommerce_cart_totals_coupon_label’, ‘sb_woocommerce_cart_totals_coupon_label’, 10, 3);

    function sb_woocommerce_cart_totals_coupon_label($coupon_text, $coupon) {
    if ( $post = get_post( $coupon->id ) ) {
    if ( !empty( $post->post_excerpt ) ) {
    $coupon_text .= ‘
    ‘ . $post->post_excerpt . ”;

    return $coupon_text;


Submit a Comment

Your email address will not be published. Required fields are marked *

CommentLuv badge

Divi United

About this site and Sean Barton

Picture of Sean
Sean Barton is a Freelance PHP Website Developer in Crewe, Cheshire. He is a Wordpress and CMS/Framework specialist.
This site was set up in 2008 as a tutorial and scripting resource for the PHP language and Wordpress.
Find out more about Sean on the About Me page or use the Hire Me page to get in touch. For more information about Sean's work take a look at the Portfolio

Our Services

  • Wordpress plugin/theme development
  • Divi specialist
  • Ecommerce (Woocommerce, WPSC, Shopify, Magento)
  • PSD to Wordpress theme conversion (Responsive)
  • Website design work (Banners, Logos, Full Site, etc)
  • Website analysis (security, usability, SEO)
  • API Integrations (InfusionSoft, SalesForce, Ontraport, Customer Thermometer, etc..)
  • Wordpress consultancy & expert advice
  • Crisis support
  • Website hosting

The main services offered are Wordpress based although we do a great deal of technical programming for bespoke systems. From troubleshooting, extending frameworks, finding bugs to writing them from scratch.

Find out more by looking through our past projects or get a quote.

Be the first to hear about new products/updates!

This is a mailing list for those people interested in being told when we release a new product (Divi plugin or Theme).

We shall also use this list to let you know about product updates and releases.

You have Successfully Subscribed!