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

Uncaught TypeError on order edit screen #6

Open
lakrisgubben opened this issue Feb 6, 2024 · 0 comments
Open

Uncaught TypeError on order edit screen #6

lakrisgubben opened this issue Feb 6, 2024 · 0 comments

Comments

@lakrisgubben
Copy link

Hey,

I'm trying out this new plugin for a customer that currently uses https://github.com/SwedbankPay/swedbank-pay-woocommerce-payments/. Am I correct to assume that this plugin is the recommended one to use going forward?

Found one bug when visiting a single order in wp-admin (.../wp-admin/admin.php?page=wc-orders&action=edit&id=NN) while using WooCommerce's high performance order storage (HPOS).

PHP Fatal error: Uncaught TypeError: swedbank_pay_get_payment_method(): Argument #1 ($order) must be of type WC_Order, bool given, called in [...]/plugins/swedbank-pay-payment-menu/includes/class-swedbank-pay-admin.php on line 366

This is easily fixed by checking that $order !== false here https://github.com/SwedbankPay/swedbank-pay-woocommerce-paymentmenu/blob/main/includes/class-swedbank-pay-admin.php#L365

But the underlying issue is that this method https://github.com/SwedbankPay/swedbank-pay-woocommerce-paymentmenu/blob/main/includes/class-swedbank-pay-admin.php#L213 uses the global $post_id which is not set when using HPOS. Using the following code instead of relying on $post_id seems to work for both the old order system (using wp_posts) and HPOS.

$order = wc_get_order();
if ( ! $order ) {
	return;
}
...
'order_id'  => $order->get_id(),
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

No branches or pull requests

1 participant