The following answer code is not working, as I use the custom order status pre-ordered
:
Change admin payment status back to unpaid for pending order status in Woocommerce
All my products are pre-orders and for that I use a pre-order plugin (from Bright) and the custom payment plugin (from WPRuby), which I have named "Betaal later" (which means "pay later"). Then I have created a custom order status "Pre Ordered", and I have set up this custom status in the custom payment plugin settings, so every order using this payment option, get’s the status Pre Ordered.
If the customer makes an order and the only payment option is ‘Betaal later’, then the order already gets a paid date (the date of the creation of the order) and that’s not correct because it is not paid. Can someone help me with this code to work for my situation? It looks like this answer code is not made to work with custom order statuses. Because I have tried to add pre-ordered in the code, but it gives a critical error.
Here is my code attempt:
add_action( 'woocommerce_order_status_changed', 'reset_order_paid_date', 20, 4 );
function reset_order_paid_date( $order_id, $old_status, $new_status, $order ){
if ( in_array( $old_status, array('on-hold', 'processing', 'completed', 'pending') ) && $new_status == 'pre-ordered') {
$order->set_date_paid(null);
$order->save();
}
}
Here are some screenshots:
2
Answers
Try the following for your
pre-ordered
custom status:It should work.
Addition
You can try to add the following too:
It could solve the issue.
You can use the standard woocomerce update_status command. Example:
You can add this code in your active theme’s functions.php file or in a custom plugin
To correct the text describing the payment in the order notes in this role in WooCommerce, you can include this procedure. Example:
Be sure to test this in a staging environment before implementing it on your production site.