Merge pull request '1.8.1: a group's own coupon and the group discount do not stack' (#5) from shipping-only into main
CI / WordPress latest + WooCommerce latest on PHP 8.3 (push) Successful in 1m17s
Release / release (push) Successful in 1m26s
CI / Static checks (push) Successful in 4m23s

This commit was merged in pull request #5.
This commit is contained in:
kw
2026-11-18 11:40:52 +00:00
8 changed files with 37 additions and 8 deletions
+4 -1
View File
@@ -4,7 +4,7 @@ Tags: woocommerce, discount, email, shipping, coupon
Requires at least: 5.8 Requires at least: 5.8
Tested up to: 7.1.2 Tested up to: 7.1.2
Requires PHP: 7.4 Requires PHP: 7.4
Stable tag: 1.8.0 Stable tag: 1.8.1
WC requires at least: 6.0 WC requires at least: 6.0
WC tested up to: 11.1.2 WC tested up to: 11.1.2
License: GPLv2 or later License: GPLv2 or later
@@ -97,6 +97,9 @@ The most specific match wins: exact email, then domain, then partial match.
== Changelog == == Changelog ==
= 1.8.1 =
* A group member who uses one of the group's own coupons (listed under Shipping Rules → Coupon codes) now gets the coupon's discount instead of the group's, never both. Before, the two stacked: 20% from the coupon and then 20% off what was left. A coupon the group does not list works as before.
= 1.8.0 = = 1.8.0 =
* Shipping rules can follow a coupon. Under Shipping Rules each group has a new "Coupon codes" field: a customer with one of those coupons in the cart gets the group's shipping methods, including the ones marked "Only", whatever email address they use. Only the shipping follows the coupon; the coupon gives its own discount, and the group's percentage stays with the group's email addresses. To keep the shipping for the right people, restrict the coupon to their addresses under "Allowed emails" in WooCommerce. * Shipping rules can follow a coupon. Under Shipping Rules each group has a new "Coupon codes" field: a customer with one of those coupons in the cart gets the group's shipping methods, including the ones marked "Only", whatever email address they use. Only the shipping follows the coupon; the coupon gives its own discount, and the group's percentage stays with the group's email addresses. To keep the shipping for the right people, restrict the coupon to their addresses under "Allowed emails" in WooCommerce.
+1 -1
View File
@@ -1,6 +1,6 @@
# Contract # Contract
Every hook this plugin offers, and every family hook it answers. Version 1.8.0. Every hook this plugin offers, and every family hook it answers. Version 1.8.1.
A contract is a name somebody else has to know. Core hooks this plugin merely A contract is a name somebody else has to know. Core hooks this plugin merely
listens to — `init`, `admin_menu`, `wp_enqueue_scripts` — are not here; listens to — `init`, `admin_menu`, `wp_enqueue_scripts` — are not here;
+1 -1
View File
@@ -1,6 +1,6 @@
# Nolimit Discounts # Nolimit Discounts
Version 1.8.0 · a WooCommerce plugin · slug `woocommerce-email-discount-manager` Version 1.8.1 · a WooCommerce plugin · slug `woocommerce-email-discount-manager`
Gives a customer a discount, and decides which shipping methods they may Gives a customer a discount, and decides which shipping methods they may
choose, based on the email address they check out with. choose, based on the email address they check out with.
+2 -2
View File
@@ -1,6 +1,6 @@
# Releasing # Releasing
One release a day at most, cut by hand. Version 1.8.0 is current. One release a day at most, cut by hand. Version 1.8.1 is current.
## The sequence ## The sequence
@@ -45,7 +45,7 @@ is loud, an id that belongs to something else is not.
| --- | --- | --- | | --- | --- | --- |
| `ci/static.sh` | syntax, guards, text domain, no secrets, every loaded file ships, one version everywhere, the two compat files agree, no tracked file writes a git identity, the docs still describe this tree | a count on every passing line | | `ci/static.sh` | syntax, guards, text domain, no secrets, every loaded file ships, one version everywhere, the two compat files agree, no tracked file writes a git identity, the docs still describe this tree | a count on every passing line |
| `ci/selftest.sh` | **the checkers themselves** — see below | `all N assertions passed` | | `ci/selftest.sh` | **the checkers themselves** — see below | `all N assertions passed` |
| `ci/site-test.sh` | a real WordPress + WooCommerce + MySQL install, this plugin activated, `tests/smoke.php` run through `wp eval-file` | `All 100 assertions passed`, floored at 60 by the caller | | `ci/site-test.sh` | a real WordPress + WooCommerce + MySQL install, this plugin activated, `tests/smoke.php` run through `wp eval-file` | `All 104 assertions passed`, floored at 60 by the caller |
| `.github/workflows/compat.yml` | the matrix: PHP 7.4 / 8.3 / 8.4, WP latest and nightly, WC latest and beta | one job per cell | | `.github/workflows/compat.yml` | the matrix: PHP 7.4 / 8.3 / 8.4, WP latest and nightly, WC latest and beta | one job per cell |
## The checkers are themselves tested, and that is unusual ## The checkers are themselves tested, and that is unusual
+1 -1
View File
@@ -205,7 +205,7 @@ class WC_EDM_Admin_Shipping {
<?php endforeach; ?> <?php endforeach; ?>
</datalist> </datalist>
<p class="description"> <p class="description">
<?php esc_html_e( 'A customer with one of these coupons in the cart gets this group\'s shipping rules too, whatever their email address. Separate several with commas. Only the shipping rules follow the coupon — the coupon gives its own discount, not the group\'s. To keep the shipping for the right people, restrict the coupon to their addresses under the coupon\'s "Usage restriction" → "Allowed emails" in WooCommerce.', 'wc-email-discount' ); ?> <?php esc_html_e( 'A customer with one of these coupons in the cart gets this group\'s shipping rules too, whatever their email address. Separate several with commas. Only the shipping rules follow the coupon — the coupon gives its own discount, not the group\'s. A group member who uses one of these coupons gets the coupon\'s discount instead of the group\'s, never both. To keep the shipping for the right people, restrict the coupon to their addresses under the coupon\'s "Usage restriction" → "Allowed emails" in WooCommerce.', 'wc-email-discount' ); ?>
</p> </p>
</td> </td>
</tr> </tr>
+10
View File
@@ -263,6 +263,16 @@ class WC_EDM_Frontend {
return; return;
} }
// 🔴 A group's own coupon and the group's percentage are the same deal
// offered two ways, never two deals. Before 1.8.1 a member who also
// typed the group's coupon got both: 20% off from the coupon, then 20%
// off what was left — 36% in all, on a live order. The coupon wins,
// because it is the discount the customer chose and can see.
$own_coupons = WC_EDM_DB::get_group_shipping_coupons( (int) $group->id );
if ( $own_coupons && array_intersect( $own_coupons, WC_EDM_DB::parse_coupon_list( implode( ',', $cart->get_applied_coupons() ) ) ) ) {
return;
}
$category_ids = WC_EDM_DB::get_group_category_ids( (int) $group->id ); $category_ids = WC_EDM_DB::get_group_category_ids( (int) $group->id );
if ( empty( $category_ids ) ) { if ( empty( $category_ids ) ) {
+16
View File
@@ -393,6 +393,22 @@ wc_edm_is(
array( 'local_pickup:2' ), array( 'local_pickup:2' ),
array_keys( wc_edm()->frontend->filter_shipping_rates( $wc_edm_ship_rates, array() ) ) array_keys( wc_edm()->frontend->filter_shipping_rates( $wc_edm_ship_rates, array() ) )
); );
// 🔴 A member using the group's own coupon gets the coupon OR the group's
// percentage, never both. Before 1.8.1 they stacked: a live order took 20% from
// the coupon and then 20% of what was left, 36% in all.
wc_edm_cart_for( '[email protected]', array( $fixtures['product_in'] => 1, $fixtures['product_out'] => 1 ) );
wc_edm_is( 'a group member without the coupon gets the group discount', 20.0, wc_edm_discount_total() );
WC()->cart->apply_coupon( 'ciflat10' );
WC()->cart->calculate_totals();
wc_edm_is( 'with the group own coupon the group discount steps aside', 0.0, wc_edm_discount_total() );
wc_edm_is( 'and the coupon discount is what they get', 10.0, round( WC()->cart->get_discount_total(), 2 ) );
WC_EDM_DB::set_group_shipping_coupons( (int) $fixtures['group_id'], array() );
WC()->cart->calculate_totals();
// 19, not 20: stacked, the group takes its 20% of what the 10 kr coupon left.
wc_edm_is( 'a coupon the group does not list still stacks as before', 19.0, wc_edm_discount_total() );
WC()->cart->remove_coupons();
WC()->cart->calculate_totals();
WC_EDM_DB::set_group_shipping_coupons( (int) $fixtures['group_id'], array() ); WC_EDM_DB::set_group_shipping_coupons( (int) $fixtures['group_id'], array() );
wc_edm_is( 'an empty list unlinks the coupon', 0, WC_EDM_DB::group_for_coupons( array( 'ciflat10' ) ) ); wc_edm_is( 'an empty list unlinks the coupon', 0, WC_EDM_DB::group_for_coupons( array( 'ciflat10' ) ) );
WC_EDM_DB::replace_shipping_rules( (int) $fixtures['group_id'], array() ); WC_EDM_DB::replace_shipping_rules( (int) $fixtures['group_id'], array() );
+2 -2
View File
@@ -4,7 +4,7 @@
* Plugin URI: https://gitea.nolimit.dk/kw/woo-discount-manager * Plugin URI: https://gitea.nolimit.dk/kw/woo-discount-manager
* Update URI: https://gitea.nolimit.dk/kw/nolimit-discounts-dist * Update URI: https://gitea.nolimit.dk/kw/nolimit-discounts-dist
* Description: Apply discounts and show/hide shipping methods based on the customer's email address (full address, domain or partial match). * Description: Apply discounts and show/hide shipping methods based on the customer's email address (full address, domain or partial match).
* Version: 1.8.0 * Version: 1.8.1
* Author: Kristian Wind * Author: Kristian Wind
* Author URI: https://gitea.nolimit.dk/kw * Author URI: https://gitea.nolimit.dk/kw
* License: GPL-2.0-or-later * License: GPL-2.0-or-later
@@ -28,7 +28,7 @@ if ( ! defined( 'ABSPATH' ) ) {
exit; exit;
} }
define( 'WC_EDM_VERSION', '1.8.0' ); define( 'WC_EDM_VERSION', '1.8.1' );
define( 'WC_EDM_PLUGIN_FILE', __FILE__ ); define( 'WC_EDM_PLUGIN_FILE', __FILE__ );
define( 'WC_EDM_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); define( 'WC_EDM_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'WC_EDM_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); define( 'WC_EDM_PLUGIN_URL', plugin_dir_url( __FILE__ ) );