Conditional Discount for WooCommerce
A WordPress plugin to apply conditional discounts in your WooCommerce store — based on specific condition like minimum amount, product count, and more.
by Riadujjaman Shanto · github.com/shanto-w3dev/conditional-discount-for-woocommerce · website
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/shanto-w3dev/conditional-discount-for-woocommerce/archive/refs/heads/main.zipConditional Discount for WooCommerce is a lightweight and modular WordPress plugin that allows store owners to apply smart, rule-based discounts to WooCommerce products during cart and checkout.
You can create unlimited discount rules based on product conditions, cart totals, user details, and more.
This plugin is fully OOP-based, uses a namespace-driven architecture, follows the Singleton pattern, and includes an autoloader for clean, scalable development.

Features
- Apply conditional cart discounts
- Create unlimited discount rules
- Lightweight, clean, and modular code structure
- Uses namespaces + autoloader
- Follows the Singleton design pattern
- WooCommerce-friendly architecture
- Easy to extend with custom conditions
- No unnecessary scripts or assets loaded on the frontend
Plugin Architecture
1. Namespaces
Improves readability and prevents function/class conflicts.
Namespaces used:
Shanto\ConditionalDiscount
Shanto\ConditionalDiscount\App
Shanto\ConditionalDiscount\App\Traits
2. Autoloader
Loads all classes automatically based on folder structure:
includes/
App/
Traits/
No manual includes required.
3. Singleton Pattern
Every major class uses a Singleton trait:
trait Singleton {
private static $instance = null;
public static function instance(){
if (! self::$instance){
self::$instance = new self();
}
return self::$instance;
}
}
Ensures only one instance of each module runs.
Installation
-
Download the plugin or clone the repository:
git clone https://github.com/shanto-w3dev/Conditional-Discount-for-WooCommerce.git -
Place the folder inside:
wp-content/plugins/ -
Activate Conditional Discount for WooCommerce from the WordPress Plugins screen.
Example Usage
The plugin automatically applies:
- A cart discount if cart subtotal exceeds a specific condition
- Discounts through WooCommerce's fee API
Hooks Used
WooCommerce Hooks
| Hook | Purpose |
|---|---|
woocommerce_cart_calculate_fees |
Applies discount dynamically |
WordPress Hooks
| Hook | Purpose |
|---|---|
plugins_loaded |
Initializes plugin |
License
This plugin is open-source and licensed under the GPL v2 License.
Contributing
Pull requests are welcome!
If you find bugs or want new features, feel free to open an issue in the repo.
Author
Riadujjaman Shanto
WordPress Developer
Website: https://shanto.net