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

Fix issues with discounts being applied to manually created parent orders #439

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

Conversation

james-allan
Copy link
Contributor

Fixes woocommerce-subscriptions/issues/4504

🛑 This PR is on-hold while more work and testing is done. I've submitted it as a draft for now.

Description

When you apply a coupon to a subscription manually and then pay for a newly created subscription parent order, the discount is supposed to be copied into into the cart as a coupon. Because of a rounding discrepancy with how WC core stores coupon line item totals and order discounts, this was not working as intended. What's more, because this wasn't working as intended, customers would end up in a flow that had even more issues.

This PR fixes those issues. Namely:

  1. When the order discount total doesn't match the coupon line item total because of a rounding discrepancy, allow for a delta of 1 unit of precision (eg 1 cent). This allows us to use the actual coupon rather than having to retrofit a custom coupon to match the actual total.
  2. When using a custom coupon (eg when a discount is applied to the line item manually), make sure we use the discount total + the discount tax, otherwise the total will be incorrect.
  3. 🕙 TODO when a custom coupon is applied, it should also apply to the subscription if the same discount also applies to the subscription.

How to test this PR

Set up:

  1. Create a 50% Recurring Product % Discount coupon
  2. Create a $10 monthly subscription
    • This 50% and $10 combination is important as it leads to the rounding discrepancy.
  3. Store Tax settings: prices entered including taxes and a 10% store tax applies
  4. manually create a subscription
  5. Add the product, recalculate taxes, apply the coupon. The amount is right.
  6. Create a pending order
  7. click the pay for order link
    8. On trunk the order total will be incorrect ($5.46) and the recurring cart won't have the coupon applied.
    9. On this branch the total should be correct and the coupon should apply to both the initial amount and recurring cart.

Further tests should be ran to make sure different tax, amounts and ways of applying discounts to parent orders and subscriptions should be tested.

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

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.

1 participant