Skip to content

Commit 3ee2abc

Browse files
committed
Simplify logic
1 parent ea81105 commit 3ee2abc

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

includes/class-wc-subscriptions-coupon.php

+9-8
Original file line numberDiff line numberDiff line change
@@ -219,17 +219,18 @@ public static function get_discount_amount_for_cart_item( $cart_item, $discount,
219219
}
220220
}
221221

222-
// Compute the original sign-up fee. If it's a switch, we need to get the signup fee less
223-
// upgrade costs.
222+
// Compute the true sign-up fee.
223+
// If it's a switch, we need to get the signup fee less upgrade costs.
224224
if ( $is_switch ) {
225-
$sign_up_fee_prorated = (float) $cart_item['data']->get_meta( '_subscription_sign_up_fee_prorated' );
226-
$price_prorated = (float) $cart_item['data']->get_meta( '_subscription_price_prorated' );
225+
// When sign-up fees are prorated, this meta will store the prorated amount:
226+
// the original sign-up fee less what's already paid. When recurring fees are prorated,
227+
// this meta contains the sign-up fee before extra fees are applied.
228+
$is_sign_up_fee_prorated = (float) $cart_item['data']->meta_exists( '_subscription_sign_up_fee_prorated' );
227229

228-
if ( 0.0 === $sign_up_fee_prorated && 0.0 === $price_prorated ) {
229-
// No prorated recurring fees, i.e. no extra upgrade costs, so we can use the original sign-up fee.
230-
$sign_up_fee = WC_Subscriptions_Product::get_sign_up_fee( $cart_item['data'] );
230+
if ( $is_sign_up_fee_prorated ) {
231+
$sign_up_fee = (float) $cart_item['data']->get_meta( '_subscription_sign_up_fee_prorated' );
231232
} else {
232-
$sign_up_fee = $sign_up_fee_prorated;
233+
$sign_up_fee = WC_Subscriptions_Product::get_sign_up_fee( $cart_item['data'] );
233234
}
234235
} else {
235236
$sign_up_fee = WC_Subscriptions_Product::get_sign_up_fee( $cart_item['data'] );

0 commit comments

Comments
 (0)