Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sign-up fee discount not applied when switching subscription #726

Open
2 tasks
annemirasol opened this issue Nov 15, 2024 · 1 comment
Open
2 tasks

Sign-up fee discount not applied when switching subscription #726

annemirasol opened this issue Nov 15, 2024 · 1 comment
Labels
type: bug The issue is a confirmed bug.

Comments

@annemirasol
Copy link

Describe the bug

Reported by @allie500 in p1731683240284119-slack-C055WHLA98D:

A merchant has reported an issue with applying a sign up % discount coupon when a shopper with an active subscription of a variable subscription product switches to a new variation with a sign up fee. The coupon percentage is not applied to the sign up fee.

The HE who escalated the issue to Woo-Devs was able to replicate the issue. I spun up a JN site and was also able to replicate the issue. I also didn't see anything relevant in the debug.log file nor the wc-logs.

When I applied the coupon no exception or errors were thrown. The coupon was showing up on the page but the percentage amount was not deducted from the sign up fee.

Processing the order resulted in the full sign up fee being charged. I checked the coupons page in the wp-admin and it shows that the coupon has one usage.

To Reproduce

  1. Go to the coupon page in the wp-admin and make note of the current usage number for the coupon.
  2. Buy the annual variation of the subscription.
  3. Confirm the order was successful.
  4. Then on the my account page go to the subscriptions subpage and click the upgrade or downgrade button.
  5. Select the lifetime variation.
  6. Apply the coupon: lifetime20
  7. Observe that the amount due is not updated to reflect a 20% discount on the sign up price.
  8. Observe that the coupon is successfully added to the order.
  9. Finish checkout.
  10. Go to the coupons page in the wp-admin and confirm that the number incremented.

Expected behavior

Sign up fee coupons get applied when upgrading/downgrading subscriptions.

Actual behavior

Sign up fee coupons get ignored when upgrading/downgrading subscriptions.

Product impact

  • Does this issue affect WooCommerce Subscriptions? yes
  • Does this issue affect WooCommerce Payments? no

Additional context

Initial investigation by @annemirasol traced the behavior to

if ( ! $is_switch && WC_Subscriptions_Product::get_sign_up_fee( $cart_item['data'] ) > 0 ) {
, which seemingly skips "switches" on purpose when computing sign-up fee discounts.

@annemirasol annemirasol added the type: bug The issue is a confirmed bug. label Nov 15, 2024
@mattallan
Copy link
Contributor

mattallan commented Nov 18, 2024

Thanks @annemirasol for opening an issue. Calculating sign-up fee discounts on a switch item may be difficult because after calculating the upgrade costs of the switch, we set the upgrade cost as the signup fee on the cart item. See set_upgrade_cost()

Part of the challenge is ensuring we calculate the correct discount_amount based on our "Prorate Sign Up Fee" setting:

Image

Thinking out aloud here... inside our class-wc-subscriptions-coupon.php class, we are getting the signup fee using WC_Subscriptions_Product::get_sign_up_fee( $cart_item['data'] ) which will return $existing_sign_up_fee + $extra_to_pay (set by set_upgrade_cost()).
Because we don't want the discount to apply to the switch upgrade cost, what we might be refactor our get_discount_amount_for_cart_item() function to fetch the correct signup fee when calculating the signup and discount amounts here.

Correct sign-up fee amount to use:

  • For switches, use $cart_item['data']->get_meta( '_subscription_sign_up_fee_prorated' ); if it exists.
  • In all other cases, we should be able to use WC_Subscriptions_Product::get_sign_up_fee( $cart_item['data'] )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug The issue is a confirmed bug.
Projects
None yet
Development

No branches or pull requests

2 participants