Skip to content

Commit

Permalink
Simplify logic
Browse files Browse the repository at this point in the history
  • Loading branch information
annemirasol committed Jan 8, 2025
1 parent ea81105 commit 3ee2abc
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions includes/class-wc-subscriptions-coupon.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,17 +219,18 @@ public static function get_discount_amount_for_cart_item( $cart_item, $discount,
}
}

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

if ( 0.0 === $sign_up_fee_prorated && 0.0 === $price_prorated ) {
// No prorated recurring fees, i.e. no extra upgrade costs, so we can use the original sign-up fee.
$sign_up_fee = WC_Subscriptions_Product::get_sign_up_fee( $cart_item['data'] );
if ( $is_sign_up_fee_prorated ) {
$sign_up_fee = (float) $cart_item['data']->get_meta( '_subscription_sign_up_fee_prorated' );
} else {
$sign_up_fee = $sign_up_fee_prorated;
$sign_up_fee = WC_Subscriptions_Product::get_sign_up_fee( $cart_item['data'] );
}
} else {
$sign_up_fee = WC_Subscriptions_Product::get_sign_up_fee( $cart_item['data'] );
Expand Down

0 comments on commit 3ee2abc

Please sign in to comment.