Prepping Your WooCommerce Discount Rules Plugin for Publish
You’ve now built a functional, real-world WooCommerce discount rules plugin.
Whether you want to:
-
Share it on your blog
-
Upload it to GitHub
-
Include it inside client projects
-
Or submit it to the WordPress Plugin Directory
…this chapter walks you through creating a professional, production-ready plugin package.
✅ 1. Final Folder Structure
Your plugin should have a clean, organized folder layout like this:
simple-discount-rules/
│
├── simple-discount-rules.php <– main plugin bootstrap
├── readme.txt <– WordPress.org format (optional)
├── README.md <– GitHub documentation file
├── assets/
│ ├── banner-772×250.png <– WordPress.org banner
│ ├── icon-256×256.png <– plugin icon
│ └── screenshot-1.png <– admin screenshot
└── uninstall.php <– cleanup logic (optional)
A clear structure makes your plugin easy to maintain and publish.
✅ 2. Polished Plugin Header
Update the top of simple-discount-rules.php:
<?php
/**
* Plugin Name: Simple Discount Rules for WooCommerce
* Plugin URI: https://yourwebsite.com/simple-discount-rules/
* Description: A lightweight WooCommerce extension for creating custom discount rules with coupon code, conditions, and usage limits.
* Version: 1.0.0
* Author: Your Name / Your Company
* Author URI: https://yourwebsite.com
* Text Domain: simple-discount-rules
* Domain Path: /languages
* Requires at least: 5.8
* Requires PHP: 7.4
* License: GPLv2 or later
* WC requires at least: 5.0
* WC tested up to: 9.0
*/
Tips:
-
Use your own URL and name.
-
Start with version 1.0.0.
-
Include WooCommerce compatibility tags if publishing publicly.
✅ 3. Create uninstall.php (Professional Touch)
This file removes the plugin’s custom options when the user deletes the plugin from WordPress.
Create: **uninstall.php**
<?php
/**
* Uninstall script for Simple Discount Rules.
*/
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) )
{ exit;
}
delete_option( 'sdr_checkout_message' );
delete_option( 'sdr_enable_discount' );
delete_option( 'sdr_coupons' );
// Optional: Remove user coupon usage
$users = get_users( array( 'fields' => 'ID' ) );
foreach ( $users as $user_id ) {
delete_user_meta( $user_id, 'sdr_coupon_usage' );
}
If performance is a concern, you may skip cleaning user meta.
✅ 4. Create a Clean README.md (For GitHub)
Here is a finished, polished README.md:
Simple Discount Rules for WooCommerce
A lightweight WooCommerce extension that lets you create custom discount rules with:
– Multiple coupon codes
– Flat or percentage discounts
– Min/max cart value checks
– New/existing customer targeting
– Per-customer usage limits
– Active/inactive status control
Perfect for simple promotional campaigns without heavy plugins.
🔧 Features
– Add unlimited custom coupons
– User-friendly admin UI
– Works with WooCommerce cart totals
– Automatic validation + messages
– Tracks per-customer usage
– Clean, optimized PHP code
📦 Installation
1. Download the ZIP.
2. Go to **Plugins → Add New → Upload Plugin**.
3. Activate the plugin.
4. Open
**WooCommerce → Simple Discount Rules**
to configure your coupons.
🧪 Compatibility
– WordPress 5.8+
– WooCommerce 5.0+
– PHP 7.4+ (recommended: 8.1+)
📘 How It Works
1. User enters coupon code at checkout.
2. Plugin checks:
– Coupon activation status
– Discount type/value
– Min/max cart value
– Customer type
– Usage limit
3. Applies discount as a **negative cart fee**.
🔒 GDPR / Cleanup
Deleting the plugin removes all stored plugin data.
🧑💻 Developer Notes
Hook into discount application:
woocommerce_cart_calculate_fees
Order tracking uses:
woocommerce_checkout_create_order
woocommerce_order_status_completed
📄 License
GPLv2 or later.
✅ 5. Create a WordPress.org-Compatible readme.txt (If Needed)
If you plan to publish your plugin on WordPress.org, the readme.txt format is mandatory.
Below is a clean and ready-to-use template:
=== Simple Discount Rules for WooCommerce ===
Contributors: your-username
Tags: woo commerce, discount, coupons, cart rules, offers
Requires at least: 5.8
Tested up to: 6.7
Requires PHP: 7.4
Stable tag: 1.0.0
License: GPLv2 or later
Lightweight WooCommerce discount rules plugin that supports multiple coupons, min/max order value, customer-type restrictions, and usage limits per customer.
== Description ==
Simple Discount Rules for WooCommerce helps store owners create basic promotional rules without heavy plugins.
Features include:
* Multiple custom coupon codes
* Flat or percentage discounts
* Min/max order value conditions
* New/existing customer targeting
* Per-customer usage limits
* Active/inactive coupon status
== Installation ==
1. Upload the plugin files to `/wp-content/plugins/simple-discount-rules/`
2. Activate the plugin from the 'Plugins' menu
3. Go to WooCommerce → Simple Discount Rules
== Frequently Asked Questions ==
= Does it override WooCommerce coupons? =
No. This is an independent system.
= Does it work with guest checkout? =
Yes, except for “per-customer usage” rules (requires login).
== Screenshots ==
1. Admin settings page with coupon list
2. Add new coupon form
3. Checkout page displaying custom message
== Changelog ==
= 1.0.0 =
Initial release.
== License ==
GPLv2 or later.
✅ 6. Add Plugin Assets (Optional but Recommended)
If you’re publishing on WordPress.org, prepare:
-
icon-256×256.png
-
banner-772×250.png
Place them inside your plugin’s /assets/ folder.
If using GitHub, add promotional screenshots to improve visibility.
✅ 7. Do a Final Code Cleanup
Before packaging your plugin for release, ensure that:
-
All
var_dump(),print_r(), debug logs are removed -
No hardcoded file paths remain
-
No temporary or commented test code is left
-
Inline comments are clean and meaningful
-
Spacing follows WordPress coding standards
Search your plugin for leftover debug markers:
TODO
NOTE:
DEBUG
error_log
✅ 8. Zip Your Plugin Correctly
Your final plugin folder must be:
simple-discount-rules/
Not a parent folder with extra layers.
Mac/Linux:
cd wp-content/plugins/
zip -r simple-discount-rules-1.0.0.zip simple-discount-rules
Windows PowerShell:
Compress-Archive -Path simple-discount-rules -DestinationPath simple-discount-rules-1.0.0.zip
✅ 9. Test a Fresh Install
Install the ZIP into a **fresh WordPress with WooCommerce**:
1. Activate plugin
2. Create sample coupons
3. Test:
- Flat discount
- Percentage discount
- Min/max cart value
- New/existing customers
- Usage limit per customer4. Test with guest checkout
5. Test multiple logins
6. Test order completion updates usage correctly
7. Ensure deactivate/reactivate keeps settings
✅Ensure uninstall **removes all data** (if intended)
🎉 Your Plugin Is Now Ready for Distribution!
You have built a **complete WooCommerce discount rules engine:
- Modular
- Safe
- Extendable
- Production-ready
- Easy to publish
If you want a **Chapter 10** (optional), we can cover:
- Shortcodes(display active offers on front-end)
- REST API endpoints for coupons
- Export/import JSON of discount rules
- Adding translations (.pot file)**
- UI improvements (React/JS-based admin)
Just tell me — we can continue expanding this into a real commercial-grade plugin.














0 Comments