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

9341-warning-due-to-unhandled-possible-return-value #9628

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

duotive
Copy link

@duotive duotive commented Oct 25, 2024

Fixes #9341

Changes proposed in this Pull Request

When going through checkout without a payment method, the plugin throws the following warning:

PHP Warning:  Attempt to read property "id" on bool in /home/public_html/wp-content/plugins/woocommerce-payments/includes/class-woopay-tracker.php on line 546

Testing instructions

  • create a coupon that has a big value, and will enable free shipping on checkout
  • add a product to checkout, and apply the coupon created
  • when completing the checkout the total sum to pay should be 0

  • Run npm run changelog to add a changelog file, choose patch to leave it empty if the change is not significant. You can add multiple changelog files in one PR by running this command a few times.
  • Covered with tests (or have a good reason not to test in description ☝️)
  • Tested on mobile (or does not apply)

Post merge

@@ -541,7 +541,7 @@ public function checkout_order_processed( $order_id ) {
$properties = [ 'payment_title' => 'other' ];

// If the order was placed using WooCommerce Payments, record the payment title using Tracks.
if ( strpos( $payment_gateway->id, 'woocommerce_payments' ) === 0 ) {
if ( $payment_gateway && strpos( $payment_gateway->id, 'woocommerce_payments' ) === 0 ) {
Copy link

@retrofox retrofox Nov 5, 2024

Choose a reason for hiding this comment

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

what about checking if the variable is string?

Suggested change
if ( $payment_gateway && strpos( $payment_gateway->id, 'woocommerce_payments' ) === 0 ) {
if ( is_string( $payment_gateway ) && strpos( $payment_gateway->id, 'woocommerce_payments' ) === 0 ) {

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.

Warning due to unhandled possible return value
2 participants