woocommerce virtual order auto complete after payment
-
Hi I really am struggling with this “simple” feature. I sell courses and so after a payment the user should be able to enroll withouth any other requirement.
I set the product as a virtual, but the order status will not be complete after payment.
I try two different plugins, not working.
Also I try some different codes like thisadd_action( 'woocommerce_payment_complete_order_status', 'custom_woocommerce_auto_complete_order' ); function custom_woocommerce_auto_complete_order( $order_id ) { if ( ! $order_id ) { return; } $order = wc_get_order( $order_id ); $order->update_status( 'completed' ); }
or this one
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; } // For paid Orders with all others payment methods (paid order status "processing") elseif( $order->has_status('processing') ) { $order->update_status( 'completed' ); } }
with variations to get the order id global $order; $order_id = $order->get_order_number();
$order = new WC_Order($post->ID); //to escape # from order id $order_id = trim(str_replace('#', '', $order->get_order_number()));
but is never working.
Just installed 2 days ago and so everithing is at it very last version.
Any suggestion?
Viewing 8 replies - 1 through 8 (of 8 total)
Viewing 8 replies - 1 through 8 (of 8 total)
- The topic ‘woocommerce virtual order auto complete after payment’ is closed to new replies.