Coupons are a great way to convert some visitors into customers, but what if you wanted to Add a WooCommerce Discount Automatically at checkout without needing your customer to enter a code? Or maybe you want some tiered deals based on the number of items in your prospective buyer’s cart.
In this tutorial, we are going to show you 2 methods that will allow you to either have a pre-made WooCommerce coupon automatically applied to the cart, or have different discounts applied based on predetermined criteria. We will include the code snippets that get the magic done, and talk a little about how you can customize that code to suit your needs.
Video Tutorial
Table of Contents
Difficulty
Intermediate
Time
10 Minutes
Why Add a WooCommerce Discount Automatically at Checkout?
WooCommerce natively comes with a feature that allows you to create coupons and make them available to your visitors, but the functionality unfortunately is a bit limited if you wanted to do more complicated things. There might be situations where it makes sense to have a free shipping coupon be applied automatically, or maybe you want to offer better discounts as your users add more things to their cart.
It is no secret that folks that shop online are on the lookout for the best deals, so why not build that right into your site. This gives you the ability to display a nice banner at the top of your page announcing price breaks or other offers which could encourage them to spend more. This deepens engagement and obviously impacts your bottom line in a very attractive way.
Doing away with coupon codes having to be entered will also show your customers that you care which in turn will increase their LTV. If you are willing to automatically add discounts for purchases that meet certain criteria, you are probably willing to go the extra mile for them in other ways.
Adding a Coupon Code Automatically based on Minimum Spend
The first method we will be looking at will add a coupon code you created to your cart automatically. A perfect use case for this would be if you wanted to offer free shipping if customers spent over $100. The choice is really yours, and I will show you how to add the code below to your site in a few simple steps, but first, let’s create our free shipping option and coupon code.
Free Shipping Option
- Go to
- Click on Shipping
- Click on your Shipping Zone
- Click Add Shipping Method
- Select Free Shipping
- Save it by clicking Add Shipping Method then edit it
- Click the Free Shipping Requires… drop-down > Select A Valid Free Shipping Coupon
- Save Changes
Free Shipping Coupon Setup
- Go to > and create a new coupon
- Enter the code (we used “freeshipping“) you want people to enter in the Title field (this should be less than 8 characters)
- Select Fixed Cart Discount from the Discount Type drop-down
- Tick the Allows Free Shipping option
- Click Publish
Ok, we have everything set up now, all we need to do is add the code to the functions.php file to get it working. For this tutorial, we will edit the functions.php in our child theme by using the Theme Editor baked into WordPress.
Add the Code for Adding a Coupon Code Automatically based on Minimum Spend
- With the code below copied to your clipboard, head to Appearance > Theme Editor
- Select the functions.php file on the right
- Paste the copied code right above the closing PHP tag.
- Update File
NOTE: If you are not using a child theme, we strongly suggest you create one. You can follow our guide on How to set up a Divi Child Theme with Dynamic CSS which will help you do so.
Adding a Discount Automatically Based on the Number of Items in the Cart
Our second method offers another take on automatically adding a discount to the cart at checkout. With this method we will not be creating a coupon code ahead of time, instead, we will offer a calculated discount based on the number of items in the cart.
If there is 1 item in the cart the discount is 10%, if there are 2 items the discount is 15%, and when there are 3 items the discount is 25%.
To accomplish this, we will follow the same steps we did before where we added some code to the functions.php file in our child theme.
Add the Code for Adding a Coupon Code Automatically based on Minimum Spend
- With the code below copied to your clipboard, head to Appearance > Theme Editor
- Select the functions.php file on the right
- Paste the copied code right above the closing PHP tag.
- Update File
Sweet sweet automation…
Conclusion
That wasn’t so bad? Was it? Learning How to Add a WooCommerce Discount Automatically at Checkout is something that will sharpen your skills as a Divi and WordPress developer and offer your clients a new option when building their online stores. Customizing this code to extend or change the functionality is also super easy, so definitely check out the video at the start of this post to get into how you would do that.
Hopefully, this content was helpful, so if you like it, please subscribe to our youtube channel and let us know your comments and feedback below in the comments.
0 Comments