Automattic / woocommerce-subscriptions-core

Subscriptions core package for WooCommerce
Other
81 stars 29 forks source link

Only prevent Product add-ons from adjusting prices if prices are honoured #510

Closed james-allan closed 9 months ago

james-allan commented 9 months ago

Part of https://github.com/woocommerce/woocommerce-subscriptions/issues/4535

Description

When using the Product Add-ons plugin and you pay for a subscription renewal, failed initial order or resubscribe, we were telling Product Add-ons to not adjust the price.

This caused issues when paying for initial parent orders because we (subscriptions) don't automatically grandfather the price and so we need Product Add-ons to actually calculate the add-on prices in that case.

This PR fixes that by making sure we only tell Product Add-ons to not adjust prices if we're going to honour the order/subscription total. To help explain, this little table explains what the cart product price source should be for the various scenarios:

Order type Price Source
Parent product price + Add-ons
Parent w' price lock * subscription/order
Renewal subscription/order

* you can lock the parent order price by editing the order and hitting this checkbox

Screenshot 2023-09-19 at 2 28 52 pm

How to test this PR

  1. Install the WooCommerce Product Add-ons plugin.
  2. Create a subscription product with at least 1 product Add-on.
  3. Go the product page on the front end, choose an add-on and then add the product to the cart.
  4. At checkout fail the payment using a failing payment method.
  5. Go to the My Account Orders page and click the "Pay" link.
    • On trunk you'll notice 2 things.
      1. The order price will be wrong. It doesn't include the add-on prices.
      2. The add-ons are doubled up (screenshot) - you can ignore this for now.
    • On this branch the total price should be correct. ie include the add-on(s) prices.
  6. Edit the order in the admin dashboard.
  7. Change the order's status to pending.
  8. Edit the line item total and increase the price.
  9. Check the "lock manual price increases" box.
  10. Save
  11. Repeat step 5 from above.
    • On trunk the price is correct (the increased price).
    • On this branch the total price should still be correct (the increased price).
  12. Create a pending renewal order for a subscription with product add-ons.
  13. Attempt to pay for it through the cart, the cart total should always match subscription/renewal order.

The add-ons are doubled up (screenshot) - you can ignore this for now.

This doubling up of the add-ons will need to be fixed in the Product Add-ons plugin. I've got some working changes that I'll submit to their repo.

Product impact