WooCommerce Plugin Development | Chapter 9 | Discount Plugin

by | Dec 10, 2025 | Plugin Development, Web App Development | 0 comments

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

Article Summary by AI

Create a professional WooCommerce discount plugin with a clean folder structure and polished header for easy publishing and sharing. Perfect for blogs, GitHub, client projects, or WordPress Plugin Directory.

YOU MAY ALSO LIKE THESE

WooCommerce Plugin Development | Chapter 8 | Discount Plugin

WooCommerce Plugin Development | Chapter 8 | Discount Plugin

Chapter 8: Limit Number of Uses Per Customer 🔒 This chapter is critical for controlling coupon distribution by allowing you to set a maximum usage limit per customer. Our goal is to implement the following logic for logged-in users: Check Usage: Determine how many...

WooCommerce Plugin Development | Chapter 4 | Discount Plugin

WooCommerce Plugin Development | Chapter 4 | Discount Plugin

Chapter 4: Add Discount Type – Flat or Percentage What We’ll Do in This Chapter Add a “Discount Type” setting in the admin (flat / percentage) Update the discount value field to work for both types Update our checkout discount logic to handle both cases We’ll reuse...

WooCommerce Plugin Development | Chapter 2 | Discount Plugin

WooCommerce Plugin Development | Chapter 2 | Discount Plugin

Add an Admin Settings Page for the Checkout Message In Chapter 1, our plugin printed a fixed “Hello from Simple Discount Rules” message on the checkout page. That’s not practical for real-world use. Now we’ll: Add a submenu under WooCommerce Create a settings page...

WooCommerce Plugin Development | Chapter 1 | Discount Plugin

WooCommerce Plugin Development | Chapter 1 | Discount Plugin

Create the Plugin Skeleton – “Hello Woo Checkout” In this chapter, we’ll create a real WordPress plugin that WooCommerce can use. By the end, you’ll have: A proper plugin folder and main file A clean naming convention to follow A working “Hello from our plugin”...

WooCommerce Plugin Development | Introduction

WooCommerce Plugin Development | Introduction

Build Your First WooCommerce Discount Plugin WooCommerce is the most widely used eCommerce platform in the WordPress ecosystem, powering millions of online stores. One of the biggest advantages of WooCommerce is its extensibility—you can modify almost anything through...

WordPress Development | Tutorial 20 | Managing Orders

WordPress Development | Tutorial 20 | Managing Orders

Managing Orders, Coupons, and Customer Data in WooCommerce – A Practical Guide for Professionals Introduction Congratulations! Your WooCommerce store is live — you're now ready to handle real customers and real transactions. For...

WordPress Development | Tutorial 19 | Designing a Smooth Checkout

WordPress Development | Tutorial 19 | Designing a Smooth Checkout

Designing a Smooth Checkout and Cart Experience in WooCommerce Using Divi Introduction You've done the hard work — built a great product catalog, added payment options, and set up your WooCommerce store. But here's the catch: many customers abandon their cart during...

WordPress Development | Tutorial 18 | Setting Up Payments

WordPress Development | Tutorial 18 | Setting Up Payments

Setting Up Payments, Shipping, and Taxes in WooCommerce – A Complete Guide for Professionals Introduction When your online store is ready, the next step is to make it business-ready. For professionals like dentists offering health kits, consultants selling online...