0

How do I go about setting all orders that are on-hold to have a Payment method of cod?

Any tips on what hooks I can use would greatly be appreciated!

Thanks

Edit:

I have written this code but the payment method does not update as expected.

//Change the payment method of all on-hold orders to Other
add_action('woocommerce_order_status_changed', 'ddd_wc_status_change', 10, 3);
function ddd_wc_status_change($order_id, $old_status, $new_status)
{
    $order = wc_get_order($order_id);
    $status = $order->get_status();
    $payment_gateways = WC()->payment_gateways->payment_gateways();

    if($status == "on-hold"){
        $order->set_payment_method( $payment_gateways['cod'] );
        $order->add_order_note('Payment method changed to In-store Payment.',0);
    }
}

0

Your Answer

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