1.8.0: a coupon can carry a group's shipping rules
CI / WordPress latest + WooCommerce latest on PHP 8.3 (pull_request) Successful in 1m11s
Compatibility / WP latest / WC latest / PHP 7.4 (pull_request) Skipped
Compatibility / WP latest / WC beta / PHP 8.3 (pull_request) Skipped
Compatibility / WP latest / WC latest / PHP 8.3 (pull_request) Skipped
Compatibility / WP nightly / WC latest / PHP 8.3 (pull_request) Skipped
Compatibility / WP latest / WC latest / PHP 8.4 (pull_request) Skipped
Compatibility / Keep the compatibility headers honest (pull_request) Skipped
CI / Static checks (pull_request) Successful in 4m26s
CI / WordPress latest + WooCommerce latest on PHP 8.3 (pull_request) Successful in 1m11s
Compatibility / WP latest / WC latest / PHP 7.4 (pull_request) Skipped
Compatibility / WP latest / WC beta / PHP 8.3 (pull_request) Skipped
Compatibility / WP latest / WC latest / PHP 8.3 (pull_request) Skipped
Compatibility / WP nightly / WC latest / PHP 8.3 (pull_request) Skipped
Compatibility / WP latest / WC latest / PHP 8.4 (pull_request) Skipped
Compatibility / Keep the compatibility headers honest (pull_request) Skipped
CI / Static checks (pull_request) Successful in 4m26s
Shipping Rules gets a "Coupon codes" field per group. A customer with one of those coupons in the cart gets the group's shipping methods, including "Only" ones, whatever their email. Asked for on a live shop: free delivery reserved for one company's addresses had to reach people using that company's coupon too. Only the shipping follows the coupon; the group's percentage discount stays with its email assignments. An email assigned to a group still wins. The shipping package key now carries the effective group, so WooCommerce's rate cache follows a coupon being added or removed. Stored as groups.shipping_coupons (dbDelta adds the column on update). Smoke tests: 100 assertions. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
b9d8611ce2
commit
654d8632d2
+52
-1
@@ -343,10 +343,61 @@ WC()->customer->set_billing_email( '[email protected]' );
|
||||
$wc_edm_pkg_b = wc_edm()->frontend->key_packages_to_match( array( array( 'contents' => array() ) ) );
|
||||
wc_edm_ok(
|
||||
'a shipping package carries the match, so cached rates do not outlive a change of email',
|
||||
$wc_edm_pkg_a[0]['wc_edm_match'] > 0 && 0 === $wc_edm_pkg_b[0]['wc_edm_match'],
|
||||
$wc_edm_pkg_a[0]['wc_edm_match'] !== $wc_edm_pkg_b[0]['wc_edm_match'] && '0:0' === $wc_edm_pkg_b[0]['wc_edm_match'],
|
||||
sprintf( 'matched %s, unmatched %s', var_export( $wc_edm_pkg_a[0]['wc_edm_match'], true ), var_export( $wc_edm_pkg_b[0]['wc_edm_match'], true ) )
|
||||
);
|
||||
|
||||
// A coupon can carry a group's shipping rules: whoever has it in the cart gets
|
||||
// the group's methods, including the ones it reserved ("Only"), whatever the
|
||||
// email. Reported from a live shop: free delivery reserved for one company's
|
||||
// addresses had to reach people using that company's coupon as well.
|
||||
wc_edm_is( 'a coupon list is split and normalised', array( 'teamx', 'b', 'c' ), WC_EDM_DB::parse_coupon_list( ' TeamX, b c,,' ) );
|
||||
global $wpdb;
|
||||
wc_edm_ok(
|
||||
'the groups table has the coupon column',
|
||||
null !== $wpdb->get_row( 'SHOW COLUMNS FROM ' . WC_EDM_DB::table( 'groups' ) . " LIKE 'shipping_coupons'" ) // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery
|
||||
);
|
||||
WC_EDM_DB::replace_shipping_rules(
|
||||
(int) $fixtures['group_id'],
|
||||
array( array( 'shipping_method_id' => 'flat_rate:1', 'action' => 'only', 'sort_order' => 0 ) )
|
||||
);
|
||||
WC_EDM_DB::set_group_shipping_coupons( (int) $fixtures['group_id'], array( 'CIflat10' ) );
|
||||
wc_edm_is( 'a group remembers its shipping coupons, normalised', array( 'ciflat10' ), WC_EDM_DB::get_group_shipping_coupons( (int) $fixtures['group_id'] ) );
|
||||
wc_edm_is( 'the coupon leads to its group', (int) $fixtures['group_id'], WC_EDM_DB::group_for_coupons( array( 'ciflat10' ) ) );
|
||||
wc_edm_is( 'an unlinked coupon leads nowhere', 0, WC_EDM_DB::group_for_coupons( array( 'something-else' ) ) );
|
||||
|
||||
$wc_edm_ship_rates = array(
|
||||
'flat_rate:1' => new WC_Shipping_Rate( 'flat_rate:1', 'Flat rate', 10, array(), 'flat_rate' ),
|
||||
'local_pickup:2' => new WC_Shipping_Rate( 'local_pickup:2', 'Local pickup', 0, array(), 'local_pickup' ),
|
||||
);
|
||||
wc_edm_cart_for( '[email protected]', array( $fixtures['product_in'] => 1 ) );
|
||||
wc_edm_is(
|
||||
'without the coupon a stranger does not see the reserved method',
|
||||
array( 'local_pickup:2' ),
|
||||
array_keys( wc_edm()->frontend->filter_shipping_rates( $wc_edm_ship_rates, array() ) )
|
||||
);
|
||||
WC()->cart->apply_coupon( 'ciflat10' );
|
||||
WC()->cart->calculate_totals();
|
||||
wc_edm_is(
|
||||
'with the linked coupon the same stranger gets the group shipping rules',
|
||||
array( 'flat_rate:1' ),
|
||||
array_keys( wc_edm()->frontend->filter_shipping_rates( $wc_edm_ship_rates, array() ) )
|
||||
);
|
||||
wc_edm_is( 'but not the group percentage discount', 0.0, wc_edm_discount_total() );
|
||||
$wc_edm_pkg_c = wc_edm()->frontend->key_packages_to_match( array( array( 'contents' => array() ) ) );
|
||||
wc_edm_is( 'and the package key carries the coupon group', '0:' . (int) $fixtures['group_id'], $wc_edm_pkg_c[0]['wc_edm_match'] );
|
||||
WC()->cart->remove_coupons();
|
||||
WC()->cart->calculate_totals();
|
||||
wc_edm_is(
|
||||
'removing the coupon takes the reserved method away again',
|
||||
array( 'local_pickup:2' ),
|
||||
array_keys( wc_edm()->frontend->filter_shipping_rates( $wc_edm_ship_rates, 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_DB::replace_shipping_rules( (int) $fixtures['group_id'], array() );
|
||||
WC()->customer->set_billing_email( '[email protected]' );
|
||||
|
||||
// 🔴 The tracking endpoint answers anonymous visitors. It used to return
|
||||
// `matched: true|false`, which told a stranger which addresses and domains the
|
||||
// shop discounts, one request per guess. The answer must be the same bare
|
||||
|
||||
Reference in New Issue
Block a user