@@ -219,8 +219,16 @@ public static function get_discount_amount_for_cart_item( $cart_item, $discount,
219
219
}
220
220
}
221
221
222
- // Apply sign-up discounts. Exclude switch cart items because their initial amount is entirely sign-up fees but should be treated as initial amounts
223
- if ( ! $ is_switch && WC_Subscriptions_Product::get_sign_up_fee ( $ cart_item ['data ' ] ) > 0 ) {
222
+ // Compute the sign-up fee. If it's a switch, we need to get the signup fee less
223
+ // recurring payment upgrade/downgrade costs.
224
+ if ( $ is_switch ) {
225
+ $ sign_up_fee = (int ) $ cart_item ['data ' ]->get_meta ( '_subscription_sign_up_fee_prorated ' );
226
+ } else {
227
+ $ sign_up_fee = WC_Subscriptions_Product::get_sign_up_fee ( $ cart_item ['data ' ] );
228
+ }
229
+
230
+ // Apply sign-up discounts
231
+ if ( $ sign_up_fee > 0 ) {
224
232
225
233
if ( 'sign_up_fee ' == $ coupon_type ) {
226
234
$ apply_initial_coupon = true ;
@@ -236,15 +244,15 @@ public static function get_discount_amount_for_cart_item( $cart_item, $discount,
236
244
$ cart_item ['data ' ],
237
245
array (
238
246
'qty ' => 1 ,
239
- 'price ' => WC_Subscriptions_Product:: get_sign_up_fee ( $ cart_item [ ' data ' ] ) ,
247
+ 'price ' => $ sign_up_fee ,
240
248
)
241
249
);
242
250
} else {
243
251
$ signup_fee = wc_get_price_excluding_tax (
244
252
$ cart_item ['data ' ],
245
253
array (
246
254
'qty ' => 1 ,
247
- 'price ' => WC_Subscriptions_Product:: get_sign_up_fee ( $ cart_item [ ' data ' ] ) ,
255
+ 'price ' => $ sign_up_fee ,
248
256
)
249
257
);
250
258
}
@@ -253,7 +261,7 @@ public static function get_discount_amount_for_cart_item( $cart_item, $discount,
253
261
if ( in_array ( $ coupon_type , array ( 'sign_up_fee ' , 'sign_up_fee_percent ' ) ) ) {
254
262
$ discounting_amount = $ signup_fee ;
255
263
} else {
256
- $ discounting_amount -= $ signup_fee ;
264
+ $ discounting_amount = max ( 0 , $ discounting_amount - $ signup_fee ) ;
257
265
}
258
266
}
259
267
0 commit comments