How to Setup WooCommerce Customer Specific Discounts

How to Setup WooCommerce Customer Specific Discounts (Easy Steps)

Loyal returning customers are the backbone of any online store and the reason behind its growth and success. That’s why 90% of the companies now have a customer loyalty program where they reward their regular returning customers.

Over 70% of shoppers worldwide are loyal to at least one brand and spend 57% more than new customers. They are also responsible for 67% of the company’s revenue.

Do you know what’s the primary reason for a customer to become loyal to a brand?

Product price. If you offer a competitive price along with efficient order fulfillment and customer services, you can turn any customers into returning loyal ones.

Want an even more effective strategy?

Offer customer-specific discounts. This will create an emotional relationship with your brand, and 71% of them will recommend your brand to others, resulting in significant sales growth.

Today, we will discuss customer specific discounts WooCommerce or user role based discounts in detail and walk you through the steps to generate these discounts. 

How to Setup Customer Specific Discounts WooCommerce

If you have developed a WooCommerce membership website, you can create customer-specific pricing for WooCommerce based on your membership/subscription plans. In addition to that, you can also create first-order discount coupons or recurring product discounts for your customers using the built-in coupon tool.

customer specific discounts WooCommerce

However, if you have a regular Woo store where there are no recurring membership plans, you can’t, unfortunately, directly offer customer specific discounts WooCommerce.

There are two ways you can apply WooCommerce returning customer discount –

  1. Using custom codes in core WooCommerce theme files
  2. Using a WooCommerce customer specific discount plugin

While using a plugin is the easiest and best way to generate WooCommerce discounts per customer, let’s check out the manual coding method first.

Setting up Customer-Specific Discounts WooCommerce Using Custom Codes

There are three ways you can offer a WooCommerce customer discount.

  1. Customer-Specific Discount: Applies discounts based on individual user IDs.
  2. User Role-Based Discount: Applies discounts based on user roles.
  3. Purchase History Discount: Applies discounts based on purchase history, such as total spent.

Let’s start with the customer specific discounts WooCommerce option.

Set up WooCommerce Customer Specific Pricing Using Custom Codes

Here are the steps needed for setting up WooCommerce customers that automatically get a discount.

Step 1: Backup Your Site

You either must take a backup of your site or use a child theme. This allows you to restore your files if anything goes wrong.

Step 2: Access the Theme’s Functions.php File

To add custom codes to your site, you need to access your theme’s functions.php file.

  1. The easiest way to do this is from the WordPress dashboard. Additionally, you can access this file from FTP or the hosting server Cpanel as well.
  2. From the WordPress Admin Dashboard: go to Appearance >> Theme Editor.
theme file editor
  1. After that, click the functions.php and scroll down to the bottom to insert your codes.
function php
Step 3: Add Custom Code for Customer-Specific Discounts

Let’s say you want to offer a 10% discount to someone specific and a 20% discount to another customer. Here’s what you need to do for customer specific discounts WooCommerce –

  1. Identify the Customer:
    • Check if the current user is logged in and get their user ID.
  2. Apply Discount:
    • Define the discount logic for specific users.

Here are the codes –

function apply_customer_specific_discount( $cart ) {

// Define user-specific discounts

$discounts = array(

     1 => 0.10, // User ID 1 gets a 10% discount

     2 => 0.20  // User ID 2 gets a 20% discount

);

// Check if the user is logged in

if ( is_user_logged_in() ) {

     $user_id = get_current_user_id();

     // Apply discount if the user is in the discounts array

     if ( array_key_exists( $user_id, $discounts ) ) {

         $discount_percentage = $discounts[$user_id];

         // Apply discount to cart

         foreach ( $cart->get_cart() as $cart_item_key => $cart_item ) {

             $price = $cart_item['data']->get_price();

             $discounted_price = $price - ( $price * $discount_percentage );

             $cart_item['data']->set_price( $discounted_price );

         }

     }

}

}

add_action( 'woocommerce_before_calculate_totals', 'apply_customer_specific_discount' );
Step 4: Find and Replace User ID

You can find the specific customer’s ID from the Users page in the WordPress admin panel. Go to Users >> All Users.

Hover over the username you want to find the ID of, and you can find the ID from the URL that appears at the bottom left.

collect user id

Similarly, collect other IDs and replace them in the codes.

     4 => 0.10, // User ID 1 gets a 10% discount

     6 => 0.20  // User ID 2 gets a 20% discount

Step 5: Save and Test

Save all the changes you have made in the functions.php.

Test the Functionality:

Log in with one of the IDs you have selected and add some products to the cart to check if the customer specific discounts WooCommerce are working or not.

customer specific discounts WooCommerce

As you can see, a 10% discount has been automatically applied to the customer. Next, log in as the customer with the 20% discount.

Add some items to the cart and check out the cart page.

customer specific discounts WooCommerce

WooCommerce has automatically applied a 20% discount as per our set customer specific discounts WooCommerce codes.

Setup User Role-Based Discount in WooCommerce Using Custom Codes

Here’s how to add custom code for user role-based discounts in WooCommerce using custom codes.

Adding User Role-Based Discount Custom Codes

Suppose you have a loyalty program and divided your customers into different membership plans such as Gold, Silver, Platinum, etc. Let’s say you want to reward your Gold members with a 10% and Platinum members with a 20% discount.

Here’s how you do it –

Identify the User Role:

  • Check the user’s role if they are logged in.

Apply Discount:

  • Define the discount logic based on user roles.

Here are the codes –

function apply_user_role_based_discount( $cart ) {

// Define role-specific discounts

$role_discounts = array(

     'Gold' => 0.10, // Gold subscribers get a 10% discount

     'Platinum' => 0.20 // Platinum customers get a 20% discount

);

// Check if the user is logged in

if ( is_user_logged_in() ) {

     $user = wp_get_current_user();

     $user_roles = $user->roles;

     // Apply discount if the user role is in the discounts array

     foreach ( $user_roles as $role ) {

         if ( array_key_exists( $role, $role_discounts ) ) {

             $discount_percentage = $role_discounts[$role];

             // Apply discount to cart

             foreach ( $cart->get_cart() as $cart_item_key => $cart_item ) {

                 $price = $cart_item['data']->get_price();

                 $discounted_price = $price - ( $price * $discount_percentage );

                 $cart_item['data']->set_price( $discounted_price );

             }

             break; // Only apply the first matching role's discount

         }

     }

}

}

add_action( 'woocommerce_before_calculate_totals', 'apply_user_role_based_discount' );

Customer Specific Discounts WooCommerce Based on Purchase History

Let’s say you want to offer discounts based on purchase history. For example, customers who have spent $500 in total before will get a 20% discount on their subsequent purchases. Let us walk you through the steps.

Calculate Total Spent by the Customer

First, you need a function to calculate the total amount a customer has spent on your store.

function get_total_spent_by_customer( $user_id ) {

$total_spent = wc_get_customer_total_spent( $user_id );

return $total_spent;

}

Apply the Discount Based on Purchase History

Now, create a function that applies a discount if the customer has spent more than a specified amount.

function apply_purchase_history_based_discount( $cart ) {

$required_total_spent = 500; // Set the required amount spent for discount eligibility

$discount_percentage = 0.20; // Set the discount percentage (20%)

// Check if the user is logged in

if ( is_user_logged_in() ) {

     $user_id = get_current_user_id(); // Retrieve the user ID

     $total_spent = get_total_spent_by_customer( $user_id ); // Get the total amount spent by the user

     // Check if the total spent is greater than or equal to the required amount

     if ( $total_spent >= $required_total_spent ) {

         // Apply discount to cart

         foreach ( $cart->get_cart() as $cart_item_key => $cart_item ) {

             $price = $cart_item['data']->get_price();

             $discounted_price = $price - ( $price * $discount_percentage );

             $cart_item['data']->set_price( $discounted_price );

         }

     }

}

}

add_action( 'woocommerce_before_calculate_totals', 'apply_purchase_history_based_discount' );
Code Explanation
  • get_total_spent_by_customer Function:
    • This function uses WooCommerce’s built-in wc_get_customer_total_spent to get the total amount a customer has spent.
  • apply_purchase_history_based_discount Function:
    • Check if User is Logged In: Use is_user_logged_in() to verify if the user is logged in.
    • Retrieve User ID: Get the user ID of the logged-in customer.
    • Get Total Spent: Calculate the total amount the user has spent using get_total_spent_by_customer.
    • Check Spending: If the user’s total spending is greater than or equal to the required amount, apply the discount.
    • Apply Discount: Loop through the cart items and apply the discount to each item’s price.

Besides discounts based on total spent, you can also reward your first-time buyers with first-order discounts.

Setup User Role Discount Using a Customer Specific Pricing for WooCommerce Plugin

You can generate a wide range of discount types with a dedicated plugin. We have covered conditional discounts, category discounts, buy one get one discounts, quantity discounts, first order discounts, bundle discounts, etc., in our previous articles.

The plugin we will use is Discount Rules for WooCommerce. Our previous articles will help you familiarize yourself with the plugin settings.

Creating Customer Specific Discounts WooCommerce Based On User Role Using A Plugin

Let’s quickly create a user role-based discount using the plugin. Click the following button to add a new rule.

add rule

Let’s say you want to offer a 10% discount to your logged-in customers who have made purchases before and have an account on your site. Select Cart Adjustment from the discount type dropdown.

cart adjustment

Select All Products and set your percentage. From the Rules tab, add a condition.

add condition

Select User Role under the Customer section of the condition dropdown.

user role

Search and select the user role you want to assign. You can create, classify, and divide your customers into different groups to assign different customer specific discounts.

select user

Setting up Discounts for Specific Customers

For instance, you want to offer a 10% discount to specific customers. All settings will be the same as before.

From the Rules tab, add the condition called User. After that, search for and select the users to whom you want to offer discounts.

customer specific discounts WooCommerce

You can combine multiple conditions to the customer specific discounts WooCommerce. For example, you can offer customer specific discounts based on the cart subtotal.

customer specific discounts WooCommerce subtotal

You can create buy-one-get-one discounts for specific users or for user roles.

BOGO customer specific discounts WooCommerce

You can also create combination customer specific discounts WooCommerce.

Combination discount

Creating Discounts Based on Purchase History

You can reward your customers with special discounts based on their purchase history using this plugin. There’s a dedicated section in the condition dropdown for this.

total spent

Let’s say you want to offer a 30% discount to the customers who have spent over $1000 in your store. Here’s how you set up the discount.

Select Cart Adjustment and enter your percentage value. We are offering the discount on all products.

total spent discount

Select the Total Spent condition and set your minimum value. Additionally, you can select the order statuses.

customer specific discounts WooCommerce

Benefits of Customer-Specific Discounts in WooCommerce

In the competitive world of eCommerce, attracting and retaining customers is crucial. Customer-specific discounts offer a powerful tool to achieve this by going beyond generic store-wide sales and creating a more personal connection with your audience. Here’s how they can benefit your WooCommerce store:

Reward Loyalty

Show appreciation to valued customers with exclusive discounts. This fosters a sense of community and encourages repeat business, building stronger customer relationships.

Encourage Repeat Purchases

A well-timed discount can entice customers to come back for more, increasing their average order value and overall revenue.

Win Back Dormant Customers

Re-engage customers who haven’t purchased in a while with a targeted discount. This can reignite their interest and bring them back to your store.

Clear Out Inventory

Move slow-selling items by offering targeted discounts to specific customer segments who might be interested. This frees up storage space and potentially generates additional sales.

Increase Customer Lifetime Value

You can increase the total amount a customer spends at your store over time by incentivizing repeat purchases through targeted discounts.

Boost Customer Acquisition

Offer special discounts to new customers to incentivize their first purchase. This can be a great way to acquire new customers and expand your reach.

Gather Customer Data

Discount rules can be tied to specific customer information like email addresses or purchase history. This valuable data can be used for further marketing efforts and personalization.

Wrap up

Overall, customer-specific discounts offered by WooCommerce offer a strategic approach to strengthening customer relationships, boosting sales, and achieving your online store’s goals.

This was our guide to creating customer-specific discounts in WooCommerce. If you have any questions or suggestions on customer specific discounts WooCommerce, let us know in the comments.

Leave a Reply

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


This site uses Akismet to reduce spam. Learn how your comment data is processed.

5,602,228+ Downloads. 589+ plus 5-star ratings. Promote products on any platform you want.