How I Implemented Role-Based Discount System in WooCommerce [Case Study]
Hey there! Today I want to share a project I completed as part of a technical interview with a contractor from Upwork. The task was to create a role-based discount system for a beverage shop running on WooCommerce. This kind of pricing system is super valuable for businesses that offer different prices to different customer types – think wholesale buyers, VIP customers, or in this case: regular customers, special customers, resellers, and super resellers.

I’ll walk you through my implementation process, from setting up the environment to testing the final product. Let’s dive in!
Development Environment Setup
Before jumping into code, I needed to set up a proper development environment. Here’s what I did:
- Installed LocalWP for local WordPress development – this tool makes it super easy to create isolated WordPress installations
- Set up Storefront theme and created a child theme – Storefront is WooCommerce’s official theme, making it perfect for this project
- Configured Prepros as my build tool with live reload capabilities – this saved tons of time during development
With the environment ready, I could start developing the actual discount system.
Development Process
Registering Custom User Roles in WordPress
The first step was creating custom user roles to differentiate between customer types. I needed three new roles beyond the default “Customer” role:
- Special Customer
- Reseller
- Super Reseller
Here’s a snippet of how I registered these custom roles:

Implementing Discounts for Simple Products
With the roles in place, I needed to add custom discount fields to the product editor for simple products. These fields would allow the shop admin to set discount percentages for each customer type.
I added three discount fields to the “Simple Product” editor panel:
- Special Customer Discount (%)
- Reseller Discount (%)
- Super Reseller Discount (%)
Additionally, I included read-only fields that would show the calculated prices after applying the discounts. Here’s part of the implementation:
I also implemented JavaScript to dynamically calculate and display the discounted prices when the admin changes the discount percentages.

Implementing Discounts for Variable Products
For variable products (like coffee with different types and sizes), I applied a similar approach but had to account for each variation. This was more complex, as I needed to add discount fields to each product variation and provide real-time price calculations.
Here’s a glimpse of the implementation:
Setting Default Discounts Based on Product Type
To make the admin’s life easier, I implemented logic to set default discount values based on product types. For example, Cinnamon Tea would get a 15% reseller discount, while Arabica coffee in a big box would get a 32% super reseller discount.
Displaying Discount Information in the Frontend
Now that the admin could set discounts, users needed to see their special pricing. I added a feature to display the applied discount percentage and the final price on the product page, but only for users with special roles.
Implementing AJAX for Dynamic Price Calculations
For variable products, I needed to dynamically update the discount information when a user selected different variations. I implemented an AJAX solution to fetch the correct discount information whenever a variation was selected.

Testing Across Different User Roles
To verify that everything was working correctly, I tested the system with different user roles. I created test accounts for each role and verified that:
- Regular customers saw the normal prices

- Special customers saw the “Special Customer Discount” and reduced prices

- Resellers saw their specific discount and prices

- Super resellers saw their discount and the lowest prices
You can test this system yourself at https://case-study.rizwanaritonang.com/shop-1 using these credentials:
- Role: Customer
- username: JustCustomer
- password: LJneZd8YDd8J)6BwD$A#&13F
- Role: Special Customer
- username: TestSpecialCustomer
- password: Mw@okNZoNdlOLFtbgvvv3&vt
- Role: Reseller Account
- username: ResellerAccount
- password: LeRLEgvayJVcs*m&sjDSJSu%
Conclusion
Implementing a role-based discount system in WooCommerce was a challenging but rewarding project. The key takeaways from this implementation are:
- Custom user roles are essential for differentiating between customer types
- Custom meta fields provide flexible discount options for administrators
- JavaScript calculations enhance the UX for both admin and customers
- AJAX is crucial for dynamic updates with variable products
- Default values can save tremendous time for store administrators
This solution allows beverage shop owners to offer tiered pricing to different customer types without needing separate stores or complex plugins. It’s a flexible and maintainable approach that can be extended for other e-commerce needs.
Feel free to check out the demo and let me know if you have any questions or suggestions for improvement!
Leave a comment