The free shipping method has an option to limit it's availability to carts that exceed a required amount (eg free shipping is available to all orders over $100). The way this limitation interacts with subscriptions isn't immediately apparent but it does make sense and honor the limitation.
If the initial cart exceeds the minimum requirement, it will be given the free shipping method option.
Each recurring cart that exceeds the minimum requirement will be given free shipping.
On the contrary. If the initial cart doesn't meet the minimum requirement, it wont have free shipping.
And, any recurring cart that doesn't meet the requirement, won't have free shipping available to it.
When you consider mixed cart (simple and subscriptions products purchased at once), free trials and sign up fees, you can get into a mix of free shipping availability across the initial and recurring carts.
For example:
Free trial (A)
Sign up fee (B)
Mixed checkout (C) ❗
Free initial cart with no shipping, but recurring cart is eligible.
$20/year with a $100 sign up fee. Free shipping available to initial cart, but not the recurring cart.
Free shipping available to $100 recurring cart, but not $12 initial cart.
The issue this PR fixes occurs when you have free shipping available to the recurring cart but not to the initial cart - scenario C above. In this scenario, when we go to validate the shipping method on checkout submission, we incorrectly determine that the recurring cart isn't eligible for free shipping because we missed setting a flag that enables the maybe_recalculate_shipping_method_availability() function to calculate method availability for recurring carts. Essentially, because free shipping isn't available to the initial cart, the validation fails for the eligible recurring cart. This eventually leads to this error message on checkout:
This PR fixes that by making sure we set the self::$cached_recurring_cart before validating recurring shipping methods.
How to test this PR
Add a free shipping option that is limited to carts that exceed $100 (screenshot)
Add products to the cart to end up with an initial payment less than $100 and at least 1 recurring cart with a total greater than $100. Options include:
Add enough free trial subscription products to exceed the $100 requirement and at least 1 other product with an initial cost (subscription or standard product).
Add a sign up fee & free trial product to the cart where the sign up fee is less than $100, but the recurring price exceeds it. Eg a $20 sign up fee with a free trial + $100 recurring price.
Now visit the checkout. You should have standard shipping available to the initial cart, and free shipping available to the recurring cart that exceeds $100. (see screenshot example under (C) above).
Choose free shipping in the recurring cart section.
Attempt to checkout.
On trunk you should get the error message "Invalid recurring shipping method." and be blocked from checking out.
On this branch there shouldn't be any error message, checkout should be successful and the subscription set up with free shipping.
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
Fixes #409
Description
The free shipping method has an option to limit it's availability to carts that exceed a required amount (eg free shipping is available to all orders over $100). The way this limitation interacts with subscriptions isn't immediately apparent but it does make sense and honor the limitation.
When you consider mixed cart (simple and subscriptions products purchased at once), free trials and sign up fees, you can get into a mix of free shipping availability across the initial and recurring carts.
For example:
The issue this PR fixes occurs when you have free shipping available to the recurring cart but not to the initial cart - scenario C above. In this scenario, when we go to validate the shipping method on checkout submission, we incorrectly determine that the recurring cart isn't eligible for free shipping because we missed setting a flag that enables the
maybe_recalculate_shipping_method_availability()
function to calculate method availability for recurring carts. Essentially, because free shipping isn't available to the initial cart, the validation fails for the eligible recurring cart. This eventually leads to this error message on checkout:This PR fixes that by making sure we set the
self::$cached_recurring_cart
before validating recurring shipping methods.How to test this PR
trunk
you should get the error message "Invalid recurring shipping method." and be blocked from checking out.Product impact