Skip to content

Commit 7de8c10

Browse files
committed
Merge remote-tracking branch 'origin/add-order-coupon-refund-ratios' into optimize-order-date-generation
2 parents 55a0328 + e17884b commit 7de8c10

File tree

4 files changed

+355
-282
lines changed

4 files changed

+355
-282
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,13 @@ Generate orders with a specific status.
3535
- `wp wc generate orders <nr of orders> --status=completed`
3636

3737
Apply coupons to a percentage of generated orders (0.0-1.0). If no coupons exist, 6 will be created automatically (3 fixed cart, 3 percentage). Note: `--coupons` flag is equivalent to `--coupon-ratio=1.0`.
38+
39+
**Important:** Decimal ratios are converted to percentages using integer rounding. For example, `0.505` becomes 50% (not 50.5%) because the random generation uses integer comparison. Use whole percentages like `0.50` for precise 50% ratios.
3840
- `wp wc generate orders <nr of orders> --coupon-ratio=0.5`
3941

4042
Refund a percentage of completed orders (0.0-1.0). Refunds will be split evenly between partial and full, and 25% of partial refunds will receive a second partial refund.
43+
44+
**Note:** The same decimal ratio behavior applies to refund ratios as described above for coupon ratios.
4145
- `wp wc generate orders <nr of orders> --status=completed --refund-ratio=0.3`
4246

4347
#### Order Attribution

includes/CLI.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,13 +322,13 @@ function () use ( $progress ) {
322322
array(
323323
'name' => 'coupon-ratio',
324324
'type' => 'assoc',
325-
'description' => 'Decimal ratio (0.0-1.0) of orders that should have coupons applied. If no coupons exist, 6 will be created (3 fixed value, 3 percentage).',
325+
'description' => 'Decimal ratio (0.0-1.0) of orders that should have coupons applied. If no coupons exist, 6 will be created (3 fixed value, 3 percentage). Note: Decimal values are converted to percentages using integer rounding (e.g., 0.505 becomes 50%).',
326326
'optional' => true,
327327
),
328328
array(
329329
'name' => 'refund-ratio',
330330
'type' => 'assoc',
331-
'description' => 'Decimal ratio (0.0-1.0) of completed orders that should be refunded (wholly or partially).',
331+
'description' => 'Decimal ratio (0.0-1.0) of completed orders that should be refunded (wholly or partially). Note: Decimal values are converted to percentages using integer rounding (e.g., 0.505 becomes 50%).',
332332
'optional' => true,
333333
),
334334
array(

includes/Generator/Coupon.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ class Coupon extends Generator {
2424
public static function generate( $save = true, $assoc_args = array() ) {
2525
parent::maybe_initialize_generators();
2626

27-
$defaults = array(
28-
'min' => 5,
29-
'max' => 100,
30-
'discount_type' => '',
31-
);
27+
$defaults = array(
28+
'min' => 5,
29+
'max' => 100,
30+
'discount_type' => 'fixed_cart',
31+
);
3232

3333
$args = wp_parse_args( $assoc_args, $defaults );
3434

@@ -151,7 +151,7 @@ public static function batch( $amount, array $args = array() ) {
151151
* @return \WC_Coupon|false Coupon object or false if none available.
152152
*/
153153
public static function get_random() {
154-
// Note: Using posts_per_page=-1 loads all coupons into memory for random selection.
154+
// Note: Using posts_per_page=-1 loads all coupon IDs into memory for random selection.
155155
// For stores with thousands of coupons, consider using direct SQL with RAND() for better performance.
156156
// This approach was chosen for consistency with WordPress APIs and to avoid raw SQL queries.
157157
$coupon_ids = get_posts(

0 commit comments

Comments
 (0)