Coupons are great. I personally love coupons. Your customers probably love them, too.

However, you may not love coupons – there’s a reason for it. Everyone hates to think that they may have missed out on using a coupon, so this little box can be a killer on your checkout page:

EDD discount code

Customers see this box, and think, “Oh I can probably find a discount, sweet!” and off they go. Either they find one and use it, or they can’t find one and are then disappointed in their shopping experience (which we definitely don’t want).

We wrote a bit more about this when we discussed improving eCommerce conversions, but hiding or renaming the coupon code field can decrease your cart abandonment, as customers don’t jump away from your site to spend hours at RetailMeNot. This can also save you money on affiliate referrals, as customers won’t end up clicking a referral link at a coupon site that didn’t actually send them to you in the first place. KISSmetrics has an interesting study that also supports this practice.

While we could take their advice and change the coupon field around, I don’t think we need it at all. Easy Digital Downloads has a pretty cool feature that was added in version 2.0 that will allow you to pass discount codes via URL, so we can give out links for coupons instead.

Let’s discuss how we can hide the coupon field and only use URLs to apply coupons in our Easy Digital Downloads store. This should help us ensure that customers don’t leave our checkout to go coupon hunting, but we can still offer discounts as needed.

Do I need to do this?

Before we begin: do you need this code? If you’re not using discounts at all, the answer is no. The discount field is only shown if you’ve created discount codes in your shop.

This is meant to hide the coupon field on the checkout page even if you have discounts created. This will prevent customers from entering them in the discount field box and won’t give an indicator that you even allow coupons in your store. However, you can still give out coupons via a URL.

First, let’s discuss how to remove the discount code field from the checkout page. We can remove this field with a one-line code snippet. The discount code field is added via this action, so we’ll simply remove this action to hide it:

remove_action( 'edd_checkout_form_top', 'edd_discount_field', -1 );

Here’s our result on the frontend:


EDD Checkout with Discount

Before



EDD Checkout without Discount

After


Now how you do apply coupons? The basic structure that we’ll use to apply a discount will look like this:

http://mystore.com/?discount=CODE

We can add ?discount=CODE to the end of any URL, and this will apply a coupon with the corresponding code (replace CODE with your coupon).

You can also use this as part of an add-to-cart link, which can work very well for email campaigns that provide a discount on a particular product. Here are a few example URLs to show you how to use a discount with an add-to-cart link, and you can replace with your store URL.

  • Add a simple product to the cart, land on checkout:
    mystore.com/checkout/?edd_action=add_to_cart&download_id=123&discount=10off
    Replace the “123” with the ID of your download, and the “10off” with your coupon code instead.

  • Add a product variation to the cart, land on checkout:
    mystore.com/checkout/?edd_action=add_to_cart&download_id=123&edd_options[price_id]=0&discount=10off
    Replace the “123” with the ID of your download, 0 with the ID of your variation, and the “10off” with your coupon code instead.

Our article on creating pricing tables explains how to use add-to-cart links as well.

You can send these URLs with the discount passed into your customers or email list, and they’ll be able to take advantage of coupon codes, while customers who don’t have a code won’t leave your checkout page.

Get Fancy: Advanced Tips

Okay, that’s pretty neat. But what if your goal is to make sure customers can’t see the coupon codes at all? This way, they assume that the link can’t be used by others, or you can tell them that the link is uniquely generated for them.

Personally, I find this to be a lot of work, but I understand why some shops want to let Easy Digital Downloads hide coupons completely. You could do this with a few extra steps:

  1. Give out shortened links for the URL that contains the code – something like bit.ly works fine
  2. Create a redirection for the actual add to cart / discount link so customers won’t see the naked URL when the bitly link expands. This will add 2 redirects, which may be a bit slow, but it’s fairly easy to implement (we have a way to generalize this below).
  3. Hide the discount code in the checkout table when it’s applied.

Step 1: Give out a Short URL

If you use a custom link shortener, great. Use that. If not, use bit.ly to create a redirect for that ugly URL we made earlier:
mystore.com/checkout/?edd_action=add_to_cart&download_id=123&edd_options[price_id]=0&discount=10off

You’ll give out the shortened link in your email or marketing campaign to customers.

Step 2: Create a Redirection

We’ll let the shortened link act as a pass through. This ensures that the add to cart and discount actions are triggered via URL, then we’ll redirect customers to the checkout page, items and discount in hand.

I use the Redirection plugin for this. You can create a redirection that uses your ugly URL as the source URL, then the /checkout/ as the target.

However, I’m lazy. I don’t want to make a new redirect every time I use an add-to-cart or discount URL. The good news is that we can use Redirection with a regular expression. This will allow us to match a URL pattern instead of an exact URL. Let’s redirect any URL that ends in discount=CODE. I’m going to assume your discount codes only contain letters, numbers, +, ., or a hyphen (-).

We’ll enter our regular expression as our source URL: /(.*)discount=[A-Za-z0-9+.\-]+ and redirect this to /checkout/. This redirection will match anything that ends in discount=CODE, including add to cart links, then send them to the checkout page.

EDD discount redirection

This gives us a series of events:

Customer uses shortened URL → Customer is directed through the add-to-cart / discount link → before they know what hit ’em, they’re redirected to the checkout with a discount

This applies the action and discount in the background without being seen.

Last Step: Hide the Codes!

There’s one last place that coupon codes are used: the checkout order details show the coupon code when it’s applied. We can rename the discount code on the checkout page to something generic instead, like: “Discount applied – ” rather than using the code. There’s a handy filter that will let us change this.

Here’s what the checkout will look like with a code applied:

Easy Digital Downloads coupon

Code displayed

Let’s change that code to our generic message with this snippet:

function remove_edd_discount_code_display( $html, $discounts, $rate, $remove_url ) {

	$discounts = 'Discount applied - ' . $rate;
	return $discounts;
	
}
add_filter( 'edd_get_cart_discounts_html', 'remove_edd_discount_code_display', 10, 4 );

Now we won’t be using the discount code, but will rather use our message instead. You can replace “Discount applied” with whatever text you want. Now we’ve got a generic message at checkout that doesn’t reveal our code:

EDD No coupon code

Code removed

Summary

That’s it! I’ve got a full gist for summary if you’d like to view the code in one place, and thanks to Justin for fixing my regular expression madness for this sample.

As a final tip, don’t go through all this hard work, then include discount codes in your emails 😉 . You can change your standard email template to ensure this.

I’d love to hear about it if you use this tip! Let me know in the comments.


Your EDD store can drive additional revenue by improving your email marketing. Try Jilt for free to increase sales with abandoned cart recovery emails, post-purchase follow-ups, and more!
Articles you may also like:

Posted by Beka Rice

Beka Rice manages the direction of Sell with WP content and writes or edits most of our articles to share her interests in eCommerce. Or she just writes as an excuse to spend more time jamming out to anything from The Clash to Lady Gaga. Who knows.

5 Comments

  1. Beka, thanks for this clear walk-through, I completely agree with the rationale of not showing a coupon field based on my own behavior as a consumer!

    How would you go about notifying people clicking through a coupon’ed URL that they have a discount through the whole store, if you were to send them to the storefront instead of using direct add-to-cart? In a way that goes through the whole coupon logic of course, i.e. checking that it’s the right URL parameter, is the coupon active, are we during the coupon’s authorized timeframe…

    1. Hey Olivier, glad this was useful :). As I don’t believe there are core notices (i.e., a “discount applied” notice), the notice you’re describing sounds like you’d have generate it completely on your own. Certainly doable, but you’d probably have to have a custom plugin developed to use the discount functions for your coupon checks, then generate a notice on the page you’re redirecting to.

  2. I’m having so much trouble trying to add that code. I don’t know where to find the page or file to paste it on.

    I see the github page you link to, but that doesn’t tell me where to find the file.

    Can you direct me to where that is at?

    Thanks

  3. Ok I managed to figure out how to hide the coupon field. Now I’m having trouble changing the text to Discount Applied.

    I’ve tried pasting that code in so many different ways and I either get a blank page or no discount giving at all.

    Where exactly do I paste it and do I need to remove another code and replace it with yours?

    Thanks

    1. hey Joey, I’d recommend checking out this tutorial on adding custom code to your site — my preferred method is the Code Snippets plugin as outlined there.

It's been over 2 years since this post was published, so comments have been closed. Thanks for reading!