How to automatically complete orders in WooCommerce

If you’re running an online store with WooCommerce, you know how important it is to manage your orders efficiently. One way to streamline the order fulfillment process is by marking orders as completed automatically. In this tutorial, we’ll show you how to do just that using a dedicated plugin or a custom code snippet.

Why autocomplete WooCommerce orders

Autocompleting orders is a helpful way to prevent situations where orders remain pending for extended periods, leading to possible cancellations by the customer. Autocompleting orders is particularly useful for virtual products and downloadable products since they don’t usually require shipping or processing before delivery. It provides customers with instant access to their purchases, increasing their satisfaction and customer loyalty.

Autocompleting orders saves time and resources, eliminating the need for manual processing, and reducing customer service queries. This method also ensures that customers receive their purchases quickly, enhancing their overall experience while reducing operational costs and increasing efficiency.

woocommerce automatically complete orders

How to autocomplete WooCommerce orders?

In this tutorial, we will show you two ways to autocomplete WooCommerce orders, which is crucial for WooCommerce store owners to optimize their customer experience. Using a dedicated plugin or custom code snippets, both approaches can save you time and reduce errors in the order fulfillment process, leading to happier customers and increased operational efficiency.

Automatic Order Completion

Automatic order completion is the process of automatically marking an order as “completed” once it has been fulfilled. Eliminating the need for manual order completion can help save time and reduce errors.

Order Statuses

Before we dive into the specifics of how to mark orders as completed automatically, let’s review the main order statuses in WooCommerce:

  • Pending: This is the initial status of an order when a customer places an order on your site.
  • Processing: This status indicates that the order is being prepared for shipping or delivery.
  • Completed: This status indicates that the order has been fulfilled and shipped or delivered.

Understanding these statuses is important because automatic order completion will change the status of an order from “Processing” to “Completed” automatically.

Woocommerce Order Status Flow Chart

Woocommerce order status flow charts are essential tools for any store owner utilizing Woocommerce for their online sales. These charts provide a visual representation of the various stages an order can pass through from the moment it is placed until it is completed.

woocommerce order process diagram

 

With a Woocommerce order status flow chart, you can easily track each step of the process so that you are always aware of your customers’ orders.

WooCommerce orders by status report in Users Insights

The “Orders by Status” report shows you a breakdown of your WooCommerce orders in a stacked bar chart, with each order status in a different color. You can view the data at daily, weekly, monthly, or yearly intervals and scroll back to view historical data.

WooCommerce number of orders by status over time report

WooCommerce number of orders by status filtered report

The report also has interactive labels, so you can customize the chart by filtering the data. For example, clicking on a status label like “Completed” will hide those orders from the chart. This report helps you manage and visualize order trends by status.

You can also filter customers by their order status, for this, you can use the “Order Status” filter from the Users Insights filter list:

Autocomplete WooCommerce orders with a plugin

One of the easiest ways to implement automatic order completion in WooCommerce is to use a dedicated WordPress plugin. Several plugins are available that can help you accomplish this, but we recommend using Autocomplete WooCommerce Orders.

Autocomplete WooCommerce Orders

The “Auto Complete Orders for WooCommerce” plugin allows you to automatically complete your WooCommerce orders. It works with all major payment providers, including PayPal, SagePay, and Stripe. The plugin offers three options for completing orders: virtual products only, all paid orders of any product, and all orders regardless of payment status. However, enabling the plugin for all orders may allow customers to access products before payment.

Here’s how to use it:

  1. Install the plugin from the WordPress Plugin Repository. To do this, go to Plugins > Add New in your WordPress dashboard and search for “Autocomplete WooCommerce Orders.”
  2. Activate the plugin in WooCommerce. Once you’ve installed the plugin, you’ll need to activate it in WooCommerce by going to WooCommerce > Settings > Autocomplete Orders tab.
  3. Configure the plugin settings to automatically complete orders. You can customize the plugin settings to meet your specific needs. For example, you can choose which orders to apply the feature too, and you can customize the plugin settings to work with your payment gateway.

By default, the plugin will only automatically complete WooCommerce orders with for virtual and downloadable products when they have been paid for. This setting can be adjusted as follows:

  • None: No orders will be automatically completed.
  • All Orders: All paid orders, regardless of purchased products, will be automatically completed.
  • Virtual Orders: Orders that contain only Virtual products will be automatically completed.
  • Virtual & Downloadable Orders: Only paid orders for products that are both Virtual and Downloadable will be automatically completed (default behavior). This is the plugin’s default setting, which ensures that simply activating the plugin won’t impact order completions until you manually update this setting.

Unlock the Full Potential of Your WooCommerce Customer Data

Supported payment methods

It’s worth mentioning that Autocomplete WooCommerce Orders supports most payment methods, including PayPal and Stripe. However, you’ll need to configure your payment settings to ensure that orders are completed only when payment has been received.

Automatically complete orders with a code snippet

If you prefer to use a code snippet to complete WooCommerce orders automatically, here’s a sample PHP code snippet that you can use:

add_action( 'woocommerce_order_status_processing', 'custom_autocomplete_order' );
function custom_autocomplete_order( $order_id ) {
if ( ! $order_id ) {
return;
}
$order = wc_get_order( $order_id );
$order->update_status( 'completed' );
}

The code is a WordPress hook function that automatically marks WooCommerce orders as completed when the customer completes the payment on the Thank You page. Here’s how it works:

  • The add_action function tells WordPress to add an action hook to the woocommerce_thankyou event, which fires when a customer completes a payment and is redirected to the Thank You page.
  • The custom_woocommerce_auto_complete_order function is called when the woocommerce_thankyou event is triggered, and it accepts one parameter, $order_id. By default, this happens only on paid orders.
  • The if statement checks if $order_id is falsy, which would indicate an invalid order ID. If it’s invalid, the function returns without doing anything.
  • The $order = wc_get_order( $order_id ); line fetches the order data associated with the $order_id.
  • The $order->update_status( 'completed' ); line changes the order status to “completed” using the update_status function of the $order object.

Once you’ve added this code snippet, orders will be automatically marked as completed once they’ve been fulfilled. Note that this code snippet applies to all orders, so if you want to limit automatic completion to certain orders, you’ll need to modify the code accordingly.

Mark orders as Complete when they’re submitted in WooCommerce

If your business involves selling software or other downloadable/virtual products, having the order status as “processing” is not necessary. Typically, these products are delivered to the customer as soon as they complete the checkout process. In this case, it’s logical to mark the order as complete automatically.

To implement this, you can use the code snippet provided below, which will guide you through the process.

The following code is a WordPress hook function that automatically marks virtual orders as complete in WooCommerce. The code checks if an order is virtual or contains only virtual and downloadable products. If it’s a virtual order, the function changes the order status to “completed”. This helps simplify the order fulfillment process for virtual products and reduces the likelihood of human error.

add_action('woocommerce_thankyou', 'my_autocomplete_virtual_orders', 10, 1 );
function my_autocomplete_virtual_orders( $order_id ) {

    if( ! $order_id ) return;

    // Get the order
    $order = wc_get_order( $order_id );

    // get each product in the order
    $items = $order->get_items();

    // create and set variable
    $only_virtual = true;

    foreach ( $items as $item ) {

        // get product id
        $product = wc_get_product( $item['product_id'] );

        // is a virtual product
        $is_virtual = $product->is_virtual();

        // is a downloadable product
        $is_downloadable = $product->is_downloadable();

        if ( ! $is_virtual && ! $is_downloadable  ) {

            $only_virtual = false;
        }

    }

    if ( $only_virtual ) {

        $order->update_status( 'completed' );

    }
}

This code snippet adds an action hook to the “woocommerce_thankyou” event that triggers when a customer completes a payment and is redirected to the Thank You page. Then the function “wpd_autocomplete_virtual_orders” checks if an order contains only virtual or downloadable products. If so, it automatically changes the order status to “completed”.

Conclusion

In this tutorial, we’ve shown you two ways to implement automatic order completion in WooCommerce: using a plugin or a code snippet. By using one of these methods, you can save time and reduce errors in your order fulfillment process. We hope you found this tutorial helpful!