@@ -241,13 +241,13 @@ public static function generate( $save = true, $assoc_args = array() ) {
241241
242242 // Process refund based on type
243243 if ( self ::REFUND_TYPE_FULL === $ refund_type ) {
244- self ::create_refund ( $ order );
244+ self ::create_refund ( $ order, false , null , true ); // Explicitly full
245245 } elseif ( self ::REFUND_TYPE_PARTIAL === $ refund_type ) {
246- self ::create_refund ( $ order , true );
246+ self ::create_refund ( $ order , true , null , false ); // Explicitly partial
247247 } elseif ( self ::REFUND_TYPE_MULTI === $ refund_type ) {
248- $ first_refund = self ::create_refund ( $ order , true );
249- if ( $ first_refund && is_object ( $ first_refund ) ) {
250- self ::create_refund ( $ order , true , $ first_refund );
248+ $ first_refund = self ::create_refund ( $ order , true , null , false ); // Explicitly partial
249+ if ( $ first_refund && is_object ( $ first_refund ) ) {
250+ self ::create_refund ( $ order , true , $ first_refund, false ); // Explicitly partial
251251 }
252252 }
253253 }
@@ -493,11 +493,12 @@ protected static function get_or_create_coupon() {
493493 * Create a refund for an order (either full or partial).
494494 *
495495 * @param \WC_Order $order The order to refund.
496- * @param bool $force_partial Force partial refund only.
496+ * @param bool $force_partial Force partial refund only (legacy parameter) .
497497 * @param \WC_Order_Refund|null $previous_refund Previous refund to base date on (for second refunds).
498+ * @param bool|null $force_full Explicitly force full refund (overrides random logic).
498499 * @return \WC_Order_Refund|false Refund object on success, false on failure.
499500 */
500- protected static function create_refund ( $ order , $ force_partial = false , $ previous_refund = null ) {
501+ protected static function create_refund ( $ order , $ force_partial = false , $ previous_refund = null , $ force_full = null ) {
501502 if ( ! $ order instanceof \WC_Order ) {
502503 error_log ( "Error: Order is not an instance of \WC_Order: " . print_r ( $ order , true ) );
503504 return false ;
@@ -507,13 +508,20 @@ protected static function create_refund( $order, $force_partial = false, $previo
507508 $ existing_refunds = $ order ->get_refunds ();
508509 if ( ! empty ( $ existing_refunds ) ) {
509510 $ force_partial = true ;
511+ $ force_full = false ; // Can't do full refund if already has refunds
510512 }
511513
512514 // Calculate already refunded quantities
513515 $ refunded_qty_by_item = self ::calculate_refunded_quantities ( $ existing_refunds );
514516
515517 // Determine refund type (full or partial)
516- $ is_full_refund = $ force_partial ? false : (bool ) wp_rand ( 0 , 1 );
518+ if ( null !== $ force_full ) {
519+ // Explicit full/partial specified (batch mode with exact ratios)
520+ $ is_full_refund = $ force_full ;
521+ } else {
522+ // Legacy random logic (single order generation or old code)
523+ $ is_full_refund = $ force_partial ? false : (bool ) wp_rand ( 0 , 1 );
524+ }
517525
518526 // Build refund line items
519527 $ line_items = $ is_full_refund
0 commit comments