Automattic / woocommerce-subscriptions-core

Subscriptions core package for WooCommerce
Other
80 stars 29 forks source link

Fix undefined array-key order-received PHP error on order received page #599

Closed james-allan closed 2 months ago

james-allan commented 2 months ago

Fixes #418

Description

In our legacy PayPal code we have a function that is supposed to set meta when the customer lands on the order received page.

The logic at the top of the function has a gap and can lead to the following error:

PHP Warning:  Undefined array key "order-received" in /public/wp-content/plugins/woocommerce-subscriptions-core/includes/gateways/paypal/class-wcs-paypal.php on line 519 

This can occur because our wcs_is_order_received_page() just checks if order-received is anywhere in the URI.

wcs_is_order_received_page() has a function comment which indicates that checking the URI is by design. It's supposed to be used in cases where we want to check if the request is for the order received without accessing the $wp->query_vars. In this case we need to access the $wp->query_vars to pull the order ID and so it's not a good candidate for this.

This PR fixes that.

How to test this PR

[!note] I'm not sure how folks are replicating this natively, whenever I go to a legit order received page, it pulls the order ID out of the URL just fine.

  1. Go to the front page of your store and add the order-recieved query var.
  2. On trunk you should get the error I mentioned above. On this branch there will be no error.
  3. Confirm that the order received page still works as intended.
    • eg Add a breakpoint or logging to the maybe_add_payment_lock() function and verify that the $order param is still being loaded eg add a $order->get_id().
  4. Purchase a new product of any type and confirm via the breakpoint or logging that you added that the order is still loading and that maybe_add_payment_lock() would still work as intended.

Product impact