Skip to content

Conversation

@james-allan
Copy link
Contributor

@james-allan james-allan commented Mar 29, 2021

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.

image

How to test the changes in this Pull Request:

  1. While logged into a customer account (admin accounts won't work). Add a standard simple product to your cart.
  2. Log out.
  3. While logged in as admin, edit the product and set its status to draft. (https://d.pr/i/2WK27E)
  4. Log back into the customers' account.

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:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully run tests with your changes locally?

Changelog entry

Fix - Update the persistent cart after it's loaded on customer login. Fixes an issue whereby unavailable products would be validated on every login.

@scottbuscemi
Copy link

Thank you! This has been affecting a client site so it's great to see the PR on the move.

Copy link
Contributor

@roykho roykho left a comment

Choose a reason for hiding this comment

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

LGTM! Working as expected. Thanks for the PR!

@roykho roykho merged commit 1d0b068 into trunk Mar 31, 2021
@roykho roykho deleted the fix/wc-subscriptions/4002 branch March 31, 2021 20:25
@woocommercebot woocommercebot added release: add changelog Mark all PRs that have not had their changelog entries added. [auto] release: add testing instructions PRs that have not had testing instructions added to the wiki. [auto] labels Mar 31, 2021
@roykho roykho added this to the 5.3.0 milestone Mar 31, 2021
@tammullen tammullen added testing instructions added and removed release: add testing instructions PRs that have not had testing instructions added to the wiki. [auto] labels Apr 20, 2021
@scottbuscemi
Copy link

@roykho This issue is still persisting even though it's merged into the production version of WooCommerce. Let me know the best way to report this. Thanks!

@roykho
Copy link
Contributor

roykho commented Jul 6, 2021

@scottbuscemi - I would suggest you create a new issue describing the details such as what you're actually seeing and how to produce it. You can reference this PR as well. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release: add changelog Mark all PRs that have not had their changelog entries added. [auto]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants