/*wp_block_styles_on_demand_placeholder:69b2ef2c7ca27*/ /*# sourceURL=wp-block-library-inline-css */

How to Add a WooCommerce Discount Automatically at Checkout (2 Methods)

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

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

  1. Go to WooCommerce > Settings
  2. Click on Shipping
  3. Click on your Shipping Zone
  4. Click Add Shipping Method
  5. Select Free Shipping
  6. Save it by clicking Add Shipping Method then edit it
  7. Click the Free Shipping Requires… drop-down > Select A Valid Free Shipping Coupon
  8. Save Changes
WooCommerce Checkout with No Order Bump
WooCommerce Checkout with No Order Bump
WooCommerce Checkout with No Order Bump

Free Shipping Coupon Setup

  1. Go to MarketingCoupons and create a new coupon
  2. Enter the code (we used “freeshipping“) you want people to enter in the Title field (this should be less than 8 characters)
  3. Select Fixed Cart Discount from the Discount Type drop-down
  4. Tick the Allows Free Shipping option
  5. Click Publish
WooCommerce Checkout with No Order Bump

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

  1. With the code below copied to your clipboard, head to Appearance > Theme Editor
  2. Select the functions.php file on the right
  3. Paste the copied code right above the closing PHP tag.
  4. 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.

WooCommerce Checkout with No Order Bump

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

  1. With the code below copied to your clipboard, head to Appearance > Theme Editor
  2. Select the functions.php file on the right
  3. Paste the copied code right above the closing PHP tag.
  4. Update File
WooCommerce Checkout with No Order Bump

Sweet sweet automation…

Changing your Divi site URL - The End

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

Submit a Comment

Explore more from Divi Engine

Divi Form Builder

Divi Form Builder

From simple contact forms to complex frontend post or product creation, Divi Form Builder has you covered.

Divi Form Builder
Find out more
Divi Machine

Divi Machine

Build complex websites that displays dynamic fields you can filter, search and so much more with the Divi Builder.      

Divi Machine
Find out more
Divi BodyCommerce

Divi BodyCommerce

A versatile toolkit for developers using Divi and WooCommerce together, designed to boost your e-commerce site and achieve greater conversion rates.    

Divi BodyCommerce
Find out more
Divi Handoff

Divi Handoff

Let clients update content without touching the Divi Builder. Design layouts once, connect them to Flexible Content fields, and give editors simple forms for text, images, and sections.

Divi Handoff
Find out more
Divi Loop Extender

Divi Loop Extender

Unlock the Full Power of Divi 5 Loop Builder Add advanced sorting, filtering, and relationship logic right inside the Visual Builder.

Divi Loop Extender
Find out more
Divi Membership

Divi Membership

Monetize your Divi websites by transforming them into membership sites with seamless subscription management, user-friendly interfaces, and customizable membership tiers.

Divi Membership
Find out more
Divi Machine Accounts

Divi Machine Accounts

Build an account area for your customers to edit their details, access wishlist, submitted posts and more. *Note: Requires Divi Machine installed and active

Divi Machine Accounts
Find out more
Divi Ajax Filter

Divi Ajax Filter

Filter WooCommerce, Posts & Custom Posts without reloading the page.    

Divi Ajax Filter
Find out more
Divi Mobile

Divi Mobile

Divi Mobile helps you create beautiful looking mobile menus without having to code.

Divi Mobile
Find out more
Divi Nitro

Divi Nitro

Give your Divi website that extra boost of speed with our Divi Nitro plugin to enhance your customer's experience.

Divi Nitro
Find out more
Divi Protect

Divi Protect

Password protect the content of your Divi website with our Divi Protect plugin. Keep unwanted eyes out!

Divi Protect
Find out more
Divi Mega Menu

Divi Mega Menu

Create stunning, responsive, and content-rich mega menus using the Divi Builder you already know. No coding required.  

Divi Mega Menu
Find out more