Three things this repository could not do: prove the plugin still works on a
WordPress or WooCommerce released after it, get a fix onto a shop without
someone uploading a zip, and do either of those for the next plugin without
starting over.
ci/ is the test harness. ci/site-test.sh builds a throwaway WordPress +
WooCommerce in containers at any versions you name — including `nightly` and
`beta` — installs exactly the files the release zip will contain, and runs
tests/smoke.php inside it with wp eval-file. Real cart, real coupons, real
WC_Shipping_Rate objects: a mocked cart keeps passing after WooCommerce has
changed underneath it, which is the one failure worth catching here. WP_DEBUG
is on and any notice logged from this plugin's directory fails the build,
because that is the shape an upgrade actually breaks in — nothing fails, a
notice appears, and two releases later it is a fatal.
compat.yml runs that weekly against today's releases, the next WordPress and
the next WooCommerce, the oldest PHP the header promises and the newest PHP.
When it is green it opens a PR bumping "Tested up to" and "WC tested up to" —
only when green, because WooCommerce shows that second value to the shop owner
as an untested-plugin banner, and that banner is what they read before deciding
whether to press update.
includes/class-updater.php is the distribution half. It hooks
update_plugins_{hostname} for the host in the new "Update URI" header and reads
the Gitea release API, so WordPress handles the notice, the download, the
"Enable auto-updates" link and wp plugin update with no further code. Update
URI earns its place twice: since 5.8 a plugin that declares one is never asked
about on wordpress.org, so a .org plugin sharing this slug cannot be pushed
onto a shop running this one. The check sends nothing about the site and
overrides WordPress's default user agent, which carries the site's own URL.
release.yml tags, tests, builds, publishes — then reads the feed back with no
credentials. A private repository and a release with no zip attached both leave
a page that looks perfect to anyone logged in and an update no shop is ever
offered.
Measured before committing, all green: WP 7.1 + WC 11.1 on PHP 8.3 and 7.4,
WP 7.2-alpha on 8.3, and the beta cell falling back to stable on 8.4. No
deprecations from this plugin on any of them.
Three guards are there because the bug they catch is invisible without them:
the annotated tag is re-fetched before its message is read (checkout turns it
into a lightweight tag pointing at the merge commit), the two workflow roots
are kept in sync (.gitea/workflows hides .github/workflows entirely), and every
file the code loads must be in the release zip — which caught class-updater.php
being referenced and uncommitted while every local test passed.
docs/REUSE.md is the port to the next plugin: copy ci/, rewrite five lines.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
123 lines
5.9 KiB
Plaintext
123 lines
5.9 KiB
Plaintext
=== WooCommerce Email Discount Manager ===
|
|
Contributors: wedsmp
|
|
Tags: woocommerce, discount, email, shipping, coupon
|
|
Requires at least: 5.8
|
|
Tested up to: 7.1
|
|
Requires PHP: 7.4
|
|
Stable tag: 1.4.0
|
|
WC requires at least: 6.0
|
|
WC tested up to: 11.1.0
|
|
License: GPLv2 or later
|
|
License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
|
|
|
Apply discounts and show/hide shipping methods based on the customer's email address.
|
|
|
|
== Description ==
|
|
|
|
WooCommerce Email Discount Manager lets you give discounts and filter available
|
|
shipping methods based on the email address a customer logs in or checks out with.
|
|
|
|
= Discount Groups =
|
|
|
|
* Create discount groups with a name and a discount percent.
|
|
* Attach any number of WooCommerce product categories to a group (drag & drop ordering).
|
|
* The group's discount percent applies to all products in the attached categories.
|
|
|
|
= Email Assignments =
|
|
|
|
Assign an email pattern to exactly one of three discount types:
|
|
|
|
* **Group** — the customer inherits a discount group's percent and categories.
|
|
* **Coupon** — an existing WooCommerce coupon is auto-applied at checkout.
|
|
* **Custom** — a custom percent applied to the entire cart.
|
|
|
|
Email patterns can be:
|
|
|
|
* A full email address: `john@example.com`
|
|
* A domain: `@company.com` (matches everyone on that domain)
|
|
* A partial match: `john` (matches any email containing "john")
|
|
|
|
Matching priority: exact email first, then domain, then partial match.
|
|
Assignments can be toggled active/inactive and work for both logged-in users
|
|
and guests (via the checkout billing email field, tracked with AJAX).
|
|
|
|
Every assignment can additionally grant **free shipping** — all shipping
|
|
methods become free at checkout for matching emails, regardless of the
|
|
assignment type. Coupon assignments pick from your existing WooCommerce
|
|
coupons in a dropdown.
|
|
|
|
= Shipping Rules =
|
|
|
|
* Per discount group, choose which shipping methods are shown or hidden.
|
|
* No rules for a group means all shipping methods behave normally.
|
|
* If any method is set to "Show", only "Show" methods are offered (whitelist).
|
|
* Drag & drop reordering controls the order methods appear in at checkout.
|
|
|
|
= How discounts are applied =
|
|
|
|
* Group and custom discounts are applied as negative fees on the cart.
|
|
* Coupons are applied via the standard WooCommerce coupon system.
|
|
|
|
== Installation ==
|
|
|
|
1. Upload the `woocommerce-email-discount-manager` folder to `/wp-content/plugins/`.
|
|
2. Make sure WooCommerce is installed and active.
|
|
3. Activate the plugin through the Plugins screen in WordPress.
|
|
4. Go to WooCommerce → Email Discounts to configure groups, assignments and shipping rules.
|
|
|
|
= REST API =
|
|
|
|
The plugin exposes a `wc-edm/v1` namespace for remote management (groups,
|
|
email assignments, shipping rules, audit log). Every route requires an
|
|
authenticated user with the `manage_woocommerce` capability — use a WordPress
|
|
Application Password over HTTPS.
|
|
|
|
Requests are rate limited per user (or per IP when unauthenticated) and all
|
|
changes are written to the audit log. Both are adjustable with filters:
|
|
|
|
* `wc_edm_rate_limit_enabled` (bool)
|
|
* `wc_edm_rate_limit_max_requests` (int, $method)
|
|
* `wc_edm_rate_limit_window` (int seconds, $method)
|
|
* `wc_edm_audit_log_enabled` (bool)
|
|
* `wc_edm_audit_log_retention_days` (int)
|
|
* `wc_edm_client_ip` (string) — override IP resolution behind a proxy/CDN
|
|
|
|
== Frequently Asked Questions ==
|
|
|
|
= Does it work for guests? =
|
|
|
|
Yes. When a guest types their email in the checkout billing email field, the
|
|
plugin stores it in the WooCommerce session via AJAX and recalculates the cart,
|
|
so discounts and shipping rules apply immediately.
|
|
|
|
= What happens if several patterns match one email? =
|
|
|
|
The most specific match wins: exact email, then domain, then partial match.
|
|
|
|
== Changelog ==
|
|
|
|
= 1.4.0 =
|
|
* The plugin now updates itself. WordPress checks the plugin's own release feed and offers new versions in Plugins and Dashboard → Updates, so an update no longer means uploading a zip by hand. The per-plugin "Enable auto-updates" link works too.
|
|
* Tested against WordPress 7.1 and WooCommerce 11.1, and against the next release of each, so an update to either is checked before it reaches a shop rather than after.
|
|
* Nothing about the site is sent when it checks for updates. The request is an unauthenticated read of a public file, and the user agent is overridden because WordPress's default one carries the site's own address.
|
|
|
|
= 1.3.1 =
|
|
* Hardened loading: a class file that cannot be read is now recorded and reported in an admin notice instead of causing a fatal error. During a plugin upgrade WordPress replaces files one at a time, so a request landing mid-copy could previously take down wp-admin.
|
|
* Admin tabs are only shown when their controller loaded, so an incomplete install costs a tab rather than the whole screen.
|
|
|
|
= 1.3.0 =
|
|
* Added an audit log: every change made through the REST API is recorded with user, IP, endpoint and time, along with rejected and rate limited requests. Viewable under WooCommerce → Email Discounts → Audit Log, and via GET /wp-json/wc-edm/v1/audit-log.
|
|
* Added rate limiting on the REST API (default 60 reads and 20 writes per minute per user or IP), returning HTTP 429. Limits are filterable.
|
|
* Entries are pruned automatically after 30 days (filterable).
|
|
|
|
= 1.2.0 =
|
|
* Added a free shipping toggle on email assignments — matching customers get all shipping methods at zero cost, works with every assignment type.
|
|
* Coupon assignments now pick from the shop's existing WooCommerce coupons in a dropdown instead of a free-text field.
|
|
* Database schema upgrades automatically after plugin updates (no re-activation needed).
|
|
|
|
= 1.1.0 =
|
|
* Added REST API (namespace wc-edm/v1) for remote management of groups, email assignments and shipping rules. All routes require an authenticated user with the manage_woocommerce capability (use an Application Password over HTTPS).
|
|
|
|
= 1.0.0 =
|
|
* Initial release: discount groups, email assignments (group/coupon/custom), shipping rules, dashboard.
|