Have one small issue with my WooCommerce function , what was supposed to work in way i wanted, but seems that have bugs. I want to mark success paid orders as "Completed" instead of stuck on "Processing" after placed, and non success paid orders to mark as "Cancelled" orders instead stuck at "Payment Pending". This is my bugged function i have:
add_action( 'woocommerce_thankyou', 'wc_auto_complete_paid_order', 20, 1 );
function wc_auto_complete_paid_order( $order_id ) {
if ( ! $order_id )
return;
// Get an instance of the WC_Product object
$order = wc_get_order( $order_id );
// No updated status for orders delivered with Bank wire, Cash on delivery and Cheque payment methods.
if ( in_array( $order->get_payment_method(), array( 'bacs', 'cod', 'cheque', '' ) ) ) {
return;
// Updated status to "completed" for paid Orders with all others payment methods
} elseif ( $order->has_status('processing') ) {
$order->update_status( 'completed' );
}
}