3

Is there a way to update payment method of order in magento 2 via dependency Injector or Object factory without using raw sql query?

1 Answer 1

6

You need to load order instance either from order entity_id or increment_id. After that, try these code. I haven't tested these code

$payment = $order->getPayment();
$payment->setMethod('yourpaymentmethodcode');
$payment->save();
$order->save();

or

$order->getPayment()->importData(['method' => 'yourpaymentmethodcode']);
$order->save();

I hope this will help

1
  • this one doesn't return the name of assigned payment method in customer.orders query for some reason
    – Herokiller
    Jun 30, 2022 at 9:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.