@@ -224,13 +224,13 @@ public static function generate( $save = true, $assoc_args = array() ) {
224224
225225 // Process refund based on type
226226 if ( self ::REFUND_TYPE_FULL === $ refund_type ) {
227- self ::create_refund ( $ order );
227+ self ::create_refund ( $ order, false , null , true ); // Explicitly full
228228 } elseif ( self ::REFUND_TYPE_PARTIAL === $ refund_type ) {
229- self ::create_refund ( $ order , true );
229+ self ::create_refund ( $ order , true , null , false ); // Explicitly partial
230230 } elseif ( self ::REFUND_TYPE_MULTI === $ refund_type ) {
231- $ first_refund = self ::create_refund ( $ order , true );
231+ $ first_refund = self ::create_refund ( $ order , true , null , false ); // Explicitly partial
232232 if ( $ first_refund ) {
233- self ::create_refund ( $ order , true , $ first_refund );
233+ self ::create_refund ( $ order , true , $ first_refund, false ); // Explicitly partial
234234 }
235235 }
236236 }
@@ -440,11 +440,12 @@ protected static function get_or_create_coupon() {
440440 * Create a refund for an order (either full or partial).
441441 *
442442 * @param \WC_Order $order The order to refund.
443- * @param bool $force_partial Force partial refund only.
443+ * @param bool $force_partial Force partial refund only (legacy parameter) .
444444 * @param \WC_Order_Refund|null $previous_refund Previous refund to base date on (for second refunds).
445+ * @param bool|null $force_full Explicitly force full refund (overrides random logic).
445446 * @return \WC_Order_Refund|false Refund object on success, false on failure.
446447 */
447- protected static function create_refund ( $ order , $ force_partial = false , $ previous_refund = null ) {
448+ protected static function create_refund ( $ order , $ force_partial = false , $ previous_refund = null , $ force_full = null ) {
448449 if ( ! $ order instanceof \WC_Order ) {
449450 error_log ( "Error: Order is not an instance of \WC_Order: " . print_r ( $ order , true ) );
450451 return false ;
@@ -454,13 +455,20 @@ protected static function create_refund( $order, $force_partial = false, $previo
454455 $ existing_refunds = $ order ->get_refunds ();
455456 if ( ! empty ( $ existing_refunds ) ) {
456457 $ force_partial = true ;
458+ $ force_full = false ; // Can't do full refund if already has refunds
457459 }
458460
459461 // Calculate already refunded quantities
460462 $ refunded_qty_by_item = self ::calculate_refunded_quantities ( $ existing_refunds );
461463
462464 // Determine refund type (full or partial)
463- $ is_full_refund = $ force_partial ? false : (bool ) wp_rand ( 0 , 1 );
465+ if ( null !== $ force_full ) {
466+ // Explicit full/partial specified (batch mode with exact ratios)
467+ $ is_full_refund = $ force_full ;
468+ } else {
469+ // Legacy random logic (single order generation or old code)
470+ $ is_full_refund = $ force_partial ? false : (bool ) wp_rand ( 0 , 1 );
471+ }
464472
465473 // Build refund line items
466474 $ line_items = $ is_full_refund
0 commit comments