Contributors: Vijay Prakash Mahato
Tags: wordpress, woocommerce, discount, cart, conditional, accessories
Requires at least: 6.8.1
Tested up to: 6.4
Requires PHP: 7.4
Stable tag: 0.0.1
Automatically applies 15% discount when cart contains accessories products and total is ₹2000 or more. and show discount message on top of cart table
16-12-33.mp4
WooCommerce Conditional Discount is a lightweight plugin that automatically applies a 15% discount to your WooCommerce cart when specific conditions are met:
Key Features:
- Automatic discount application (no coupon codes needed)
- Non-intrusive implementation (works with existing coupons)
- Clear messaging to customers about discount status
- Responsive design with attractive styling
Condition to apply discount:
- Cart contains at least one product from the "Accessories" category
- Total cart value is ₹2000 or more
How it works:
- Customer adds products to cart
- Plugin checks if conditions are met
- If conditions are satisfied, 15% discount is automatically applied
- Customer sees confirmation message and discount amount on cart page
Requirement to Install this Plugin on Wordpress:
- Must have woo commerce plugin to be install
How to install in wordpress:
- Download the plugin ZIP file or Clone it from this repo
- Log in to your WordPress admin dashboard
- Navigate to Plugins > Install Plugins > Add Plugin
- Click "Upload Plugin" button
- Choose the ZIP file and click "Install Now"
- Activate the plugin
Requirements:
- WordPress 6.8.1 or higher
- WooCommerce 9.9.5 or higher
- PHP 7.4 or higher
1. Create Accessories Category
- Go to Products > Categories in your WordPress admin
- Create a category named "Accessories"
2. Add Products to Accessories Category
- Edit your accessory products
- Assign them to the "Accessories" category
- Save the products
3. Test the Plugin
- Add an accessories product to cart
- Add other products to reach ₹2000 total
- Visit cart page to see the discount applied
Category Recognition:
- Plugin looks for categories with slugs: "accessories"
- Category matching is case-insensitive
- Plugin checks product categories, not variations
Currency:
- Plugin assumes Indian Rupees (₹) as primary currency
- Minimum amount check is ₹2000
Discount Calculation:
- 15% discount is calculated on cart subtotal (before taxes/shipping)
- Discount is applied as a negative fee
- Does not interfere with existing coupons or other discounts
Compatibility:
- Designed for standard WooCommerce installations
- Compatible with most themes and plugins
- Uses WooCommerce hooks and filters
Q: Does this plugin interfere with existing coupons? A: No, the plugin applies discount as a fee, not a coupon, so it works alongside existing coupons.
Q: Can I change the discount percentage?
A: Yes, modify the value 0.15
in the code (line with $discount_amount = $cart_total * 0.15;
)
Q: Can I change the minimum cart amount?
A: Yes, modify the value 2000
in the condition check (line with if ($cart_total < 2000)
)
Q: What if my accessories category has a different name?
A: Edit the $accessories_slugs
array in the add_custom_message_before_cart()
and wcd_apply_conditional_discount()
function
Q: Does it work with variable products? A: Yes, the plugin checks the main product categories for variations
Q: Can I customize the discount message?
A: Yes, modify the text in the $discount_message
variable
Plugin Architecture:
- Uses procedural PHP (no OOP)
- Implements WooCommerce hooks and filters
- Session-independent (recalculates on each page load)
Key Functions:
wcd_apply_conditional_discount()
- Main discount logicwcd_display_discount_message()
- Shows customer messages
Hooks Used:
woocommerce_cart_calculate_fees
- Applies discountrender_block_woocommerce/cart
- Shows cart messages
Security Features:
- Prevents direct file access
- Sanitizes all outputs
- Uses WordPress/WooCommerce best practices
Discount not applying:
- Ensure WooCommerce is active
- Check if products are in "Accessories" category
- Verify cart total is ₹2000 or more
- Check for plugin conflicts
Message not showing:
- Clear any caching plugins
- Check theme compatibility
- Ensure you're on cart pages
Category not recognized:
- Check category slug (should be "accessories" or similar)
- Verify products are properly categorized
- Check for typos in category names
= 0.0.1 =
- Initial release
- Automatic 15% discount for accessories + ₹2000 minimum
- Customer messaging system
- WooCommerce compatibility
= 0.0.1 = Initial release of WooCommerce Conditional Discount plugin.
Code Structure:
- Single file plugin for simplicity
- All functions prefixed with
wcd_
to avoid conflicts - Follows WordPress coding standards
Customization Options:
- Easy to modify discount percentage
- Simple to change minimum amount
- Category names easily configurable
- Messages can be customized
Performance Considerations:
- Lightweight implementation
- Minimal database queries
- Efficient category checking
- No external dependencies
For support, feature requests, or bug reports, please contact me vijayprakashmh@gmail.com.
Plugin Information:
- Version: 0.0.1
- Tested with: WooCommerce 9.9.5, WordPress 6.8.1
- License: MIT License