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

Fix fatal error with PRB buttons #4042

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

Conversation

wjrosa
Copy link
Contributor

@wjrosa wjrosa commented Mar 11, 2025

Changes proposed in this Pull Request:

This PR fixes a possible fatal error happening when a product cannot be found, related to PRBs' add to cart ajax endpoint. This error was caught with Grafana:

PHP Fatal error: Uncaught Error: Call to a member function get_type() on bool in /wordpress/plugins/woocommerce-gateway-stripe/9.2.0/includes/payment-methods/class-wc-stripe-payment-request.php:1475 Stack trace: #0 /wordpress/core/6.7.2/wp-includes/class-wp-hook.php(324): WC_Stripe_Payment_Request->ajax_add_to_cart('') #1 /wordpress/core/6.7.2/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters('', Array) #2 /wordpress/core/6.7.2/wp-includes/plugin.php(517): WP_Hook->do_action(Array) #3 /wordpress/plugins/woocommerce/9.7.1/includes/class-wc-ajax.php(98): do_action('wc_ajax_wc_stri...') #4 /wordpress/core/6.7.2/wp-includes/class-wp-hook.php(324): WC_AJAX::do_wc_ajax('') #5 /wordpress/core/6.7.2/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(false, Array) #6 /wordpress/core/6.7.2/wp-includes/plugin.php(517): WP_Hook->do_action(Array) #7 /wordpress/core/6.7.2/wp-includes/template-loader.php(13): do_action('template_redire...') #8 /wordpress/core/6.7.2/wp-blog-header.php(19): require_once('/wordpress/core...') #9 /wordpress/core/6.7.2/index.php(17): require('/wordpress/core...') #10 {main} thrown in /wordpress/plugins/woocommerce-gateway-stripe/9.2.0/includes/payment-methods/class-wc-stripe-payment-request.php on line 1475

On a regular store setup, this error should not happen since we deprecated PRBs in favor of express payment methods. But this change should at least make the code safer.

Testing instructions

Code review should be enough. Check if the tests are still passing.


  • Covered with tests (or have a good reason not to test in description ☝️)
  • Tested on mobile (or does not apply)

Changelog entry

  • This Pull Request does not require a changelog entry. (Comment required below)
Changelog Entry Comment

Comment

Post merge

@wjrosa wjrosa self-assigned this Mar 11, 2025
@@ -1467,35 +1467,45 @@ public function ajax_add_to_cart() {
define( 'WOOCOMMERCE_CART', true );
}

WC()->shipping->reset_shipping();
try {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just wrapped the code inside the try...catch block, but GitHub thinks I changed more stuff here.

@wjrosa wjrosa marked this pull request as ready for review March 11, 2025 18:28
@wjrosa wjrosa requested review from a team and diegocurbelo and removed request for a team March 11, 2025 18:32
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