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

Make sure product exists before using it in ajax response #3687

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

nbloomf
Copy link
Contributor

@nbloomf nbloomf commented Dec 31, 2024

The WC_Stripe_Payment_Request::ajax_add_to_cart() function takes a product ID from the request body and passes it to wc_get_product(). That function will return null if the product is not found, and false if the function call happened out of order (that is, before some prerequisite hooks have run).

Currently we're assuming that the product lookup succeeded, but if it doesn't then the $product->get_type() call on the following line raises a critical error like Uncaught Error: Call to a member function get_type() on bool.


  • Covered with tests (or have a good reason not to test in description ☝️)
  • Added changelog entry in both changelog.txt and readme.txt (or does not apply)
  • Tested on mobile (or does not apply)

Post merge

@nbloomf nbloomf self-assigned this Dec 31, 2024
@annemirasol annemirasol requested review from a team and annemirasol and removed request for a team January 3, 2025 21:12
Copy link
Contributor

@annemirasol annemirasol left a comment

Choose a reason for hiding this comment

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

Hey @nbloomf, thanks for taking care of this!

We're actually phasing out Payment Request buttons in the next release (scheduled in a few days), so this path will soon be unused.

Could you put this check in the new path here, please? Thanks!

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.

2 participants