Update the persistent cart after it's loaded on log in #29517
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
All Submissions:
Changes proposed in this Pull Request:
After loading the user's saved cart on login, update the persistent cart with changes to the cart that might have occurred due to product purchase-ability.
There exists an issue when your persistent cart contains invalid or non-purchasable. When you log in, WC will load the cart with the contents from the previous session. If the product isn't purchasable any more it won't be added to the cart and the following notice will be displayed, however, the saved persistent cart isn't updated unless you edit your cart in some way (remove, add, restore items etc). This means each time you log in, WC will try to reload the invalid product displaying the same notice each time.
This PR fixes that by making sure to update the persistent cart after it is loaded and the products are validated and notices are displayed.
How to test the changes in this Pull Request:
trunkyou'll be presented with this notice https://d.pr/i/5DCUEN. If you continue to log in and out, you will always receive this message each time.While it's pretty unlikely or rare that merchants would change the status of their products, it's this function call (
$product->is_purchasable()) which is filtered to allow third-party plugins to determine whether a product is purchasable. WC Subscriptions uses this function's filter for one of our product features and so it's more common and wide-ranging than the changing product statuses.Other information:
Changelog entry