Wordpress

Woocommerce – Autocomplete Status on all Orders

If you are using Woocommerce and is selling virtual and downloadable products on your website, you might have noticed that the products won’t be available upon order if you are using since initially they are being marked as Processing or Pending Payment after checkout.

The products sold would only be available when they are marked as “Completed”, so here’s a little snippet that does the job of automatically setting the ordered products to Completed. Just add this code on your theme’s functions.php file:

//Auto Complete all WooCommerce orders.
add_action( 'woocommerce_thankyou', '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' );
}