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

Add support for signup fee coupons during subscription switches #751

Draft
wants to merge 10 commits into
base: trunk
Choose a base branch
from

Conversation

annemirasol
Copy link
Contributor

@annemirasol annemirasol commented Dec 18, 2024

Fixes #726

Description

This PR adds support for signup fee coupon during subscription switches. It computes for the actual signup fee amount and applies the discount to that amount.

How to test this PR

  1. Go to WooCommerce > Settings > Subscriptions > Switching, and
    • Enable Allow Switching: Between Subscription Variations.
    • For Prorate Recurring Payment: For Upgrades and Downgrades of All Subscription Products
    • For Prorate Signup Fee: Never (charge the full signup fee)
  2. Go to Marketing > Coupons and create a coupon: a signup fee % discount for 20%.
  3. Create a Variable Subscription product:
    • Under Attributes, add "Membership Tier" with "Regular|Premium" as values, and check Used for variations before saving.
    • Under Variations, create:
      • Regular: 80.00/month, with 5.00 signup fee
      • Premium: 100.00/month, with 5.00 signup fee
  4. As a shopper, purchase the "Regular" variation.
  5. Go to My Account > Subscriptions > View, and click "Upgrade or Downgrade". Upgrade to "Premium" and go to checkout.
  6. Add the signup fee % discount coupon.
  7. Verify that the "Order Summary Signup Fee" shows 25.00, but the discount amount is only 1.00 (20% of 5.00, the signup fee prior to upgrade costs).
  8. Test for different combinations of Prorate Recurring Payment and Prorate Signup Fee: no matter the combination, the discount amount should never be more than 1.00.
  9. Test using different coupon types:
    • signup fee coupon, e.g. 10.00: discount should always be 5.00 or less
    • recurring fee/recurring fee percent coupon: discount should be applied to upgrade cost excluding signup fee.
  10. Test a subscription downgrade.

Product impact

  • Added changelog entry (or does not apply)
  • Will this PR affect WooCommerce Subscriptions? yes/no/tbc, add issue ref
  • Will this PR affect WooCommerce Payments? yes/no/tbc, add issue ref
  • Added deprecated functions, hooks or classes to the spreadsheet

@annemirasol annemirasol force-pushed the add/726-support-signup-coupons-for-switches branch from 5fcdaa5 to ed0c575 Compare December 18, 2024 20:28
@annemirasol annemirasol force-pushed the add/726-support-signup-coupons-for-switches branch from ed0c575 to 912d4dc Compare December 18, 2024 21:07
@annemirasol annemirasol self-assigned this Dec 18, 2024
@annemirasol annemirasol force-pushed the add/726-support-signup-coupons-for-switches branch from 0095552 to 7e79332 Compare December 19, 2024 16:24
@annemirasol annemirasol marked this pull request as ready for review December 19, 2024 17:50
@annemirasol annemirasol requested review from a team, Mayisha and mattallan and removed request for a team December 19, 2024 17:50
@annemirasol
Copy link
Contributor Author

@mattallan Thank you again for the pointers. Added you as reviewer, for extra 👀

includes/class-wc-subscriptions-coupon.php Show resolved Hide resolved
$sign_up_fee_prorated = (int) $cart_item['data']->get_meta( '_subscription_sign_up_fee_prorated' );
$price_prorated = (int) $cart_item['data']->get_meta( '_subscription_price_prorated' );

if ( 0 === $sign_up_fee_prorated && 0 === $price_prorated ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick question for my understanding - why the price_prorated is also being checked here? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question! In 3ee2abc, I simplified the logic using meta_exists. Hopefully it's more readable.

Copy link
Contributor

@Mayisha Mayisha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have come across a confusing scenario.

  • I created 2 coupons
    • a signup fee % discount for 20% (signup percent)
    • a signup fee discount for 10 (signup 10)
  • I created a variable subscription 'Membership Tier' as mentioned in the PR description but with different signup fees.
    • Regular with a signup fee 5.
    • Premium with a signup fee 10.

Case 1:

  • Purchased the 'Regular' variation.
  • Upgraded to 'Premium' and went to the checkout page.
  • The signup fee is 30 (not 10) 🤔
  • Used the signup percent coupon. The amount is -2. (This is the correct percentage for signup fee 10 but why does it show 30 here? )
  • Used the signup 10 coupon. The amount is -10. (also correct caps for signup fee 10)
  • In this case the sign up fee is off. Also with multiple coupons used, the discount is more than the sign up fee.
Screenshot 2025-01-09 at 2 02 35 AM

Case 2:

  • Purchased the 'Premium' variation.
  • Downgraded to 'Regular' and went to the checkout page.
  • Used the signup 10 coupon. The amount is -5. (also correct)
  • Used the signup percent coupon. The amount is 0. (If I remove the previous coupon the discount becomes -1 which is correct)
  • In this case, is it the expected behavior for multiple coupons.
Screenshot 2025-01-09 at 1 58 53 AM

@annemirasol
Copy link
Contributor Author

@Mayisha

Case 1:

Purchased the 'Regular' variation.
Upgraded to 'Premium' and went to the checkout page.
The signup fee is 30 (not 10) 🤔

Did you set recurring fees to be prorated, and signup to be charged full amount? If that is the case, the signup fee displayed is 30 because it is 10 (the true signup fee) + 20 (the difference between Regular and Premium).

The signup fee being 30.00 is part of the issue why signup fee coupons are currently not supported. In this function, we overwrite the true signup fee with (true signup fee + upgrade costs from the recurring fee difference).

Used the signup percent coupon. The amount is -2. (This is the correct percentage for signup fee 10 but why does it show 30 here? )
Used the signup 10 coupon. The amount is -10. (also correct caps for signup fee 10)
In this case the sign up fee is off. Also with multiple coupons used, the discount is more than the sign up fee.

Good catch! I need to add logic for when multiple coupons are used.

@annemirasol annemirasol marked this pull request as draft January 8, 2025 20:57
@Mayisha
Copy link
Contributor

Mayisha commented Jan 9, 2025

Did you set recurring fees to be prorated, and signup to be charged full amount? If that is the case, the signup fee displayed is 30 because it is 10 (the true signup fee) + 20 (the difference between Regular and Premium).

You are right. I have these settings-

Screenshot 2025-01-09 at 11 21 52 AM

@annemirasol
Copy link
Contributor Author

annemirasol commented Jan 10, 2025

Used the signup percent coupon. The amount is -2. (This is the correct percentage for signup fee 10 but why does it show 30 here? )
Used the signup 10 coupon. The amount is -10. (also correct caps for signup fee 10)
In this case the sign up fee is off. Also with multiple coupons used, the discount is more than the sign up fee.

Good catch! I need to add logic for when multiple coupons are used.

I checked the sign up fee coupon behavior for initial subscription purchases, and the behavior seems to be the same: multiple sign up fee coupons applied to the same cart can lead to a total discount that is greater than the actual sign up fee.

Screenshot 2025-01-10 at 11 02 45 AM

@mattallan Is this a known issue, or a non-issue/expected behavior?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sign-up fee discount not applied when switching subscription
2 participants