When going through checkout without a payment method, the plugin throws the following warning:
[30-Jul-2024 18:58:42 UTC] PHP Warning: Attempt to read property "id" on false in /srv/htdocs/wp-content/plugins/woocommerce-payments/includes/class-woopay-tracker.php on line 513
$payment_gateway = wc_get_payment_gateway_by_order( $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 ) {
Basically, the wc_get_payment_gateway_by_order function can also return the value false which is not handled here. The if statement should be enhanced either with a check against false or for WC_Payment_Gateway (instanceof, e.g.).
Actual behavior
A warning is logged because the returned value wasn't expected.
Expected behavior
Ideally, there should be no warning logged when that happens.
Describe the bug
When going through checkout without a payment method, the plugin throws the following warning:
The line has changed since then: https://github.com/Automattic/woocommerce-payments/blob/244b7c937b86ba902a74fc21050d7ff1618bf690/includes/class-woopay-tracker.php#L543
To Reproduce
This is the code in question:
Basically, the
wc_get_payment_gateway_by_order
function can also return the valuefalse
which is not handled here. Theif
statement should be enhanced either with a check againstfalse
or forWC_Payment_Gateway
(instanceof
, e.g.).Actual behavior
A warning is logged because the returned value wasn't expected.
Expected behavior
Ideally, there should be no warning logged when that happens.